Liferay.Loader.define("@liferay/object-web@1.0.181/js/components/ObjectRelationship/SelectRelationship",["module","exports","require","@liferay/object-js-components-web","liferay!frontend-js-react-web$react"],(function(e,t,r){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=function SelectRelationship(e){let{error:t,objectDefinitionExternalReferenceCode:r,onChange:o,value:l}=e,i=function _objectWithoutProperties(e,t){if(null==e)return{};var r,n,a=function _objectWithoutPropertiesLoose(e,t){if(null==e)return{};var r,n,a={},o=Object.keys(e);for(n=0;n<o.length;n++)r=o[n],t.indexOf(r)>=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n<o.length;n++)r=o[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}(e,["error","objectDefinitionExternalReferenceCode","onChange","value"]);const[u,c]=(0,a.useState)(),[f,s]=(0,a.useState)([]),[d,p]=(0,a.useState)(""),b=(0,a.useMemo)((()=>f.map((({label:e,name:t})=>({label:(0,n.getLocalizableLabel)(u,e,t),name:t})))),[u,f]),y=(0,a.useMemo)((()=>{if(b)return b.filter((e=>(0,n.stringIncludesQuery)(e.label,d)))}),[b,d]),g=(0,a.useMemo)((()=>f.find((({name:e})=>e===l))),[f,l]);return(0,a.useEffect)((()=>{r?(async()=>{const e=await n.API.getObjectFieldsByExternalReferenceCode(r),t=await n.API.getObjectDefinitionByExternalReferenceCode(r);c(t.defaultLanguageId);const a=e.filter((({businessType:e})=>"Relationship"===e));c(t.defaultLanguageId),s(a)})():s([])}),[r]),a.default.createElement(n.AutoComplete,_extends({emptyStateMessage:Liferay.Language.get("no-parameters-were-found"),error:t,items:null!=y?y:[],label:Liferay.Language.get("parameter"),onActive:e=>e.name===(null==g?void 0:g.name),onChangeQuery:p,onSelectItem:({name:e})=>{var t;o(null===(t=f.find((({name:t})=>t===e)))||void 0===t?void 0:t.name)},query:d,required:!0,tooltip:Liferay.Language.get("choose-a-relationship-field-from-the-selected-object"),value:(0,n.getLocalizableLabel)(u,null==g?void 0:g.label,null==g?void 0:g.name)},i),(({label:e,name:t})=>a.default.createElement("div",{className:"d-flex justify-content-between"},null!=e?e:t)))};var n=r("@liferay/object-js-components-web"),a=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 r={},n=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var a in e)if(Object.prototype.hasOwnProperty.call(e,a)){var o=n?Object.getOwnPropertyDescriptor(e,a):null;o&&(o.get||o.set)?Object.defineProperty(r,a,o):r[a]=e[a]}r.default=e,t&&t.set(e,r);return r}(r("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}function _extends(){return(_extends=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}}}));
//# sourceMappingURL=SelectRelationship.js.map