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