Liferay.Loader.define("@liferay/search-experiences-web@3.0.7/sxp_blueprint_admin/js/view_sxp_elements/AddSXPElementModal",["module","exports","require","@frontend-taglib-clay$clayui/button","@frontend-taglib-clay$clayui/icon","@frontend-taglib-clay$clayui/modal","@liferay/frontend-js-react-web","liferay!frontend-js-react-web$classnames","frontend-js-web","liferay!frontend-js-react-web$react","../utils/constants","../utils/data","../utils/toasts","../utils/utils"],(function(e,t,a){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var l=b(a("@frontend-taglib-clay$clayui/button")),n=b(a("@frontend-taglib-clay$clayui/icon")),r=p(a("@frontend-taglib-clay$clayui/modal")),i=a("@liferay/frontend-js-react-web"),s=b(a("liferay!frontend-js-react-web$classnames")),o=a("frontend-js-web"),c=p(a("liferay!frontend-js-react-web$react")),u=a("../utils/constants"),d=a("../utils/data"),f=a("../utils/toasts"),m=a("../utils/utils");function y(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return y=function(){return e},e}function p(e){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=y();if(t&&t.has(e))return t.get(e);var a={},l=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var n in e)if(Object.prototype.hasOwnProperty.call(e,n)){var r=l?Object.getOwnPropertyDescriptor(e,n):null;r&&(r.get||r.set)?Object.defineProperty(a,n,r):a[n]=e[n]}return a.default=e,t&&t.set(e,a),a}function b(e){return e&&e.__esModule?e:{default:e}}const e="addSXPElement";var g=({defaultLocale:t,editSXPElementURL:a,portletNamespace:y})=>{const p=(0,i.useIsMounted)(),[b,g]=(0,c.useState)(""),[E,v]=(0,c.useState)(),[w,L]=(0,c.useState)(!1),[h,j]=(0,c.useState)(""),[S,_]=(0,c.useState)(!1),{observer:N,onClose:O}=(0,r.useModal)({onClose:()=>_(!1)});(0,c.useEffect)((()=>(Liferay.on(e,(()=>_(!0))),()=>{Liferay.detach(e)})),[]);const P=e=>{v(e.error||u.DEFAULT_ERROR),L(!1)};return c.default.createElement(r.ClayModalProvider,null,S&&c.default.createElement(r.default,{observer:N,size:"md"},c.default.createElement(r.default.Header,null,Liferay.Language.get("new-search-element")),c.default.createElement("form",{id:"".concat(y,"form"),onSubmit:e=>{e.preventDefault(),(0,o.fetch)("/o/search-experiences-rest/v1.0/sxp-elements",{body:JSON.stringify({description_i18n:{[t]:b},elementDefinition:d.CUSTOM_JSON_SXP_ELEMENT.elementDefinition,title_i18n:{[t]:h}}),headers:new Headers({"Content-Type":"application/json"}),method:"POST"}).then((e=>(e.ok||P(),e.json()))).then((e=>{if(p())if(e.error)P(e);else if(_(!1),(0,m.isDefined)(e.id)){const t=new URL(a);t.searchParams.set("".concat(y,"sxpElementId"),e.id),(0,f.setInitialSuccessToast)(Liferay.Language.get("the-element-was-created-successfully")),(0,o.navigate)(t)}else(0,f.setInitialSuccessToast)(Liferay.Language.get("the-element-was-created-successfully")),(0,o.navigate)(window.location.href)})).catch((e=>{P(e)})),L(!0)}},c.default.createElement(r.default.Body,null,c.default.createElement("div",{className:(0,s.default)("form-group",{"has-error":E})},c.default.createElement("label",{className:"control-label",htmlFor:"".concat(y,"title")},Liferay.Language.get("title"),c.default.createElement("span",{className:"reference-mark"},c.default.createElement(n.default,{symbol:"asterisk"}))),c.default.createElement("input",{autoFocus:!0,className:"form-control",disabled:w,id:"".concat(y,"title"),name:"".concat(y,"title"),onChange:e=>j(e.target.value),required:!0,type:"text",value:h}),E&&c.default.createElement("div",{className:"form-feedback-item"},c.default.createElement(n.default,{className:"inline-item inline-item-before",symbol:"exclamation-full"}),E)),c.default.createElement("div",{className:"form-group"},c.default.createElement("label",{className:"control-label",htmlFor:"".concat(y,"description")},Liferay.Language.get("description")),c.default.createElement("textarea",{className:"form-control",disabled:w,id:"".concat(y,"description"),name:"".concat(y,"description"),onChange:e=>g(e.target.value),value:b}))),c.default.createElement(r.default.Footer,{last:c.default.createElement(l.default.Group,{spaced:!0},c.default.createElement(l.default,{disabled:w,displayType:"secondary",onClick:O},Liferay.Language.get("cancel")),c.default.createElement(l.default,{disabled:w,displayType:"primary",type:"submit"},w&&c.default.createElement("span",{className:"inline-item inline-item-before"},c.default.createElement("span",{"aria-hidden":"true",className:"loading-animation"})),Liferay.Language.get("create")))}))))};t.default=g}}));
//# sourceMappingURL=AddSXPElementModal.js.map