import { toTitleCase } from '../../utilities/input/StringUtilities';
import { mapDotNetTypeToAgGridType } from './crudHelper';
export const CrudTableColumnDefs = (entityAttributes, actionList) => {
    let columnDefs = (entityAttributes === null || entityAttributes === void 0 ? void 0 : entityAttributes.reduce((defs, element) => {
        var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
        //skip is hidden through maintenance config
        if (((_c = (_b = (_a = element === null || element === void 0 ? void 0 : element.extendedProperties) === null || _a === void 0 ? void 0 : _a.udpFieldProperties) === null || _b === void 0 ? void 0 : _b.maintenanceConfig) === null || _c === void 0 ? void 0 : _c.hidden) === true) {
            return defs;
        }
        //skip if business object key
        if ((element === null || element === void 0 ? void 0 : element.name) === 'businessObjectKey' ||
            (element === null || element === void 0 ? void 0 : element.name) === 'ignoreLoggingTransactions') {
            return defs;
        }
        if (!((_d = element === null || element === void 0 ? void 0 : element.extendedProperties) === null || _d === void 0 ? void 0 : _d.childEntity)) {
            const columnHeader = ((_f = (_e = element === null || element === void 0 ? void 0 : element.extendedProperties) === null || _e === void 0 ? void 0 : _e.udpFieldProperties) === null || _f === void 0 ? void 0 : _f.displayName) ||
                (element === null || element === void 0 ? void 0 : element.name);
            const columnHeaderName = toTitleCase(columnHeader);
            const lookupId = ((_g = element === null || element === void 0 ? void 0 : element.extendedProperties) === null || _g === void 0 ? void 0 : _g.lookup) ||
                ((_k = (_j = (_h = element === null || element === void 0 ? void 0 : element.extendedProperties) === null || _h === void 0 ? void 0 : _h.udpFieldProperties) === null || _j === void 0 ? void 0 : _j.maintainenceConfig) === null || _k === void 0 ? void 0 : _k.lookup);
            let def = {
                headerName: columnHeaderName,
                field: (element === null || element === void 0 ? void 0 : element.name.charAt(0).toLowerCase()) + (element === null || element === void 0 ? void 0 : element.name.slice(1)),
                cellDataType: lookupId
                    ? 'text'
                    : mapDotNetTypeToAgGridType(element === null || element === void 0 ? void 0 : element.type),
                filter: (_l = element === null || element === void 0 ? void 0 : element.extendedProperties) === null || _l === void 0 ? void 0 : _l.searchable,
                sortable: (_m = element === null || element === void 0 ? void 0 : element.extendedProperties) === null || _m === void 0 ? void 0 : _m.orderable,
                hide: (_q = (_p = (_o = element === null || element === void 0 ? void 0 : element.extendedProperties) === null || _o === void 0 ? void 0 : _o.udpFieldProperties) === null || _p === void 0 ? void 0 : _p.maintainenceConfig) === null || _q === void 0 ? void 0 : _q.hidden,
                tooltipField: (element === null || element === void 0 ? void 0 : element.name.charAt(0).toLowerCase()) + (element === null || element === void 0 ? void 0 : element.name.slice(1)),
                context: Object.assign({ lookupId: lookupId }, element)
            };
            defs.push(def);
        }
        return defs;
    }, [])) || [];
    columnDefs.push({
        headerName: 'Actions',
        field: 'actions',
        cellRenderer: 'actionsRenderer',
        cellRendererParams: {
            actionList: actionList
        }
    });
    return columnDefs;
};
//# sourceMappingURL=CrudTableColumnDefs.js.map