import * as i0 from '@angular/core';
import { input, output, signal, computed, forwardRef, ChangeDetectionStrategy, Component, model, booleanAttribute, contentChild, viewChild, inject } from '@angular/core';
import { NgTemplateOutlet, DatePipe } from '@angular/common';
import * as i1 from '@angular/forms';
import { FormsModule, NG_VALUE_ACCESSOR } from '@angular/forms';
import { Button } from '@masterteam/components/button';
import { DateField } from '@masterteam/components/date-field';
import { SelectField } from '@masterteam/components/select-field';
import { TextField } from '@masterteam/components/text-field';
import * as i3 from '@jsverse/transloco';
import { TranslocoModule } from '@jsverse/transloco';
import * as i2 from 'primeng/popover';
import { PopoverModule } from 'primeng/popover';
import { ToggleField } from '@masterteam/components/toggle-field';
import { Paginator } from '@masterteam/components/paginator';
import { CheckboxField } from '@masterteam/components/checkbox-field';
import * as i1$1 from 'primeng/table';
import { TableModule } from 'primeng/table';
import { Tabs } from '@masterteam/components/tabs';
import * as i3$1 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';

class TableFilter {
    columns = input.required(...(ngDevMode ? [{ debugName: "columns" }] : []));
    data = input([], ...(ngDevMode ? [{ debugName: "data" }] : []));
    filterApplied = output();
    filterReset = output();
    pendingFilters = signal({}, ...(ngDevMode ? [{ debugName: "pendingFilters" }] : []));
    appliedFilters = signal({}, ...(ngDevMode ? [{ debugName: "appliedFilters" }] : []));
    booleanOptions = [
        { label: 'Yes', value: true },
        { label: 'No', value: false },
    ];
    onChange = () => { };
    onTouched = () => { };
    filterableColumns = computed(() => this.columns()
        .filter((col) => col.filterConfig || col.type === 'date' || col.type === 'boolean')
        .map((col) => {
        // Auto-generate select options from data if not provided
        if (col.filterConfig?.type === 'select' &&
            !col.filterConfig.options?.length) {
            const data = this.data();
            const uniqueValues = [...new Set(data.map((row) => row[col.key]))]
                .filter((value) => value !== null && value !== undefined && value !== '')
                .sort((a, b) => String(a).localeCompare(String(b)));
            return {
                ...col,
                filterConfig: {
                    ...col.filterConfig,
                    options: uniqueValues.map((value) => ({
                        label: String(value),
                        value,
                    })),
                },
            };
        }
        return col;
    }), ...(ngDevMode ? [{ debugName: "filterableColumns" }] : []));
    activeFilterCount = computed(() => {
        const filters = this.appliedFilters();
        return Object.values(filters).filter((v) => this.hasValue(v)).length;
    }, ...(ngDevMode ? [{ debugName: "activeFilterCount" }] : []));
    getFilterType(col) {
        if (col.filterConfig?.type)
            return col.filterConfig.type;
        if (col.type === 'date')
            return 'date';
        if (col.type === 'boolean')
            return 'boolean';
        return 'text';
    }
    getFilterValue(key) {
        const value = this.pendingFilters()[key];
        return value?.value ?? value ?? null;
    }
    getDateRangeValue(key, part) {
        const value = this.pendingFilters()[key];
        if (!value || typeof value !== 'object')
            return null;
        return part === 'from' ? (value.from ?? null) : (value.to ?? null);
    }
    updateFilter(key, value) {
        this.pendingFilters.update((filters) => ({
            ...filters,
            [key]: value,
        }));
        this.onTouched();
    }
    updateDateFilter(key, part, value) {
        this.pendingFilters.update((filters) => {
            const current = filters[key] ?? {};
            return {
                ...filters,
                [key]: {
                    ...current,
                    [part]: value,
                },
            };
        });
        this.onTouched();
    }
    apply() {
        const filters = { ...this.pendingFilters() };
        this.appliedFilters.set(filters);
        this.onChange(filters);
        this.filterApplied.emit(filters);
    }
    reset() {
        this.pendingFilters.set({});
        this.appliedFilters.set({});
        this.onChange({});
        this.filterReset.emit();
    }
    hasValue(value) {
        if (value === null || value === undefined || value === '')
            return false;
        if (typeof value === 'object') {
            return value.from != null || value.to != null || value.value != null;
        }
        return true;
    }
    // ControlValueAccessor
    writeValue(value) {
        const filters = value ?? {};
        this.pendingFilters.set(filters);
        this.appliedFilters.set(filters);
    }
    registerOnChange(fn) {
        this.onChange = fn;
    }
    registerOnTouched(fn) {
        this.onTouched = fn;
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: TableFilter, deps: [], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.0.3", type: TableFilter, isStandalone: true, selector: "mt-table-filter", inputs: { columns: { classPropertyName: "columns", publicName: "columns", isSignal: true, isRequired: true, transformFunction: null }, data: { classPropertyName: "data", publicName: "data", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { filterApplied: "filterApplied", filterReset: "filterReset" }, providers: [
            {
                provide: NG_VALUE_ACCESSOR,
                useExisting: forwardRef(() => TableFilter),
                multi: true,
            },
        ], ngImport: i0, template: "<mt-button\r\n  (click)=\"popover.toggle($event)\"\r\n  [label]=\"'components.table.filter' | transloco\"\r\n  [badge]=\"activeFilterCount()\"\r\n  severity=\"primary\"\r\n  icon=\"general.filter-funnel-01\"\r\n/>\r\n\r\n<p-popover #popover [style]=\"{ width: '320px' }\" appendTo=\"body\">\r\n  <div class=\"flex flex-col max-h-[50vh]\">\r\n    <h4\r\n      class=\"text-lg py-2 font-semibold border-b border-surface-200 dark:border-surface-700 shrink-0\"\r\n    >\r\n      {{ \"components.table.filterOptions\" | transloco }}\r\n    </h4>\r\n\r\n    <div\r\n      class=\"space-y-3 overflow-y-auto flex-1 py-3\"\r\n      (keydown.enter)=\"apply(); popover.hide()\"\r\n    >\r\n      @for (col of filterableColumns(); track col.key) {\r\n        <div class=\"space-y-1\">\r\n          <label\r\n            class=\"block text-sm font-medium text-gray-700 dark:text-gray-300\"\r\n          >\r\n            {{ col.filterConfig?.label || col.label }}\r\n          </label>\r\n\r\n          @switch (getFilterType(col)) {\r\n            @case (\"text\") {\r\n              <mt-text-field\r\n                [ngModel]=\"getFilterValue(col.key)\"\r\n                (ngModelChange)=\"updateFilter(col.key, $event)\"\r\n                [placeholder]=\"\r\n                  ('components.table.select' | transloco) +\r\n                  ' ' +\r\n                  (col.filterConfig?.label || col.label)\r\n                \"\r\n              />\r\n            }\r\n            @case (\"select\") {\r\n              <mt-select-field\r\n                [ngModel]=\"getFilterValue(col.key)\"\r\n                (ngModelChange)=\"updateFilter(col.key, $event)\"\r\n                [options]=\"col.filterConfig?.options ?? []\"\r\n                [placeholder]=\"\r\n                  ('components.table.select' | transloco) +\r\n                  ' ' +\r\n                  (col.filterConfig?.label || col.label)\r\n                \"\r\n                [hasPlaceholderPrefix]=\"false\"\r\n                showClear\r\n              />\r\n            }\r\n            @case (\"date\") {\r\n              <div class=\"space-y-3\">\r\n                <div class=\"space-y-1\">\r\n                  <label\r\n                    class=\"block text-sm font-medium text-gray-700 dark:text-gray-300\"\r\n                  >\r\n                    {{ \"components.table.from\" | transloco }}\r\n                  </label>\r\n                  <mt-date-field\r\n                    [ngModel]=\"getDateRangeValue(col.key, 'from')\"\r\n                    (ngModelChange)=\"updateDateFilter(col.key, 'from', $event)\"\r\n                    [placeholder]=\"'components.table.from' | transloco\"\r\n                  />\r\n                </div>\r\n                <div class=\"space-y-1\">\r\n                  <label\r\n                    class=\"block text-sm font-medium text-gray-700 dark:text-gray-300\"\r\n                  >\r\n                    {{ \"components.table.to\" | transloco }}\r\n                  </label>\r\n                  <mt-date-field\r\n                    [ngModel]=\"getDateRangeValue(col.key, 'to')\"\r\n                    (ngModelChange)=\"updateDateFilter(col.key, 'to', $event)\"\r\n                    [placeholder]=\"'components.table.to' | transloco\"\r\n                  />\r\n                </div>\r\n              </div>\r\n            }\r\n            @case (\"boolean\") {\r\n              <mt-select-field\r\n                [ngModel]=\"getFilterValue(col.key)\"\r\n                (ngModelChange)=\"updateFilter(col.key, $event)\"\r\n                [options]=\"booleanOptions\"\r\n                [placeholder]=\"'components.table.select' | transloco\"\r\n                [hasPlaceholderPrefix]=\"false\"\r\n                showClear\r\n              />\r\n            }\r\n          }\r\n        </div>\r\n      }\r\n    </div>\r\n\r\n    <div\r\n      class=\"flex justify-end gap-2 pt-4 border-t border-surface-200 dark:border-surface-700 shrink-0\"\r\n    >\r\n      <mt-button\r\n        variant=\"outlined\"\r\n        (click)=\"reset(); popover.hide()\"\r\n        [label]=\"'components.table.reset' | transloco\"\r\n      />\r\n      <mt-button\r\n        (click)=\"apply(); popover.hide()\"\r\n        [label]=\"'components.table.apply' | transloco\"\r\n      />\r\n    </div>\r\n  </div>\r\n</p-popover>\r\n", dependencies: [{ kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { 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: DateField, selector: "mt-date-field", inputs: ["field", "label", "placeholder", "class", "readonly", "showIcon", "showClear", "showTime", "pInputs", "required"] }, { 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: "ngmodule", type: PopoverModule }, { kind: "component", type: i2.Popover, selector: "p-popover", inputs: ["ariaLabel", "ariaLabelledBy", "dismissable", "style", "styleClass", "appendTo", "autoZIndex", "ariaCloseLabel", "baseZIndex", "focusOnShow", "showTransitionOptions", "hideTransitionOptions", "motionOptions"], outputs: ["onShow", "onHide"] }, { kind: "ngmodule", type: TranslocoModule }, { kind: "pipe", type: i3.TranslocoPipe, name: "transloco" }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: TableFilter, decorators: [{
            type: Component,
            args: [{ selector: 'mt-table-filter', standalone: true, imports: [
                        FormsModule,
                        TextField,
                        SelectField,
                        DateField,
                        Button,
                        PopoverModule,
                        TranslocoModule,
                    ], changeDetection: ChangeDetectionStrategy.OnPush, providers: [
                        {
                            provide: NG_VALUE_ACCESSOR,
                            useExisting: forwardRef(() => TableFilter),
                            multi: true,
                        },
                    ], template: "<mt-button\r\n  (click)=\"popover.toggle($event)\"\r\n  [label]=\"'components.table.filter' | transloco\"\r\n  [badge]=\"activeFilterCount()\"\r\n  severity=\"primary\"\r\n  icon=\"general.filter-funnel-01\"\r\n/>\r\n\r\n<p-popover #popover [style]=\"{ width: '320px' }\" appendTo=\"body\">\r\n  <div class=\"flex flex-col max-h-[50vh]\">\r\n    <h4\r\n      class=\"text-lg py-2 font-semibold border-b border-surface-200 dark:border-surface-700 shrink-0\"\r\n    >\r\n      {{ \"components.table.filterOptions\" | transloco }}\r\n    </h4>\r\n\r\n    <div\r\n      class=\"space-y-3 overflow-y-auto flex-1 py-3\"\r\n      (keydown.enter)=\"apply(); popover.hide()\"\r\n    >\r\n      @for (col of filterableColumns(); track col.key) {\r\n        <div class=\"space-y-1\">\r\n          <label\r\n            class=\"block text-sm font-medium text-gray-700 dark:text-gray-300\"\r\n          >\r\n            {{ col.filterConfig?.label || col.label }}\r\n          </label>\r\n\r\n          @switch (getFilterType(col)) {\r\n            @case (\"text\") {\r\n              <mt-text-field\r\n                [ngModel]=\"getFilterValue(col.key)\"\r\n                (ngModelChange)=\"updateFilter(col.key, $event)\"\r\n                [placeholder]=\"\r\n                  ('components.table.select' | transloco) +\r\n                  ' ' +\r\n                  (col.filterConfig?.label || col.label)\r\n                \"\r\n              />\r\n            }\r\n            @case (\"select\") {\r\n              <mt-select-field\r\n                [ngModel]=\"getFilterValue(col.key)\"\r\n                (ngModelChange)=\"updateFilter(col.key, $event)\"\r\n                [options]=\"col.filterConfig?.options ?? []\"\r\n                [placeholder]=\"\r\n                  ('components.table.select' | transloco) +\r\n                  ' ' +\r\n                  (col.filterConfig?.label || col.label)\r\n                \"\r\n                [hasPlaceholderPrefix]=\"false\"\r\n                showClear\r\n              />\r\n            }\r\n            @case (\"date\") {\r\n              <div class=\"space-y-3\">\r\n                <div class=\"space-y-1\">\r\n                  <label\r\n                    class=\"block text-sm font-medium text-gray-700 dark:text-gray-300\"\r\n                  >\r\n                    {{ \"components.table.from\" | transloco }}\r\n                  </label>\r\n                  <mt-date-field\r\n                    [ngModel]=\"getDateRangeValue(col.key, 'from')\"\r\n                    (ngModelChange)=\"updateDateFilter(col.key, 'from', $event)\"\r\n                    [placeholder]=\"'components.table.from' | transloco\"\r\n                  />\r\n                </div>\r\n                <div class=\"space-y-1\">\r\n                  <label\r\n                    class=\"block text-sm font-medium text-gray-700 dark:text-gray-300\"\r\n                  >\r\n                    {{ \"components.table.to\" | transloco }}\r\n                  </label>\r\n                  <mt-date-field\r\n                    [ngModel]=\"getDateRangeValue(col.key, 'to')\"\r\n                    (ngModelChange)=\"updateDateFilter(col.key, 'to', $event)\"\r\n                    [placeholder]=\"'components.table.to' | transloco\"\r\n                  />\r\n                </div>\r\n              </div>\r\n            }\r\n            @case (\"boolean\") {\r\n              <mt-select-field\r\n                [ngModel]=\"getFilterValue(col.key)\"\r\n                (ngModelChange)=\"updateFilter(col.key, $event)\"\r\n                [options]=\"booleanOptions\"\r\n                [placeholder]=\"'components.table.select' | transloco\"\r\n                [hasPlaceholderPrefix]=\"false\"\r\n                showClear\r\n              />\r\n            }\r\n          }\r\n        </div>\r\n      }\r\n    </div>\r\n\r\n    <div\r\n      class=\"flex justify-end gap-2 pt-4 border-t border-surface-200 dark:border-surface-700 shrink-0\"\r\n    >\r\n      <mt-button\r\n        variant=\"outlined\"\r\n        (click)=\"reset(); popover.hide()\"\r\n        [label]=\"'components.table.reset' | transloco\"\r\n      />\r\n      <mt-button\r\n        (click)=\"apply(); popover.hide()\"\r\n        [label]=\"'components.table.apply' | transloco\"\r\n      />\r\n    </div>\r\n  </div>\r\n</p-popover>\r\n" }]
        }], propDecorators: { columns: [{ type: i0.Input, args: [{ isSignal: true, alias: "columns", required: true }] }], data: [{ type: i0.Input, args: [{ isSignal: true, alias: "data", required: false }] }], filterApplied: [{ type: i0.Output, args: ["filterApplied"] }], filterReset: [{ type: i0.Output, args: ["filterReset"] }] } });

class Table {
    selectionChange = output();
    cellChange = output();
    lazyLoad = output();
    columnReorder = output();
    rowReorder = output();
    filters = model({}, ...(ngDevMode ? [{ debugName: "filters" }] : []));
    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 });
    lazy = input(false, { ...(ngDevMode ? { debugName: "lazy" } : {}), transform: booleanAttribute });
    lazyTotalRecords = input(...(ngDevMode ? [undefined, { debugName: "lazyTotalRecords" }] : []));
    reorderableColumns = input(false, { ...(ngDevMode ? { debugName: "reorderableColumns" } : {}), transform: booleanAttribute });
    reorderableRows = input(false, { ...(ngDevMode ? { debugName: "reorderableRows" } : {}), transform: booleanAttribute });
    dataKey = input(...(ngDevMode ? [undefined, { debugName: "dataKey" }] : []));
    exportable = input(false, { ...(ngDevMode ? { debugName: "exportable" } : {}), transform: booleanAttribute });
    exportFilename = input('download', ...(ngDevMode ? [{ debugName: "exportFilename" }] : []));
    // 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" }] : []));
    // Table reference for export
    tableRef = viewChild('dt', ...(ngDevMode ? [{ debugName: "tableRef" }] : []));
    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" }] : []));
    // Map columns for PrimeNG export (key -> field)
    exportColumns = computed(() => this.columns()
        .filter((col) => col.type !== 'custom')
        .map((col) => ({ ...col, field: col.key, header: col.label })), ...(ngDevMode ? [{ debugName: "exportColumns" }] : []));
    activeFilterCount = computed(() => {
        const filters = this.filters();
        return Object.values(filters).filter((value) => value !== null && value !== undefined && value !== '').length;
    }, ...(ngDevMode ? [{ debugName: "activeFilterCount" }] : []));
    filteredData = computed(() => {
        const data = this.data();
        // Skip local filtering when lazy mode is enabled
        if (this.lazy()) {
            return data;
        }
        const searchTerm = this.filterTerm().toLowerCase();
        const filters = this.filters();
        const filterKeys = Object.keys(filters);
        let result = data;
        // Apply search term
        if (searchTerm !== '') {
            result = result.filter((item) => Object.values(item).some((value) => typeof value === 'string' &&
                value.toLowerCase().includes(searchTerm)));
        }
        // Apply column filters
        if (filterKeys.length > 0) {
            result = result.filter((item) => filterKeys.every((key) => this.matchesFilter(item, key, filters[key])));
        }
        return result;
    }, ...(ngDevMode ? [{ debugName: "filteredData" }] : []));
    displayData = computed(() => {
        if (this.loading()) {
            return Array.from({ length: this.pageSize() }, () => ({}));
        }
        return this.lazy() ? this.data() : this.filteredData();
    }, ...(ngDevMode ? [{ debugName: "displayData" }] : []));
    totalRecords = computed(() => {
        if (this.lazy() && this.lazyTotalRecords() !== undefined) {
            return this.lazyTotalRecords();
        }
        return this.filteredData().length;
    }, ...(ngDevMode ? [{ debugName: "totalRecords" }] : []));
    // TODO: remove after updating the toggle and checkbox logic
    paginatedData = computed(() => {
        const data = this.lazy() ? this.data() : this.filteredData();
        const first = this.first();
        const pageSize = this.pageSize();
        if (this.lazy()) {
            return data;
        }
        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" }] : []));
    onFilterApplied(filters) {
        this.filters.set(filters);
        this.first.set(0);
        this.currentPage.set(0);
        if (this.lazy()) {
            this.emitLazyLoad({});
        }
    }
    onFilterReset() {
        this.filters.set({});
        this.first.set(0);
        this.currentPage.set(0);
        if (this.lazy()) {
            this.emitLazyLoad({});
        }
    }
    matchesFilter(item, key, filterValue) {
        if (filterValue === null ||
            filterValue === undefined ||
            filterValue === '') {
            return true;
        }
        const itemValue = this.getProperty(item, key);
        // Date range filter
        if (typeof filterValue === 'object' &&
            (filterValue.from || filterValue.to)) {
            const itemDate = itemValue instanceof Date ? itemValue : new Date(itemValue);
            if (isNaN(itemDate.getTime()))
                return true;
            if (filterValue.from && itemDate < new Date(filterValue.from)) {
                return false;
            }
            if (filterValue.to && itemDate > new Date(filterValue.to)) {
                return false;
            }
            return true;
        }
        // Boolean filter
        if (typeof filterValue === 'boolean') {
            return itemValue === filterValue;
        }
        // Text filter
        if (typeof itemValue === 'string') {
            return itemValue
                .toLowerCase()
                .includes(String(filterValue).toLowerCase());
        }
        return itemValue === filterValue;
    }
    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) {
        if (this.lazy()) {
            this.handleLazyLoad(event);
            return;
        }
        this.updatePagingFromEvent(event);
    }
    handleLazyLoad(event) {
        this.updatePagingFromEvent(event);
        this.emitLazyLoad(event);
    }
    onPaginatorPage(event) {
        if (this.lazy()) {
            this.handleLazyLoad(event);
            return;
        }
        this.updatePagingFromEvent(event);
    }
    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;
    }
    onColumnReorder(event) {
        this.columnReorder.emit(event);
    }
    onRowReorder(event) {
        this.rowReorder.emit({
            ...event,
            value: event.value ?? this.data(),
        });
    }
    updatePagingFromEvent(event) {
        const first = event?.first ?? this.first();
        const rows = event?.rows ?? this.pageSize();
        this.first.set(first);
        this.pageSize.set(rows);
        const page = typeof event?.page === 'number'
            ? event.page
            : Math.floor((first ?? 0) / (rows || 1));
        this.currentPage.set(page);
    }
    emitLazyLoad(event) {
        this.lazyLoad.emit({
            ...event,
            pageSize: this.pageSize(),
            currentPage: this.currentPage() + 1,
            first: this.first(),
            filters: this.filters(),
        });
    }
    exportCSV() {
        const table = this.tableRef();
        if (table) {
            // Temporarily set columns with field property for PrimeNG export
            const originalColumns = table.columns;
            table.columns = this.exportColumns();
            table.exportCSV();
            table.columns = originalColumns;
        }
    }
    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: { filters: { classPropertyName: "filters", publicName: "filters", isSignal: true, isRequired: false, transformFunction: null }, 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 }, lazy: { classPropertyName: "lazy", publicName: "lazy", isSignal: true, isRequired: false, transformFunction: null }, lazyTotalRecords: { classPropertyName: "lazyTotalRecords", publicName: "lazyTotalRecords", isSignal: true, isRequired: false, transformFunction: null }, reorderableColumns: { classPropertyName: "reorderableColumns", publicName: "reorderableColumns", isSignal: true, isRequired: false, transformFunction: null }, reorderableRows: { classPropertyName: "reorderableRows", publicName: "reorderableRows", isSignal: true, isRequired: false, transformFunction: null }, dataKey: { classPropertyName: "dataKey", publicName: "dataKey", isSignal: true, isRequired: false, transformFunction: null }, exportable: { classPropertyName: "exportable", publicName: "exportable", isSignal: true, isRequired: false, transformFunction: null }, exportFilename: { classPropertyName: "exportFilename", publicName: "exportFilename", 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", lazyLoad: "lazyLoad", columnReorder: "columnReorder", rowReorder: "rowReorder", filters: "filtersChange", 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 }], viewQueries: [{ propertyName: "tableRef", first: true, predicate: ["dt"], descendants: true, isSignal: true }], ngImport: i0, template: "<div class=\"space-y-4 rounded-2xl\">\r\n  <div>\r\n    @if (\r\n      captionStartContent() ||\r\n      captionEndContent() ||\r\n      generalSearch() ||\r\n      showFilters() ||\r\n      tabs()?.length > 0 ||\r\n      actions()?.length > 0\r\n    ) {\r\n      <div class=\"p-datatable-header rounded-t-2xl\">\r\n        <div\r\n          class=\"flex relative\"\r\n          [class]=\"!generalSearch() ? 'justify-end' : 'justify-between'\"\r\n        >\r\n          <div class=\"flex items-center gap-2\">\r\n            <ng-container\r\n              *ngTemplateOutlet=\"captionStartContent()\"\r\n            ></ng-container>\r\n            @if (tabs()) {\r\n              <mt-tabs\r\n                [(active)]=\"activeTab\"\r\n                [options]=\"tabs()\"\r\n                [optionLabel]=\"tabsOptionLabel()\"\r\n                [optionValue]=\"tabsOptionValue()\"\r\n                (onChange)=\"tabChanged($event)\"\r\n                [disabled]=\"data().length === 0\"\r\n                size=\"large\"\r\n              ></mt-tabs>\r\n            }\r\n            @if (generalSearch()) {\r\n              <mt-text-field\r\n                [(ngModel)]=\"filterTerm\"\r\n                (change)=\"onSearchChange($event)\"\r\n                icon=\"general.search-lg\"\r\n                [placeholder]=\"'components.table.search' | transloco\"\r\n              ></mt-text-field>\r\n            }\r\n          </div>\r\n          <div class=\"flex items-center gap-2\">\r\n            @if (showFilters()) {\r\n              <mt-table-filter\r\n                [columns]=\"columns()\"\r\n                [data]=\"data()\"\r\n                [ngModel]=\"filters()\"\r\n                (filterApplied)=\"onFilterApplied($event)\"\r\n                (filterReset)=\"onFilterReset()\"\r\n              />\r\n            }\r\n            @if (exportable()) {\r\n              <mt-button\r\n                icon=\"general.share-05\"\r\n                [label]=\"'components.table.export' | transloco\"\r\n                (click)=\"exportCSV()\"\r\n              />\r\n            }\r\n            @if (actions()?.length > 0) {\r\n              <div class=\"flex items-center space-x-2\">\r\n                @for (action of actions(); track action.label) {\r\n                  <mt-button\r\n                    [icon]=\"action.icon\"\r\n                    [severity]=\"action.color\"\r\n                    [variant]=\"action.variant\"\r\n                    [size]=\"action.size\"\r\n                    (click)=\"action.action(row)\"\r\n                    [label]=\"action.label\"\r\n                    [tooltip]=\"action.tooltip\"\r\n                  ></mt-button>\r\n                }\r\n              </div>\r\n            }\r\n            <ng-container\r\n              *ngTemplateOutlet=\"captionEndContent()\"\r\n            ></ng-container>\r\n          </div>\r\n        </div>\r\n      </div>\r\n    }\r\n    @if (!loading() && emptyContent() && data().length === 0) {\r\n      <div\r\n        class=\"p-4 bg-content rounded-md text-center text-gray-600 dark:text-gray-300\"\r\n      >\r\n        <ng-container *ngTemplateOutlet=\"emptyContent()\"></ng-container>\r\n      </div>\r\n    } @else {\r\n      <div class=\"overflow-x-auto bg-content\">\r\n        <p-table\r\n          #dt\r\n          [value]=\"displayData()\"\r\n          [columns]=\"columns()\"\r\n          [size]=\"size()\"\r\n          [showGridlines]=\"showGridlines()\"\r\n          [stripedRows]=\"stripedRows()\"\r\n          [lazy]=\"lazy()\"\r\n          [totalRecords]=\"totalRecords()\"\r\n          [reorderableColumns]=\"reorderableColumns()\"\r\n          [reorderableRows]=\"reorderableRows()\"\r\n          [dataKey]=\"dataKey()\"\r\n          [first]=\"first()\"\r\n          [rows]=\"pageSize()\"\r\n          [exportFilename]=\"exportFilename()\"\r\n          (onPage)=\"onTablePage($event)\"\r\n          (onLazyLoad)=\"handleLazyLoad($event)\"\r\n          (onColReorder)=\"onColumnReorder($event)\"\r\n          (onRowReorder)=\"onRowReorder($event)\"\r\n          paginator\r\n          paginatorStyleClass=\"hidden!\"\r\n          class=\"min-w-full text-sm align-middle table-fixed\"\r\n        >\r\n          <ng-template\r\n            #header\r\n            let-columns\r\n            class=\"bg-surface-50 dark:bg-surface-950 border-b border-surface-300 dark:border-surface-500\"\r\n          >\r\n            <tr>\r\n              @if (reorderableRows()) {\r\n                <th class=\"w-10\"></th>\r\n              }\r\n              @if (selectableRows()) {\r\n                <th class=\"w-12 text-start\">\r\n                  <mt-checkbox-field\r\n                    [ngModel]=\"allSelectedOnPage()\"\r\n                    (ngModelChange)=\"toggleAllRowsOnPage()\"\r\n                  ></mt-checkbox-field>\r\n                </th>\r\n              }\r\n\r\n              @for (col of columns; track col.key || col.label || $index) {\r\n                @if (reorderableColumns()) {\r\n                  <th\r\n                    pReorderableColumn\r\n                    class=\"text-start font-semibold text-gray-600 dark:text-gray-50 uppercase tracking-wider\"\r\n                  >\r\n                    <div class=\"flex items-center gap-2\">\r\n                      {{ col.label }}\r\n                      <!--                      <mt-icon-->\r\n                      <!--                        icon=\"general.menu-05\"-->\r\n                      <!--                        class=\"text-xs text-gray-400\"-->\r\n                      <!--                      ></mt-icon>-->\r\n                      <mt-button\r\n                        styleClass=\"cursor-move!\"\r\n                        severity=\"secondary\"\r\n                        variant=\"outlined\"\r\n                        size=\"small\"\r\n                        icon=\"general.menu-05\"\r\n                      ></mt-button>\r\n                    </div>\r\n                  </th>\r\n                } @else {\r\n                  <th\r\n                    class=\"text-start font-semibold text-gray-600 dark:text-gray-50 uppercase tracking-wider\"\r\n                  >\r\n                    {{ col.label }}\r\n                  </th>\r\n                }\r\n              }\r\n\r\n              @if (rowActions().length > 0) {\r\n                <th\r\n                  class=\"text-end! font-semibold text-gray-600 dark:text-gray-50 uppercase tracking-wider\"\r\n                >\r\n                  Actions\r\n                </th>\r\n              }\r\n            </tr>\r\n            @if (updating()) {\r\n              <tr>\r\n                <th\r\n                  [attr.colspan]=\"\r\n                    columns.length +\r\n                    (reorderableRows() ? 1 : 0) +\r\n                    (selectableRows() ? 1 : 0) +\r\n                    (rowActions().length > 0 ? 1 : 0)\r\n                  \"\r\n                  class=\"!p-0\"\r\n                >\r\n                  <p-progressBar\r\n                    mode=\"indeterminate\"\r\n                    [style]=\"{ height: '4px' }\"\r\n                  />\r\n                </th>\r\n              </tr>\r\n            }\r\n          </ng-template>\r\n          <ng-template\r\n            #body\r\n            let-row\r\n            let-columns=\"columns\"\r\n            let-index=\"rowIndex\"\r\n            class=\"divide-y divide-gray-200\"\r\n          >\r\n            @if (loading()) {\r\n              <tr>\r\n                @if (reorderableRows()) {\r\n                  <td><p-skeleton /></td>\r\n                }\r\n                @if (selectableRows()) {\r\n                  <td><p-skeleton /></td>\r\n                }\r\n                @for (col of columns; track col.key || col.label || $index) {\r\n                  <td><p-skeleton /></td>\r\n                }\r\n                @if (rowActions().length > 0) {\r\n                  <td><p-skeleton /></td>\r\n                }\r\n              </tr>\r\n            } @else {\r\n              <tr\r\n                class=\"hover:bg-gray-50 dark:hover:bg-surface-950 border-surface-300 dark:border-surface-500\"\r\n                [pReorderableRow]=\"index\"\r\n              >\r\n                @if (reorderableRows()) {\r\n                  <td class=\"w-10 text-center\">\r\n                    <mt-button\r\n                      styleClass=\"cursor-move!\"\r\n                      pReorderableRowHandle\r\n                      severity=\"secondary\"\r\n                      variant=\"outlined\"\r\n                      size=\"small\"\r\n                      icon=\"general.menu-05\"\r\n                    ></mt-button>\r\n                    <!--                    <mt-icon-->\r\n                    <!--                      icon=\"general.menu-05\"-->\r\n                    <!--                      class=\"cursor-move text-gray-500\"-->\r\n                    <!--                      pReorderableRowHandle-->\r\n                    <!--                    ></mt-icon>-->\r\n                  </td>\r\n                }\r\n                @if (selectableRows()) {\r\n                  <td class=\"w-12\">\r\n                    <mt-checkbox-field\r\n                      [ngModel]=\"selectedRows().has(row)\"\r\n                      (ngModelChange)=\"toggleRow(row)\"\r\n                    ></mt-checkbox-field>\r\n                  </td>\r\n                }\r\n\r\n                @for (col of columns; track col.key || col.label || $index) {\r\n                  <td class=\"text-gray-700 dark:text-gray-100\">\r\n                    @switch (col.type) {\r\n                      @case (\"boolean\") {\r\n                        <mt-toggle-field\r\n                          [(ngModel)]=\"row[col.key]\"\r\n                          (ngModelChange)=\"\r\n                            onCellChange(row, col.key, $event, 'boolean')\r\n                          \"\r\n                          [readonly]=\"col.readonly ?? false\"\r\n                        ></mt-toggle-field>\r\n                      }\r\n                      @case (\"date\") {\r\n                        {{ getProperty(row, col.key) | date: \"mediumDate\" }}\r\n                      }\r\n                      @case (\"custom\") {\r\n                        <ng-container\r\n                          *ngTemplateOutlet=\"\r\n                            col.customCellTpl;\r\n                            context: { $implicit: row }\r\n                          \"\r\n                        >\r\n                        </ng-container>\r\n                      }\r\n                      @default {\r\n                        {{ getProperty(row, col.key) }}\r\n                      }\r\n                    }\r\n                  </td>\r\n                }\r\n\r\n                @if (rowActions().length > 0) {\r\n                  <td class=\"text-right\">\r\n                    <div class=\"flex items-center justify-end space-x-2\">\r\n                      @for (action of rowActions(); track $index) {\r\n                        @let hidden = action.hidden?.(row);\r\n                        @if (!hidden) {\r\n                          <mt-button\r\n                            [icon]=\"action.icon\"\r\n                            [severity]=\"action.color\"\r\n                            [variant]=\"action.variant\"\r\n                            [size]=\"action.size || 'small'\"\r\n                            (click)=\"rowAction($event, action, row)\"\r\n                            [tooltip]=\"action.tooltip\"\r\n                            [label]=\"action.label\"\r\n                            [loading]=\"resolveActionLoading(action, row)\"\r\n                          ></mt-button>\r\n                        }\r\n                      }\r\n                    </div>\r\n                  </td>\r\n                }\r\n              </tr>\r\n            }\r\n          </ng-template>\r\n          <ng-template #emptymessage>\r\n            <tr>\r\n              <td colspan=\"20\" class=\"text-center\">\r\n                <div class=\"flex justify-center\">No data found.</div>\r\n              </td>\r\n            </tr>\r\n          </ng-template>\r\n        </p-table>\r\n      </div>\r\n    }\r\n  </div>\r\n\r\n  <div\r\n    class=\"flex flex-col gap-3 pb-3 px-4\"\r\n    [class]=\"'items-' + paginatorPosition()\"\r\n  >\r\n    <mt-paginator\r\n      [(rows)]=\"pageSize\"\r\n      [(first)]=\"first\"\r\n      [(page)]=\"currentPage\"\r\n      [totalRecords]=\"totalRecords()\"\r\n      [alwaysShow]=\"false\"\r\n      [rowsPerPageOptions]=\"[5, 10, 20, 50]\"\r\n      (onPageChange)=\"onPaginatorPage($event)\"\r\n    ></mt-paginator>\r\n  </div>\r\n</div>\r\n", styles: [""], dependencies: [{ kind: "ngmodule", type: TableModule }, { kind: "component", type: i1$1.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: i1$1.ReorderableColumn, selector: "[pReorderableColumn]", inputs: ["pReorderableColumnDisabled"] }, { kind: "directive", type: i1$1.ReorderableRowHandle, selector: "[pReorderableRowHandle]" }, { kind: "directive", type: i1$1.ReorderableRow, selector: "[pReorderableRow]", inputs: ["pReorderableRow", "pReorderableRowDisabled"] }, { 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", "toggleShape", "size", "icon", "descriptionCard"], outputs: ["onChange"] }, { kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.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: 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$1.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: "component", type: TableFilter, selector: "mt-table-filter", inputs: ["columns", "data"], outputs: ["filterApplied", "filterReset"] }, { kind: "pipe", type: DatePipe, name: "date" }, { kind: "pipe", type: i3.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,
                        Paginator,
                        CheckboxField,
                        Tabs,
                        SkeletonModule,
                        ProgressBarModule,
                        TranslocoModule,
                        TableFilter,
                    ], changeDetection: ChangeDetectionStrategy.OnPush, template: "<div class=\"space-y-4 rounded-2xl\">\r\n  <div>\r\n    @if (\r\n      captionStartContent() ||\r\n      captionEndContent() ||\r\n      generalSearch() ||\r\n      showFilters() ||\r\n      tabs()?.length > 0 ||\r\n      actions()?.length > 0\r\n    ) {\r\n      <div class=\"p-datatable-header rounded-t-2xl\">\r\n        <div\r\n          class=\"flex relative\"\r\n          [class]=\"!generalSearch() ? 'justify-end' : 'justify-between'\"\r\n        >\r\n          <div class=\"flex items-center gap-2\">\r\n            <ng-container\r\n              *ngTemplateOutlet=\"captionStartContent()\"\r\n            ></ng-container>\r\n            @if (tabs()) {\r\n              <mt-tabs\r\n                [(active)]=\"activeTab\"\r\n                [options]=\"tabs()\"\r\n                [optionLabel]=\"tabsOptionLabel()\"\r\n                [optionValue]=\"tabsOptionValue()\"\r\n                (onChange)=\"tabChanged($event)\"\r\n                [disabled]=\"data().length === 0\"\r\n                size=\"large\"\r\n              ></mt-tabs>\r\n            }\r\n            @if (generalSearch()) {\r\n              <mt-text-field\r\n                [(ngModel)]=\"filterTerm\"\r\n                (change)=\"onSearchChange($event)\"\r\n                icon=\"general.search-lg\"\r\n                [placeholder]=\"'components.table.search' | transloco\"\r\n              ></mt-text-field>\r\n            }\r\n          </div>\r\n          <div class=\"flex items-center gap-2\">\r\n            @if (showFilters()) {\r\n              <mt-table-filter\r\n                [columns]=\"columns()\"\r\n                [data]=\"data()\"\r\n                [ngModel]=\"filters()\"\r\n                (filterApplied)=\"onFilterApplied($event)\"\r\n                (filterReset)=\"onFilterReset()\"\r\n              />\r\n            }\r\n            @if (exportable()) {\r\n              <mt-button\r\n                icon=\"general.share-05\"\r\n                [label]=\"'components.table.export' | transloco\"\r\n                (click)=\"exportCSV()\"\r\n              />\r\n            }\r\n            @if (actions()?.length > 0) {\r\n              <div class=\"flex items-center space-x-2\">\r\n                @for (action of actions(); track action.label) {\r\n                  <mt-button\r\n                    [icon]=\"action.icon\"\r\n                    [severity]=\"action.color\"\r\n                    [variant]=\"action.variant\"\r\n                    [size]=\"action.size\"\r\n                    (click)=\"action.action(row)\"\r\n                    [label]=\"action.label\"\r\n                    [tooltip]=\"action.tooltip\"\r\n                  ></mt-button>\r\n                }\r\n              </div>\r\n            }\r\n            <ng-container\r\n              *ngTemplateOutlet=\"captionEndContent()\"\r\n            ></ng-container>\r\n          </div>\r\n        </div>\r\n      </div>\r\n    }\r\n    @if (!loading() && emptyContent() && data().length === 0) {\r\n      <div\r\n        class=\"p-4 bg-content rounded-md text-center text-gray-600 dark:text-gray-300\"\r\n      >\r\n        <ng-container *ngTemplateOutlet=\"emptyContent()\"></ng-container>\r\n      </div>\r\n    } @else {\r\n      <div class=\"overflow-x-auto bg-content\">\r\n        <p-table\r\n          #dt\r\n          [value]=\"displayData()\"\r\n          [columns]=\"columns()\"\r\n          [size]=\"size()\"\r\n          [showGridlines]=\"showGridlines()\"\r\n          [stripedRows]=\"stripedRows()\"\r\n          [lazy]=\"lazy()\"\r\n          [totalRecords]=\"totalRecords()\"\r\n          [reorderableColumns]=\"reorderableColumns()\"\r\n          [reorderableRows]=\"reorderableRows()\"\r\n          [dataKey]=\"dataKey()\"\r\n          [first]=\"first()\"\r\n          [rows]=\"pageSize()\"\r\n          [exportFilename]=\"exportFilename()\"\r\n          (onPage)=\"onTablePage($event)\"\r\n          (onLazyLoad)=\"handleLazyLoad($event)\"\r\n          (onColReorder)=\"onColumnReorder($event)\"\r\n          (onRowReorder)=\"onRowReorder($event)\"\r\n          paginator\r\n          paginatorStyleClass=\"hidden!\"\r\n          class=\"min-w-full text-sm align-middle table-fixed\"\r\n        >\r\n          <ng-template\r\n            #header\r\n            let-columns\r\n            class=\"bg-surface-50 dark:bg-surface-950 border-b border-surface-300 dark:border-surface-500\"\r\n          >\r\n            <tr>\r\n              @if (reorderableRows()) {\r\n                <th class=\"w-10\"></th>\r\n              }\r\n              @if (selectableRows()) {\r\n                <th class=\"w-12 text-start\">\r\n                  <mt-checkbox-field\r\n                    [ngModel]=\"allSelectedOnPage()\"\r\n                    (ngModelChange)=\"toggleAllRowsOnPage()\"\r\n                  ></mt-checkbox-field>\r\n                </th>\r\n              }\r\n\r\n              @for (col of columns; track col.key || col.label || $index) {\r\n                @if (reorderableColumns()) {\r\n                  <th\r\n                    pReorderableColumn\r\n                    class=\"text-start font-semibold text-gray-600 dark:text-gray-50 uppercase tracking-wider\"\r\n                  >\r\n                    <div class=\"flex items-center gap-2\">\r\n                      {{ col.label }}\r\n                      <!--                      <mt-icon-->\r\n                      <!--                        icon=\"general.menu-05\"-->\r\n                      <!--                        class=\"text-xs text-gray-400\"-->\r\n                      <!--                      ></mt-icon>-->\r\n                      <mt-button\r\n                        styleClass=\"cursor-move!\"\r\n                        severity=\"secondary\"\r\n                        variant=\"outlined\"\r\n                        size=\"small\"\r\n                        icon=\"general.menu-05\"\r\n                      ></mt-button>\r\n                    </div>\r\n                  </th>\r\n                } @else {\r\n                  <th\r\n                    class=\"text-start font-semibold text-gray-600 dark:text-gray-50 uppercase tracking-wider\"\r\n                  >\r\n                    {{ col.label }}\r\n                  </th>\r\n                }\r\n              }\r\n\r\n              @if (rowActions().length > 0) {\r\n                <th\r\n                  class=\"text-end! font-semibold text-gray-600 dark:text-gray-50 uppercase tracking-wider\"\r\n                >\r\n                  Actions\r\n                </th>\r\n              }\r\n            </tr>\r\n            @if (updating()) {\r\n              <tr>\r\n                <th\r\n                  [attr.colspan]=\"\r\n                    columns.length +\r\n                    (reorderableRows() ? 1 : 0) +\r\n                    (selectableRows() ? 1 : 0) +\r\n                    (rowActions().length > 0 ? 1 : 0)\r\n                  \"\r\n                  class=\"!p-0\"\r\n                >\r\n                  <p-progressBar\r\n                    mode=\"indeterminate\"\r\n                    [style]=\"{ height: '4px' }\"\r\n                  />\r\n                </th>\r\n              </tr>\r\n            }\r\n          </ng-template>\r\n          <ng-template\r\n            #body\r\n            let-row\r\n            let-columns=\"columns\"\r\n            let-index=\"rowIndex\"\r\n            class=\"divide-y divide-gray-200\"\r\n          >\r\n            @if (loading()) {\r\n              <tr>\r\n                @if (reorderableRows()) {\r\n                  <td><p-skeleton /></td>\r\n                }\r\n                @if (selectableRows()) {\r\n                  <td><p-skeleton /></td>\r\n                }\r\n                @for (col of columns; track col.key || col.label || $index) {\r\n                  <td><p-skeleton /></td>\r\n                }\r\n                @if (rowActions().length > 0) {\r\n                  <td><p-skeleton /></td>\r\n                }\r\n              </tr>\r\n            } @else {\r\n              <tr\r\n                class=\"hover:bg-gray-50 dark:hover:bg-surface-950 border-surface-300 dark:border-surface-500\"\r\n                [pReorderableRow]=\"index\"\r\n              >\r\n                @if (reorderableRows()) {\r\n                  <td class=\"w-10 text-center\">\r\n                    <mt-button\r\n                      styleClass=\"cursor-move!\"\r\n                      pReorderableRowHandle\r\n                      severity=\"secondary\"\r\n                      variant=\"outlined\"\r\n                      size=\"small\"\r\n                      icon=\"general.menu-05\"\r\n                    ></mt-button>\r\n                    <!--                    <mt-icon-->\r\n                    <!--                      icon=\"general.menu-05\"-->\r\n                    <!--                      class=\"cursor-move text-gray-500\"-->\r\n                    <!--                      pReorderableRowHandle-->\r\n                    <!--                    ></mt-icon>-->\r\n                  </td>\r\n                }\r\n                @if (selectableRows()) {\r\n                  <td class=\"w-12\">\r\n                    <mt-checkbox-field\r\n                      [ngModel]=\"selectedRows().has(row)\"\r\n                      (ngModelChange)=\"toggleRow(row)\"\r\n                    ></mt-checkbox-field>\r\n                  </td>\r\n                }\r\n\r\n                @for (col of columns; track col.key || col.label || $index) {\r\n                  <td class=\"text-gray-700 dark:text-gray-100\">\r\n                    @switch (col.type) {\r\n                      @case (\"boolean\") {\r\n                        <mt-toggle-field\r\n                          [(ngModel)]=\"row[col.key]\"\r\n                          (ngModelChange)=\"\r\n                            onCellChange(row, col.key, $event, 'boolean')\r\n                          \"\r\n                          [readonly]=\"col.readonly ?? false\"\r\n                        ></mt-toggle-field>\r\n                      }\r\n                      @case (\"date\") {\r\n                        {{ getProperty(row, col.key) | date: \"mediumDate\" }}\r\n                      }\r\n                      @case (\"custom\") {\r\n                        <ng-container\r\n                          *ngTemplateOutlet=\"\r\n                            col.customCellTpl;\r\n                            context: { $implicit: row }\r\n                          \"\r\n                        >\r\n                        </ng-container>\r\n                      }\r\n                      @default {\r\n                        {{ getProperty(row, col.key) }}\r\n                      }\r\n                    }\r\n                  </td>\r\n                }\r\n\r\n                @if (rowActions().length > 0) {\r\n                  <td class=\"text-right\">\r\n                    <div class=\"flex items-center justify-end space-x-2\">\r\n                      @for (action of rowActions(); track $index) {\r\n                        @let hidden = action.hidden?.(row);\r\n                        @if (!hidden) {\r\n                          <mt-button\r\n                            [icon]=\"action.icon\"\r\n                            [severity]=\"action.color\"\r\n                            [variant]=\"action.variant\"\r\n                            [size]=\"action.size || 'small'\"\r\n                            (click)=\"rowAction($event, action, row)\"\r\n                            [tooltip]=\"action.tooltip\"\r\n                            [label]=\"action.label\"\r\n                            [loading]=\"resolveActionLoading(action, row)\"\r\n                          ></mt-button>\r\n                        }\r\n                      }\r\n                    </div>\r\n                  </td>\r\n                }\r\n              </tr>\r\n            }\r\n          </ng-template>\r\n          <ng-template #emptymessage>\r\n            <tr>\r\n              <td colspan=\"20\" class=\"text-center\">\r\n                <div class=\"flex justify-center\">No data found.</div>\r\n              </td>\r\n            </tr>\r\n          </ng-template>\r\n        </p-table>\r\n      </div>\r\n    }\r\n  </div>\r\n\r\n  <div\r\n    class=\"flex flex-col gap-3 pb-3 px-4\"\r\n    [class]=\"'items-' + paginatorPosition()\"\r\n  >\r\n    <mt-paginator\r\n      [(rows)]=\"pageSize\"\r\n      [(first)]=\"first\"\r\n      [(page)]=\"currentPage\"\r\n      [totalRecords]=\"totalRecords()\"\r\n      [alwaysShow]=\"false\"\r\n      [rowsPerPageOptions]=\"[5, 10, 20, 50]\"\r\n      (onPageChange)=\"onPaginatorPage($event)\"\r\n    ></mt-paginator>\r\n  </div>\r\n</div>\r\n" }]
        }], propDecorators: { selectionChange: [{ type: i0.Output, args: ["selectionChange"] }], cellChange: [{ type: i0.Output, args: ["cellChange"] }], lazyLoad: [{ type: i0.Output, args: ["lazyLoad"] }], columnReorder: [{ type: i0.Output, args: ["columnReorder"] }], rowReorder: [{ type: i0.Output, args: ["rowReorder"] }], filters: [{ type: i0.Input, args: [{ isSignal: true, alias: "filters", required: false }] }, { type: i0.Output, args: ["filtersChange"] }], 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 }] }], lazy: [{ type: i0.Input, args: [{ isSignal: true, alias: "lazy", required: false }] }], lazyTotalRecords: [{ type: i0.Input, args: [{ isSignal: true, alias: "lazyTotalRecords", required: false }] }], reorderableColumns: [{ type: i0.Input, args: [{ isSignal: true, alias: "reorderableColumns", required: false }] }], reorderableRows: [{ type: i0.Input, args: [{ isSignal: true, alias: "reorderableRows", required: false }] }], dataKey: [{ type: i0.Input, args: [{ isSignal: true, alias: "dataKey", required: false }] }], exportable: [{ type: i0.Input, args: [{ isSignal: true, alias: "exportable", required: false }] }], exportFilename: [{ type: i0.Input, args: [{ isSignal: true, alias: "exportFilename", 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 }] }], tableRef: [{ type: i0.ViewChild, args: ['dt', { 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, TableFilter };
//# sourceMappingURL=masterteam-components-table.mjs.map
