/**
 * @license
 * Copyright 2023 Tyler Technologies, Inc. 
 * License: Apache-2.0
 */
import { addClass, removeAllChildren, removeClass } from '@tylertech/forge-core';
import { BaseAdapter } from '../core/base/base-adapter';
import { TABLE_CONSTANTS } from './table-constants';
import { TableUtils } from './table-utils';
/**
 * Provides facilities for interacting with the internal DOM of `TableComponent`.
 */
export class TableAdapter extends BaseAdapter {
    constructor(component) {
        super(component);
    }
    initialize() {
        if (!this._tableElement) {
            this._tableElement = document.createElement('table');
            this._tableElement.classList.add(TABLE_CONSTANTS.classes.TABLE);
            if (this._component.children.length) {
                removeAllChildren(this._component);
            }
            this._component.appendChild(this._tableElement);
        }
    }
    getTableElement() {
        if (!this._tableElement) {
            this.initialize();
        }
        return this._tableElement;
    }
    createTable(configuration) {
        return TableUtils.createTable(configuration);
    }
    recreateTableBody(configuration) {
        TableUtils.recreateTableBody(configuration);
    }
    setSelectedRows(tableElement, key, data, selectedRows, preserveExisting = false) {
        TableUtils.setSelectedRows(tableElement, key, data, selectedRows, preserveExisting);
    }
    clearSelectedRows(tableElement) {
        TableUtils.clearSelectedRows(tableElement);
    }
    updateSelectedState(rowElement, isSelected) {
        TableUtils.updateSelectedState(rowElement, isSelected);
    }
    updateSelectAllState(tableElement, isAllSelected, isIndeterminate) {
        TableUtils.updateSelectAllState(tableElement, isAllSelected, isIndeterminate);
    }
    setSortedColumn(tableElement, columnIndex, sortDirection) {
        TableUtils.setSortedColumn(tableElement, columnIndex, sortDirection);
    }
    removeColumnSort(tableElement, columnIndex) {
        TableUtils.removeColumnSort(tableElement, columnIndex);
    }
    setSortDirection(tableElement, columnIndex, sortDirection) {
        TableUtils.setSortDirection(tableElement, columnIndex, sortDirection);
    }
    setSelectColumnVisibility(tableElement, isVisible, selectListener, selectAllListener, selectAllTemplate, selectCheckboxAlignment, data, tooltipSelect, tooltipSelectAll) {
        TableUtils.setSelectColumnVisibility(tableElement, isVisible, selectListener, selectAllListener || null, selectAllTemplate || null, selectCheckboxAlignment || null, data || [], tooltipSelect || null, tooltipSelectAll || null);
    }
    setDense(tableElement, isDense) {
        TableUtils.setDenseState(tableElement, isDense);
    }
    setRoomy(tableElement, isRoomy) {
        TableUtils.setRoomyState(tableElement, isRoomy);
    }
    setResizable(configuration) {
        TableUtils.setResizable(configuration);
    }
    setSelectAllVisibility(tableElement, isVisible, listener, selectAllTemplate, selectCheckboxAlignment, tooltipSelectAll = null) {
        TableUtils.setSelectAllVisibility(tableElement, isVisible, listener, selectAllTemplate, selectCheckboxAlignment || null, tooltipSelectAll || null);
    }
    setFilterRow(configuration) {
        TableUtils.setFilterRow(configuration);
    }
    expandRow(configuration, rowIndex, template) {
        return TableUtils.expandRow(configuration, rowIndex, template);
    }
    collapseRow(configuration, rowIndex) {
        return TableUtils.collapseRow(configuration, rowIndex);
    }
    isRowExpanded(configuration, rowIndex) {
        return TableUtils.isRowExpanded(configuration, rowIndex);
    }
    setFixedHeaders(configuration) {
        TableUtils.setFixedHeaders(configuration);
    }
    setTableLayoutType(configuration) {
        TableUtils.setLayoutType(configuration);
    }
    setWrapContentState(configuration) {
        TableUtils.setWrapContentState(configuration.tableElement, configuration.wrapContent);
    }
    addDocumentListener(type, listener) {
        TableUtils.getOwnerDocument(this._component).addEventListener(type, listener);
    }
    removeDocumentListener(type, listener) {
        TableUtils.getOwnerDocument(this._component).removeEventListener(type, listener);
    }
    normalizeColumnWidths(configuration) {
        TableUtils.normalizeColumnWidths(configuration);
    }
    setResizeColumnVisibility(configuration, columnIndex, isVisible) {
        TableUtils.setColumnResizeIndicatorVisibility(configuration, columnIndex, isVisible);
    }
    addTableClass(classes) {
        addClass(classes, this._tableElement);
    }
    removeTableClass(classes) {
        removeClass(classes, this._tableElement);
    }
    setRowClickListeners(tableElement, allowClick, clickListener, doubleClickListener) {
        TableUtils.setRowClickListeners(tableElement, allowClick, clickListener, doubleClickListener);
    }
    setRowClickAttributes(tableElement, allowClick) {
        TableUtils.setRowClickAttributes(tableElement, allowClick);
    }
}
