Liferay.Loader.define("@liferay/object-web@1.0.108/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){var n;window;{Object.defineProperty(t,"__esModule",{value:!0}),t.useObjectRelationshipForm=function({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=d),(0,r.invalidateRequired)(null!==(i=t.name)&&void 0!==i?i:l)&&(o.name=d),(0,r.invalidateRequired)(t.type)&&(o.type=d),t.objectDefinitionId2||(o.objectDefinitionId2=d),n&&t.type===e.ONE_TO_MANY&&!t.parameterObjectFieldId&&(o.parameterObjectFieldId=d),o}});return{errors:i,handleChange:o,handleSubmit:l,setValues:u,values:s}},t.ObjectRelationshipFormBase=function({errors:t,ffOneToOneRelationshipConfigurationEnabled:a,handleChange:n,readonly:l,setValues:d,values:y}){const[b,g]=(0,o.useState)([]),[m,p]=(0,o.useState)(""),[j,L]=(0,o.useMemo)((()=>{var e;const t=[s,u];return a&&t.push(c),[t,null===(e=t.find((({value:e})=>e===y.type)))||void 0===e?void 0:e.label]}),[a,y.type]);(0,o.useEffect)((()=>{l?g([{id:y.objectDefinitionId2,label:y.label,name:y.objectDefinitionName2,system:!1}]):(async()=>{const e=await r.API.getObjectDefinitions(),t=e.find((({id:e})=>y.objectDefinitionId1===e)),a=e.filter((({parameterRequired:e,storageType:a,system:n})=>!(t.system&&n||Liferay.FeatureFlags["LPS-135430"]&&"default"!==a||e)));g(a)})()}),[l,y.objectDefinitionId1]);const v=(0,o.useMemo)((()=>y.type===e.MANY_TO_MANY?b.filter((({id:e})=>e!==y.objectDefinitionId1)):b),[b,y.objectDefinitionId1,y.type]),O=(0,o.useMemo)((()=>Liferay.FeatureFlags["LPS-158478"]?b.filter((({label:e})=>(0,r.stringIncludesQuery)(e[f],m))):v.filter((({label:e})=>{var t;return null===(t=e[f])||void 0===t?void 0:t.toLocaleLowerCase().includes(m.toLowerCase())}))),[v,b,m]);return o.default.createElement(o.default.Fragment,null,o.default.createElement(r.Input,{disabled:l,error:t.name,label:Liferay.Language.get("name"),name:"name",onChange:n,required:!0,value:y.name}),o.default.createElement(r.SingleSelect,{disabled:l,error:t.type,label:Liferay.Language.get("type"),onChange:({value:e})=>d({type:e}),options:j,required:!0,value:L}),o.default.createElement(r.AutoComplete,{disabled:l,emptyStateMessage:Liferay.Language.get("no-objects-were-found"),error:t.objectDefinitionId2,items:O,label:Liferay.Language.get("object"),onChangeQuery:p,onSelectItem:e=>{d({objectDefinitionId2:e.id,objectDefinitionName2:e.name})},query:m,required:!0,value:y.objectDefinitionName2},(({label:e,name:t,system:a})=>{var n;return o.default.createElement("div",{className:"d-flex justify-content-between"},o.default.createElement("div",null,null!==(n=e[f])&&void 0!==n?n:t),o.default.createElement(i.default,{displayType:a?"info":"warning"},a?Liferay.Language.get("system"):Liferay.Language.get("custom")))})))},t.ObjectRelationshipType=void 0;var i=(n=a("@frontend-taglib-clay$clayui/label"))&&n.__esModule?n:{default:n},r=a("@liferay/object-js-components-web"),o=function(e){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=l();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 l(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return l=function(){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 u={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},s={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},c={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},d=Liferay.Language.get("required"),f=Liferay.ThemeDisplay.getDefaultLanguageId()}}));
//# sourceMappingURL=ObjectRelationshipFormBase.js.map