Liferay.Loader.define("@liferay/object-web@1.0.108/js/components/ModalAddObjectValidation",["module","exports","require","@frontend-taglib-clay$clayui/alert","@frontend-taglib-clay$clayui/button","@frontend-taglib-clay$clayui/form","@frontend-taglib-clay$clayui/modal","@liferay/object-js-components-web","liferay!frontend-js-react-web$react"],(function(e,t,a){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=function({apiURL:e,objectValidationRuleEngines:t}){const[a,r]=(0,i.useState)(!1),{observer:n,onClose:l}=(0,o.useModal)({onClose:()=>r(!1)});return(0,i.useEffect)((()=>(Liferay.on("addObjectValidation",(()=>r(!0))),()=>Liferay.detach("addObjectValidation"))),[]),i.default.createElement(o.ClayModalProvider,null,a&&i.default.createElement(y,{apiURL:e,objectValidationRuleEngines:t,observer:n,onClose:l}))};var r=d(a("@frontend-taglib-clay$clayui/alert")),n=d(a("@frontend-taglib-clay$clayui/button")),l=d(a("@frontend-taglib-clay$clayui/form")),o=f(a("@frontend-taglib-clay$clayui/modal")),u=a("@liferay/object-js-components-web"),i=f(a("liferay!frontend-js-react-web$react"));function c(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return c=function(){return e},e}function f(e){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=c();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 d(e){return e&&e.__esModule?e:{default:e}}function b(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,r)}return a}function s(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}const e=Liferay.ThemeDisplay.getDefaultLanguageId(),p=Liferay.Language.get("required");function y({apiURL:t,objectValidationRuleEngines:a,observer:c,onClose:f}){const[d,y]=(0,i.useState)({label:"",name:""}),[g,m]=(0,i.useState)({[e]:""}),[j,O]=(0,i.useState)(""),[E,v]=(0,i.useState)({labelError:"",typeError:""}),[w,L]=(0,i.useState)(!1);(0,i.useEffect)((()=>{v((t=>{const a=function(e){for(var t=1;t<arguments.length;t++){var a=null!=arguments[t]?arguments[t]:{};t%2?b(Object(a),!0).forEach((function(t){s(e,t,a[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(a)):b(Object(a)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(a,t))}))}return e}({},t);return a.labelError=""===g[e]?p:"",a.typeError=""===d.label?p:"",a}))}),[g,d]);return i.default.createElement(o.default,{observer:c},i.default.createElement(l.default,{onSubmit:async a=>{if(a.preventDefault(),Object.values(E).some((e=>""!==e)))L(!0);else{L(!1);try{await u.API.save(t,{active:!1,engine:d.name,name:{[e]:g[e]},script:"script_placeholder"},"POST"),f(),window.location.reload()}catch(e){O(e.message)}}}},i.default.createElement(o.default.Header,null,Liferay.Language.get("new-validation")),i.default.createElement(o.default.Body,null,j&&i.default.createElement(r.default,{displayType:"danger"},j),i.default.createElement(u.Input,{autoComplete:"off",error:w&&""!==E.labelError?E.labelError:"",id:"objectFieldLabel",label:Liferay.Language.get("label"),name:"label",onChange:({target:{value:t}})=>{m({[e]:t})},required:!0,value:g[e]}),i.default.createElement(u.SingleSelect,{error:w&&""!==E.typeError?E.typeError:"",label:Liferay.Language.get("type"),onChange:e=>{y({label:e.label,name:e.name})},options:a,required:!0,value:d.label})),i.default.createElement(o.default.Footer,{last:i.default.createElement(n.default.Group,{spaced:!0},i.default.createElement(n.default,{displayType:"secondary",onClick:()=>f()},Liferay.Language.get("cancel")),i.default.createElement(n.default,{type:"submit"},Liferay.Language.get("save")))})))}}}));
//# sourceMappingURL=ModalAddObjectValidation.js.map