import * as i0 from '@angular/core';
import { Directive, Input } from '@angular/core';
import { AbstractTableDataSource, RxapTableDataSourceError, DynamicTableDataSource } from '@rxap/data-source/table';
import { DataSourceCollectionDirective } from '@rxap/data-source/directive';

class TableDataSourceDirective extends DataSourceCollectionDirective {
    constructor() {
        super(...arguments);
        this.viewer = { id: '[rxapDataSourceCollection]' };
    }
    loadDataSource() {
        const dataSource = super.loadDataSource();
        if (dataSource) {
            if (!(dataSource instanceof AbstractTableDataSource)) {
                throw new RxapTableDataSourceError('The data source is not a AbstractTableDataSource', '');
            }
            if (this.viewer.id && dataSource instanceof DynamicTableDataSource) {
                dataSource.setPaginator(this.paginator, this.viewer.id);
                dataSource.setSort(this.sort, this.viewer.id);
                dataSource.setFilter(this.filter, this.viewer.id);
            }
            else {
                if (dataSource.paginator !== this.paginator) {
                    dataSource.paginator = this.paginator;
                }
                if (dataSource.sort !== this.sort) {
                    dataSource.sort = this.sort;
                }
                if (dataSource.filter !== this.filter) {
                    dataSource.filter = this.filter;
                }
            }
        }
        return dataSource;
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.1.3", ngImport: i0, type: TableDataSourceDirective, deps: null, target: i0.ɵɵFactoryTarget.Directive }); }
    static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.1.3", type: TableDataSourceDirective, isStandalone: true, selector: "[rxapTableDataSource]", inputs: { paginator: ["rxapTableDataSourcePaginator", "paginator"], sort: ["rxapTableDataSourceSort", "sort"], filter: ["rxapTableDataSourceFilter", "filter"], dataSourceOrIdOrToken: ["rxapTableDataSourceFrom", "dataSourceOrIdOrToken"], viewer: ["rxapTableDataSourceViewer", "viewer"] }, usesInheritance: true, ngImport: i0 }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.3", ngImport: i0, type: TableDataSourceDirective, decorators: [{
            type: Directive,
            args: [{
                    selector: '[rxapTableDataSource]',
                    standalone: true,
                }]
        }], propDecorators: { paginator: [{
                type: Input,
                args: ['rxapTableDataSourcePaginator']
            }], sort: [{
                type: Input,
                args: ['rxapTableDataSourceSort']
            }], filter: [{
                type: Input,
                args: ['rxapTableDataSourceFilter']
            }], dataSourceOrIdOrToken: [{
                type: Input,
                args: [{
                        required: true,
                        alias: 'rxapTableDataSourceFrom',
                    }]
            }], viewer: [{
                type: Input,
                args: ['rxapTableDataSourceViewer']
            }] } });

// region 
// endregion

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

export { TableDataSourceDirective };
//# sourceMappingURL=rxap-data-source-table-directives.mjs.map
