import moment from "moment";
import { UIInternal } from './../../../utils/ui-internal';
import { CamelCase } from './../../../utils/came-case';
import Select2CellEditor from './editors/select2-cell-editor';
import NumberCellEditor from './editors/number-cell-editor';
import { CurrencyCellRenderer } from './renderers/currency-cell-renderer';
import EnumerationRenderer from '../../renderers/enumeration-renderer';
import HyperlinkRenderer from '../../renderers/hyperlink-renderer';
import ButtonRenderer from '../../renderers/button-renderer';
import SelectionCellRenderer from '../../renderers/selection-cell-renderer';
import { ManyToManyTagRenderer } from '../../renderers/many-to-many-tag-renderer';
import TagRenderer from '../../renderers/tag-renderer';
import { StringFilter, BooleanFilter, BooleanFloatingFilter, NumberFilter, NumberFloatingFilter, DateFilter, DateFloatingFilter, EnumerationFilter, EnumerationFloatingFilter, EnumFilter, EnumFloatingFilter, StringFloatingFilter, UserFilter, UserFloatingFilter, ManyToManyFilter, ManyToManyFloatingFilter, OneToManyFilter, OneToManyFloatingFilter } from '../../filters/index';
import CustomHtmlRendererEditor from './custom-html-renderer-editor';
export var 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 moment(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 moment(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 = 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 = 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 + "." + 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': BooleanFloatingFilter,
        'customBooleanFilter': BooleanFilter,
        'customNumberFloatingFilter': NumberFloatingFilter,
        'customNumberFilter': NumberFilter,
        'customDateFloatingFilter': DateFloatingFilter,
        'customDateFilter': DateFilter,
        'customEnumerationFloatingFilter': EnumerationFloatingFilter,
        'customEnumerationFilter': EnumerationFilter,
        'customEnumFloatingFilter': EnumFloatingFilter,
        'customEnumFilter': EnumFilter,
        'customStringFloatingFilter': StringFloatingFilter,
        'customStringFilter': StringFilter,
        'customUserFloatingFilter': UserFloatingFilter,
        'customUserFilter': UserFilter,
        'customManyToManyFloatingFilter': ManyToManyFloatingFilter,
        'customManyToManyFilter': ManyToManyFilter,
        'customOneToManyFloatingFilter': OneToManyFloatingFilter,
        'customOneToManyFilter': OneToManyFilter,
        'select2CellEditor': Select2CellEditor,
        'currencyCellRenderer': CurrencyCellRenderer,
        'enumerationRenderer': EnumerationRenderer,
        'numberCellEditor': NumberCellEditor,
        'hyperlinkRenderer': HyperlinkRenderer,
        'buttonRenderer': ButtonRenderer,
        'manyToManyTagRenderer': ManyToManyTagRenderer,
        'selectionCellRenderer': SelectionCellRenderer,
        'customHtmlRendererEditor': CustomHtmlRendererEditor,
        'tagRenderer': TagRenderer
    };
    return CustomAgGridOptions;
}());

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