Liferay.Loader.define("@liferay/object-web@1.0.108/js/components/ModalAddListTypeEntry",["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,a,t){window;{Object.defineProperty(a,"__esModule",{value:!0}),a.default=void 0;var n=y(t("@frontend-taglib-clay$clayui/alert")),l=y(t("@frontend-taglib-clay$clayui/button")),r=y(t("@frontend-taglib-clay$clayui/form")),o=f(t("@frontend-taglib-clay$clayui/modal")),i=t("@liferay/object-js-components-web"),u=f(t("liferay!frontend-js-react-web$react")),d=t("../utils/string");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 a=c();if(a&&a.has(e))return a.get(e);var t={},n=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var l in e)if(Object.prototype.hasOwnProperty.call(e,l)){var r=n?Object.getOwnPropertyDescriptor(e,l):null;r&&(r.get||r.set)?Object.defineProperty(t,l,r):t[l]=e[l]}return t.default=e,a&&a.set(e,t),t}function y(e){return e&&e.__esModule?e:{default:e}}const e=Liferay.ThemeDisplay.getDefaultLanguageId(),m=({apiURL:a,observer:t,onClose:c})=>{var f,y;const[s,m]=(0,u.useState)(""),[g,b]=(0,u.useState)({label:e,symbol:e.replace("_","-").toLowerCase()}),p={key:void 0,name_i18n:{[e]:""}},{errors:L,handleChange:v,handleSubmit:E,setValues:w,values:_}=(0,i.useForm)({initialValues:p,onSubmit:async({key:e,name_i18n:t})=>{try{await i.API.save(a,{key:e||(0,d.toCamelCase)(t[g.label]),name_i18n:t},"POST"),c(),window.location.reload()}catch(e){m(e.message)}},validate:e=>{var a;const t={};return e.name_i18n[g.label]||(t.name_i18n=Liferay.Language.get("required")),(null!==(a=e.key)&&void 0!==a?a:e.name_i18n[g.label])||(t.key=Liferay.Language.get("required")),t}});return u.default.createElement(o.default,{observer:t},u.default.createElement(r.default,{onSubmit:E},u.default.createElement(o.default.Header,null,Liferay.Language.get("new-item")),u.default.createElement(o.default.Body,null,s&&u.default.createElement(n.default,{displayType:"danger"},s),u.default.createElement(i.InputLocalized,{error:L.name_i18n,id:"locale",label:Liferay.Language.get("name"),onChange:(e,a)=>{w({name_i18n:e}),(e=>{b(e);const a=document.querySelector(".dropdown-menu.show");null==a||a.classList.add("hide");const t=document.querySelector("#locale");t instanceof HTMLElement&&t.focus()})(a)},required:!0,translations:_.name_i18n}),u.default.createElement(i.Input,{error:L.key||L.name_i18n,id:"listTypeEntryKey",label:Liferay.Language.get("key"),name:"key",onChange:v,required:!0,value:null!==(f=_.key)&&void 0!==f?f:(0,d.toCamelCase)(null!==(y=_.name_i18n[g.label])&&void 0!==y?y:"")})),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 s=({apiURL:e})=>{const[a,t]=(0,u.useState)(!1),{observer:n,onClose:l}=(0,o.useModal)({onClose:()=>t(!1)});return(0,u.useEffect)((()=>(Liferay.on("addListTypeEntry",(()=>t(!0))),()=>{Liferay.detach("addListTypeEntry")})),[]),u.default.createElement(o.ClayModalProvider,null,a&&u.default.createElement(m,{apiURL:e,observer:n,onClose:l}))};a.default=s}}));
//# sourceMappingURL=ModalAddListTypeEntry.js.map