import { Component, Input } from '@angular/core';
import { MatTableDataSource } from '@angular/material/table';
import { ZuiExcelService } from '../../../excel';
export class ZuiTableExportComponent {
    constructor(zuiExcelService) {
        this.zuiExcelService = zuiExcelService;
        this.exportItems = [];
    }
    ngOnInit() { }
    ngOnChanges() {
        if (this.visible) {
            this.exportItems = [];
            const { config: { export: { excel: { visible: excelVisible = true, transform: excelTransform, fileName, showTime }, csv: { visible: csvVisible = true, transform: csvTransform, fileName: csvFileName, showTime: csvShowTime }, custom: { visible: customVisible = true, transform: customTransform, fileName: customFileName, showTime: customShowTime }, }, }, } = this.currentOptions;
            if (excelVisible) {
                this.exportItems.push({
                    label: 'Excel',
                    prefixIcon: 'add',
                    action: (event) => {
                        console.log('Excel', event);
                    },
                });
            }
            if (csvVisible) {
                this.exportItems.push({
                    label: 'CSV',
                    prefixIcon: 'save',
                    action: () => {
                        const columns = this.currentOptions.columns.map(column => ({
                            field: column.field,
                            title: column.title,
                        }));
                        this.zuiExcelService.exportCsv({
                            columns,
                            items: this.dataSource.data,
                            fileName: csvFileName,
                            showTime: csvShowTime,
                        });
                    },
                });
            }
            if (customVisible) {
                this.exportItems.push({
                    label: 'Custom',
                    prefixIcon: 'settings',
                    action: (event) => {
                        console.log('custom', event);
                    },
                });
            }
            // this.exportItems = [
            //   {
            //     label: 'Export Excel',
            //     action: (event): void => {
            //       console.log('item1', event)
            //     },
            //   },
            //   {
            //     label: 'Export CSV',
            //     action: (event): void => {
            //       const {columns, items} = this.currentOptions
            //       // this.zuiExportService.exportCsv<T>({
            //       //   columns: [
            //       //     {title: 'Tên', field: 'field1'},
            //       //     {title: 'Số', field: 'field2'},
            //       //   ],
            //       //   items: [...items],
            //       // })
            //       // this.zuiExportService.exportCsv({
            //       //   columns: [
            //       //     {title: 'Tên', field: 'field1'},
            //       //     {title: 'Số', field: 'field2'},
            //       //   ],
            //       //   items: [],
            //       //   fileName: 'file-csv-downloaded',
            //       //   showTime: false,
            //       // })
            //       console.log('item1', event, this.dataSource, columns)
            //     },
            //   },
            // ]
        }
    }
    get visible() {
        var _a, _b, _c;
        return (_c = (_b = (_a = this.currentOptions) === null || _a === void 0 ? void 0 : _a.config) === null || _b === void 0 ? void 0 : _b.export) === null || _c === void 0 ? void 0 : _c.visible;
    }
}
ZuiTableExportComponent.decorators = [
    { type: Component, args: [{
                selector: 'zui-table-export',
                template: "<zui-menu *ngIf=\"visible\" label=\"Export\" prefixIcon=\"get_app\" [items]=\"exportItems\"></zui-menu>\n",
                styles: [".zui-table table{width:100%}.zui-table-set-height{overflow:hidden;display:flex;flex-direction:column}.zui-table-container{flex:1;overflow-y:auto}.zui-table-container-hide-scrollbar{overflow:hidden}.zui-table-container-hide-scrollbar:hover{padding:0}.zui-table-highlight:hover{background-color:var(--hoverHighlightColor)}.zui-table-highlight-checked,.zui-table-highlight-checked:hover{background-color:var(--checkedHighlightColor)}.zui-table-expanded-detail{overflow:hidden}.zui-table-time{color:grey}:host ::ng-deep .zui-table-head{vertical-align:middle;font-weight:700;font-size:15px;padding:0 10px}:host ::ng-deep .zui-table-head.mat-header-cell:first-of-type{padding-left:10px}:host ::ng-deep .zui-table-head.mat-header-cell:last-of-type{padding-right:10px}:host ::ng-deep .zui-table-head-left>div{justify-content:left}:host ::ng-deep .zui-table-head-center>div{justify-content:center}:host ::ng-deep .zui-table-head-right>div{justify-content:right}:host ::ng-deep .zui-table-content{padding:0 10px}:host ::ng-deep .zui-table-content.mat-cell:first-of-type{padding-left:10px}:host ::ng-deep .zui-table-content.mat-cell:last-of-type{padding-right:10px}:host ::ng-deep .zui-table-footer{padding:10px 0;text-align:center}:host ::ng-deep .zui-table-footer.mat-footer-cell:first-of-type{padding-left:10px}:host ::ng-deep .zui-table-footer.mat-footer-cell:last-of-type{padding-right:10px}"]
            },] }
];
ZuiTableExportComponent.ctorParameters = () => [
    { type: ZuiExcelService }
];
ZuiTableExportComponent.propDecorators = {
    currentOptions: [{ type: Input }],
    dataSource: [{ type: Input }]
};
//# sourceMappingURL=index.component.js.map