Liferay.Loader.define("@liferay/object-web@1.0.132/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({disabled:t,errors:a,editingField:o,onAggregationFilterChange:u,onRelationshipChange:s,objectDefinitionId:c,objectFieldSettings:f=[],setValues:d}){const[g,b]=(0,i.useState)(""),[m,y]=(0,i.useState)(""),[j,p]=(0,i.useState)(),[v,L]=(0,i.useState)(),[S,F]=(0,i.useState)(),[h,w]=(0,i.useState)(),[I,N]=(0,i.useState)(),O=(0,i.useMemo)((()=>{if(h)return(0,n.filterArrayByQuery)(h,"label",g)}),[h,g]),D=(0,i.useMemo)((()=>{if(I)return(0,n.filterArrayByQuery)(I,"label",m)}),[I,m]);(0,i.useEffect)((()=>{(async()=>{const e=await n.API.getObjectRelationships(c);w(e.filter((e=>!("manyToMany"===e.type&&e.reverse&&e.objectDefinitionId1===e.objectDefinitionId2))))})()}),[c]),(0,i.useEffect)((()=>{o&&h&&(async()=>{const t=(0,l.normalizeFieldSettings)(f),a=h.find((e=>e.name===t.objectRelationshipName)),i=r.find((e=>e.value===t.function)),o=await n.API.getObjectFields(a.objectDefinitionId2),u=o.find((e=>e.name===t.objectFieldName));s&&s(a.objectDefinitionId2),N(o.filter((e=>"Integer"===e.businessType||"LongInteger"===e.businessType||"Decimal"===e.businessType||"PrecisionDecimal"===e.businessType))),p(a),F(i),u&&L(u.label[e])})()}),[o,h,f,s]);return i.default.createElement(i.default.Fragment,null,i.default.createElement(n.AutoComplete,{emptyStateMessage:Liferay.Language.get("no-relationships-were-found"),error:a.objectRelationshipName,items:null!=O?O:[],label:Liferay.Language.get("relationship"),onChangeQuery:b,onSelectItem:e=>{(async e=>{p(e),L("");const t=(await n.API.getObjectFields(e.objectDefinitionId2)).filter((e=>"Integer"===e.businessType||"LongInteger"===e.businessType||"Decimal"===e.businessType||"PrecisionDecimal"===e.businessType));N(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}),s&&s(e.objectDefinitionId2)})(e)},query:g,required:!0,value:null==j?void 0:j.label[e]},(({label:t})=>i.default.createElement("div",{className:"d-flex justify-content-between"},i.default.createElement("div",null,t[e])))),i.default.createElement(n.SingleSelect,{disabled:t,error:a.function,label:Liferay.Language.get("function"),onChange:({label:e,value:t})=>{let a;if(F({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:r,required:!0,value:null==S?void 0:S.label}),"COUNT"!==(null==S?void 0:S.value)&&i.default.createElement(n.AutoComplete,{emptyStateMessage:Liferay.Language.get("no-fields-were-found"),error:a.objectFieldName,items:null!=D?D:[],label:Liferay.Language.get("field"),onChangeQuery:y,onSelectItem:t=>{(t=>{L(t.label[e]);const a=[...f.filter((e=>"objectFieldName"!==e.name)),{name:"objectFieldName",value:t.name}];d({objectFieldSettings:a})})(t)},query:m,required:!0,value:v},(({label:t})=>i.default.createElement("div",{className:"d-flex justify-content-between"},i.default.createElement("div",null,t[e])))))};var n=a("@liferay/object-js-components-web"),i=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 l=n?Object.getOwnPropertyDescriptor(e,i):null;l&&(l.get||l.set)?Object.defineProperty(a,i,l):a[i]=e[i]}a.default=e,t&&t.set(e,a);return a}(a("liferay!frontend-js-react-web$react")),l=a("../../utils/fieldSettings");function _getRequireWildcardCache(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return _getRequireWildcardCache=function _getRequireWildcardCache(){return e},e}const e=Liferay.ThemeDisplay.getDefaultLanguageId(),r=[{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