/**
 * @license
 * Copyright 2023 Tyler Technologies, Inc. 
 * License: Apache-2.0
 */
import { __decorate } from "tslib";
import { coerceBoolean, coerceNumber, CustomElement, FoundationProperty } from '@tylertech/forge-core';
import { tylIconArrowDownward } from '@tylertech/tyler-icons/standard';
import { ExpansionPanelComponent } from '../expansion-panel';
import { CheckboxComponent } from '../checkbox';
import { TableAdapter } from './table-adapter';
import { TABLE_CONSTANTS } from './table-constants';
import { TableFoundation } from './table-foundation';
import { IconRegistry, IconComponent } from '../icon';
import { BaseComponent } from '../core/base/base-component';
import { CellAlign } from './types';
/**
 * The custom element class behind the `<forge-table>` component.
 *
 * @tag forge-table
 */
let TableComponent = class TableComponent extends BaseComponent {
    constructor() {
        super();
        IconRegistry.define(tylIconArrowDownward);
        this._foundation = new TableFoundation(new TableAdapter(this));
    }
    static get observedAttributes() {
        return [
            TABLE_CONSTANTS.attributes.SELECT,
            TABLE_CONSTANTS.attributes.MULTISELECT,
            TABLE_CONSTANTS.attributes.SELECT_KEY,
            TABLE_CONSTANTS.attributes.DENSE,
            TABLE_CONSTANTS.attributes.ROOMY,
            TABLE_CONSTANTS.attributes.FILTER,
            TABLE_CONSTANTS.attributes.FIXED_HEADERS,
            TABLE_CONSTANTS.attributes.LAYOUT_TYPE,
            TABLE_CONSTANTS.attributes.WRAP_CONTENT,
            TABLE_CONSTANTS.attributes.RESIZABLE,
            TABLE_CONSTANTS.attributes.MIN_RESIZE_WIDTH,
            TABLE_CONSTANTS.attributes.ALLOW_ROW_CLICK,
            TABLE_CONSTANTS.attributes.MULTI_COLUMN_SORT,
            TABLE_CONSTANTS.attributes.SELECT_CHECKBOX_ALIGNMENT,
            TABLE_CONSTANTS.attributes.TOOLTIP_SELECT,
            TABLE_CONSTANTS.attributes.TOOLTIP_SELECT_ALL
        ];
    }
    initializedCallback() {
        this._foundation.initialize();
    }
    connectedCallback() {
        this._foundation.connect();
    }
    disconnectedCallback() {
        this._foundation.disconnect();
    }
    attributeChangedCallback(name, oldValue, newValue) {
        switch (name) {
            case TABLE_CONSTANTS.attributes.SELECT:
                this.select = coerceBoolean(newValue);
                break;
            case TABLE_CONSTANTS.attributes.MULTISELECT:
                this.multiselect = coerceBoolean(newValue);
                break;
            case TABLE_CONSTANTS.attributes.SELECT_KEY:
                this.selectKey = newValue;
                break;
            case TABLE_CONSTANTS.attributes.DENSE:
                this.dense = coerceBoolean(newValue);
                break;
            case TABLE_CONSTANTS.attributes.ROOMY:
                this.roomy = coerceBoolean(newValue);
                break;
            case TABLE_CONSTANTS.attributes.FILTER:
                this.filter = coerceBoolean(newValue);
                break;
            case TABLE_CONSTANTS.attributes.FIXED_HEADERS:
                this.fixedHeaders = coerceBoolean(newValue);
                break;
            case TABLE_CONSTANTS.attributes.LAYOUT_TYPE:
                this.layoutType = newValue;
                break;
            case TABLE_CONSTANTS.attributes.WRAP_CONTENT:
                this.wrapContent = coerceBoolean(newValue);
                break;
            case TABLE_CONSTANTS.attributes.RESIZABLE:
                this.resizable = coerceBoolean(newValue);
                break;
            case TABLE_CONSTANTS.attributes.MIN_RESIZE_WIDTH:
                this.minResizeWidth = coerceNumber(newValue);
                break;
            case TABLE_CONSTANTS.attributes.ALLOW_ROW_CLICK:
                this.allowRowClick = coerceBoolean(newValue);
                break;
            case TABLE_CONSTANTS.attributes.MULTI_COLUMN_SORT:
                this.multiColumnSort = coerceBoolean(newValue);
                break;
            case TABLE_CONSTANTS.attributes.SELECT_CHECKBOX_ALIGNMENT:
                this.selectCheckboxAlignment = (this.getAttribute(TABLE_CONSTANTS.attributes.SELECT_CHECKBOX_ALIGNMENT) || CellAlign.Center);
                break;
            case TABLE_CONSTANTS.attributes.TOOLTIP_SELECT:
                this.tooltipSelect = newValue;
                break;
            case TABLE_CONSTANTS.attributes.TOOLTIP_SELECT_ALL:
                this.tooltipSelectAll = newValue;
                break;
        }
    }
    /**
     * Hides a column from the table.
     * @param columnIndex The index of the column to hide.
     */
    hideColumn(columnIndex) {
        this._foundation.hideColumn(columnIndex);
    }
    /**
     * Shows a hidden column in th table.
     * @param columnIndex The index of the column to show.
     */
    showColumn(columnIndex) {
        this._foundation.showColumn(columnIndex);
    }
    /**
     * Determines if a column at the given index is hidden or not.
     * @param {number} columnIndex The index of the column.
     * @returns {boolean} `true` if the column is hidden, `false` otherwise.
     */
    isColumnHidden(columnIndex) {
        return this._foundation.isColumnHidden(columnIndex);
    }
    /** Returns the selected row instances. */
    getSelectedRows() {
        return this._foundation.getSelectedRows();
    }
    /**
     * Selects a row in the table. Only applicable if `select` is true.
     * @param data The row data behind the row that should be selected.
     */
    selectRow(data) {
        this._foundation.selectRows([data], false);
    }
    /**
     * Selects one or more rows in the table. Only applicable if `select` is true.
     * @param data The row data begind the rows that should be selected.
     * @param [preserveExisting=false] Should existing row selections be preserved or cleared.
     */
    selectRows(data, preserveExisting = false) {
        this._foundation.selectRows(data, !preserveExisting);
    }
    /**
     * Deselects a single row in the table.
     * @param data The data behind the row that should be deselected.
     */
    deselectRow(data) {
        this._foundation.deselectRows([data]);
    }
    /**
     * Deselects one or more rows in the table.
     * @param data The data behind the rows that should be deselected.
     */
    deselectRows(data) {
        this._foundation.deselectRows(data);
    }
    /**
     * Clears all selected table rows.
     */
    clearSelections() {
        this._foundation.clearSelections();
    }
    /**
     * Forces the table to re-render based on its current configuration.
     */
    render() {
        this._foundation.render();
    }
    /**
     * Expands a collapsed row.
     * @param rowIndex The index of the row to expand.
     */
    expandRow(rowIndex, template) {
        return this._foundation.expandRow(rowIndex, template);
    }
    /**
     * Collapses an expanded row.
     * @param rowIndex The index of the row to expand.
     */
    collapseRow(rowIndex) {
        return this._foundation.collapseRow(rowIndex);
    }
    /**
     * Checks if a row is expanded or not.
     * @param rowIndex The row index to check.
     */
    isRowExpanded(rowIndex) {
        return this._foundation.isRowExpanded(rowIndex);
    }
    /**
     * Selects a rows by an index or array of indexes.
     * @param indexes The row index/indexes to select.
     */
    selectRowsByIndex(indexes, preserveExisting) {
        if (typeof indexes === 'number') {
            this._foundation.selectRowsByIndex([indexes], preserveExisting);
        }
        else if (Array.isArray(indexes)) {
            this._foundation.selectRowsByIndex(indexes, preserveExisting);
        }
    }
    /**
     * Deselects a rows by an index or array of indexes.
     * @param indexes The row index/indexes to deselect
     */
    deselectRowsByIndex(indexes) {
        if (typeof indexes === 'number') {
            this._foundation.deselectRowsByIndex([indexes]);
        }
        else if (Array.isArray(indexes)) {
            this._foundation.deselectRowsByIndex(indexes);
        }
    }
    /**
     * Checks if a row is selected or not.
     * @param rowData The row object data to check.
     */
    isRowSelected(rowData) {
        return this._foundation.isRowSelected(rowData);
    }
};
__decorate([
    FoundationProperty()
], TableComponent.prototype, "data", void 0);
__decorate([
    FoundationProperty()
], TableComponent.prototype, "columnConfigurations", void 0);
__decorate([
    FoundationProperty()
], TableComponent.prototype, "select", void 0);
__decorate([
    FoundationProperty()
], TableComponent.prototype, "multiselect", void 0);
__decorate([
    FoundationProperty()
], TableComponent.prototype, "selectKey", void 0);
__decorate([
    FoundationProperty()
], TableComponent.prototype, "tooltipSelect", void 0);
__decorate([
    FoundationProperty()
], TableComponent.prototype, "tooltipSelectAll", void 0);
__decorate([
    FoundationProperty()
], TableComponent.prototype, "dense", void 0);
__decorate([
    FoundationProperty()
], TableComponent.prototype, "roomy", void 0);
__decorate([
    FoundationProperty()
], TableComponent.prototype, "filter", void 0);
__decorate([
    FoundationProperty()
], TableComponent.prototype, "fixedHeaders", void 0);
__decorate([
    FoundationProperty()
], TableComponent.prototype, "layoutType", void 0);
__decorate([
    FoundationProperty()
], TableComponent.prototype, "wrapContent", void 0);
__decorate([
    FoundationProperty()
], TableComponent.prototype, "resizable", void 0);
__decorate([
    FoundationProperty()
], TableComponent.prototype, "minResizeWidth", void 0);
__decorate([
    FoundationProperty()
], TableComponent.prototype, "allowRowClick", void 0);
__decorate([
    FoundationProperty()
], TableComponent.prototype, "multiColumnSort", void 0);
__decorate([
    FoundationProperty()
], TableComponent.prototype, "rowCreated", void 0);
__decorate([
    FoundationProperty()
], TableComponent.prototype, "cellCreated", void 0);
__decorate([
    FoundationProperty()
], TableComponent.prototype, "selectAllTemplate", void 0);
__decorate([
    FoundationProperty()
], TableComponent.prototype, "selectCheckboxAlignment", void 0);
TableComponent = __decorate([
    CustomElement({
        name: TABLE_CONSTANTS.elementName,
        dependencies: [
            ExpansionPanelComponent,
            IconComponent,
            CheckboxComponent
        ]
    })
], TableComponent);
export { TableComponent };
