import * as i0 from '@angular/core';
import { output, input, booleanAttribute, model, contentChild, inject, signal, computed, ChangeDetectionStrategy, Component } from '@angular/core';
import { NgTemplateOutlet, DatePipe } from '@angular/common';
import { ToggleField } from '@masterteam/components/toggle-field';
import * as i2 from '@angular/forms';
import { FormsModule } from '@angular/forms';
import { Button } from '@masterteam/components/button';
import { TextField } from '@masterteam/components/text-field';
import { SelectField } from '@masterteam/components/select-field';
import { Paginator } from '@masterteam/components/paginator';
import { CheckboxField } from '@masterteam/components/checkbox-field';
import * as i1 from 'primeng/table';
import { TableModule } from 'primeng/table';
import { Tabs } from '@masterteam/components/tabs';
import * as i3 from 'primeng/skeleton';
import { SkeletonModule } from 'primeng/skeleton';
import * as i4 from 'primeng/progressbar';
import { ProgressBarModule } from 'primeng/progressbar';
import { ConfirmationService } from '@masterteam/components/confirmation';
import * as i5 from '@jsverse/transloco';
import { TranslocoModule } from '@jsverse/transloco';

class Table {
    selectionChange = output();
    cellChange = output();
    data = input.required(...(ngDevMode ? [{ debugName: "data" }] : []));
    columns = input.required(...(ngDevMode ? [{ debugName: "columns" }] : []));
    rowActions = input([], ...(ngDevMode ? [{ debugName: "rowActions" }] : []));
    size = input(undefined, ...(ngDevMode ? [{ debugName: "size" }] : []));
    showGridlines = input(false, { ...(ngDevMode ? { debugName: "showGridlines" } : {}), transform: booleanAttribute });
    stripedRows = input(false, { ...(ngDevMode ? { debugName: "stripedRows" } : {}), transform: booleanAttribute });
    selectableRows = input(false, { ...(ngDevMode ? { debugName: "selectableRows" } : {}), transform: booleanAttribute });
    generalSearch = input(false, { ...(ngDevMode ? { debugName: "generalSearch" } : {}), transform: booleanAttribute });
    showFilters = input(false, { ...(ngDevMode ? { debugName: "showFilters" } : {}), transform: booleanAttribute });
    loading = input(false, { ...(ngDevMode ? { debugName: "loading" } : {}), transform: booleanAttribute });
    updating = input(false, { ...(ngDevMode ? { debugName: "updating" } : {}), transform: booleanAttribute });
    // Tabs inputs and outputs
    tabs = input(...(ngDevMode ? [undefined, { debugName: "tabs" }] : []));
    tabsOptionLabel = input(...(ngDevMode ? [undefined, { debugName: "tabsOptionLabel" }] : []));
    tabsOptionValue = input(...(ngDevMode ? [undefined, { debugName: "tabsOptionValue" }] : []));
    activeTab = model(...(ngDevMode ? [undefined, { debugName: "activeTab" }] : []));
    onTabChange = output();
    // Table actions inputs and outputs
    actions = input([], ...(ngDevMode ? [{ debugName: "actions" }] : []));
    // Content TemplateRefs
    captionStartContent = contentChild('captionStart', ...(ngDevMode ? [{ debugName: "captionStartContent" }] : []));
    captionEndContent = contentChild('captionEnd', ...(ngDevMode ? [{ debugName: "captionEndContent" }] : []));
    emptyContent = contentChild('empty', ...(ngDevMode ? [{ debugName: "emptyContent" }] : []));
    paginatorPosition = input('end', ...(ngDevMode ? [{ debugName: "paginatorPosition" }] : []));
    pageSize = model(10, ...(ngDevMode ? [{ debugName: "pageSize" }] : []));
    currentPage = model(0, ...(ngDevMode ? [{ debugName: "currentPage" }] : []));
    first = model(0, ...(ngDevMode ? [{ debugName: "first" }] : []));
    filterTerm = model('', ...(ngDevMode ? [{ debugName: "filterTerm" }] : []));
    confirmationService = inject(ConfirmationService);
    selectedRows = signal(new Set(), ...(ngDevMode ? [{ debugName: "selectedRows" }] : []));
    isFilterPanelOpen = signal(false, ...(ngDevMode ? [{ debugName: "isFilterPanelOpen" }] : []));
    pendingFilters = signal({}, ...(ngDevMode ? [{ debugName: "pendingFilters" }] : []));
    appliedFilters = signal({}, ...(ngDevMode ? [{ debugName: "appliedFilters" }] : []));
    filterableColumns = computed(() => this.columns().filter((col) => !!col.filterConfig), ...(ngDevMode ? [{ debugName: "filterableColumns" }] : []));
    activeFilterCount = computed(() => {
        return Object.values(this.appliedFilters()).filter((value) => value !== null && value !== undefined && value !== '').length;
    }, ...(ngDevMode ? [{ debugName: "activeFilterCount" }] : []));
    filteredData = computed(() => {
        const data = this.data();
        const searchTerm = this.filterTerm().toLowerCase();
        const filters = this.appliedFilters();
        const filterKeys = Object.keys(filters);
        if (searchTerm != '') {
            return data.filter((item) => {
                return Object.values(item).some((value) => {
                    if (typeof value === 'string') {
                        return value.toLowerCase().includes(searchTerm);
                    }
                    return false;
                });
            });
        }
        if (filterKeys.length === 0) {
            return data;
        }
        return data.filter((item) => {
            return filterKeys.every((key) => {
                const filterValue = filters[key];
                const itemValue = this.getProperty(item, key);
                if (filterValue === null ||
                    filterValue === undefined ||
                    filterValue === '') {
                    return true;
                }
                if (typeof itemValue === 'string') {
                    return itemValue
                        .toLowerCase()
                        .includes(String(filterValue).toLowerCase());
                }
                return itemValue === filterValue;
            });
        });
    }, ...(ngDevMode ? [{ debugName: "filteredData" }] : []));
    displayData = computed(() => {
        if (this.loading()) {
            return Array.from({ length: this.pageSize() }, () => ({}));
        }
        return this.filteredData();
    }, ...(ngDevMode ? [{ debugName: "displayData" }] : []));
    totalRecords = computed(() => this.filteredData().length, ...(ngDevMode ? [{ debugName: "totalRecords" }] : []));
    // TODO: remove after updating the toggle and checkbox logic
    paginatedData = computed(() => {
        const data = this.filteredData();
        const first = this.first();
        const pageSize = this.pageSize();
        return data.slice(first, first + pageSize);
    }, ...(ngDevMode ? [{ debugName: "paginatedData" }] : []));
    allSelectedOnPage = computed(() => {
        const pageData = this.paginatedData();
        if (pageData.length === 0)
            return false;
        return pageData.every((row) => this.selectedRows().has(row));
    }, ...(ngDevMode ? [{ debugName: "allSelectedOnPage" }] : []));
    toggleFilterPanel() {
        const isOpen = this.isFilterPanelOpen();
        if (!isOpen) {
            this.pendingFilters.set({ ...this.appliedFilters() });
        }
        this.isFilterPanelOpen.set(!isOpen);
    }
    updatePendingFilter(key, value) {
        if (value === 'true')
            value = true;
        if (value === 'false')
            value = false;
        this.pendingFilters.update((current) => ({ ...current, [key]: value }));
    }
    applyFilters() {
        this.appliedFilters.set({ ...this.pendingFilters() });
        this.first.set(0);
        this.currentPage.set(0);
        this.isFilterPanelOpen.set(false);
    }
    resetFilters() {
        this.pendingFilters.set({});
        this.appliedFilters.set({});
        this.first.set(0);
        this.currentPage.set(0);
        this.isFilterPanelOpen.set(false);
    }
    toggleRow(row) {
        const newSet = new Set(this.selectedRows());
        if (newSet.has(row))
            newSet.delete(row);
        else
            newSet.add(row);
        this.selectedRows.set(newSet);
        this.selectionChange.emit(Array.from(this.selectedRows()));
    }
    toggleAllRowsOnPage() {
        const currentSelection = new Set(this.selectedRows());
        const pageData = this.paginatedData();
        const allSelected = this.allSelectedOnPage();
        if (allSelected) {
            pageData.forEach((row) => currentSelection.delete(row));
        }
        else {
            pageData.forEach((row) => currentSelection.add(row));
        }
        this.selectedRows.set(currentSelection);
        this.selectionChange.emit(Array.from(this.selectedRows()));
    }
    getProperty(obj, key) {
        return key.split('.').reduce((o, i) => (o ? o[i] : undefined), obj);
    }
    tabChanged(tab) {
        this.filterTerm.set('');
        this.first.set(0);
        this.currentPage.set(0);
        this.onTabChange.emit(tab);
    }
    onTablePage(event) {
        console.log('internal page change', event);
        this.first.set(event.first ?? 0);
        this.pageSize.set(event.rows ?? this.pageSize());
        this.currentPage.set(Math.floor((this.first() ?? 0) / (this.pageSize() || 1)));
    }
    onSearchChange(searchTerm) {
        const value = searchTerm.target.value;
        this.filterTerm.set(value);
        this.first.set(0);
        this.currentPage.set(0);
    }
    onCellChange(row, columnKey, newValue, type) {
        row[columnKey] = newValue;
        this.cellChange.emit({
            row,
            column: columnKey,
            value: newValue,
            type: type,
        });
    }
    resolveActionLoading(action, row) {
        if (typeof action.loading === 'function') {
            return action.loading(row);
        }
        return action.loading;
    }
    rowAction(event, action, row) {
        if (!action.confirmation) {
            action.action(row);
        }
        else if (action.confirmation?.confirmationType === 'delete') {
            this.confirmationService.confirmDelete({
                event: event,
                ...action.confirmation,
                accept: () => {
                    action.action(row);
                },
                reject: () => { },
            });
        }
        else {
            this.confirmationService.confirm({
                event: event,
                ...action.confirmation,
                accept: () => {
                    action.action(row);
                },
                reject: () => { },
            });
        }
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: Table, deps: [], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.0.3", type: Table, isStandalone: true, selector: "mt-table", inputs: { data: { classPropertyName: "data", publicName: "data", isSignal: true, isRequired: true, transformFunction: null }, columns: { classPropertyName: "columns", publicName: "columns", isSignal: true, isRequired: true, transformFunction: null }, rowActions: { classPropertyName: "rowActions", publicName: "rowActions", isSignal: true, isRequired: false, transformFunction: null }, size: { classPropertyName: "size", publicName: "size", isSignal: true, isRequired: false, transformFunction: null }, showGridlines: { classPropertyName: "showGridlines", publicName: "showGridlines", isSignal: true, isRequired: false, transformFunction: null }, stripedRows: { classPropertyName: "stripedRows", publicName: "stripedRows", isSignal: true, isRequired: false, transformFunction: null }, selectableRows: { classPropertyName: "selectableRows", publicName: "selectableRows", isSignal: true, isRequired: false, transformFunction: null }, generalSearch: { classPropertyName: "generalSearch", publicName: "generalSearch", isSignal: true, isRequired: false, transformFunction: null }, showFilters: { classPropertyName: "showFilters", publicName: "showFilters", isSignal: true, isRequired: false, transformFunction: null }, loading: { classPropertyName: "loading", publicName: "loading", isSignal: true, isRequired: false, transformFunction: null }, updating: { classPropertyName: "updating", publicName: "updating", isSignal: true, isRequired: false, transformFunction: null }, tabs: { classPropertyName: "tabs", publicName: "tabs", isSignal: true, isRequired: false, transformFunction: null }, tabsOptionLabel: { classPropertyName: "tabsOptionLabel", publicName: "tabsOptionLabel", isSignal: true, isRequired: false, transformFunction: null }, tabsOptionValue: { classPropertyName: "tabsOptionValue", publicName: "tabsOptionValue", isSignal: true, isRequired: false, transformFunction: null }, activeTab: { classPropertyName: "activeTab", publicName: "activeTab", isSignal: true, isRequired: false, transformFunction: null }, actions: { classPropertyName: "actions", publicName: "actions", isSignal: true, isRequired: false, transformFunction: null }, paginatorPosition: { classPropertyName: "paginatorPosition", publicName: "paginatorPosition", isSignal: true, isRequired: false, transformFunction: null }, pageSize: { classPropertyName: "pageSize", publicName: "pageSize", isSignal: true, isRequired: false, transformFunction: null }, currentPage: { classPropertyName: "currentPage", publicName: "currentPage", isSignal: true, isRequired: false, transformFunction: null }, first: { classPropertyName: "first", publicName: "first", isSignal: true, isRequired: false, transformFunction: null }, filterTerm: { classPropertyName: "filterTerm", publicName: "filterTerm", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { selectionChange: "selectionChange", cellChange: "cellChange", activeTab: "activeTabChange", onTabChange: "onTabChange", pageSize: "pageSizeChange", currentPage: "currentPageChange", first: "firstChange", filterTerm: "filterTermChange" }, queries: [{ propertyName: "captionStartContent", first: true, predicate: ["captionStart"], descendants: true, isSignal: true }, { propertyName: "captionEndContent", first: true, predicate: ["captionEnd"], descendants: true, isSignal: true }, { propertyName: "emptyContent", first: true, predicate: ["empty"], descendants: true, isSignal: true }], ngImport: i0, template: "<div class=\"space-y-4 rounded-2xl\">\n  <div>\n    @if (\n      captionStartContent() ||\n      captionEndContent() ||\n      generalSearch() ||\n      showFilters() ||\n      tabs()?.length > 0 ||\n      actions()?.length > 0\n    ) {\n      <div class=\"p-datatable-header rounded-t-2xl\">\n        <div\n          class=\"flex relative\"\n          [class]=\"!generalSearch() ? 'justify-end' : 'justify-between'\"\n        >\n          <div class=\"flex items-center gap-2\">\n            <ng-container\n              *ngTemplateOutlet=\"captionStartContent()\"\n            ></ng-container>\n            @if (tabs()) {\n              <mt-tabs\n                [(active)]=\"activeTab\"\n                [options]=\"tabs()\"\n                [optionLabel]=\"tabsOptionLabel()\"\n                [optionValue]=\"tabsOptionValue()\"\n                (onChange)=\"tabChanged($event)\"\n                size=\"large\"\n              ></mt-tabs>\n            }\n            @if (generalSearch()) {\n              <mt-text-field\n                [(ngModel)]=\"filterTerm\"\n                (change)=\"onSearchChange($event)\"\n                icon=\"general.search-lg\"\n                [placeholder]=\"'components.table.search' | transloco\"\n              ></mt-text-field>\n            }\n          </div>\n          <div class=\"flex items-center gap-2\">\n            @if (showFilters()) {\n              <mt-button\n                variant=\"outline\"\n                (click)=\"toggleFilterPanel()\"\n                [label]=\"'components.table.filter' | transloco\"\n                [badge]=\"activeFilterCount()\"\n                icon=\"general.filter-funnel-01\"\n              >\n              </mt-button>\n              @if (isFilterPanelOpen()) {\n                <div\n                  class=\"absolute top-full end-0 z-10 mt-2 w-72 origin-top-right rounded-md bg-content shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none\"\n                  role=\"menu\"\n                >\n                  <div class=\"p-4\">\n                    <h3 class=\"text-base font-semibold\">\n                      {{ \"components.table.filterOptions\" | transloco }}\n                    </h3>\n                  </div>\n                  <div\n                    class=\"border-t border-surface-300 dark:border-surface-500 p-4 space-y-4\"\n                  >\n                    @for (col of filterableColumns(); track col.key) {\n                      <div class=\"space-y-1\">\n                        <label class=\"block text-sm font-medium\">\n                          {{ col.filterConfig?.label }}\n                        </label>\n                        @switch (col.filterConfig?.type) {\n                          @case (\"text\") {\n                            <mt-text-field\n                              [(ngModel)]=\"pendingFilters()[col.key]\"\n                              (ngModelChange)=\"\n                                updatePendingFilter(col.key, $event)\n                              \"\n                            ></mt-text-field>\n                          }\n                          @case (\"select\") {\n                            <mt-select-field\n                              [(ngModel)]=\"pendingFilters()[col.key]\"\n                              (ngModelChange)=\"\n                                updatePendingFilter(col.key, $event)\n                              \"\n                              [options]=\"col.filterConfig?.options\"\n                              [hasPlaceholderPrefix]=\"false\"\n                              [placeholder]=\"\n                                ('components.table.select' | transloco) +\n                                ' ' +\n                                col.filterConfig?.label\n                              \"\n                              showClear\n                            ></mt-select-field>\n                          }\n                        }\n                      </div>\n                    }\n                  </div>\n                  <div\n                    class=\"flex items-center justify-end space-x-2 border-t border-surface-300 dark:border-surface-500 bg-surface-50 dark:bg-surface-950 p-4 rounded-b-md\"\n                  >\n                    <mt-button\n                      variant=\"outlined\"\n                      (click)=\"resetFilters()\"\n                      [label]=\"'components.table.reset' | transloco\"\n                    />\n                    <mt-button\n                      (click)=\"applyFilters()\"\n                      [label]=\"'components.table.apply' | transloco\"\n                    />\n                  </div>\n                </div>\n              }\n            }\n            @if (actions()?.length > 0) {\n              <div class=\"flex items-center space-x-2\">\n                @for (action of actions(); track action.label) {\n                  <mt-button\n                    [icon]=\"action.icon\"\n                    [severity]=\"action.color\"\n                    [variant]=\"action.variant\"\n                    [size]=\"action.size\"\n                    (click)=\"action.action(row)\"\n                    [label]=\"action.label\"\n                    [tooltip]=\"action.tooltip\"\n                  ></mt-button>\n                }\n              </div>\n            }\n            <ng-container\n              *ngTemplateOutlet=\"captionEndContent()\"\n            ></ng-container>\n          </div>\n        </div>\n      </div>\n    }\n    @if (!loading() && emptyContent() && data().length === 0) {\n      <div\n        class=\"p-4 bg-content rounded-md text-center text-gray-600 dark:text-gray-300\"\n      >\n        <ng-container *ngTemplateOutlet=\"emptyContent()\"></ng-container>\n      </div>\n    } @else {\n      <div class=\"overflow-x-auto bg-content\">\n        <p-table\n          [value]=\"displayData()\"\n          [columns]=\"columns()\"\n          [size]=\"size()\"\n          [showGridlines]=\"showGridlines()\"\n          [stripedRows]=\"stripedRows()\"\n          [first]=\"first()\"\n          [rows]=\"pageSize()\"\n          (onPage)=\"onTablePage($event)\"\n          paginator\n          paginatorStyleClass=\"hidden!\"\n          class=\"min-w-full text-sm align-middle table-fixed\"\n        >\n          <ng-template\n            #header\n            let-columns\n            class=\"bg-surface-50 dark:bg-surface-950 border-b border-surface-300 dark:border-surface-500\"\n          >\n            <tr>\n              @if (selectableRows()) {\n                <th class=\"w-12 text-start\">\n                  <mt-checkbox-field\n                    [ngModel]=\"allSelectedOnPage()\"\n                    (ngModelChange)=\"toggleAllRowsOnPage()\"\n                  ></mt-checkbox-field>\n                </th>\n              }\n\n              @for (col of columns; track col.key) {\n                <th\n                  class=\"text-start font-semibold text-gray-600 dark:text-gray-50 uppercase tracking-wider\"\n                >\n                  {{ col.label }}\n                </th>\n              }\n\n              @if (rowActions().length > 0) {\n                <th\n                  class=\"text-end! font-semibold text-gray-600 dark:text-gray-50 uppercase tracking-wider\"\n                >\n                  Actions\n                </th>\n              }\n            </tr>\n            @if (updating()) {\n              <tr>\n                <th\n                  [attr.colspan]=\"\n                    columns.length +\n                    (selectableRows() ? 1 : 0) +\n                    (rowActions().length > 0 ? 1 : 0)\n                  \"\n                  class=\"!p-0\"\n                >\n                  <p-progressBar\n                    mode=\"indeterminate\"\n                    [style]=\"{ height: '4px' }\"\n                  />\n                </th>\n              </tr>\n            }\n          </ng-template>\n          <ng-template\n            #body\n            let-row\n            let-columns=\"columns\"\n            class=\"divide-y divide-gray-200\"\n          >\n            @if (loading()) {\n              <tr>\n                @if (selectableRows()) {\n                  <td><p-skeleton /></td>\n                }\n                @for (col of columns; track col.key) {\n                  <td><p-skeleton /></td>\n                }\n                @if (rowActions().length > 0) {\n                  <td><p-skeleton /></td>\n                }\n              </tr>\n            } @else {\n              <tr\n                class=\"hover:bg-gray-50 dark:hover:bg-surface-950 border-surface-300 dark:border-surface-500\"\n              >\n                @if (selectableRows()) {\n                  <td class=\"w-12\">\n                    <mt-checkbox-field\n                      [ngModel]=\"selectedRows().has(row)\"\n                      (ngModelChange)=\"toggleRow(row)\"\n                    ></mt-checkbox-field>\n                  </td>\n                }\n\n                @for (col of columns; track col.key) {\n                  <td class=\"text-gray-700 dark:text-gray-100\">\n                    @switch (col.type) {\n                      @case (\"boolean\") {\n                        <mt-toggle-field\n                          [(ngModel)]=\"row[col.key]\"\n                          (ngModelChange)=\"\n                            onCellChange(row, col.key, $event, 'boolean')\n                          \"\n                        ></mt-toggle-field>\n                      }\n                      @case (\"date\") {\n                        {{ getProperty(row, col.key) | date: \"mediumDate\" }}\n                      }\n                      @case (\"custom\") {\n                        <ng-container\n                          *ngTemplateOutlet=\"\n                            col.customCellTpl;\n                            context: { $implicit: row }\n                          \"\n                        >\n                        </ng-container>\n                      }\n                      @default {\n                        {{ getProperty(row, col.key) }}\n                      }\n                    }\n                  </td>\n                }\n\n                @if (rowActions().length > 0) {\n                  <td class=\"text-right\">\n                    <div class=\"flex items-center justify-end space-x-2\">\n                      @for (action of rowActions(); track action.label) {\n                        @let hidden = action.hidden?.(row);\n                        @if (!hidden) {\n                          <mt-button\n                            [icon]=\"action.icon\"\n                            [severity]=\"action.color\"\n                            [variant]=\"action.variant\"\n                            [size]=\"action.size || 'small'\"\n                            (click)=\"rowAction($event, action, row)\"\n                            [tooltip]=\"action.tooltip\"\n                            [label]=\"action.label\"\n                            [loading]=\"resolveActionLoading(action, row)\"\n                          ></mt-button>\n                        }\n                      }\n                    </div>\n                  </td>\n                }\n              </tr>\n            }\n          </ng-template>\n          <ng-template #emptymessage>\n            <tr>\n              <td colspan=\"20\" class=\"text-center\">\n                <div class=\"flex justify-center\">No data found.</div>\n              </td>\n            </tr>\n          </ng-template>\n        </p-table>\n      </div>\n    }\n  </div>\n\n  <div\n    class=\"flex flex-col gap-3 pb-3 px-4\"\n    [class]=\"'items-' + paginatorPosition()\"\n  >\n    <mt-paginator\n      [(rows)]=\"pageSize\"\n      [(first)]=\"first\"\n      [(page)]=\"currentPage\"\n      [totalRecords]=\"totalRecords()\"\n      [alwaysShow]=\"false\"\n      [rowsPerPageOptions]=\"[5, 10, 20, 50]\"\n    ></mt-paginator>\n  </div>\n</div>\n", styles: [""], dependencies: [{ kind: "ngmodule", type: TableModule }, { kind: "component", type: i1.Table, selector: "p-table", inputs: ["frozenColumns", "frozenValue", "styleClass", "tableStyle", "tableStyleClass", "paginator", "pageLinks", "rowsPerPageOptions", "alwaysShowPaginator", "paginatorPosition", "paginatorStyleClass", "paginatorDropdownAppendTo", "paginatorDropdownScrollHeight", "currentPageReportTemplate", "showCurrentPageReport", "showJumpToPageDropdown", "showJumpToPageInput", "showFirstLastIcon", "showPageLinks", "defaultSortOrder", "sortMode", "resetPageOnSort", "selectionMode", "selectionPageOnly", "contextMenuSelection", "contextMenuSelectionMode", "dataKey", "metaKeySelection", "rowSelectable", "rowTrackBy", "lazy", "lazyLoadOnInit", "compareSelectionBy", "csvSeparator", "exportFilename", "filters", "globalFilterFields", "filterDelay", "filterLocale", "expandedRowKeys", "editingRowKeys", "rowExpandMode", "scrollable", "rowGroupMode", "scrollHeight", "virtualScroll", "virtualScrollItemSize", "virtualScrollOptions", "virtualScrollDelay", "frozenWidth", "contextMenu", "resizableColumns", "columnResizeMode", "reorderableColumns", "loading", "loadingIcon", "showLoader", "rowHover", "customSort", "showInitialSortBadge", "exportFunction", "exportHeader", "stateKey", "stateStorage", "editMode", "groupRowsBy", "size", "showGridlines", "stripedRows", "groupRowsByOrder", "responsiveLayout", "breakpoint", "paginatorLocale", "value", "columns", "first", "rows", "totalRecords", "sortField", "sortOrder", "multiSortMeta", "selection", "selectAll"], outputs: ["contextMenuSelectionChange", "selectAllChange", "selectionChange", "onRowSelect", "onRowUnselect", "onPage", "onSort", "onFilter", "onLazyLoad", "onRowExpand", "onRowCollapse", "onContextMenuSelect", "onColResize", "onColReorder", "onRowReorder", "onEditInit", "onEditComplete", "onEditCancel", "onHeaderCheckboxToggle", "sortFunction", "firstChange", "rowsChange", "onStateSave", "onStateRestore"] }, { kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "component", type: ToggleField, selector: "mt-toggle-field", inputs: ["label", "labelPosition", "placeholder", "readonly", "pInputs", "required"], outputs: ["onChange"] }, { kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i2.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i2.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "component", type: Button, selector: "mt-button", inputs: ["icon", "label", "tooltip", "class", "type", "styleClass", "severity", "badge", "variant", "badgeSeverity", "size", "iconPos", "autofocus", "fluid", "raised", "rounded", "text", "plain", "outlined", "link", "disabled", "loading", "pInputs"], outputs: ["onClick", "onFocus", "onBlur"] }, { kind: "component", type: TextField, selector: "mt-text-field", inputs: ["field", "hint", "label", "placeholder", "class", "type", "readonly", "pInputs", "required", "icon", "iconPosition"] }, { kind: "component", type: SelectField, selector: "mt-select-field", inputs: ["field", "label", "placeholder", "hasPlaceholderPrefix", "class", "readonly", "pInputs", "options", "optionValue", "optionLabel", "filter", "filterBy", "dataKey", "showClear", "clearAfterSelect", "required", "group", "optionGroupLabel", "optionGroupChildren", "loading"], outputs: ["onChange"] }, { kind: "component", type: Paginator, selector: "mt-paginator", inputs: ["rows", "totalRecords", "first", "page", "rowsPerPageOptions", "showFirstLastIcon", "showCurrentPageReport", "fluid", "pageLinkSize", "alwaysShow"], outputs: ["rowsChange", "firstChange", "pageChange", "onPageChange"] }, { kind: "component", type: CheckboxField, selector: "mt-checkbox-field", inputs: ["label", "labelPosition", "placeholder", "readonly", "pInputs", "required"], outputs: ["onChange"] }, { kind: "component", type: Tabs, selector: "mt-tabs", inputs: ["options", "optionLabel", "optionValue", "active", "size", "fluid", "disabled"], outputs: ["activeChange", "onChange"] }, { kind: "ngmodule", type: SkeletonModule }, { kind: "component", type: i3.Skeleton, selector: "p-skeleton", inputs: ["styleClass", "shape", "animation", "borderRadius", "size", "width", "height"] }, { kind: "ngmodule", type: ProgressBarModule }, { kind: "component", type: i4.ProgressBar, selector: "p-progressBar, p-progressbar, p-progress-bar", inputs: ["value", "showValue", "styleClass", "valueStyleClass", "unit", "mode", "color"] }, { kind: "ngmodule", type: TranslocoModule }, { kind: "pipe", type: DatePipe, name: "date" }, { kind: "pipe", type: i5.TranslocoPipe, name: "transloco" }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: Table, decorators: [{
            type: Component,
            args: [{ selector: 'mt-table', standalone: true, imports: [
                        TableModule,
                        NgTemplateOutlet,
                        DatePipe,
                        ToggleField,
                        FormsModule,
                        Button,
                        TextField,
                        SelectField,
                        Paginator,
                        CheckboxField,
                        Tabs,
                        SkeletonModule,
                        ProgressBarModule,
                        TranslocoModule,
                    ], changeDetection: ChangeDetectionStrategy.OnPush, template: "<div class=\"space-y-4 rounded-2xl\">\n  <div>\n    @if (\n      captionStartContent() ||\n      captionEndContent() ||\n      generalSearch() ||\n      showFilters() ||\n      tabs()?.length > 0 ||\n      actions()?.length > 0\n    ) {\n      <div class=\"p-datatable-header rounded-t-2xl\">\n        <div\n          class=\"flex relative\"\n          [class]=\"!generalSearch() ? 'justify-end' : 'justify-between'\"\n        >\n          <div class=\"flex items-center gap-2\">\n            <ng-container\n              *ngTemplateOutlet=\"captionStartContent()\"\n            ></ng-container>\n            @if (tabs()) {\n              <mt-tabs\n                [(active)]=\"activeTab\"\n                [options]=\"tabs()\"\n                [optionLabel]=\"tabsOptionLabel()\"\n                [optionValue]=\"tabsOptionValue()\"\n                (onChange)=\"tabChanged($event)\"\n                size=\"large\"\n              ></mt-tabs>\n            }\n            @if (generalSearch()) {\n              <mt-text-field\n                [(ngModel)]=\"filterTerm\"\n                (change)=\"onSearchChange($event)\"\n                icon=\"general.search-lg\"\n                [placeholder]=\"'components.table.search' | transloco\"\n              ></mt-text-field>\n            }\n          </div>\n          <div class=\"flex items-center gap-2\">\n            @if (showFilters()) {\n              <mt-button\n                variant=\"outline\"\n                (click)=\"toggleFilterPanel()\"\n                [label]=\"'components.table.filter' | transloco\"\n                [badge]=\"activeFilterCount()\"\n                icon=\"general.filter-funnel-01\"\n              >\n              </mt-button>\n              @if (isFilterPanelOpen()) {\n                <div\n                  class=\"absolute top-full end-0 z-10 mt-2 w-72 origin-top-right rounded-md bg-content shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none\"\n                  role=\"menu\"\n                >\n                  <div class=\"p-4\">\n                    <h3 class=\"text-base font-semibold\">\n                      {{ \"components.table.filterOptions\" | transloco }}\n                    </h3>\n                  </div>\n                  <div\n                    class=\"border-t border-surface-300 dark:border-surface-500 p-4 space-y-4\"\n                  >\n                    @for (col of filterableColumns(); track col.key) {\n                      <div class=\"space-y-1\">\n                        <label class=\"block text-sm font-medium\">\n                          {{ col.filterConfig?.label }}\n                        </label>\n                        @switch (col.filterConfig?.type) {\n                          @case (\"text\") {\n                            <mt-text-field\n                              [(ngModel)]=\"pendingFilters()[col.key]\"\n                              (ngModelChange)=\"\n                                updatePendingFilter(col.key, $event)\n                              \"\n                            ></mt-text-field>\n                          }\n                          @case (\"select\") {\n                            <mt-select-field\n                              [(ngModel)]=\"pendingFilters()[col.key]\"\n                              (ngModelChange)=\"\n                                updatePendingFilter(col.key, $event)\n                              \"\n                              [options]=\"col.filterConfig?.options\"\n                              [hasPlaceholderPrefix]=\"false\"\n                              [placeholder]=\"\n                                ('components.table.select' | transloco) +\n                                ' ' +\n                                col.filterConfig?.label\n                              \"\n                              showClear\n                            ></mt-select-field>\n                          }\n                        }\n                      </div>\n                    }\n                  </div>\n                  <div\n                    class=\"flex items-center justify-end space-x-2 border-t border-surface-300 dark:border-surface-500 bg-surface-50 dark:bg-surface-950 p-4 rounded-b-md\"\n                  >\n                    <mt-button\n                      variant=\"outlined\"\n                      (click)=\"resetFilters()\"\n                      [label]=\"'components.table.reset' | transloco\"\n                    />\n                    <mt-button\n                      (click)=\"applyFilters()\"\n                      [label]=\"'components.table.apply' | transloco\"\n                    />\n                  </div>\n                </div>\n              }\n            }\n            @if (actions()?.length > 0) {\n              <div class=\"flex items-center space-x-2\">\n                @for (action of actions(); track action.label) {\n                  <mt-button\n                    [icon]=\"action.icon\"\n                    [severity]=\"action.color\"\n                    [variant]=\"action.variant\"\n                    [size]=\"action.size\"\n                    (click)=\"action.action(row)\"\n                    [label]=\"action.label\"\n                    [tooltip]=\"action.tooltip\"\n                  ></mt-button>\n                }\n              </div>\n            }\n            <ng-container\n              *ngTemplateOutlet=\"captionEndContent()\"\n            ></ng-container>\n          </div>\n        </div>\n      </div>\n    }\n    @if (!loading() && emptyContent() && data().length === 0) {\n      <div\n        class=\"p-4 bg-content rounded-md text-center text-gray-600 dark:text-gray-300\"\n      >\n        <ng-container *ngTemplateOutlet=\"emptyContent()\"></ng-container>\n      </div>\n    } @else {\n      <div class=\"overflow-x-auto bg-content\">\n        <p-table\n          [value]=\"displayData()\"\n          [columns]=\"columns()\"\n          [size]=\"size()\"\n          [showGridlines]=\"showGridlines()\"\n          [stripedRows]=\"stripedRows()\"\n          [first]=\"first()\"\n          [rows]=\"pageSize()\"\n          (onPage)=\"onTablePage($event)\"\n          paginator\n          paginatorStyleClass=\"hidden!\"\n          class=\"min-w-full text-sm align-middle table-fixed\"\n        >\n          <ng-template\n            #header\n            let-columns\n            class=\"bg-surface-50 dark:bg-surface-950 border-b border-surface-300 dark:border-surface-500\"\n          >\n            <tr>\n              @if (selectableRows()) {\n                <th class=\"w-12 text-start\">\n                  <mt-checkbox-field\n                    [ngModel]=\"allSelectedOnPage()\"\n                    (ngModelChange)=\"toggleAllRowsOnPage()\"\n                  ></mt-checkbox-field>\n                </th>\n              }\n\n              @for (col of columns; track col.key) {\n                <th\n                  class=\"text-start font-semibold text-gray-600 dark:text-gray-50 uppercase tracking-wider\"\n                >\n                  {{ col.label }}\n                </th>\n              }\n\n              @if (rowActions().length > 0) {\n                <th\n                  class=\"text-end! font-semibold text-gray-600 dark:text-gray-50 uppercase tracking-wider\"\n                >\n                  Actions\n                </th>\n              }\n            </tr>\n            @if (updating()) {\n              <tr>\n                <th\n                  [attr.colspan]=\"\n                    columns.length +\n                    (selectableRows() ? 1 : 0) +\n                    (rowActions().length > 0 ? 1 : 0)\n                  \"\n                  class=\"!p-0\"\n                >\n                  <p-progressBar\n                    mode=\"indeterminate\"\n                    [style]=\"{ height: '4px' }\"\n                  />\n                </th>\n              </tr>\n            }\n          </ng-template>\n          <ng-template\n            #body\n            let-row\n            let-columns=\"columns\"\n            class=\"divide-y divide-gray-200\"\n          >\n            @if (loading()) {\n              <tr>\n                @if (selectableRows()) {\n                  <td><p-skeleton /></td>\n                }\n                @for (col of columns; track col.key) {\n                  <td><p-skeleton /></td>\n                }\n                @if (rowActions().length > 0) {\n                  <td><p-skeleton /></td>\n                }\n              </tr>\n            } @else {\n              <tr\n                class=\"hover:bg-gray-50 dark:hover:bg-surface-950 border-surface-300 dark:border-surface-500\"\n              >\n                @if (selectableRows()) {\n                  <td class=\"w-12\">\n                    <mt-checkbox-field\n                      [ngModel]=\"selectedRows().has(row)\"\n                      (ngModelChange)=\"toggleRow(row)\"\n                    ></mt-checkbox-field>\n                  </td>\n                }\n\n                @for (col of columns; track col.key) {\n                  <td class=\"text-gray-700 dark:text-gray-100\">\n                    @switch (col.type) {\n                      @case (\"boolean\") {\n                        <mt-toggle-field\n                          [(ngModel)]=\"row[col.key]\"\n                          (ngModelChange)=\"\n                            onCellChange(row, col.key, $event, 'boolean')\n                          \"\n                        ></mt-toggle-field>\n                      }\n                      @case (\"date\") {\n                        {{ getProperty(row, col.key) | date: \"mediumDate\" }}\n                      }\n                      @case (\"custom\") {\n                        <ng-container\n                          *ngTemplateOutlet=\"\n                            col.customCellTpl;\n                            context: { $implicit: row }\n                          \"\n                        >\n                        </ng-container>\n                      }\n                      @default {\n                        {{ getProperty(row, col.key) }}\n                      }\n                    }\n                  </td>\n                }\n\n                @if (rowActions().length > 0) {\n                  <td class=\"text-right\">\n                    <div class=\"flex items-center justify-end space-x-2\">\n                      @for (action of rowActions(); track action.label) {\n                        @let hidden = action.hidden?.(row);\n                        @if (!hidden) {\n                          <mt-button\n                            [icon]=\"action.icon\"\n                            [severity]=\"action.color\"\n                            [variant]=\"action.variant\"\n                            [size]=\"action.size || 'small'\"\n                            (click)=\"rowAction($event, action, row)\"\n                            [tooltip]=\"action.tooltip\"\n                            [label]=\"action.label\"\n                            [loading]=\"resolveActionLoading(action, row)\"\n                          ></mt-button>\n                        }\n                      }\n                    </div>\n                  </td>\n                }\n              </tr>\n            }\n          </ng-template>\n          <ng-template #emptymessage>\n            <tr>\n              <td colspan=\"20\" class=\"text-center\">\n                <div class=\"flex justify-center\">No data found.</div>\n              </td>\n            </tr>\n          </ng-template>\n        </p-table>\n      </div>\n    }\n  </div>\n\n  <div\n    class=\"flex flex-col gap-3 pb-3 px-4\"\n    [class]=\"'items-' + paginatorPosition()\"\n  >\n    <mt-paginator\n      [(rows)]=\"pageSize\"\n      [(first)]=\"first\"\n      [(page)]=\"currentPage\"\n      [totalRecords]=\"totalRecords()\"\n      [alwaysShow]=\"false\"\n      [rowsPerPageOptions]=\"[5, 10, 20, 50]\"\n    ></mt-paginator>\n  </div>\n</div>\n" }]
        }], propDecorators: { selectionChange: [{ type: i0.Output, args: ["selectionChange"] }], cellChange: [{ type: i0.Output, args: ["cellChange"] }], data: [{ type: i0.Input, args: [{ isSignal: true, alias: "data", required: true }] }], columns: [{ type: i0.Input, args: [{ isSignal: true, alias: "columns", required: true }] }], rowActions: [{ type: i0.Input, args: [{ isSignal: true, alias: "rowActions", required: false }] }], size: [{ type: i0.Input, args: [{ isSignal: true, alias: "size", required: false }] }], showGridlines: [{ type: i0.Input, args: [{ isSignal: true, alias: "showGridlines", required: false }] }], stripedRows: [{ type: i0.Input, args: [{ isSignal: true, alias: "stripedRows", required: false }] }], selectableRows: [{ type: i0.Input, args: [{ isSignal: true, alias: "selectableRows", required: false }] }], generalSearch: [{ type: i0.Input, args: [{ isSignal: true, alias: "generalSearch", required: false }] }], showFilters: [{ type: i0.Input, args: [{ isSignal: true, alias: "showFilters", required: false }] }], loading: [{ type: i0.Input, args: [{ isSignal: true, alias: "loading", required: false }] }], updating: [{ type: i0.Input, args: [{ isSignal: true, alias: "updating", required: false }] }], tabs: [{ type: i0.Input, args: [{ isSignal: true, alias: "tabs", required: false }] }], tabsOptionLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "tabsOptionLabel", required: false }] }], tabsOptionValue: [{ type: i0.Input, args: [{ isSignal: true, alias: "tabsOptionValue", required: false }] }], activeTab: [{ type: i0.Input, args: [{ isSignal: true, alias: "activeTab", required: false }] }, { type: i0.Output, args: ["activeTabChange"] }], onTabChange: [{ type: i0.Output, args: ["onTabChange"] }], actions: [{ type: i0.Input, args: [{ isSignal: true, alias: "actions", required: false }] }], captionStartContent: [{ type: i0.ContentChild, args: ['captionStart', { isSignal: true }] }], captionEndContent: [{ type: i0.ContentChild, args: ['captionEnd', { isSignal: true }] }], emptyContent: [{ type: i0.ContentChild, args: ['empty', { isSignal: true }] }], paginatorPosition: [{ type: i0.Input, args: [{ isSignal: true, alias: "paginatorPosition", required: false }] }], pageSize: [{ type: i0.Input, args: [{ isSignal: true, alias: "pageSize", required: false }] }, { type: i0.Output, args: ["pageSizeChange"] }], currentPage: [{ type: i0.Input, args: [{ isSignal: true, alias: "currentPage", required: false }] }, { type: i0.Output, args: ["currentPageChange"] }], first: [{ type: i0.Input, args: [{ isSignal: true, alias: "first", required: false }] }, { type: i0.Output, args: ["firstChange"] }], filterTerm: [{ type: i0.Input, args: [{ isSignal: true, alias: "filterTerm", required: false }] }, { type: i0.Output, args: ["filterTermChange"] }] } });

/**
 * Generated bundle index. Do not edit.
 */

export { Table };
//# sourceMappingURL=masterteam-components-table.mjs.map
