(function(n,m){typeof exports=="object"&&typeof module<"u"?m(exports):typeof define=="function"&&define.amd?define(["exports"],m):(n=typeof globalThis<"u"?globalThis:n||self,m(n.FMGofer={}))})(this,function(n){"use strict";const x="The FM script call timed out",c="fmGoferCallbackD7738642C91848E08720EAC24EDDA483";function v(){return"xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx".replace(/[xy]/g,t=>{var r=Math.random()*16|0,e=t=="x"?r:r&3|8;return e.toString(16)})}function h(){return typeof window.fmGofer=="object"&&window.fmGofer!==null&&!Array.isArray(window.fmGofer)}function D(){h()||(window.fmGofer={promises:{},callbackName:c},window[c]=M)}function G(o,t,r,e){const i=v(),f={resolve:o,reject:t};return r!==0&&(f.timeoutID=setTimeout(()=>{f.fmOnReadyIntervalID&&clearInterval(f.fmOnReadyIntervalID),d(i),t(e)},r)),window.fmGofer.promises[i]=f,i}function O(o){return window.fmGofer.promises[o]}function d(o){var r,e;const t=(e=(r=window.fmGofer)==null?void 0:r.promises)==null?void 0:e[o];return t&&(t.timeoutID&&clearTimeout(t.timeoutID),t.fmOnReadyIntervalID&&clearInterval(t.fmOnReadyIntervalID)),delete window.fmGofer.promises[o]}function M(o,t,r){try{r==="0"&&(r="");const e=O(o);if(typeof e>"u")throw new Error(`No promise found for promiseID ${o}.`);e.timeoutID&&clearTimeout(e.timeoutID),r?e.reject(t):e.resolve(t),d(o)}catch(e){console.error(e)}}function P(o,t,r){let e;return{promise:new Promise((f,a)=>{if(typeof window.FileMaker=="object"){window.FileMaker.PerformScriptWithOption(o,t,r);return}const s=5,u=2e3;let l=0;e=setInterval(()=>{l+=s,l>u&&(clearInterval(e),a(`window.FileMaker not found within ${u} ms`)),typeof window.FileMaker=="object"&&(clearInterval(e),window.FileMaker.PerformScriptWithOption(o,t,r),f())},s)}),intervalID:e}}class y extends Promise{json(){return this.then(t=>JSON.parse(t))}}function p(o,t,r,e=0,i=x){if(typeof o!="string"||!o)throw new Error("script must be a string");if(typeof e!="number")throw new Error("timeout must be a number");if(typeof i!="string")throw new Error("timeoutMessage must be a string");return new y(async(f,a)=>{D();const s=G(f,a,e,i),u={promiseID:s,callbackName:c,parameter:t},l=JSON.stringify(u);try{const{promise:w,intervalID:g}=P(o,l,r);window.fmGofer.promises[s].fmOnReadyIntervalID=g,await w}catch(w){d(s),a(w)}})}function I(o,t=void 0,r=0,e=x){return p(o,t,void 0,r,e)}const b={Default:0,Continue:0,Halt:1,Exit:2,Resume:3,Pause:4,SuspendAndResume:5},S={PerformScript:I,PerformScriptWithOption:p};n.FMGPromise=y,n.Option=b,n.PerformScript=I,n.PerformScriptWithOption=p,n.default=S,Object.defineProperties(n,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});