"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CustomAgGridOptions = void 0;
var moment_1 = __importDefault(require("moment"));
var ui_internal_1 = require("./../../../utils/ui-internal");
var came_case_1 = require("./../../../utils/came-case");
var select2_cell_editor_1 = __importDefault(require("./editors/select2-cell-editor"));
var number_cell_editor_1 = __importDefault(require("./editors/number-cell-editor"));
var currency_cell_renderer_1 = require("./renderers/currency-cell-renderer");
var enumeration_renderer_1 = __importDefault(require("../../renderers/enumeration-renderer"));
var hyperlink_renderer_1 = __importDefault(require("../../renderers/hyperlink-renderer"));
var button_renderer_1 = __importDefault(require("../../renderers/button-renderer"));
var selection_cell_renderer_1 = __importDefault(require("../../renderers/selection-cell-renderer"));
var many_to_many_tag_renderer_1 = require("../../renderers/many-to-many-tag-renderer");
var tag_renderer_1 = __importDefault(require("../../renderers/tag-renderer"));
var index_1 = require("../../filters/index");
var custom_html_renderer_editor_1 = __importDefault(require("./custom-html-renderer-editor"));
var CustomAgGridOptions = exports.CustomAgGridOptions = (function () {
    function CustomAgGridOptions() {
    }
    CustomAgGridOptions.ColumnTypeDefinitions = function (i18n, numberFloatingFilterDefaultLocale) {
        return {
            "Base": {
                sortable: true,
                resizable: true
            },
            "String": {
                sortable: true,
                resizable: true,
                filter: 'customStringFilter',
                floatingFilterComponent: 'customStringFloatingFilter',
                floatingFilterComponentParams: {
                    suppressFilterButton: true
                },
            },
            "Html": {
                sortable: true,
                resizable: true,
                filter: 'customStringFilter',
                floatingFilterComponent: 'customStringFloatingFilter',
                floatingFilterComponentParams: {
                    suppressFilterButton: true
                },
                cellRenderer: function (data) {
                    if (data.value != null) {
                        return data.value;
                    }
                    return;
                }
            },
            "Number": {
                sortable: true,
                resizable: true,
                filter: 'customNumberFilter',
                floatingFilterComponent: 'customNumberFloatingFilter',
                floatingFilterComponentParams: {
                    suppressFilterButton: true,
                    defaultLocale: numberFloatingFilterDefaultLocale
                },
                cellStyle: { "text-align": "right" },
                valueFormatter: function (params) {
                    var _a;
                    if (((_a = params.data) === null || _a === void 0 ? void 0 : _a[params.colDef.field]) != null) {
                        return (!isNaN(params.data[params.colDef.field])
                            ? new Intl.NumberFormat(numberFloatingFilterDefaultLocale, { minimumFractionDigits: params.colDef.cellRendererParams.minimumFractionDigits, maximumFractionDigits: params.colDef.cellRendererParams.maximumFractionDigits }).format(params.data[params.colDef.field])
                            : params.data[params.colDef.field]);
                    }
                    return;
                },
                cellRendererParams: {
                    minimumFractionDigits: 0,
                    maximumFractionDigits: 2
                }
            },
            "Currency": {
                sortable: true,
                resizable: true,
                filter: 'customNumberFilter',
                floatingFilterComponent: 'customNumberFloatingFilter',
                floatingFilterComponentParams: {
                    suppressFilterButton: true
                },
                cellStyle: { "text-align": "right" },
                cellRenderer: 'currencyCellRenderer'
            },
            "Date": {
                sortable: true,
                resizable: true,
                filter: 'customDateFilter',
                floatingFilterComponent: 'customDateFloatingFilter',
                floatingFilterComponentParams: {
                    suppressFilterButton: true,
                    dateFormat: "DD/MM/YYYY"
                },
                valueFormatter: function (data) {
                    var _a;
                    if (data.value != null) {
                        if (((_a = data.colDef.floatingFilterComponentParams) === null || _a === void 0 ? void 0 : _a.dateFormat) != null) {
                            return (0, moment_1.default)(data.value).format(data.colDef.floatingFilterComponentParams.dateFormat);
                        }
                    }
                    return '';
                }
            },
            "DateTime": {
                sortable: true,
                resizable: true,
                filter: 'customDateFilter',
                floatingFilterComponent: 'customDateFloatingFilter',
                floatingFilterComponentParams: {
                    suppressFilterButton: true,
                    dateFormat: "DD/MM/YYYY HH:mm:ss"
                },
                valueFormatter: function (data) {
                    var _a;
                    if (data.value != null) {
                        if (((_a = data.colDef.floatingFilterComponentParams) === null || _a === void 0 ? void 0 : _a.dateFormat) != null) {
                            return (0, moment_1.default)(data.value).format(data.colDef.floatingFilterComponentParams.dateFormat);
                        }
                    }
                    return '';
                }
            },
            "Boolean": {
                sortable: true,
                resizable: true,
                filter: 'customBooleanFilter',
                floatingFilterComponent: 'customBooleanFloatingFilter',
                floatingFilterComponentParams: {
                    suppressFilterButton: true
                },
                valueGetter: function (data) {
                    if (data.data != null) {
                        var temp = ui_internal_1.UIInternal.getValue(data.data, data.colDef.field);
                        return (temp === true ? i18n.tr("general.yes", { ns: "common" }) : i18n.tr("general.no", { ns: "common" }));
                    }
                    return;
                }
            },
            "Enumeration": {
                sortable: true,
                resizable: true,
                floatingFilter: false,
                filter: 'customEnumerationFilter',
                floatingFilterComponent: 'customEnumerationFloatingFilter',
                floatingFilterComponentParams: {
                    suppressFilterButton: true
                },
                cellRenderer: 'enumerationRenderer'
            },
            "Enum": {
                sortable: true,
                resizable: true,
                filter: 'customEnumFilter',
                floatingFilterComponent: 'customEnumFloatingFilter',
                floatingFilterComponentParams: {
                    suppressFilterButton: true
                },
                valueGetter: function (data) {
                    var _a, _b;
                    if (data.data != null) {
                        var temp = ui_internal_1.UIInternal.getValue(data.data, data.colDef.field);
                        if (((_a = data.data) === null || _a === void 0 ? void 0 : _a[data.colDef.field]) != null && ((_b = data.colDef.floatingFilterComponentParams) === null || _b === void 0 ? void 0 : _b.category) != null) {
                            return i18n.tr(data.colDef.floatingFilterComponentParams.category + "." + came_case_1.CamelCase.toCamelCase(temp));
                        }
                    }
                    return;
                }
            },
            "User": {
                sortable: true,
                resizable: true,
                filter: 'customUserFilter',
                floatingFilterComponent: 'customUserFloatingFilter',
                floatingFilterComponentParams: {
                    suppressFilterButton: true
                }
            },
            "ManyToMany": {
                sortable: false,
                resizable: true,
                filter: 'customManyToManyFilter',
                floatingFilterComponent: 'customManyToManyFloatingFilter',
                floatingFilterComponentParams: {
                    suppressFilterButton: true
                },
                valueGetter: function (data) {
                    var _a;
                    if (data.data != null) {
                        var allFieldPath = data.colDef.field.split('.');
                        var arrayField_1 = (_a = data.colDef.floatingFilterComponentParams.arrayField) !== null && _a !== void 0 ? _a : data.colDef.field.split('.')[0];
                        var arrayIndex = allFieldPath.findIndex(function (x) { return x == arrayField_1; });
                        var fieldPath_1 = allFieldPath.slice(arrayIndex + 1);
                        var arrayName = allFieldPath.slice(0, arrayIndex + 1);
                        var array_1 = data.data;
                        arrayName.forEach(function (x) {
                            if (array_1 != null) {
                                array_1 = array_1[x];
                            }
                        });
                        if (array_1 == null) {
                            return "";
                        }
                        return array_1.map(function (element) {
                            var fieldValue = element;
                            for (var fieldName in fieldPath_1) {
                                if (fieldValue == null)
                                    return '';
                                fieldValue = fieldValue[fieldName];
                            }
                            return fieldValue;
                        }).join(", ");
                    }
                }
            },
            "OneToMany": {
                sortable: true,
                resizable: true,
                filter: 'customOneToManyFilter',
                floatingFilterComponent: 'customOneToManyFloatingFilter',
                floatingFilterComponentParams: {
                    suppressFilterButton: true
                }
            }
        };
    };
    CustomAgGridOptions.Components = {
        'customBooleanFloatingFilter': index_1.BooleanFloatingFilter,
        'customBooleanFilter': index_1.BooleanFilter,
        'customNumberFloatingFilter': index_1.NumberFloatingFilter,
        'customNumberFilter': index_1.NumberFilter,
        'customDateFloatingFilter': index_1.DateFloatingFilter,
        'customDateFilter': index_1.DateFilter,
        'customEnumerationFloatingFilter': index_1.EnumerationFloatingFilter,
        'customEnumerationFilter': index_1.EnumerationFilter,
        'customEnumFloatingFilter': index_1.EnumFloatingFilter,
        'customEnumFilter': index_1.EnumFilter,
        'customStringFloatingFilter': index_1.StringFloatingFilter,
        'customStringFilter': index_1.StringFilter,
        'customUserFloatingFilter': index_1.UserFloatingFilter,
        'customUserFilter': index_1.UserFilter,
        'customManyToManyFloatingFilter': index_1.ManyToManyFloatingFilter,
        'customManyToManyFilter': index_1.ManyToManyFilter,
        'customOneToManyFloatingFilter': index_1.OneToManyFloatingFilter,
        'customOneToManyFilter': index_1.OneToManyFilter,
        'select2CellEditor': select2_cell_editor_1.default,
        'currencyCellRenderer': currency_cell_renderer_1.CurrencyCellRenderer,
        'enumerationRenderer': enumeration_renderer_1.default,
        'numberCellEditor': number_cell_editor_1.default,
        'hyperlinkRenderer': hyperlink_renderer_1.default,
        'buttonRenderer': button_renderer_1.default,
        'manyToManyTagRenderer': many_to_many_tag_renderer_1.ManyToManyTagRenderer,
        'selectionCellRenderer': selection_cell_renderer_1.default,
        'customHtmlRendererEditor': custom_html_renderer_editor_1.default,
        'tagRenderer': tag_renderer_1.default
    };
    return CustomAgGridOptions;
}());

//# sourceMappingURL=custom-ag-grid-options.js.map
