Liferay.Loader.define("@liferay/object-web@1.0.108/js/components/ModalAddObjectDefinition",["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","../utils/string"],(function(e,t,a){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var r=d(a("@frontend-taglib-clay$clayui/alert")),l=d(a("@frontend-taglib-clay$clayui/button")),n=d(a("@frontend-taglib-clay$clayui/form")),o=s(a("@frontend-taglib-clay$clayui/modal")),i=a("@liferay/object-js-components-web"),u=s(a("liferay!frontend-js-react-web$react")),c=a("../utils/string");function f(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return f=function(){return e},e}function s(e){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=f();if(t&&t.has(e))return t.get(e);var a={},r=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var l in e)if(Object.prototype.hasOwnProperty.call(e,l)){var n=r?Object.getOwnPropertyDescriptor(e,l):null;n&&(n.get||n.set)?Object.defineProperty(a,l,n):a[l]=e[l]}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 y(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){p(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}function p(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=e=>{const t=e.split(" ").map((e=>(0,c.firstLetterUppercase)(e))).join("");return(0,c.removeAllSpecialCharacters)(t)},m=({apiURL:t,observer:a,onClose:c,storageTypes:f})=>{var s;const d={label:"",name:void 0,pluralLabel:"",storageType:f[0]},[b,p]=(0,u.useState)(""),{errors:g,handleChange:m,handleSubmit:L,setValues:j,values:v}=(0,i.useForm)({initialValues:d,onSubmit:async({label:a,name:r,pluralLabel:l,storageType:n})=>{const o=Liferay.ThemeDisplay.getDefaultLanguageId(),u={label:{[o]:a},name:r||e(a),objectFields:[],pluralLabel:{[o]:l},scope:"company"};Liferay.FeatureFlags["LPS-135430"]&&(u.storageType=n.toLowerCase());try{await i.API.save(t,u,"POST"),c(),window.location.reload()}catch(e){p(e.message)}},validate:e=>{var t;const a={};return e.label||(a.label=Liferay.Language.get("required")),(null!==(t=e.name)&&void 0!==t?t:e.label)||(a.name=Liferay.Language.get("required")),e.pluralLabel||(a.pluralLabel=Liferay.Language.get("required")),a}});return u.default.createElement(o.default,{observer:a},u.default.createElement(n.default,{onSubmit:L},u.default.createElement(o.default.Header,null,Liferay.Language.get("new-custom-object")),u.default.createElement(o.default.Body,null,b&&u.default.createElement(r.default,{displayType:"danger"},b),u.default.createElement(i.Input,{error:g.label,id:"objectDefinitionLabel",label:Liferay.Language.get("label"),name:"label",onChange:m,required:!0,value:v.label}),u.default.createElement(i.Input,{error:g.pluralLabel,id:"objectDefinitionPluralLabel",label:Liferay.Language.get("plural-label"),name:"pluralLabel",onChange:m,required:!0,value:v.pluralLabel}),u.default.createElement(i.Input,{error:g.name,id:"objectDefinitionName",label:Liferay.Language.get("object-name"),name:"name",onChange:m,required:!0,value:null!==(s=v.name)&&void 0!==s?s:e(v.label)}),Liferay.FeatureFlags["LPS-135430"]&&u.default.createElement(i.Select,{label:Liferay.Language.get("storage-type"),name:"storageType",onChange:({target:{value:e}})=>{j(y(y({},v),{},{storageType:f[Number(e)]}))},options:f,tooltip:Liferay.Language.get("object-definition-storage-type-tooltip"),value:(e=>{const t=e.toLowerCase();return f.findIndex((e=>e.toLowerCase()===t))})(v.storageType)})),u.default.createElement(o.default.Footer,{last:u.default.createElement(l.default.Group,{key:1,spaced:!0},u.default.createElement(l.default,{displayType:"secondary",onClick:()=>c()},Liferay.Language.get("cancel")),u.default.createElement(l.default,{displayType:"primary",type:"submit"},Liferay.Language.get("save")))})))};var g=({apiURL:e,storageTypes:t})=>{const[a,r]=(0,u.useState)(!1),{observer:l,onClose:n}=(0,o.useModal)({onClose:()=>r(!1)});return(0,u.useEffect)((()=>(Liferay.on("addObjectDefinition",(()=>r(!0))),()=>{Liferay.detach("addObjectDefinition")})),[]),u.default.createElement(o.ClayModalProvider,null,a&&u.default.createElement(m,{apiURL:e,observer:l,onClose:n,storageTypes:t}))};t.default=g}}));
//# sourceMappingURL=ModalAddObjectDefinition.js.map