text: !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.formla=e():t.formla=e()}(self,(function(){return(()=>{"use strict";var t={105:(t,e)=>{e.__esModule=!0,e.ReactNativeFile=void 0;e.ReactNativeFile=function(t){var e=t.uri,r=t.name,n=t.type;this.uri=e,this.name=r,this.type=n}},811:(t,e,r)=>{e.__esModule=!0,e.extractFiles=function t(e,r){void 0===r&&(r="");var i,s=new Map;function o(t,e){var r=s.get(e);r?r.push.apply(r,t):s.set(e,t)}if("undefined"!=typeof File&&e instanceof File||"undefined"!=typeof Blob&&e instanceof Blob||e instanceof n.ReactNativeFile)i=null,o([r],e);else{var a=r?r+".":"";if("undefined"!=typeof FileList&&e instanceof FileList)i=Array.prototype.map.call(e,(function(t,e){return o([""+a+e],t),null}));else if(Array.isArray(e))i=e.map((function(e,r){var n=t(e,""+a+r);return n.files.forEach(o),n.clone}));else if(e&&e.constructor===Object)for(var l in i={},e){var u=t(e[l],""+a+l);u.files.forEach(o),i[l]=u.clone}else i=e}return{clone:i,files:s}};var n=r(105)},475:(t,e,r)=>{e.Al=void 0;var n=r(811);e.Al=n.extractFiles,r(105).ReactNativeFile}},e={};function r(n){var i=e[n];if(void 0!==i)return i.exports;var s=e[n]={exports:{}};return t[n](s,s.exports,r),s.exports}r.d=(t,e)=>{for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var n={};return(()=>{r.r(n),r.d(n,{default:()=>E});var t=r(475);const e=Object.prototype.hasOwnProperty;function i(t,r){return e.call(t,r)}function s(t){return!!t&&t instanceof Blob}function o(t){if(l(t))return t.map(o);if(null==t)return null;if(s(t)||["number","string","boolean"].includes(typeof t))return t;if(a(t)){let e={};return Object.keys(t).forEach((r=>e[r]=o(t[r]))),e}}function a(t){return null!==t&&"object"==typeof t}function l(t){return t instanceof Array}function u(t){return null==t}function h(t){return"string"==typeof t}function f(t){if(l(t))for(let e=0;e<t.length;e++){if(t[e]instanceof File)return!0;if(a(t[e]))return f(t[e])}else for(let e in t){if(t[e]instanceof File)return!0;if(a(t[e]))return f(t[e])}return!1}function c(t){let e={};return t.forEach(((t,r)=>{e[r]=t})),e}function d(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}const p=class{constructor(){d(this,"errors",void 0),d(this,"elements",void 0),this.errors={},this.elements=[]}has(t){return t instanceof RegExp?Object.keys(this.errors).some((e=>t.test(e))):this.errors.hasOwnProperty(t)}any(){return Object.keys(this.errors).length>0}getFirst(t){let e=this.get(t);if(e)return l(e)?e.length?e[0]:null:e||null}get(t){return this.errors[t]}add(t,e){let r=arguments.length>2&&void 0!==arguments[2]&&arguments[2];this.has(t)&&!r||(this.errors[t]=e)}record(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:3e3;this.errors=t,e&&window.setTimeout((()=>{this.clear()}),e)}clear(t){t?delete this.errors[t]:this.errors={}}addElement(t,e){l(t)?t.forEach((t=>this.addElement(t,e))):this.elements.push({key:t,el:e})}removeElement(t){this.elements=this.elements.filter((e=>{let{el:r}=e;return r!==t}))}removeElementKey(t){l(t)?t.forEach((t=>this.removeElementKey(t))):this.elements=this.elements.filter((e=>{let{key:r}=e;return r!==t}))}hasElements(){return!!this.elements.length}scrollToFirst(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;t=u(t)?{behavior:"smooth",inline:"center"}:t;const e=this.elements.find((t=>{let e,{key:r,el:n}=t;if(r instanceof RegExp)e=r;else{let t=r.replace(/[\\^$.*+?()[\]{}|]/g,"\\$&");e=new RegExp(t.replace("*",".*"))}if(Object.keys(this.errors).some((t=>e.test(t))))return!0}));e&&!function(t){const e=t.getBoundingClientRect();return e.top>=0&&e.bottom<=(window.innerHeight||window.document.documentElement.clientHeight)}(e.el)&&e.el.scrollIntoView(t)}};function m(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function b(t,e,r){(h(e)||"number"==typeof e)&&(e=(""+e).split("."));let n=e.shift();a(t)&&!s(t)&&(e.length?(i(t,n)||(l(t)?t[+n]="0"===n?[]:{}:t[n]="0"===n?[]:{}),l(t)?b(t[+n],e,r):b(t[n],e,r)):l(t)?t[+n]=r:t[n]=r)}function y(t,e){h(e)&&(e=e.split("."));let r,n=e.shift();if(a(t)&&!s(t)&&i(t,n))return r=l(t)?t[+n]:a(t)&&!s(t)?t[n]:void 0,e.length?void y(r,e):r}function g(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",r={};return l(t)?t.forEach((t=>{let n=`${e}[]`;!a(t)||s(t)?r[n]=s(t)?t:v(t):r={...r,...g(t,n)}})):Object.keys(t).forEach((n=>{let i=t[n],o=e?`${e}[${n}]`:""+n;!a(i)||s(i)?r[o]=s(i)?i:v(i):r={...r,...g(i,o)}})),r}function v(t){return"boolean"==typeof t?""+ +t:"number"==typeof t?t.toString():t||""}class _{constructor(t,e){m(this,"_errors",void 0),m(this,"_data",void 0),m(this,"_dataCb",void 0),m(this,"_originalData",void 0),m(this,"_originalConstantData",void 0),m(this,"_options",void 0),this.setOptions(e),t instanceof Function&&(this._dataCb=t,t=t()),this._originalData={},this._originalConstantData={},this._data={},this.append(t,void 0,!1,!1),this._errors=new p}setOptions(t){this._options=this._options||_.defaultOptions,t&&(this._options={...this._options,...t})}append(t,e){let r=arguments.length>2&&void 0!==arguments[2]&&arguments[2],n=!(arguments.length>3&&void 0!==arguments[3])||arguments[3];if(this._dataCb&&!r&&this._options.addAppendToDataCallback&&n){const r=this._dataCb;this._dataCb=()=>{const n=r();return a(t)?{...n,...t}:{...n,[t]:e}}}return a(t)?(Object.keys(t).forEach((e=>{this.append(e,t[e],r,!1)})),this):(e=this.parseData(e),r?b(this._originalConstantData,t,e):b(this._originalData,t,this.parseData(e)),r?Object.defineProperty(this,t,{get:()=>{},set:()=>{throw new Error(`The "${t}" value has been set as constant and cannot be modified`)}}):(b(this._data,t,e),this.defineProperty(t)),this)}defineProperty(t){Object.defineProperty(this,t,{configurable:!0,enumerable:!0,get:()=>y(this._data,t),set:e=>{this.setData(t,e)}})}constantData(t,e){return this.append(t,e,!0,!1)}getData(){return{...this._data,...this._originalConstantData}}setData(t,e){b(this._data,t,e),this._options.autoRemoveError&&this._errors.clear(t)}errors(){return this._errors}reset(){const t=this._dataCb?this._dataCb():this._originalData;for(let t in this._data)delete this[t];return this._originalData={},this._data={},this.append(t,void 0,!1,!1),this._errors.clear(),this}clear(t){var e;return i(this,t)&&b(this._data,t,(e=y(this._data,t))instanceof Array?[]:"object"==typeof e?{}:"string"==typeof e?"":null),this}parseData(t){return this._options.clone?o(t):t}addFileFromEvent(t,e){let r=t.target;if(!(r instanceof HTMLInputElement))throw new Error("Incompatible event target, must be of type HTMLInputElement");return e||(e=r.name),e in this&&""!==r.value&&(t instanceof DragEvent?this.setData(e,t.dataTransfer&&t.dataTransfer.files.length&&t.dataTransfer.files[0]):this.setData(e,r.files&&r.files.length&&r.files[0]),r.value=""),this}post(t,e){return this.submit("post",t,e)}put(t,e){return this.submit("put",t,e)}patch(t,e){return this.submit("patch",t,e)}delete(t,e){return this.submit("delete",t,e)}get(t,e){return this.submit("get",t,e)}graphql(e,r){const n=(r=r||{}).formatData||this._options.formatData;return r.url=r.graphql||this._options.graphql,r.useJson=!this.hasFile(),r.formatData=r=>{r=n?n(r):r;const i={query:e,variables:r};if(!this.hasFile())return i;const{clone:s,files:o}=(0,t.Al)(r);return i.variables=s,{operations:JSON.stringify(i),map:JSON.stringify(c(Array.from(o.values()))),...c(Array.from(o.keys()))}},this.post(r)}submit(t,e,r){r=function(t,e,r){return t=t?a(t)?t:{method:t}:{},e=e?a(e)?e:{url:e}:{},r=r||{},{...r,...e,...t}}(t,e,r);const n={...this._options,...r};let i,s=n.formatData(this.getData());if(this.shouldConvertToFormData(n)){i=new FormData;let t=g(s);Object.keys(t).forEach((e=>{i.append(e,t[e])})),s=i}return(0,n.sendWith)(n.method,this.buildBaseUrl(n),s,n).then((t=>(n.isValidationError(t)?this.onFail(t,n):this.onSuccess(n),t))).catch((t=>(n.isValidationError(t)&&this.onFail(t,n),function(t){if(t instanceof Error)throw t;return Promise.reject(t)}(t))))}shouldConvertToFormData(t){return(t=t||this._options).strictMode?!t.useJson:!t.useJson||this.hasFile()}hasFile(){return f(this.getData())}onSuccess(t){(t=t||this._options).clear&&this.reset()}onFail(t,e){if(!(e=e||this._options).quiet){let r=e.formatErrorResponse(t);this._errors.record(r,e.timeout),this._errors.hasElements()&&this._errors.scrollToFirst()}}buildBaseUrl(t){if((t=t||this._options).url.includes("://"))return t.url;let e=t.baseUrl,r=t.url;return e=e.replace(/\/+$/g,""),r=r.replace(/^\/+/g,""),`${e}/${r}`}makeUrl(t){let e=this.buildBaseUrl(t),r=e.includes("?")?"&":"?",n=e+r,i=[],o=g(this.getData());return Object.keys(o).forEach((t=>{let e=o[t];if(s(e))throw new Error("Cannot convert file to a string");i.push(t+(u(e)?"":`=${e}`))})),n+i.join("&")}addElement(t,e){this._errors.addElement(t,e)}removeElement(t){this._errors.removeElement(t)}removeElementKey(t){this._errors.removeElementKey(t)}}m(_,"defaultOptions",{method:"post",baseUrl:"",url:"",graphql:"graphql",sendWith:function(t,e,r,n){let i=new XMLHttpRequest,s=new Promise(((t,e)=>{i.onload=()=>{i.status>=200&&i.status<300?t(i):e(i)},i.onerror=()=>e(i)}));return i.open(t,e),r instanceof FormData?(i.setRequestHeader("Content-Type","multipart/form-data"),i.send(r)):(i.setRequestHeader("Content-Type","application/json"),i.send(JSON.stringify(r))),s},useJson:!1,strictMode:!1,isValidationError:t=>{let{status:e}=t;return 422===e},formatData:t=>t,formatErrorResponse:t=>{let e=t.data||t.response;if("string"==typeof e)try{e=JSON.parse(e)}catch(t){throw new Error("Unable to find errors in the response")}let r=e.errors;if(function(t){return!t||"object"!=typeof t||!Object.keys(t).length||Object.values(t).some((t=>l(t)?t.some((t=>!h(t))):!h(t)))}(r))throw new Error("Unable to find errors in the response");return r},timeout:!1,autoRemoveError:!0,clear:!0,quiet:!1,clone:!0,addAppendToDataCallback:!0}),m(_,"setOptions",(function(t){_.defaultOptions={..._.defaultOptions,...t}}));const E=_})(),n})()}));
  //# sourceMappingURL=Form.min.map