Liferay.Loader.define("@liferay/object-web@1.0.132/js/components/ListTypeDefinition/ListTypeEntriesModal",["module","exports","require","@frontend-taglib-clay$clayui/button","@frontend-taglib-clay$clayui/modal","@liferay/object-js-components-web","frontend-js-web","liferay!frontend-js-react-web$react","../../utils/string","./utils"],(function(e,t,a){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var r=function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}(a("@frontend-taglib-clay$clayui/button")),n=_interopRequireWildcard(a("@frontend-taglib-clay$clayui/modal")),i=a("@liferay/object-js-components-web"),o=a("frontend-js-web"),l=_interopRequireWildcard(a("liferay!frontend-js-react-web$react")),u=a("../../utils/string"),c=a("./utils");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 i=r?Object.getOwnPropertyDescriptor(e,n):null;i&&(i.get||i.set)?Object.defineProperty(a,n,i):a[n]=e[n]}return a.default=e,t&&t.set(e,a),a}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 _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}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.Language.get("required"),s=Liferay.ThemeDisplay.getDefaultLanguageId();var d=function ListTypeEntriesModal(){const[{header:t,itemId:a,itemKey:d,modalType:f,name_i18n:y,pickListId:p,readOnly:b,reloadIframeWindow:m},g]=(0,l.useState)({}),[j,_]=(0,l.useState)(!1),[L,O]=(0,l.useState)(""),[w,v]=(0,l.useState)({name:"",name_i18n:""}),{observer:P,onClose:h}=(0,n.useModal)({onClose:()=>{O(""),g({}),v({}),_(!1)}});return(0,l.useEffect)((()=>{const openModal=e=>{const t=_objectSpread({},e);t.name_i18n&&(t.name_i18n=(0,c.fixLocaleKeys)(t.name_i18n)),g(t)};return Liferay.on("openListTypeEntriesModal",openModal),()=>Liferay.detach("openListTypeEntriesModal",openModal)}),[]),(0,l.useEffect)((()=>{L&&(0,o.openToast)({message:L,type:"danger"}),O("")}),[L]),t?l.default.createElement(n.default,{observer:P},l.default.createElement(n.default.Header,null,t),l.default.createElement(n.default.Body,null,l.default.createElement(i.InputLocalized,{disabled:b,error:w.name_i18n,id:"locale",label:Liferay.Language.get("name"),onChange:e=>(e=>{g((t=>_objectSpread(_objectSpread(_objectSpread({},t),"edit"!==f&&!1===j&&(null==e?void 0:e[s])&&{itemKey:(0,u.toCamelCase)(e[s])}),{},{name_i18n:_objectSpread({},e)})))})(e),required:!0,translations:null!=y?y:{[s]:""}}),l.default.createElement(i.Input,{disabled:"edit"===f,error:w.name,label:Liferay.Language.get("key"),name:"name",onChange:({target:e})=>{return t=e.value,!1===j&&_(!0),void g((e=>_objectSpread(_objectSpread({},e),{},{itemKey:(0,u.toCamelCase)(t)})));var t},required:!0,value:null!=d?d:""})),l.default.createElement(n.default.Footer,{last:l.default.createElement(r.default.Group,{spaced:!0},l.default.createElement(r.default,{displayType:"secondary",onClick:()=>h()},Liferay.Language.get("cancel")),l.default.createElement(r.default,{disabled:b,displayType:"primary",onClick:async()=>{const t=(t=>{var a;const r={},n=null===(a=t.name_i18n)||void 0===a?void 0:a[s],o=t.key;return(0,i.invalidateRequired)(n)&&(r.name_i18n=e),(0,i.invalidateRequired)(o)&&(r.name=e),r})({key:d,name_i18n:y});if(Object.keys(t).length)v(t);else{v({});try{"add"===f?(await i.API.addPickListItem({id:p,key:d,name_i18n:y}),(0,o.openToast)({message:Liferay.Language.get("the-picklist-item-was-created-successfully"),type:"success"})):"edit"===f&&(await i.API.updatePickListItem({id:a,name_i18n:y}),(0,o.openToast)({message:Liferay.Language.get("the-picklist-item-was-updated-successfully"),type:"success"})),h(),m&&m()}catch(e){O(e.message)}}},type:"submit"},Liferay.Language.get("save")))})):null};t.default=d}}));
//# sourceMappingURL=ListTypeEntriesModal.js.map