Liferay.Loader.define("@liferay/object-web@1.0.153/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:r,handleChange:o,handleSubmit:l,setValues:u,values:c}=(0,i.useForm)({initialValues:t,onSubmit:a,validate:t=>{var a,r;const o={},l=null===(a=t.label)||void 0===a?void 0:a[Liferay.ThemeDisplay.getDefaultLanguageId()];return(0,i.invalidateRequired)(l)&&(o.label=i.REQUIRED_MSG),(0,i.invalidateRequired)(null!==(r=t.name)&&void 0!==r?r:l)&&(o.name=i.REQUIRED_MSG),(0,i.invalidateRequired)(t.type)&&(o.type=i.REQUIRED_MSG),t.objectDefinitionId2||(o.objectDefinitionId2=i.REQUIRED_MSG),n&&t.type===e.ONE_TO_MANY&&!t.parameterObjectFieldName&&(o.parameterObjectFieldName=i.REQUIRED_MSG),o}});return{errors:r,handleChange:o,handleSubmit:l,setValues:u,values:c}},t.ObjectRelationshipFormBase=function ObjectRelationshipFormBase({errors:e,ffOneToOneRelationshipConfigurationEnabled:t,handleChange:a,readonly:c,setValues:s,values:d}){const[f,y]=(0,r.useState)(),[b,g]=(0,r.useState)([]),[m,p]=(0,r.useState)(""),[j,O]=(0,r.useMemo)((()=>{var e;const a=[l,o];return t&&a.push(u),[a,null===(e=a.find((({value:e})=>e===d.type)))||void 0===e?void 0:e.label]}),[t,d.type]);(0,r.useEffect)((()=>{(async()=>{const e=await i.API.getObjectDefinitionByExternalReferenceCode(d.objectDefinitionExternalReferenceCode1);y(e.defaultLanguageId)})()}),[d]),(0,r.useEffect)((()=>{c?g([{externalReferenceCode:d.objectDefinitionExternalReferenceCode2,id:d.objectDefinitionId2,label:d.label,name:d.objectDefinitionName2,system:!1}]):(async()=>{const e=await i.API.getAllObjectDefinitions(),t=e.find((({externalReferenceCode:e})=>d.objectDefinitionExternalReferenceCode1===e)),a=e.filter((({parameterRequired:e,storageType:a,system:n})=>!(t.system&&n||Liferay.FeatureFlags["LPS-135430"]&&"default"!==a||e)));y(t.defaultLanguageId),g(a)})()}),[c,d.objectDefinitionId1]);const R=(0,r.useMemo)((()=>(0,i.filterArrayByQuery)({array:b,creationLanguageId:f,query:m,str:"label"})),[f,b,m]);return r.default.createElement(r.default.Fragment,null,r.default.createElement(i.Input,{disabled:c,error:e.name,label:Liferay.Language.get("name"),name:"name",onChange:a,required:!0,value:d.name}),r.default.createElement(i.SingleSelect,{disabled:c,error:e.type,label:Liferay.Language.get("type"),onChange:({value:e})=>s({type:e}),options:j,required:!0,value:O}),r.default.createElement(i.AutoComplete,{creationLanguageId:f,disabled:c,emptyStateMessage:Liferay.Language.get("no-objects-were-found"),error:e.objectDefinitionId2,items:R,label:Liferay.Language.get("object"),onChangeQuery:p,onSelectItem:e=>{s({objectDefinitionExternalReferenceCode2:e.externalReferenceCode,objectDefinitionId2:e.id,objectDefinitionName2:e.name})},query:m,required:!0,value:d.objectDefinitionName2},(({label:e,name:t,system:a})=>r.default.createElement("div",{className:"d-flex justify-content-between"},r.default.createElement("div",null,(0,i.getLocalizableLabel)(f,e,t)),r.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")),i=a("@liferay/object-js-components-web"),r=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 i in e)if(Object.prototype.hasOwnProperty.call(e,i)){var r=n?Object.getOwnPropertyDescriptor(e,i):null;r&&(r.get||r.set)?Object.defineProperty(a,i,r):a[i]=e[i]}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}}}));
//# sourceMappingURL=ObjectRelationshipFormBase.js.map