Liferay.Loader.define("@liferay/object-web@1.0.132/js/components/ObjectField/AddObjectField",["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","./ObjectFieldFormBase","./useObjectFieldForm"],(function(e,t,a){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=function AddObjectField({apiURL:e,objectDefinitionId:t,objectFieldTypes:a,objectName:r}){const[l,n]=(0,u.useState)(!1),{observer:o,onClose:c}=(0,i.useModal)({onClose:()=>n(!1)});return(0,u.useEffect)((()=>(Liferay.on("addObjectField",(()=>n(!0))),()=>Liferay.detach("addObjectField"))),[]),u.default.createElement(i.ClayModalProvider,null,l&&u.default.createElement(ModalAddObjectField,{apiURL:e,objectDefinitionId:t,objectFieldTypes:Liferay.FeatureFlags["LPS-164948"]&&Liferay.FeatureFlags["LPS-158776"]?a:(()=>a.filter((e=>Liferay.FeatureFlags["LPS-164948"]||Liferay.FeatureFlags["LPS-158776"]?Liferay.FeatureFlags["LPS-164948"]?Liferay.FeatureFlags["LPS-158776"]?void 0:"MultiselectPicklist"!==e.businessType:"Formula"!==e.businessType:"Formula"!==e.businessType&&"MultiselectPicklist"!==e.businessType)))(),objectName:r,observer:o,onClose:c}))};var r=_interopRequireDefault(a("@frontend-taglib-clay$clayui/alert")),l=_interopRequireDefault(a("@frontend-taglib-clay$clayui/button")),n=_interopRequireDefault(a("@frontend-taglib-clay$clayui/form")),i=_interopRequireWildcard(a("@frontend-taglib-clay$clayui/modal")),o=a("@liferay/object-js-components-web"),u=_interopRequireWildcard(a("liferay!frontend-js-react-web$react")),c=a("../../utils/string"),d=_interopRequireDefault(a("./ObjectFieldFormBase")),f=a("./useObjectFieldForm");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 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 _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 _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.ThemeDisplay.getDefaultLanguageId();function ModalAddObjectField({apiURL:t,objectDefinitionId:a,objectFieldTypes:s,objectName:b,observer:y,onClose:p}){var g;const[j,m]=(0,u.useState)(""),{errors:O,handleChange:F,handleSubmit:L,setValues:P,values:v}=(0,f.useObjectFieldForm)({initialValues:{indexed:!0,indexedAsKeyword:!1,indexedLanguageId:null,listTypeDefinitionExternalReferenceCode:"",listTypeDefinitionId:0,required:!1},onSubmit:async a=>{if(a.label){delete(a=_objectSpread(_objectSpread({},a),{},{name:a.name||(0,c.toCamelCase)(a.label[e])})).listTypeDefinitionId;try{await o.API.save(t,a,"POST"),p(),window.location.reload()}catch(e){m(e.message)}}}});return u.default.createElement(i.default,{observer:y},u.default.createElement(n.default,{onSubmit:L},u.default.createElement(i.default.Header,null,Liferay.Language.get("new-field")),u.default.createElement(i.default.Body,null,j&&u.default.createElement(r.default,{displayType:"danger"},j),u.default.createElement(o.Input,{error:O.label,label:Liferay.Language.get("label"),name:"label",onChange:({target:{value:t}})=>{P({label:{[e]:t}})},required:!0,value:null===(g=v.label)||void 0===g?void 0:g[e]}),u.default.createElement(d.default,{errors:O,handleChange:F,objectDefinitionId:a,objectField:v,objectFieldTypes:s,objectName:b,setValues:P})),u.default.createElement(i.default.Footer,{last:u.default.createElement(l.default.Group,{spaced:!0},u.default.createElement(l.default,{displayType:"secondary",onClick:()=>p()},Liferay.Language.get("cancel")),u.default.createElement(l.default,{type:"submit"},Liferay.Language.get("save")))})))}}}));
//# sourceMappingURL=AddObjectField.js.map