import * as i0 from '@angular/core';
import { input, model, computed, ChangeDetectionStrategy, Component, NgModule } from '@angular/core';
import { elementRight3, elementLeft3 } from '@siemens/element-icons';
import { addIcons, SiIconComponent } from '@siemens/element-ng/icon';
import { t, SiTranslatePipe } from '@siemens/element-translate-ng/translate';

/**
 * Copyright (c) Siemens 2016 - 2026
 * SPDX-License-Identifier: MIT
 */
class SiPaginationComponent {
    static maxItems = 7;
    /**
     * The total number of pages.
     * Alternatively use `itemsPerPage` and `totalItems`
     */
    totalPages = input(...(ngDevMode ? [undefined, { debugName: "totalPages" }] : []));
    /**
     * The current active page, counting starts from 1
     *
     * @defaultValue 1
     */
    currentPage = model(1, ...(ngDevMode ? [{ debugName: "currentPage" }] : []));
    /**
     * The number of items per page.
     * Used to calculate the total number of page if `totalPages` is not available
     */
    pageSize = input(...(ngDevMode ? [undefined, { debugName: "pageSize" }] : []));
    /**
     * The total number of items.
     * Used to calculate the total number of page if `totalPages` is not available
     */
    totalRowCount = input(...(ngDevMode ? [undefined, { debugName: "totalRowCount" }] : []));
    /**
     * The text of the back button for pagination. Required for a11y.
     *
     * @defaultValue
     * ```
     * t(() => $localize`:@@SI_PAGINATION.BACK:Back`)
     * ```
     */
    backButtonText = input(t(() => $localize `:@@SI_PAGINATION.BACK:Back`), ...(ngDevMode ? [{ debugName: "backButtonText" }] : []));
    /**
     * The text of the forward button for pagination. Required for a11y.
     *
     * @defaultValue
     * ```
     * t(() => $localize`:@@SI_PAGINATION.FORWARD:Forward`)
     * ```
     */
    forwardButtonText = input(t(() => $localize `:@@SI_PAGINATION.FORWARD:Forward`), ...(ngDevMode ? [{ debugName: "forwardButtonText" }] : []));
    /**
     * When multiple paginations are used on the same page each pagination needs a distinct aria label.
     * Required for a11y.
     *
     * @defaultValue
     * ```
     * t(() => $localize`:@@SI_PAGINATION.NAV_LABEL:Pagination`)
     * ```
     */
    navAriaLabel = input(t(() => $localize `:@@SI_PAGINATION.NAV_LABEL:Pagination`), ...(ngDevMode ? [{ debugName: "navAriaLabel" }] : []));
    calculatedTotalPages = computed(() => this.totalPages() ?? Math.ceil((this.totalRowCount() ?? 0) / (this.pageSize() ?? 1)), ...(ngDevMode ? [{ debugName: "calculatedTotalPages" }] : []));
    prevDisabled = computed(() => this.currentPage() === 1, ...(ngDevMode ? [{ debugName: "prevDisabled" }] : []));
    nextDisabled = computed(() => this.currentPage() === this.calculatedTotalPages(), ...(ngDevMode ? [{ debugName: "nextDisabled" }] : []));
    pageButtons = computed(() => {
        const pageButtons = [];
        const totalPages = this.calculatedTotalPages();
        const currentPage = this.currentPage();
        if (totalPages <= SiPaginationComponent.maxItems) {
            for (let i = 0; i < totalPages; i++) {
                pageButtons.push({ page: i + 1, sep: false });
            }
        }
        else if (currentPage < SiPaginationComponent.maxItems - 2) {
            // separator only on the right (in LTR)
            for (let i = 0; i < SiPaginationComponent.maxItems - 2; i++) {
                pageButtons.push({ page: i + 1, sep: false });
            }
            pageButtons.push({ page: 0, sep: true });
            pageButtons.push({ page: totalPages, sep: false });
        }
        else if (currentPage >= totalPages - 3) {
            // separator only on the left (in LTR)
            pageButtons.push({ page: 1, sep: false });
            pageButtons.push({ page: 0, sep: true });
            for (let i = totalPages - SiPaginationComponent.maxItems + 2; i < totalPages; i++) {
                pageButtons.push({ page: i + 1, sep: false });
            }
        }
        else {
            // separator on both sides
            pageButtons.push({ page: 1, sep: false });
            pageButtons.push({ page: 0, sep: true });
            for (let i = -1; i <= 1; i++) {
                pageButtons.push({ page: currentPage + i, sep: false });
            }
            pageButtons.push({ page: 0, sep: true });
            pageButtons.push({ page: totalPages, sep: false });
        }
        return pageButtons;
    }, ...(ngDevMode ? [{ debugName: "pageButtons" }] : []));
    icons = addIcons({ elementLeft3, elementRight3 });
    direction(event, delta) {
        this.setPage(event, this.currentPage() + delta);
    }
    setPage(event, page) {
        event.currentTarget.blur();
        this.currentPage.set(page);
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.8", ngImport: i0, type: SiPaginationComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.0.8", type: SiPaginationComponent, isStandalone: true, selector: "si-pagination", inputs: { totalPages: { classPropertyName: "totalPages", publicName: "totalPages", isSignal: true, isRequired: false, transformFunction: null }, currentPage: { classPropertyName: "currentPage", publicName: "currentPage", isSignal: true, isRequired: false, transformFunction: null }, pageSize: { classPropertyName: "pageSize", publicName: "pageSize", isSignal: true, isRequired: false, transformFunction: null }, totalRowCount: { classPropertyName: "totalRowCount", publicName: "totalRowCount", isSignal: true, isRequired: false, transformFunction: null }, backButtonText: { classPropertyName: "backButtonText", publicName: "backButtonText", isSignal: true, isRequired: false, transformFunction: null }, forwardButtonText: { classPropertyName: "forwardButtonText", publicName: "forwardButtonText", isSignal: true, isRequired: false, transformFunction: null }, navAriaLabel: { classPropertyName: "navAriaLabel", publicName: "navAriaLabel", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { currentPage: "currentPageChange" }, ngImport: i0, template: "<nav role=\"navigation\" [attr.aria-label]=\"navAriaLabel() | translate\">\n  <ul class=\"pagination\">\n    <li class=\"me-5\">\n      <button\n        type=\"button\"\n        class=\"page-item mx-4\"\n        [class.disabled]=\"prevDisabled()\"\n        [disabled]=\"prevDisabled()\"\n        [attr.aria-label]=\"backButtonText() | translate\"\n        (click)=\"direction($event, -1)\"\n      >\n        <si-icon class=\"icon flip-rtl\" [icon]=\"icons.elementLeft3\" />\n      </button>\n    </li>\n    @for (page of pageButtons(); track $index) {\n      <li>\n        @if (!page.sep) {\n          <button\n            type=\"button\"\n            class=\"page-item\"\n            [attr.aria-current]=\"page.page === currentPage() ? 'page' : ''\"\n            [class.active]=\"page.page === currentPage()\"\n            [disabled]=\"page.page === currentPage()\"\n            (click)=\"setPage($event, page.page)\"\n          >\n            {{ page.page }}\n          </button>\n        } @else {\n          <span class=\"page-item separator mx-2\">&hellip;</span>\n        }\n      </li>\n    }\n    <li class=\"ms-5\">\n      <button\n        type=\"button\"\n        class=\"page-item mx-4\"\n        [class.disabled]=\"nextDisabled()\"\n        [disabled]=\"nextDisabled()\"\n        [attr.aria-label]=\"forwardButtonText() | translate\"\n        (click)=\"direction($event, 1)\"\n      >\n        <si-icon class=\"icon flip-rtl\" [icon]=\"icons.elementRight3\" />\n      </button>\n    </li>\n  </ul>\n</nav>\n", dependencies: [{ kind: "component", type: SiIconComponent, selector: "si-icon", inputs: ["icon"] }, { kind: "pipe", type: SiTranslatePipe, name: "translate" }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.8", ngImport: i0, type: SiPaginationComponent, decorators: [{
            type: Component,
            args: [{ selector: 'si-pagination', imports: [SiIconComponent, SiTranslatePipe], changeDetection: ChangeDetectionStrategy.OnPush, template: "<nav role=\"navigation\" [attr.aria-label]=\"navAriaLabel() | translate\">\n  <ul class=\"pagination\">\n    <li class=\"me-5\">\n      <button\n        type=\"button\"\n        class=\"page-item mx-4\"\n        [class.disabled]=\"prevDisabled()\"\n        [disabled]=\"prevDisabled()\"\n        [attr.aria-label]=\"backButtonText() | translate\"\n        (click)=\"direction($event, -1)\"\n      >\n        <si-icon class=\"icon flip-rtl\" [icon]=\"icons.elementLeft3\" />\n      </button>\n    </li>\n    @for (page of pageButtons(); track $index) {\n      <li>\n        @if (!page.sep) {\n          <button\n            type=\"button\"\n            class=\"page-item\"\n            [attr.aria-current]=\"page.page === currentPage() ? 'page' : ''\"\n            [class.active]=\"page.page === currentPage()\"\n            [disabled]=\"page.page === currentPage()\"\n            (click)=\"setPage($event, page.page)\"\n          >\n            {{ page.page }}\n          </button>\n        } @else {\n          <span class=\"page-item separator mx-2\">&hellip;</span>\n        }\n      </li>\n    }\n    <li class=\"ms-5\">\n      <button\n        type=\"button\"\n        class=\"page-item mx-4\"\n        [class.disabled]=\"nextDisabled()\"\n        [disabled]=\"nextDisabled()\"\n        [attr.aria-label]=\"forwardButtonText() | translate\"\n        (click)=\"direction($event, 1)\"\n      >\n        <si-icon class=\"icon flip-rtl\" [icon]=\"icons.elementRight3\" />\n      </button>\n    </li>\n  </ul>\n</nav>\n" }]
        }], propDecorators: { totalPages: [{ type: i0.Input, args: [{ isSignal: true, alias: "totalPages", required: false }] }], currentPage: [{ type: i0.Input, args: [{ isSignal: true, alias: "currentPage", required: false }] }, { type: i0.Output, args: ["currentPageChange"] }], pageSize: [{ type: i0.Input, args: [{ isSignal: true, alias: "pageSize", required: false }] }], totalRowCount: [{ type: i0.Input, args: [{ isSignal: true, alias: "totalRowCount", required: false }] }], backButtonText: [{ type: i0.Input, args: [{ isSignal: true, alias: "backButtonText", required: false }] }], forwardButtonText: [{ type: i0.Input, args: [{ isSignal: true, alias: "forwardButtonText", required: false }] }], navAriaLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "navAriaLabel", required: false }] }] } });

/**
 * Copyright (c) Siemens 2016 - 2026
 * SPDX-License-Identifier: MIT
 */
class SiPaginationModule {
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.8", ngImport: i0, type: SiPaginationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
    static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "21.0.8", ngImport: i0, type: SiPaginationModule, imports: [SiPaginationComponent], exports: [SiPaginationComponent] });
    static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "21.0.8", ngImport: i0, type: SiPaginationModule, imports: [SiPaginationComponent] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.8", ngImport: i0, type: SiPaginationModule, decorators: [{
            type: NgModule,
            args: [{
                    imports: [SiPaginationComponent],
                    exports: [SiPaginationComponent]
                }]
        }] });

/**
 * Copyright (c) Siemens 2016 - 2026
 * SPDX-License-Identifier: MIT
 */

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

export { SiPaginationComponent, SiPaginationModule };
//# sourceMappingURL=siemens-element-ng-pagination.mjs.map
