import * as i0 from '@angular/core';
import { Directive, Input, Pipe } from '@angular/core';
import { DataSourceCollectionDirective } from '@rxap/data-source/directive';
import { AbstractPaginationDataSource, RxapPaginationDataSourceError, PaginationDataSource } from '@rxap/data-source/pagination';
import { staticDataSource, observableDataSource } from '@rxap/data-source';
import { isObservable } from 'rxjs';

class PaginationDataSourceDirective extends DataSourceCollectionDirective {
    loadDataSource() {
        const dataSource = super.loadDataSource();
        if (dataSource) {
            if (!(dataSource instanceof AbstractPaginationDataSource)) {
                throw new RxapPaginationDataSourceError('The data source is not a AbstractPaginationDataSource', '');
            }
            if (dataSource.paginator !== this.paginator) {
                dataSource.paginator = this.paginator;
            }
        }
        return dataSource;
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: PaginationDataSourceDirective, deps: null, target: i0.ɵɵFactoryTarget.Directive }); }
    static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.1", type: PaginationDataSourceDirective, isStandalone: true, selector: "[rxapPaginationDataSource]", inputs: { paginator: ["rxapPaginationDataSourcePaginator", "paginator"], dataSourceOrIdOrToken: ["rxapPaginationDataSourceFrom", "dataSourceOrIdOrToken"] }, usesInheritance: true, ngImport: i0 }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: PaginationDataSourceDirective, decorators: [{
            type: Directive,
            args: [{
                    selector: '[rxapPaginationDataSource]',
                    standalone: true,
                }]
        }], propDecorators: { paginator: [{
                type: Input,
                args: ['rxapPaginationDataSourcePaginator']
            }], dataSourceOrIdOrToken: [{
                type: Input,
                args: [{
                        required: true,
                        alias: 'rxapPaginationDataSourceFrom',
                    }]
            }] } });

class ToPaginationPipe {
    transform(value, paginator = null) {
        let dataSource;
        if (Array.isArray(value)) {
            dataSource = staticDataSource(value, { id: 'auto-to-pagination' });
        }
        else if (isObservable(value)) {
            dataSource = observableDataSource(value, { id: 'auto-to-pagination' });
        }
        else {
            dataSource = value;
        }
        return new PaginationDataSource(dataSource, paginator);
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: ToPaginationPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
    static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.2.1", ngImport: i0, type: ToPaginationPipe, isStandalone: true, name: "toPagination" }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: ToPaginationPipe, decorators: [{
            type: Pipe,
            args: [{
                    name: 'toPagination',
                    standalone: true,
                }]
        }] });

// region 
// endregion

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

export { PaginationDataSourceDirective, ToPaginationPipe };
//# sourceMappingURL=rxap-data-source-pagination-directives.mjs.map
