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