Liferay.Loader.define("@liferay/search-experiences-web@3.0.30/sxp_blueprint_admin/js/view_sxp_blueprints/ImportSXPBlueprintModal",["module","exports","require","@frontend-taglib-clay$clayui/alert","@frontend-taglib-clay$clayui/button","@frontend-taglib-clay$clayui/form","@frontend-taglib-clay$clayui/icon","@frontend-taglib-clay$clayui/modal","frontend-js-web","liferay!frontend-js-react-web$react","../utils/fetch/fetch_data"],(function(e,t,a){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var r=_interopRequireDefault(a("@frontend-taglib-clay$clayui/alert")),n=_interopRequireDefault(a("@frontend-taglib-clay$clayui/button")),l=a("@frontend-taglib-clay$clayui/form"),i=_interopRequireDefault(a("@frontend-taglib-clay$clayui/icon")),o=_interopRequireWildcard(a("@frontend-taglib-clay$clayui/modal")),u=a("frontend-js-web"),c=_interopRequireWildcard(a("liferay!frontend-js-react-web$react")),f=a("../utils/fetch/fetch_data");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={},r=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var n in e)if(Object.prototype.hasOwnProperty.call(e,n)){var l=r?Object.getOwnPropertyDescriptor(e,n):null;l&&(l.get||l.set)?Object.defineProperty(a,n,l):a[n]=e[n]}return a.default=e,t&&t.set(e,a),a}function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}const e=".json";var _default=({portletNamespace:t,redirectURL:a})=>{const[d,s]=(0,c.useState)(),[p,y]=(0,c.useState)(!1),[m,g]=(0,c.useState)(),[b,h]=(0,c.useState)(!1),L="".concat(t,"importModal"),{observer:_,onClose:E}=(0,o.useModal)({onClose:()=>{h(!1)}}),_handleClose=e=>{s(""),g(null),E(!1),e&&(0,u.navigate)(e)},_handleFormError=e=>{s(e||Liferay.Language.get("an-unexpected-error-occurred-while-importing-your-file")),y(!1)};return(0,c.useEffect)((()=>(Liferay.component(L,{open:()=>{h(!0)}},{destroyOnNavigate:!0}),()=>Liferay.destroyComponent(L))),[L,h]),b?c.default.createElement(o.default,{className:"import-sxp-blueprint-form",observer:_,size:"full-screen"},c.default.createElement(o.default.Header,null,Liferay.Language.get("import")),c.default.createElement(o.default.Body,null,d&&c.default.createElement(r.default,{displayType:"danger",onClose:()=>s(""),title:Liferay.Language.get("error")},d),c.default.createElement("p",{className:"text-secondary"},Liferay.Language.get("select-a-blueprint-or-element-json-file-to-import")),c.default.createElement("div",{className:"form-group"},c.default.createElement("label",{className:"control-label",htmlFor:"file"},Liferay.Language.get("select-file"),c.default.createElement("span",{className:"reference-mark"},c.default.createElement(i.default,{symbol:"asterisk"}))),c.default.createElement(l.ClayInput,{accept:e,name:"file",onChange:e=>{g(e.target.files[0])},required:!0,type:"file"}))),c.default.createElement(o.default.Footer,{last:c.default.createElement(n.default.Group,{spaced:!0},c.default.createElement(n.default,{disabled:p,displayType:"secondary",onClick:_handleClose},Liferay.Language.get("cancel")),c.default.createElement(n.default,{disabled:!m||p,displayType:"primary",onClick:async()=>{y(!0);const e=await new Response(m).text();try{const t=!!JSON.parse(e).elementDefinition,r=t?"/o/search-experiences-rest/v1.0/sxp-elements":"/o/search-experiences-rest/v1.0/sxp-blueprints";(0,u.fetch)(r,{body:e,headers:f.DEFAULT_HEADERS,method:"POST"}).then((e=>e.json().then((t=>({ok:e.ok,responseContent:t}))))).then((({ok:e,responseContent:r})=>{e||_handleFormError(t?Liferay.Language.get("unable-to-import-because-the-element-configuration-is-invalid"):Liferay.Language.get("unable-to-import-because-the-blueprint-configuration-is-invalid")),y(!1),e&&_handleClose(a)})).catch((()=>{_handleFormError()}))}catch(e){_handleFormError()}}},p&&c.default.createElement("span",{className:"inline-item inline-item-before"},c.default.createElement("span",{"aria-hidden":"true",className:"loading-animation"})),Liferay.Language.get("import")))})):null};t.default=_default}}));
//# sourceMappingURL=ImportSXPBlueprintModal.js.map