Liferay.Loader.define("commerce-frontend-js@4.0.75/components/modal/Modal",["module","exports","require","@frontend-taglib-clay$clayui/loading-indicator","@frontend-taglib-clay$clayui/modal","liferay!frontend-js-react-web$prop-types","liferay!frontend-js-react-web$react","../../utilities/eventsDefinitions","../../utilities/index","../../utilities/modals/constants","../../utilities/modals/index"],(function(e,t,a){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var n=_interopRequireDefault(a("@frontend-taglib-clay$clayui/loading-indicator")),i=_interopRequireWildcard(a("@frontend-taglib-clay$clayui/modal")),r=(_interopRequireDefault(a("liferay!frontend-js-react-web$prop-types")),_interopRequireWildcard(a("liferay!frontend-js-react-web$react"))),l=a("../../utilities/eventsDefinitions"),o=a("../../utilities/index"),d=a("../../utilities/modals/constants"),u=a("../../utilities/modals/index");function _getRequireWildcardCache(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return _getRequireWildcardCache=function _getRequireWildcardCache(){return e},e}function _interopRequireWildcard(e){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=_getRequireWildcardCache();if(t&&t.has(e))return t.get(e);var a={},n=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var i in e)if(Object.prototype.hasOwnProperty.call(e,i)){var r=n?Object.getOwnPropertyDescriptor(e,i):null;r&&(r.get||r.set)?Object.defineProperty(a,i,r):a[i]=e[i]}return a.default=e,t&&t.set(e,a),a}function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}const isPageInIframe=()=>window.location!==window.parent.location;var s=function Modal(e){const[t,a]=(0,r.useState)(!1),[s,c]=(0,r.useState)(!1),[f,y]=(0,r.useState)(null),[p,L]=(0,r.useState)(e.title),[m,_]=(0,r.useState)(e.url),[O,g]=(0,r.useState)(d.INITIAL_MODAL_SIZE),{observer:h,onClose:v}=(0,i.useModal)({onClose:e=>{f&&f(e),c(!1),a(!1)}});return(0,r.useEffect)((()=>{function handleOpenEvent(n){e.id!==n.id||t||isPageInIframe()||(c(!0),a(!0),n.url&&_(n.url),n.onClose&&y((()=>n.onClose)),n.title&&L(n.title),n.size||g(d.INITIAL_MODAL_SIZE))}function handleCloseModal({redirectURL:e="",successNotification:a={}}){t&&(e?(0,o.liferayNavigate)(e):v(a))}function handleSetLoading(e){const{isLoading:t}=e;c(t||!1)}function cleanUpListeners(){Liferay.detach(l.OPEN_MODAL,handleOpenEvent),Liferay.detach(l.CLOSE_MODAL,handleCloseModal),Liferay.detach(l.IS_LOADING_MODAL,handleSetLoading),Liferay.detach("destroyPortlet",cleanUpListeners)}return Liferay.on&&(Liferay.on(l.OPEN_MODAL,handleOpenEvent),Liferay.on(l.CLOSE_MODAL,handleCloseModal),Liferay.on(l.IS_LOADING_MODAL,handleSetLoading),Liferay.on("destroyPortlet",cleanUpListeners)),()=>cleanUpListeners()}),[v,e.id,t]),(0,r.useEffect)((()=>{y((()=>e.onClose))}),[e.onClose]),r.default.createElement(r.default.Fragment,null,t&&r.default.createElement(i.default,{className:"commerce-modal",observer:h,size:O,status:e.status},p&&r.default.createElement(i.default.Header,null,p),r.default.createElement("div",{className:"modal-body modal-body-iframe",style:{height:(0,u.resolveModalHeight)(O),maxHeight:"100%"}},r.default.createElement("iframe",{src:m,title:p}),s&&r.default.createElement("div",{className:"loader-container"},r.default.createElement(n.default,null)))))};t.default=s}}));
//# sourceMappingURL=Modal.js.map