Liferay.Loader.define("@liferay/object-web@1.0.181/js/components/ObjectRelationship/ObjectRelationshipFormBase",["module","exports","require","@frontend-taglib-clay$clayui/label","@liferay/object-js-components-web","liferay!frontend-js-react-web$react","../../utils/constants"],(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:u,setValues:c,values:s}=(0,i.useForm)({initialValues:t,onSubmit:a,validate:t=>{var a,r;const o={},u=null===(a=t.label)||void 0===a?void 0:a[l.defaultLanguageId];return(0,i.invalidateRequired)(u)&&(o.label=i.REQUIRED_MSG),(0,i.invalidateRequired)(null!==(r=t.name)&&void 0!==r?r:u)&&(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:u,setValues:c,values:s}},t.ObjectRelationshipFormBase=function ObjectRelationshipFormBase({errors:e,handleChange:t,objectRelationshipTypes:a,readonly:l,setValues:u,values:c}){var s;const[d,f]=(0,r.useState)(),[b,y]=(0,r.useState)([]),[g,m]=(0,r.useState)(""),p=(0,r.useMemo)((()=>o.filter((e=>null==a?void 0:a.includes(e.value)))),[a]),j=(0,r.useMemo)((()=>(0,i.filterArrayByQuery)({array:b,creationLanguageId:d,query:g,str:"label"})),[d,b,g]);return(0,r.useEffect)((()=>{l?y([{externalReferenceCode:c.objectDefinitionExternalReferenceCode2,id:c.objectDefinitionId2,label:c.label,name:c.objectDefinitionName2,system:!1}]):(async()=>{const e=await i.API.getAllObjectDefinitions(),t=e.find((({externalReferenceCode:e})=>c.objectDefinitionExternalReferenceCode1===e)),a=e.filter((({modifiable:e,parameterRequired:a,storageType:n,system:i})=>Liferay.FeatureFlags["LPS-167253"]?(t.modifiable||e)&&(!Liferay.FeatureFlags["LPS-135430"]||"default"===n)&&!a:!(t.system&&i||Liferay.FeatureFlags["LPS-135430"]&&"default"!==n||a)));f(t.defaultLanguageId),y(a)})()}),[l,c.objectDefinitionExternalReferenceCode1]),r.default.createElement(r.default.Fragment,null,r.default.createElement(i.Input,{disabled:l,error:e.name,label:Liferay.Language.get("name"),name:"name",onChange:t,required:!0,value:c.name}),r.default.createElement(i.SingleSelect,{disabled:l,error:e.type,label:Liferay.Language.get("type"),onChange:({value:e})=>u({type:e}),options:p,required:!0,value:null===(s=o.find((({value:e})=>e===c.type)))||void 0===s?void 0:s.label}),r.default.createElement(i.AutoComplete,{disabled:l,emptyStateMessage:Liferay.Language.get("no-objects-were-found"),error:e.objectDefinitionId2,items:j,label:Liferay.Language.get("object"),onActive:e=>e.name===c.objectDefinitionName2,onChangeQuery:m,onSelectItem:e=>{u({objectDefinitionExternalReferenceCode2:e.externalReferenceCode,objectDefinitionId2:e.id,objectDefinitionName2:e.name})},query:g,required:!0,value:c.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)(d,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")),l=a("../../utils/constants");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},{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},{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