import { ColumnRenderer, FILTER_TYPES } from './column.renderer';
import Tunnel from '../../locale/i18n.provider';
export class Column {
    constructor() {
        /**
         * The type of data
         */
        this.dataType = 'string';
        /**
         * The default value to use for editing.
         * Can be a static value or a function fitting: (c: Column) => any;
         */
        this.defaultValue = '';
        /**
         * Is the column editable
         */
        this.editable = true;
        /**
         * Is the column filterable
         */
        this.filterable = true;
        /**
         * The types of filtering supported by the column, all other things being equal (ie. boolean data types will only ever filter "equal").
         * Default is: ['contains', 'ends-with', 'equals', 'starts-with'].
         * This can be constrained by passing an array with your chosen subset.
         */
        this.filterTypes = FILTER_TYPES;
        /**
         * The property that holds child items for grouping
         */
        this.groupKey = 'items';
        /**
         * Renderer of the column header
         */
        this.headerRenderer = ColumnRenderer.renderHeader;
        /**
         * Is the column defined by an internal component
         */
        this.internal = false;
        /**
         * Is the column pinnable
         */
        this.pinnable = true;
        /**
         * Is the column pinned
         * Possible values are: `"left"`, `"right"`, `null`.
         */
        this.pinned = null;
        /**
         * Is the column re-orderable by users
         */
        this.orderable = true;
        /**
         * Validation rules for editing.
         * See the anj-validation-rule docs.
         */
        this.rules = [];
        /**
         * Is the column selectable by users
         */
        this.selectable = true;
        /**
         * Is the column re-sizable by users
         */
        this.sizable = true;
        /**
         * Is the column sortable by users
         */
        this.sortable = true;
        /**
         * Width of the column default is auto
         */
        this.width = 'auto';
        /**
         * Is the column visible
         */
        this.visible = true;
    }
    injectedPropWatcher() {
        this.configEditRenderer();
    }
    componentWillLoad() {
        this.renderer = new ColumnRenderer(this.element);
        if (!this.name) {
            this.name = ColumnRenderer.generateColumnName(this.field, this.caption);
        }
        if (!this.cellRenderer) {
            this.cellRenderer = ColumnRenderer.renderCell;
        }
        this.configEditRenderer();
    }
    componentDidLoad() {
        this.table = this.element.closest('anj-table');
    }
    onOptionsLoaded({ target }) {
        this.options = target;
    }
    onValidationRuleLoaded({ target }) {
        this.rules.push(target);
    }
    async contextMenu() {
        return this.renderer.contextMenu();
    }
    async setOffset(offset) {
        return this.renderer.setOffset(offset);
    }
    async setWidth(width) {
        return this.renderer.setWidth(width);
    }
    async initCell(cell, offset) {
        return this.renderer.initCell(cell, offset);
    }
    configEditRenderer() {
        const isDefaultRenderer = this.editRenderer && this.editRenderer['isDefault'];
        if (isDefaultRenderer || !this.editRenderer) {
            this.editRenderer = ColumnRenderer.renderEdit.bind({ translator: this.translator });
            this.editRenderer['isDefault'] = true;
        }
    }
    static get is() { return "anj-column"; }
    static get properties() { return {
        "translator": {
            "type": "unknown",
            "mutable": false,
            "complexType": {
                "original": "IntlFormatFn",
                "resolved": "(value: any, variables?: any) => string",
                "references": {
                    "IntlFormatFn": {
                        "location": "import",
                        "path": "../../locale/i18n.provider"
                    }
                }
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [{
                        "text": undefined,
                        "name": "internal"
                    }],
                "text": ""
            }
        },
        "caption": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "string",
                "resolved": "string",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": "Label for the column, otherwise the name is used"
            },
            "attribute": "caption",
            "reflect": false
        },
        "cellFormatter": {
            "type": "unknown",
            "mutable": false,
            "complexType": {
                "original": "CellFormatter",
                "resolved": "(row: RowData, field: ColumnDefinition, rowIndex?: number) => string",
                "references": {
                    "CellFormatter": {
                        "location": "import",
                        "path": "../table.types"
                    }
                }
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": "Formatter for cell data"
            }
        },
        "cellRenderer": {
            "type": "unknown",
            "mutable": false,
            "complexType": {
                "original": "CellRenderer",
                "resolved": "(row: RowData, field: ColumnDefinition, rowIndex?: number) => any",
                "references": {
                    "CellRenderer": {
                        "location": "import",
                        "path": "../table.types"
                    }
                }
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": "Renderer for cell data"
            }
        },
        "cellTemplate": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "string",
                "resolved": "string",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": "Name of the template to use"
            },
            "attribute": "cell-template",
            "reflect": false
        },
        "dataType": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "DataType",
                "resolved": "\"boolean\" | \"date\" | \"datetime\" | \"number\" | \"string\"",
                "references": {
                    "DataType": {
                        "location": "import",
                        "path": "../table.types"
                    }
                }
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": "The type of data"
            },
            "attribute": "data-type",
            "reflect": false,
            "defaultValue": "'string'"
        },
        "defaultValue": {
            "type": "any",
            "mutable": false,
            "complexType": {
                "original": "any",
                "resolved": "any",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": "The default value to use for editing.\nCan be a static value or a function fitting: (c: Column) => any;"
            },
            "attribute": "default-value",
            "reflect": false,
            "defaultValue": "''"
        },
        "editFormatter": {
            "type": "unknown",
            "mutable": false,
            "complexType": {
                "original": "CellFormatter",
                "resolved": "(row: RowData, field: ColumnDefinition, rowIndex?: number) => string",
                "references": {
                    "CellFormatter": {
                        "location": "import",
                        "path": "../table.types"
                    }
                }
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": "Formatter for cell data when editing"
            }
        },
        "editRenderer": {
            "type": "unknown",
            "mutable": false,
            "complexType": {
                "original": "CellRenderer",
                "resolved": "(row: RowData, field: ColumnDefinition, rowIndex?: number) => any",
                "references": {
                    "CellRenderer": {
                        "location": "import",
                        "path": "../table.types"
                    }
                }
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": "Renderer for cell data when editing"
            }
        },
        "editTemplate": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "string",
                "resolved": "string",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": "Name of the template to use when editing"
            },
            "attribute": "edit-template",
            "reflect": false
        },
        "editable": {
            "type": "boolean",
            "mutable": false,
            "complexType": {
                "original": "boolean",
                "resolved": "boolean",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": "Is the column editable"
            },
            "attribute": "editable",
            "reflect": false,
            "defaultValue": "true"
        },
        "field": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "string | undefined",
                "resolved": "string",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": "Name of the column which pairs it with a property in a row object"
            },
            "attribute": "field",
            "reflect": false
        },
        "filter": {
            "type": "unknown",
            "mutable": false,
            "complexType": {
                "original": "ColumnFilter",
                "resolved": "ColumnFilter",
                "references": {
                    "ColumnFilter": {
                        "location": "import",
                        "path": "../table.types"
                    }
                }
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": "Is the active filter for the column which.\nWill be in { field: string, type: FilterType, query: any } format."
            }
        },
        "filterable": {
            "type": "boolean",
            "mutable": false,
            "complexType": {
                "original": "boolean",
                "resolved": "boolean",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": "Is the column filterable"
            },
            "attribute": "filterable",
            "reflect": false,
            "defaultValue": "true"
        },
        "filterTypes": {
            "type": "unknown",
            "mutable": false,
            "complexType": {
                "original": "FilterType[]",
                "resolved": "FilterType[]",
                "references": {
                    "FilterType": {
                        "location": "import",
                        "path": "../table.types"
                    }
                }
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": "The types of filtering supported by the column, all other things being equal (ie. boolean data types will only ever filter \"equal\").\nDefault is: ['contains', 'ends-with', 'equals', 'starts-with'].\nThis can be constrained by passing an array with your chosen subset."
            },
            "defaultValue": "FILTER_TYPES"
        },
        "groupIndex": {
            "type": "number",
            "mutable": false,
            "complexType": {
                "original": "number | undefined",
                "resolved": "number",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": "Order in which rows should be grouped according to this column"
            },
            "attribute": "group-index",
            "reflect": false
        },
        "groupKey": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "string",
                "resolved": "string",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": "The property that holds child items for grouping"
            },
            "attribute": "group-key",
            "reflect": false,
            "defaultValue": "'items'"
        },
        "groupKeys": {
            "type": "unknown",
            "mutable": false,
            "complexType": {
                "original": "string[]",
                "resolved": "string[]",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": "Array of keys of note for the columns grouping.\nTracks expanded groups for the default behavior, otherwise it tracks collapsed keys."
            }
        },
        "headerFormatter": {
            "type": "unknown",
            "mutable": false,
            "complexType": {
                "original": "ColumnHeaderFormatter",
                "resolved": "(field: string, caption?: string) => string",
                "references": {
                    "ColumnHeaderFormatter": {
                        "location": "import",
                        "path": "../table.types"
                    }
                }
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": "Format of the column header"
            }
        },
        "headerRenderer": {
            "type": "unknown",
            "mutable": false,
            "complexType": {
                "original": "ColumnHeaderRenderer",
                "resolved": "(field: string, caption?: string) => any",
                "references": {
                    "ColumnHeaderRenderer": {
                        "location": "import",
                        "path": "../table.types"
                    }
                }
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": "Renderer of the column header"
            },
            "defaultValue": "ColumnRenderer.renderHeader"
        },
        "index": {
            "type": "number",
            "mutable": false,
            "complexType": {
                "original": "number",
                "resolved": "number",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": "The order the column appears in"
            },
            "attribute": "index",
            "reflect": false
        },
        "internal": {
            "type": "boolean",
            "mutable": false,
            "complexType": {
                "original": "boolean",
                "resolved": "boolean",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": "Is the column defined by an internal component"
            },
            "attribute": "internal",
            "reflect": false,
            "defaultValue": "false"
        },
        "name": {
            "type": "string",
            "mutable": true,
            "complexType": {
                "original": "string",
                "resolved": "string",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": "Name of the column which pairs it with a property in a row object"
            },
            "attribute": "name",
            "reflect": false
        },
        "pinnable": {
            "type": "boolean",
            "mutable": false,
            "complexType": {
                "original": "boolean",
                "resolved": "boolean",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": "Is the column pinnable"
            },
            "attribute": "pinnable",
            "reflect": false,
            "defaultValue": "true"
        },
        "pinned": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "PinnedType",
                "resolved": "\"left\" | \"right\"",
                "references": {
                    "PinnedType": {
                        "location": "import",
                        "path": "../table.types"
                    }
                }
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": "Is the column pinned\nPossible values are: `\"left\"`, `\"right\"`, `null`."
            },
            "attribute": "pinned",
            "reflect": false,
            "defaultValue": "null"
        },
        "options": {
            "type": "unknown",
            "mutable": true,
            "complexType": {
                "original": "OptionsProvider",
                "resolved": "OptionsProvider",
                "references": {
                    "OptionsProvider": {
                        "location": "import",
                        "path": "../table.types"
                    }
                }
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": "Options to display as a select in edit scenarios.\nSee the anj-look up docs for the API."
            }
        },
        "orderable": {
            "type": "boolean",
            "mutable": false,
            "complexType": {
                "original": "boolean",
                "resolved": "boolean",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": "Is the column re-orderable by users"
            },
            "attribute": "orderable",
            "reflect": false,
            "defaultValue": "true"
        },
        "overflow": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "TableOverflow",
                "resolved": "\"all\" | \"cell\" | \"header\"",
                "references": {
                    "TableOverflow": {
                        "location": "import",
                        "path": "../table.types"
                    }
                }
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": "How the column handles overflow of the cell.\nWe truncate with an ellipses by default, but this can be overridden at the \"cell\", \"header\", or both (\"all\") level."
            },
            "attribute": "overflow",
            "reflect": false
        },
        "rules": {
            "type": "unknown",
            "mutable": false,
            "complexType": {
                "original": "ValidationRule[]",
                "resolved": "ValidationRule[]",
                "references": {
                    "ValidationRule": {
                        "location": "import",
                        "path": "../validation-rule/validation-rule"
                    }
                }
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": "Validation rules for editing.\nSee the anj-validation-rule docs."
            },
            "defaultValue": "[]"
        },
        "selectable": {
            "type": "boolean",
            "mutable": false,
            "complexType": {
                "original": "boolean",
                "resolved": "boolean",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": "Is the column selectable by users"
            },
            "attribute": "selectable",
            "reflect": false,
            "defaultValue": "true"
        },
        "sizable": {
            "type": "boolean",
            "mutable": false,
            "complexType": {
                "original": "boolean",
                "resolved": "boolean",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": "Is the column re-sizable by users"
            },
            "attribute": "sizable",
            "reflect": false,
            "defaultValue": "true"
        },
        "sortable": {
            "type": "boolean",
            "mutable": false,
            "complexType": {
                "original": "boolean",
                "resolved": "boolean",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": "Is the column sortable by users"
            },
            "attribute": "sortable",
            "reflect": false,
            "defaultValue": "true"
        },
        "sortIndex": {
            "type": "number",
            "mutable": false,
            "complexType": {
                "original": "number",
                "resolved": "number",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": "Sort priority when using multi-sort"
            },
            "attribute": "sort-index",
            "reflect": false
        },
        "sortOrder": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "SortType",
                "resolved": "\"asc\" | \"desc\"",
                "references": {
                    "SortType": {
                        "location": "import",
                        "path": "../../../utils/data-source/data-source.types"
                    }
                }
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": "Is the column sorted\nPossible values are: `\"asc\"`, `\"desc\"`, `undefined`."
            },
            "attribute": "sort-order",
            "reflect": false
        },
        "span": {
            "type": "number",
            "mutable": false,
            "complexType": {
                "original": "number",
                "resolved": "number",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": "The number of columns to span"
            },
            "attribute": "span",
            "reflect": false
        },
        "table": {
            "type": "unknown",
            "mutable": true,
            "complexType": {
                "original": "HTMLAnjTableElement",
                "resolved": "HTMLAnjTableElement",
                "references": {
                    "HTMLAnjTableElement": {
                        "location": "global"
                    }
                }
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            }
        },
        "width": {
            "type": "string",
            "mutable": true,
            "complexType": {
                "original": "string",
                "resolved": "string",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": "Width of the column default is auto"
            },
            "attribute": "width",
            "reflect": false,
            "defaultValue": "'auto'"
        },
        "visible": {
            "type": "boolean",
            "mutable": false,
            "complexType": {
                "original": "boolean",
                "resolved": "boolean",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": "Is the column visible"
            },
            "attribute": "visible",
            "reflect": false,
            "defaultValue": "true"
        }
    }; }
    static get methods() { return {
        "contextMenu": {
            "complexType": {
                "signature": "() => Promise<HTMLAnjContextMenuItemElement[]>",
                "parameters": [],
                "references": {
                    "Promise": {
                        "location": "global"
                    },
                    "HTMLAnjContextMenuItemElement": {
                        "location": "global"
                    }
                },
                "return": "Promise<HTMLAnjContextMenuItemElement[]>"
            },
            "docs": {
                "text": "",
                "tags": []
            }
        },
        "setOffset": {
            "complexType": {
                "signature": "(offset: string) => Promise<void>",
                "parameters": [{
                        "tags": [],
                        "text": ""
                    }],
                "references": {
                    "Promise": {
                        "location": "global"
                    }
                },
                "return": "Promise<void>"
            },
            "docs": {
                "text": "",
                "tags": []
            }
        },
        "setWidth": {
            "complexType": {
                "signature": "(width: string) => Promise<void>",
                "parameters": [{
                        "tags": [],
                        "text": ""
                    }],
                "references": {
                    "Promise": {
                        "location": "global"
                    }
                },
                "return": "Promise<void>"
            },
            "docs": {
                "text": "",
                "tags": []
            }
        },
        "initCell": {
            "complexType": {
                "signature": "(cell: HTMLElement, offset?: string) => Promise<void>",
                "parameters": [{
                        "tags": [],
                        "text": ""
                    }, {
                        "tags": [],
                        "text": ""
                    }],
                "references": {
                    "Promise": {
                        "location": "global"
                    },
                    "HTMLElement": {
                        "location": "global"
                    }
                },
                "return": "Promise<void>"
            },
            "docs": {
                "text": "",
                "tags": []
            }
        }
    }; }
    static get elementRef() { return "element"; }
    static get watchers() { return [{
            "propName": "translator",
            "methodName": "injectedPropWatcher"
        }]; }
    static get listeners() { return [{
            "name": "anjLookupDidLoad",
            "method": "onOptionsLoaded",
            "target": undefined,
            "capture": false,
            "passive": false
        }, {
            "name": "anjValidationRuleDidLoad",
            "method": "onValidationRuleLoaded",
            "target": undefined,
            "capture": false,
            "passive": false
        }]; }
}
Tunnel.injectProps(Column, ['translator']);
