'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const core = require('./core-859ae5a6.js');
require('./utils-2a7c8f6e.js');
const i18n_provider = require('./i18n.provider-ca81b0a0.js');
const column_renderer = require('./column.renderer-607c4f4e.js');

const Column = class {
    constructor(hostRef) {
        core.registerInstance(this, hostRef);
        /**
         * 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 = column_renderer.FILTER_TYPES;
        /**
         * The property that holds child items for grouping
         */
        this.groupKey = 'items';
        /**
         * Renderer of the column header
         */
        this.headerRenderer = column_renderer.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 column_renderer.ColumnRenderer(this.element);
        if (!this.name) {
            this.name = column_renderer.ColumnRenderer.generateColumnName(this.field, this.caption);
        }
        if (!this.cellRenderer) {
            this.cellRenderer = column_renderer.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 = column_renderer.ColumnRenderer.renderEdit.bind({ translator: this.translator });
            this.editRenderer['isDefault'] = true;
        }
    }
    get element() { return core.getElement(this); }
    static get watchers() { return {
        "translator": ["injectedPropWatcher"]
    }; }
};
i18n_provider.Tunnel.injectProps(Column, ['translator']);

exports.anj_column = Column;
