Liferay.Loader.define("@liferay/search-experiences-web@3.0.7/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","@liferay/frontend-js-react-web","frontend-js-web","liferay!frontend-js-react-web$react"],(function(e,t,a){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var n=d(a("@frontend-taglib-clay$clayui/alert")),r=d(a("@frontend-taglib-clay$clayui/button")),l=a("@frontend-taglib-clay$clayui/form"),i=d(a("@frontend-taglib-clay$clayui/icon")),o=d(a("@frontend-taglib-clay$clayui/modal")),c=a("@liferay/frontend-js-react-web"),u=a("frontend-js-web"),f=function(e){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=s();if(t&&t.has(e))return t.get(e);var a={},n=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var r in e)if(Object.prototype.hasOwnProperty.call(e,r)){var l=n?Object.getOwnPropertyDescriptor(e,r):null;l&&(l.get||l.set)?Object.defineProperty(a,r,l):a[r]=e[r]}a.default=e,t&&t.set(e,a);return a}(a("liferay!frontend-js-react-web$react"));function s(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return s=function(){return e},e}function d(e){return e&&e.__esModule?e:{default:e}}const e=".json";var p=({redirectURL:t})=>{const a=(0,c.useIsMounted)(),[s,d]=(0,f.useState)(),[p,y]=(0,f.useState)(!1),[m,g]=(0,f.useState)(),b=e=>{Liferay.Util.getOpener().Liferay.fire("closeModal",e)},L=e=>{d(e||Liferay.Language.get("an-unexpected-error-occurred-while-importing-your-file")),y(!1)};return f.default.createElement("div",{className:"import-sxp-blueprint-form"},f.default.createElement(o.default.Body,null,s&&f.default.createElement(n.default,{displayType:"danger",onClose:()=>d(""),title:Liferay.Language.get("error")},s),f.default.createElement("p",{className:"text-secondary"},Liferay.Language.get("select-a-blueprint-or-element-json-file-to-import")),f.default.createElement("div",{className:"form-group"},f.default.createElement("label",{className:"control-label",htmlFor:"file"},Liferay.Language.get("select-file"),f.default.createElement("span",{className:"reference-mark"},f.default.createElement(i.default,{symbol:"asterisk"}))),f.default.createElement(l.ClayInput,{accept:e,name:"file",onChange:e=>{g(e.target.files[0])},required:!0,type:"file"}))),f.default.createElement(o.default.Footer,{last:f.default.createElement(r.default.Group,{spaced:!0},f.default.createElement(r.default,{disabled:p,displayType:"secondary",onClick:b},Liferay.Language.get("cancel")),f.default.createElement(r.default,{disabled:!m||p,displayType:"primary",onClick:async()=>{y(!0);const e=await new Response(m).text();try{const n=!!JSON.parse(e).elementDefinition,r=n?"/o/search-experiences-rest/v1.0/sxp-elements":"/o/search-experiences-rest/v1.0/sxp-blueprints";(0,u.fetch)(r,{body:e,headers:new Headers({"Content-Type":"application/json"}),method:"POST"}).then((e=>e.json().then((t=>({ok:e.ok,responseContent:t}))))).then((({ok:e,responseContent:r})=>{e||L(n?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&&a()&&b({redirect:t})})).catch((()=>{L()}))}catch(e){L()}}},p&&f.default.createElement("span",{className:"inline-item inline-item-before"},f.default.createElement("span",{"aria-hidden":"true",className:"loading-animation"})),Liferay.Language.get("import")))}))};t.default=p}}));
//# sourceMappingURL=ImportSXPBlueprintModal.js.map