"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t,n=require("react");!function(e){e.SUCCESS="success",e.CANCEL="cancel"}(e||(e={})),function(e){e.TEST="test",e.STAGING="staging",e.PRODUCTION="production"}(t||(t={}));var a={__proto__:null,get RESPONSE_STATUSES(){return e},get ENVIRONMENT(){return t}},o=function(a){var o=a.aggregator_id,r=a.bank_account_number,c=a.bank_code,d=a.borrower_phone,u=a.bvn_number,s=a.aggregator_loan_ref,i=void 0===s?""+Date.now().toString():s,l=a.onSuccess,_=a.onCancel,v=a.showWidget,m=a.autoStart,p=void 0!==m&&m,g=a.environment,b=void 0===g?t.TEST:g,f={aggregator_id:o,bank_account_number:r,bank_code:c,borrower_phone:d,bvn_number:u,aggregator_loan_ref:i,cac_number:a.cac_number,city:a.city,company_name:a.company_name,customer_type:a.customer_type,email:a.email,first_name:a.first_name,gender:a.gender,last_name:a.last_name,photo_url:a.photo_url,public_key:a.public_key,residence_address:a.residence_address,state:a.state,product_id:a.product_id,product_code:a.product_code,tenure:a.tenure,customStyles:a.customStyles},S=function(){switch(b){case t.TEST:return"https://advancly-borrower.test.vggdev.com/create-loan-account/";case t.STAGING:return"https://advancly-borrower.staging.vggdev.com/create-loan-account/";case t.PRODUCTION:return"https://borrower.advancly.com/create-loan-account/";default:return"https://advancly-borrower.test.vggdev.com/create-loan-account/"}},y=n.useCallback((function(){!function(){var e=document.createElement("style");e.innerHTML=" \n        body {\n        margin: 0;\n      }\n      .advancly {\n        border: none;\n        height: 100vh;\n        width: 100vw;\n        position: fixed;\n        left: 0;\n        top: 0;\n        overflow: hidden;\n      }";var t=document.createElement("div");t.setAttribute("class","advancly-widget");var n=document.createElement("iframe");n.setAttribute("class","advancly"),n.src=S(),window.addEventListener("message",(function(e){h(null==e?void 0:e.data),t.remove()})),t.appendChild(n),document.head.appendChild(e),document.body.appendChild(t),n.onload=function(){var e;return null==(e=n.contentWindow)?void 0:e.postMessage(f,S())}}()}),[]),h=function(t){switch(t.status){case e.SUCCESS:l&&l({status:e.SUCCESS,data:null==t?void 0:t.data});break;case e.CANCEL:_&&_({status:e.CANCEL,data:null==t?void 0:t.data})}};return n.useEffect((function(){p&&setTimeout((function(){y()}),500)}),[y,p]),n.useEffect((function(){v&&y()}),[y,v]),null};exports.AdvanclyWidget=o,exports.advanclyProps=a,exports.default=o;
//# sourceMappingURL=advancly-widget-react.cjs.production.min.js.map
