Liferay.Loader.define("@liferay/object-web@1.0.145/js/components/ObjectRelationship/ObjectRelationshipFormBase",["module","exports","require","@frontend-taglib-clay$clayui/label","@liferay/object-js-components-web","liferay!frontend-js-react-web$react"],(function(e,t,a){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.useObjectRelationshipForm=function useObjectRelationshipForm({initialValues:t,onSubmit:a,parameterRequired:n}){const{errors:i,handleChange:o,handleSubmit:l,setValues:u,values:s}=(0,r.useForm)({initialValues:t,onSubmit:a,validate:t=>{var a,i;const o={},l=null===(a=t.label)||void 0===a?void 0:a[Liferay.ThemeDisplay.getDefaultLanguageId()];return(0,r.invalidateRequired)(l)&&(o.label=c),(0,r.invalidateRequired)(null!==(i=t.name)&&void 0!==i?i:l)&&(o.name=c),(0,r.invalidateRequired)(t.type)&&(o.type=c),t.objectDefinitionId2||(o.objectDefinitionId2=c),n&&t.type===e.ONE_TO_MANY&&!t.parameterObjectFieldName&&(o.parameterObjectFieldName=c),o}});return{errors:i,handleChange:o,handleSubmit:l,setValues:u,values:s}},t.ObjectRelationshipFormBase=function ObjectRelationshipFormBase({errors:e,ffOneToOneRelationshipConfigurationEnabled:t,handleChange:a,readonly:c,setValues:d,values:f}){const[y,b]=(0,i.useState)([]),[g,m]=(0,i.useState)(""),[p,j]=(0,i.useMemo)((()=>{var e;const a=[l,o];return t&&a.push(u),[a,null===(e=a.find((({value:e})=>e===f.type)))||void 0===e?void 0:e.label]}),[t,f.type]);(0,i.useEffect)((()=>{c?b([{externalReferenceCode:f.objectDefinitionExternalReferenceCode2,id:f.objectDefinitionId2,label:f.label,name:f.objectDefinitionName2,system:!1}]):(async()=>{const e=await r.API.getAllObjectDefinitions(),t=e.find((({externalReferenceCode:e})=>f.objectDefinitionExternalReferenceCode1===e)),a=e.filter((({parameterRequired:e,storageType:a,system:n})=>!(t.system&&n||Liferay.FeatureFlags["LPS-135430"]&&"default"!==a||e)));b(a)})()}),[c,f.objectDefinitionId1]);const O=(0,i.useMemo)((()=>(0,r.filterArrayByQuery)({array:y,query:g,str:"label"})),[y,g]);return i.default.createElement(i.default.Fragment,null,i.default.createElement(r.Input,{disabled:c,error:e.name,label:Liferay.Language.get("name"),name:"name",onChange:a,required:!0,value:f.name}),i.default.createElement(r.SingleSelect,{disabled:c,error:e.type,label:Liferay.Language.get("type"),onChange:({value:e})=>d({type:e}),options:p,required:!0,value:j}),i.default.createElement(r.AutoComplete,{disabled:c,emptyStateMessage:Liferay.Language.get("no-objects-were-found"),error:e.objectDefinitionId2,items:O,label:Liferay.Language.get("object"),onChangeQuery:m,onSelectItem:e=>{d({objectDefinitionExternalReferenceCode2:e.externalReferenceCode,objectDefinitionId2:e.id,objectDefinitionName2:e.name})},query:g,required:!0,value:f.objectDefinitionName2},(({label:e,name:t,system:a})=>{var r;return i.default.createElement("div",{className:"d-flex justify-content-between"},i.default.createElement("div",null,null!==(r=e[s])&&void 0!==r?r:t),i.default.createElement(n.default,{displayType:a?"info":"warning"},a?Liferay.Language.get("system"):Liferay.Language.get("custom")))})))},t.ObjectRelationshipType=void 0;var n=function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}(a("@frontend-taglib-clay$clayui/label")),r=a("@liferay/object-js-components-web"),i=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={},n=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var r in e)if(Object.prototype.hasOwnProperty.call(e,r)){var i=n?Object.getOwnPropertyDescriptor(e,r):null;i&&(i.get||i.set)?Object.defineProperty(a,r,i):a[r]=e[r]}a.default=e,t&&t.set(e,a);return a}(a("liferay!frontend-js-react-web$react"));function _getRequireWildcardCache(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return _getRequireWildcardCache=function _getRequireWildcardCache(){return e},e}let e;t.ObjectRelationshipType=e,function(e){e.MANY_TO_MANY="manyToMany",e.ONE_TO_MANY="oneToMany",e.ONE_TO_ONE="oneToOne"}(e||(t.ObjectRelationshipType=e={}));const o={description:Liferay.Language.get("multiple-object's-entries-can-interact-with-many-others-object's-entries"),label:Liferay.Language.get("many-to-many"),value:e.MANY_TO_MANY},l={description:Liferay.Language.get("one-object's-entry-interacts-with-many-others-object's-entries"),label:Liferay.Language.get("one-to-many"),value:e.ONE_TO_MANY},u={description:Liferay.Language.get("one-object's-entry-interacts-only-with-one-other-object's-entry"),label:Liferay.Language.get("one-to-one"),value:e.ONE_TO_ONE},c=Liferay.Language.get("required"),s=Liferay.ThemeDisplay.getDefaultLanguageId()}}));
//# sourceMappingURL=ObjectRelationshipFormBase.js.map