Liferay.Loader.define("@liferay/object-web@1.0.145/js/components/ObjectField/AggregationFormBase",["module","exports","require","@liferay/object-js-components-web","liferay!frontend-js-react-web$react","../../utils/fieldSettings"],(function(e,t,a){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.AggregationFormBase=function AggregationFormBase({creationLanguageId:t,disabled:a,errors:r,editingField:o,onAggregationFilterChange:u,onRelationshipChange:c,objectDefinitionExternalReferenceCode:s,objectFieldSettings:f=[],setValues:d}){const[g,b]=(0,l.useState)(""),[m,y]=(0,l.useState)(""),[j,p]=(0,l.useState)(),[v,L]=(0,l.useState)(),[C,E]=(0,l.useState)(),[R,S]=(0,l.useState)(),[F,h]=(0,l.useState)(),w=(0,l.useMemo)((()=>{if(R)return(0,n.filterArrayByQuery)({array:R,query:g,str:"label"})}),[R,g]),N=(0,l.useMemo)((()=>{if(F)return(0,n.filterArrayByQuery)({array:F,query:m,str:"label"})}),[F,m]);(0,l.useEffect)((()=>{(async()=>{const e=await n.API.getObjectRelationshipsByExternalReferenceCode(s);S(e.filter((e=>!("manyToMany"===e.type&&e.reverse&&e.objectDefinitionExternalReferenceCode1===e.objectDefinitionExternalReferenceCode2))))})()}),[s]),(0,l.useEffect)((()=>{o&&R&&(async()=>{const a=(0,i.normalizeFieldSettings)(f),l=R.find((e=>e.name===a.objectRelationshipName)),r=e.find((e=>e.value===a.function)),o=await n.API.getObjectFieldsByExternalReferenceCode(l.objectDefinitionExternalReferenceCode2),u=o.find((e=>e.name===a.objectFieldName));c&&c(l.objectDefinitionExternalReferenceCode2),h(o.filter((e=>"Integer"===e.businessType||"LongInteger"===e.businessType||"Decimal"===e.businessType||"PrecisionDecimal"===e.businessType))),p(l),E(r),u&&L((0,n.getLocalizableLabel)(t,u.label,u.name))})()}),[t,o,R,f,c]);return l.default.createElement(l.default.Fragment,null,l.default.createElement(n.AutoComplete,{emptyStateMessage:Liferay.Language.get("no-relationships-were-found"),error:r.objectRelationshipName,items:null!=w?w:[],label:Liferay.Language.get("relationship"),onChangeQuery:b,onSelectItem:e=>{(async e=>{p(e),L("");const t=(await n.API.getObjectFieldsByExternalReferenceCode(e.objectDefinitionExternalReferenceCode2)).filter((e=>"Integer"===e.businessType||"LongInteger"===e.businessType||"Decimal"===e.businessType||"PrecisionDecimal"===e.businessType));h(t);const a=[...f.filter((e=>"objectFieldName"!==e.name&&"filters"!==e.name&&"objectRelationshipName"!==e.name)),{name:"objectRelationshipName",value:e.name},{name:"filters",value:[]}];u&&u([]),d({objectFieldSettings:a}),c&&c(e.objectDefinitionExternalReferenceCode2)})(e)},query:g,required:!0,value:(0,n.getLocalizableLabel)(t,null==j?void 0:j.label,null==j?void 0:j.name)},(({label:e,name:a})=>l.default.createElement("div",{className:"d-flex justify-content-between"},l.default.createElement("div",null,(0,n.getLocalizableLabel)(t,e,a))))),l.default.createElement(n.SingleSelect,{disabled:a,error:r.function,label:Liferay.Language.get("function"),onChange:({label:e,value:t})=>{let a;if(E({label:e,value:t}),"COUNT"===t){L("");return a=[...f.filter((e=>"objectFieldName"!==e.name)).filter((e=>"function"!==e.name)),{name:"function",value:t}],void d({objectFieldSettings:a})}a=[...f.filter((e=>"function"!==e.name)),{name:"function",value:t}],d({objectFieldSettings:a})},options:e,required:!0,value:null==C?void 0:C.label}),"COUNT"!==(null==C?void 0:C.value)&&l.default.createElement(n.AutoComplete,{emptyStateMessage:Liferay.Language.get("no-fields-were-found"),error:r.objectFieldName,items:null!=N?N:[],label:Liferay.Language.get("field"),onChangeQuery:y,onSelectItem:e=>{(e=>{L((0,n.getLocalizableLabel)(t,e.label,e.name));const a=[...f.filter((e=>"objectFieldName"!==e.name)),{name:"objectFieldName",value:e.name}];d({objectFieldSettings:a})})(e)},query:m,required:!0,value:v},(({label:e,name:a})=>l.default.createElement("div",{className:"d-flex justify-content-between"},l.default.createElement("div",null,(0,n.getLocalizableLabel)(t,e,a))))))};var n=a("@liferay/object-js-components-web"),l=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 l in e)if(Object.prototype.hasOwnProperty.call(e,l)){var i=n?Object.getOwnPropertyDescriptor(e,l):null;i&&(i.get||i.set)?Object.defineProperty(a,l,i):a[l]=e[l]}a.default=e,t&&t.set(e,a);return a}(a("liferay!frontend-js-react-web$react")),i=a("../../utils/fieldSettings");function _getRequireWildcardCache(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return _getRequireWildcardCache=function _getRequireWildcardCache(){return e},e}const e=[{label:Liferay.Language.get("count"),value:"COUNT"},{label:Liferay.Language.get("sum"),value:"SUM"},{label:Liferay.Language.get("average"),value:"AVERAGE"},{label:Liferay.Language.get("min"),value:"MIN"},{label:Liferay.Language.get("max"),value:"MAX"}]}}));
//# sourceMappingURL=AggregationFormBase.js.map