var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
import React, { useEffect, useMemo } from 'react';
import { TableColumnDefs } from './TableColumnDefs';
import { AmbientGridTemplate } from '../../UI/templates/deprecated/AmbientGridTemplate/AmbientGridTemplate';
import { ActionsRenderer } from '../../UI/templates/ui/renderers/ActionsRenderer';
import { useAgGridApi } from '../../utilities/aggrid/AgTable';
import { executeQueryAdHoc } from '../../udp/utilities/methodUtils';
import { SearchServiceDatasource } from '../../utilities/aggrid/datasources/SearchServiceDatasource';
import { useBuildEnvironment } from '../../shell/ui/useBuildEnvironment';
export const TableContainer = (props) => {
    const { actionList, loading, rowData, catalog, isServerSide = false, promotedEntity, filterElements, customColumnDefs, eagerLoad = false, logicalSearchOperator = 1, frameworkComponents = { actionsRenderer: ActionsRenderer }, additionalGridOptions, headerBackgroundColor, api, columnApi, gridReady, dynamicSizing } = props, other = __rest(props, ["actionList", "loading", "rowData", "catalog", "isServerSide", "promotedEntity", "filterElements", "customColumnDefs", "eagerLoad", "logicalSearchOperator", "frameworkComponents", "additionalGridOptions", "headerBackgroundColor", "api", "columnApi", "gridReady", "dynamicSizing"]);
    const { gridApi, gridColumnApi, onGridReady } = useAgGridApi();
    const gApi = api || gridApi;
    const cApi = columnApi || gridColumnApi;
    const gReady = gridReady || onGridReady;
    const buildEnv = useBuildEnvironment();
    const columnDefs = customColumnDefs || TableColumnDefs(actionList);
    const groupData = useMemo(() => {
        return columnDefs === null || columnDefs === void 0 ? void 0 : columnDefs.map((item) => {
            return {
                groupItem: item.field,
                label: item.headerName,
                value: item.field
            };
        });
    }, [columnDefs]);
    useEffect(() => {
        var _a;
        if (!gApi)
            return;
        if (promotedEntity && isServerSide) {
            let datasource = SearchServiceDatasource(null, (_a = promotedEntity === null || promotedEntity === void 0 ? void 0 : promotedEntity.unityBaseSearchMethod) === null || _a === void 0 ? void 0 : _a.apiMethodId, filterElements, logicalSearchOperator, executeQueryAdHoc, null, null, eagerLoad);
            // eslint-disable-next-line no-unused-expressions
            gApi === null || gApi === void 0 ? void 0 : gApi.setServerSideDatasource(datasource);
        }
    }, [gApi, promotedEntity, isServerSide, filterElements, eagerLoad, logicalSearchOperator]);
    return (React.createElement(AmbientGridTemplate, Object.assign({ useNewHeader: true, api: gApi, onGridReady: gReady, columnApi: cApi, title: catalog === null || catalog === void 0 ? void 0 : catalog.name, data: !isServerSide && rowData, columnDefs: columnDefs, groupingData: groupData, height: `calc(100vh - ${buildEnv ? '139px' : '114px'})`, frameworkComponents: frameworkComponents, hideSearchBar: isServerSide, loading: loading, suppressScrollOnNewData: true, dynamicSizing: dynamicSizing !== null && dynamicSizing !== void 0 ? dynamicSizing : false, disableRowSelection: true, rowModelType: isServerSide ? 'serverSide' : null, serverSideStoreType: isServerSide ? 'partial' : null, cacheOverflowSize: isServerSide ? 2 : null, cacheBlockSize: isServerSide ? 20 : null, maxConcurrentDatasourceRequests: isServerSide ? 1 : null, additionalGridOptions: additionalGridOptions, headerBackgroundColor: headerBackgroundColor }, other)));
};
//# sourceMappingURL=TableContainer.js.map