Liferay.Loader.define("@liferay/object-web@1.0.108/js/components/ObjectRelationship/AddRelationship",["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","./ObjectRelationshipFormBase","./SelectRelationship"],(function(e,t,a){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=function({apiURL:e,ffOneToOneRelationshipConfigurationEnabled:t,objectDefinitionId:a,parameterRequired:n}){const[r,l]=(0,u.useState)(!1),{observer:i,onClose:c}=(0,o.useModal)({onClose:()=>l(!1)});return(0,u.useEffect)((()=>(Liferay.on("addObjectRelationship",(()=>l(!0))),()=>{Liferay.detach("addObjectRelationship")})),[]),u.default.createElement(o.ClayModalProvider,null,r&&u.default.createElement(j,{apiURL:e,ffOneToOneRelationshipConfigurationEnabled:t,objectDefinitionId:a,observer:i,onClose:c,parameterRequired:n}))};var n=p(a("@frontend-taglib-clay$clayui/alert")),r=p(a("@frontend-taglib-clay$clayui/button")),l=p(a("@frontend-taglib-clay$clayui/form")),o=b(a("@frontend-taglib-clay$clayui/modal")),i=a("@liferay/object-js-components-web"),u=b(a("liferay!frontend-js-react-web$react")),c=a("../../utils/string"),f=a("./ObjectRelationshipFormBase"),d=p(a("./SelectRelationship"));function s(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return s=function(){return e},e}function b(e){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=s();if(t&&t.has(e))return t.get(e);var a={},n=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var r in e)if(Object.prototype.hasOwnProperty.call(e,r)){var l=n?Object.getOwnPropertyDescriptor(e,r):null;l&&(l.get||l.set)?Object.defineProperty(a,r,l):a[r]=e[r]}return a.default=e,t&&t.set(e,a),a}function p(e){return e&&e.__esModule?e:{default:e}}function y(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,n)}return a}function O(e){for(var t=1;t<arguments.length;t++){var a=null!=arguments[t]?arguments[t]:{};t%2?y(Object(a),!0).forEach((function(t){m(e,t,a[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(a)):y(Object(a)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(a,t))}))}return e}function m(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function g(e,t){if(null==e)return{};var a,n,r=function(e,t){if(null==e)return{};var a,n,r={},l=Object.keys(e);for(n=0;n<l.length;n++)a=l[n],t.indexOf(a)>=0||(r[a]=e[a]);return r}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(n=0;n<l.length;n++)a=l[n],t.indexOf(a)>=0||Object.prototype.propertyIsEnumerable.call(e,a)&&(r[a]=e[a])}return r}const e=Liferay.ThemeDisplay.getDefaultLanguageId();function j({apiURL:t,ffOneToOneRelationshipConfigurationEnabled:a,objectDefinitionId:s,observer:b,onClose:p,parameterRequired:y}){var m,j,h,v;const[w,E]=(0,u.useState)(""),R={objectDefinitionId1:Number(s)},{errors:P,handleChange:C,handleSubmit:L,setValues:D,values:I}=(0,f.useObjectRelationshipForm)({initialValues:R,onSubmit:async a=>{let{label:n,name:r}=a,l=g(a,["label","name"]);try{await i.API.save(t,O(O({},l),{},{label:n,name:null!=r?r:(0,c.toCamelCase)(n[e])}),"POST"),p(),window.location.reload()}catch({message:e}){E(e)}},parameterRequired:y});return u.default.createElement(o.default,{observer:b},u.default.createElement(l.default,{onSubmit:L},u.default.createElement(o.default.Header,null,Liferay.Language.get("new-relationship")),u.default.createElement(o.default.Body,null,w&&u.default.createElement(n.default,{displayType:"danger"},w),u.default.createElement(i.Input,{error:P.label,label:Liferay.Language.get("label"),onChange:({target:{value:t}})=>D({label:{[e]:t}}),required:!0,value:null===(m=I.label)||void 0===m?void 0:m[e]}),u.default.createElement(f.ObjectRelationshipFormBase,{errors:P,ffOneToOneRelationshipConfigurationEnabled:a,handleChange:C,setValues:D,values:O(O({},I),{},{name:null!==(j=I.name)&&void 0!==j?j:(0,c.toCamelCase)(null!==(h=null===(v=I.label)||void 0===v?void 0:v[e])&&void 0!==h?h:"")})}),y&&I.type===f.ObjectRelationshipType.ONE_TO_MANY&&u.default.createElement(d.default,{error:P.parameterObjectFieldId,objectDefinitionId:I.objectDefinitionId2,onChange:e=>D({parameterObjectFieldId:e}),value:I.parameterObjectFieldId})),u.default.createElement(o.default.Footer,{last:u.default.createElement(r.default.Group,{spaced:!0},u.default.createElement(r.default,{displayType:"secondary",onClick:()=>p()},Liferay.Language.get("cancel")),u.default.createElement(r.default,{displayType:"primary",type:"submit"},Liferay.Language.get("save")))})))}}}));
//# sourceMappingURL=AddRelationship.js.map