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