import * as i0 from '@angular/core';
import { inject, output, model, input, computed, ChangeDetectionStrategy, Component } from '@angular/core';
import * as i1 from '@angular/forms';
import { FormsModule } from '@angular/forms';
import { TranslatePipe } from '@ngx-translate/core';
import { ZButtonComponent } from '@shival99/z-ui/components/z-button';
import { ZButtonGroupComponent } from '@shival99/z-ui/components/z-button-group';
import { ZIconComponent } from '@shival99/z-ui/components/z-icon';
import { ZInputComponent } from '@shival99/z-ui/components/z-input';
import { ZSelectComponent } from '@shival99/z-ui/components/z-select';
import { ZTranslateService } from '@shival99/z-ui/services';

class ZPaginationComponent {
    _zTranslate = inject(ZTranslateService);
    zOnPageChange = output();
    zPageIndex = model(1, ...(ngDevMode ? [{ debugName: "zPageIndex" }] : []));
    zPageSize = model(10, ...(ngDevMode ? [{ debugName: "zPageSize" }] : []));
    zTotal = input.required(...(ngDevMode ? [{ debugName: "zTotal" }] : []));
    zPageSizeOptions = input([10, 20, 50, 100], ...(ngDevMode ? [{ debugName: "zPageSizeOptions" }] : []));
    zShowSizeChanger = input(true, ...(ngDevMode ? [{ debugName: "zShowSizeChanger" }] : []));
    zShowQuickJumper = input(false, ...(ngDevMode ? [{ debugName: "zShowQuickJumper" }] : []));
    zShowTotal = input(true, ...(ngDevMode ? [{ debugName: "zShowTotal" }] : []));
    zSimple = input(false, ...(ngDevMode ? [{ debugName: "zSimple" }] : []));
    zSize = input('default', ...(ngDevMode ? [{ debugName: "zSize" }] : []));
    zDisabled = input(false, ...(ngDevMode ? [{ debugName: "zDisabled" }] : []));
    zTotalLabel = input(null, ...(ngDevMode ? [{ debugName: "zTotalLabel" }] : []));
    zPerPageLabel = input(null, ...(ngDevMode ? [{ debugName: "zPerPageLabel" }] : []));
    zGoToLabel = input(null, ...(ngDevMode ? [{ debugName: "zGoToLabel" }] : []));
    totalLabelText = computed(() => {
        this._zTranslate.currentLang();
        if (this.zTotalLabel()) {
            return this.zTotalLabel().replace('{{total}}', String(this.zTotal()));
        }
        return this._zTranslate.instant('i18n_z_ui_pagination_total_label', { total: this.zTotal() });
    }, ...(ngDevMode ? [{ debugName: "totalLabelText" }] : []));
    perPageLabelText = computed(() => {
        this._zTranslate.currentLang();
        return this.zPerPageLabel() ?? this._zTranslate.instant('i18n_z_ui_pagination_per_page');
    }, ...(ngDevMode ? [{ debugName: "perPageLabelText" }] : []));
    goToLabelText = computed(() => {
        this._zTranslate.currentLang();
        return this.zGoToLabel() ?? this._zTranslate.instant('i18n_z_ui_pagination_go_to');
    }, ...(ngDevMode ? [{ debugName: "goToLabelText" }] : []));
    totalPages = computed(() => {
        const total = this.zTotal();
        const pageSize = this.zPageSize();
        return Math.max(1, Math.ceil(total / pageSize));
    }, ...(ngDevMode ? [{ debugName: "totalPages" }] : []));
    pageSizeOptions = computed(() => this.zPageSizeOptions().map(size => ({
        label: `${size} ${this.perPageLabelText()}`,
        value: size,
    })), ...(ngDevMode ? [{ debugName: "pageSizeOptions" }] : []));
    visiblePages = computed(() => {
        const current = this.zPageIndex();
        const total = this.totalPages();
        const pages = [];
        const maxVisible = 5;
        if (total <= maxVisible) {
            for (let i = 1; i <= total; i++) {
                pages.push(i);
            }
            return pages;
        }
        pages.push(1);
        let startPage = Math.max(2, current - 1);
        let endPage = Math.min(total - 1, current + 1);
        if (current <= 3) {
            endPage = Math.min(total - 1, 3);
        }
        else if (current >= total - 2) {
            startPage = Math.max(2, total - 2);
        }
        if (startPage > 2) {
            pages.push('ellipsis');
        }
        for (let i = startPage; i <= endPage; i++) {
            pages.push(i);
        }
        if (endPage < total - 1) {
            pages.push('ellipsis');
        }
        pages.push(total);
        return pages;
    }, ...(ngDevMode ? [{ debugName: "visiblePages" }] : []));
    canGoPrev = computed(() => this.zPageIndex() > 1, ...(ngDevMode ? [{ debugName: "canGoPrev" }] : []));
    canGoNext = computed(() => this.zPageIndex() < this.totalPages(), ...(ngDevMode ? [{ debugName: "canGoNext" }] : []));
    goToPage(page) {
        if (page < 1 || page > this.totalPages()) {
            return;
        }
        if (page === this.zPageIndex()) {
            return;
        }
        this.zPageIndex.set(page);
        this._emitChange();
    }
    goToPrev() {
        if (!this.canGoPrev()) {
            return;
        }
        this.goToPage(this.zPageIndex() - 1);
    }
    goToNext() {
        if (!this.canGoNext()) {
            return;
        }
        this.goToPage(this.zPageIndex() + 1);
    }
    onPageSizeChange(size) {
        const sizeValue = typeof size === 'object' && size !== null && 'value' in size
            ? size.value
            : size;
        if (!Number.isFinite(sizeValue) || sizeValue <= 0) {
            return;
        }
        this.zPageSize.set(sizeValue);
        this.zPageIndex.set(1);
        this._emitChange();
    }
    onQuickJump(event) {
        const input = event.target;
        const page = parseInt(input.value, 10);
        if (isNaN(page) || page < 1 || page > this.totalPages()) {
            input.value = String(this.zPageIndex());
            return;
        }
        this.goToPage(page);
    }
    _emitChange() {
        this.zOnPageChange.emit({
            pageIndex: this.zPageIndex(),
            pageSize: this.zPageSize(),
        });
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.9", ngImport: i0, type: ZPaginationComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.0.9", type: ZPaginationComponent, isStandalone: true, selector: "z-pagination", inputs: { zPageIndex: { classPropertyName: "zPageIndex", publicName: "zPageIndex", isSignal: true, isRequired: false, transformFunction: null }, zPageSize: { classPropertyName: "zPageSize", publicName: "zPageSize", isSignal: true, isRequired: false, transformFunction: null }, zTotal: { classPropertyName: "zTotal", publicName: "zTotal", isSignal: true, isRequired: true, transformFunction: null }, zPageSizeOptions: { classPropertyName: "zPageSizeOptions", publicName: "zPageSizeOptions", isSignal: true, isRequired: false, transformFunction: null }, zShowSizeChanger: { classPropertyName: "zShowSizeChanger", publicName: "zShowSizeChanger", isSignal: true, isRequired: false, transformFunction: null }, zShowQuickJumper: { classPropertyName: "zShowQuickJumper", publicName: "zShowQuickJumper", isSignal: true, isRequired: false, transformFunction: null }, zShowTotal: { classPropertyName: "zShowTotal", publicName: "zShowTotal", isSignal: true, isRequired: false, transformFunction: null }, zSimple: { classPropertyName: "zSimple", publicName: "zSimple", isSignal: true, isRequired: false, transformFunction: null }, zSize: { classPropertyName: "zSize", publicName: "zSize", isSignal: true, isRequired: false, transformFunction: null }, zDisabled: { classPropertyName: "zDisabled", publicName: "zDisabled", isSignal: true, isRequired: false, transformFunction: null }, zTotalLabel: { classPropertyName: "zTotalLabel", publicName: "zTotalLabel", isSignal: true, isRequired: false, transformFunction: null }, zPerPageLabel: { classPropertyName: "zPerPageLabel", publicName: "zPerPageLabel", isSignal: true, isRequired: false, transformFunction: null }, zGoToLabel: { classPropertyName: "zGoToLabel", publicName: "zGoToLabel", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { zOnPageChange: "zOnPageChange", zPageIndex: "zPageIndexChange", zPageSize: "zPageSizeChange" }, host: { classAttribute: "z-pagination flex items-center gap-2" }, ngImport: i0, template: "@if (zShowTotal()) {\n  <span class=\"text-muted-foreground text-sm whitespace-nowrap\">{{ totalLabelText() }}</span>\n}\n\n@if (!zSimple()) {\n  <!-- Page Size Selector -->\n  @if (zShowSizeChanger()) {\n    <z-select\n      class=\"w-fit\"\n      zSize=\"sm\"\n      [zOptions]=\"pageSizeOptions()\"\n      [ngModel]=\"zPageSize()\"\n      (ngModelChange)=\"onPageSizeChange($event)\"\n      [zDisabled]=\"zDisabled()\"\n      [zShowSearch]=\"false\" />\n  }\n\n  <z-button-group class=\"z-pagination-pages\">\n    <!-- Prev Button -->\n    <z-button zType=\"outline\" zSize=\"sm\" [zDisabled]=\"!canGoPrev() || zDisabled()\" (click)=\"goToPrev()\">\n      <z-icon zType=\"lucideChevronLeft\" zSize=\"16\" />\n    </z-button>\n\n    <!-- Page Numbers -->\n    @for (page of visiblePages(); track $index) {\n      @if (page === 'ellipsis') {\n        <span\n          class=\"z-pagination-ellipsis text-muted-foreground border-input flex h-8 w-8 items-center justify-center border-y border-r bg-transparent text-sm\">\n          ...\n        </span>\n      } @else {\n        <z-button\n          zType=\"outline\"\n          [zWave]=\"false\"\n          zSize=\"sm\"\n          [class]=\"\n            page === zPageIndex() ? 'relative min-w-8 overflow-hidden !bg-transparent hover:!bg-transparent' : 'min-w-8'\n          \"\n          [zDisabled]=\"zDisabled()\"\n          (click)=\"goToPage(page)\">\n          @if (page === zPageIndex()) {\n            <span class=\"bg-primary pointer-events-none absolute inset-[1px] rounded-[1px]\"></span>\n          }\n          <span [class]=\"page === zPageIndex() ? 'text-primary-foreground relative z-[1]' : ''\">{{ page }}</span>\n        </z-button>\n      }\n    }\n\n    <!-- Next Button -->\n    <z-button zType=\"outline\" zSize=\"sm\" [zDisabled]=\"!canGoNext() || zDisabled()\" (click)=\"goToNext()\">\n      <z-icon zType=\"lucideChevronRight\" zSize=\"16\" />\n    </z-button>\n  </z-button-group>\n\n  <!-- Quick Jumper -->\n  @if (zShowQuickJumper()) {\n    <div class=\"flex items-center gap-2 text-sm\">\n      <span class=\"text-muted-foreground whitespace-nowrap\">{{ goToLabelText() }}</span>\n      <z-input\n        zType=\"number\"\n        zSize=\"sm\"\n        class=\"w-14\"\n        [ngModel]=\"zPageIndex()\"\n        [zMin]=\"1\"\n        [zMax]=\"totalPages()\"\n        [zDisabled]=\"zDisabled()\"\n        (keydown.enter)=\"onQuickJump($event)\"\n        (blur)=\"onQuickJump($event)\" />\n    </div>\n  }\n} @else {\n  <!-- Simple Mode -->\n  <z-button-group>\n    <z-button zType=\"outline\" zSize=\"sm\" [zDisabled]=\"!canGoPrev() || zDisabled()\" (click)=\"goToPrev()\">\n      <z-icon zType=\"lucideChevronLeft\" zSize=\"16\" />\n      <span class=\"ml-1\">{{ 'i18n_z_ui_pagination_previous' | translate }}</span>\n    </z-button>\n\n    <span class=\"text-muted-foreground border-input flex h-8 items-center border-y bg-transparent px-3 text-sm\">\n      {{ zPageIndex() }} / {{ totalPages() }}\n    </span>\n\n    <z-button zType=\"outline\" zSize=\"sm\" [zDisabled]=\"!canGoNext() || zDisabled()\" (click)=\"goToNext()\">\n      <span class=\"mr-1\">{{ 'i18n_z_ui_pagination_next' | translate }}</span>\n      <z-icon zType=\"lucideChevronRight\" zSize=\"16\" />\n    </z-button>\n  </z-button-group>\n}\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: ZButtonComponent, selector: "z-button, button[z-button], a[z-button]", inputs: ["class", "zType", "zSize", "zShape", "zLabel", "zLoading", "zDisabled", "zTypeIcon", "zAnimatedTypeIcon", "zAnimateIcon", "zAnimationTriggerIcon", "zSizeIcon", "zStrokeWidthIcon", "zWave"], exportAs: ["zButton"] }, { kind: "component", type: ZButtonGroupComponent, selector: "z-button-group", inputs: ["zClass", "zOrientation", "zActive"], outputs: ["zActiveChange"], exportAs: ["zButtonGroup"] }, { kind: "component", type: ZIconComponent, selector: "z-icon, [z-icon]", inputs: ["class", "zType", "zAnimatedType", "zAnimate", "zAnimationTrigger", "zSize", "zStrokeWidth", "zSvg"] }, { kind: "component", type: ZInputComponent, selector: "z-input", inputs: ["class", "zType", "zSize", "zAlign", "zLabel", "zLabelClass", "zPlaceholder", "zRequired", "zDisabled", "zReadonly", "zPrefix", "zSuffix", "zMin", "zMax", "zStep", "zShowArrows", "zMask", "zDecimalPlaces", "zAllowNegative", "zThousandSeparator", "zDecimalMarker", "zValidators", "zAsyncValidators", "zAsyncDebounce", "zAsyncValidateOn", "zShowPasswordToggle", "zSearch", "zDebounce", "zAutofocus", "zAutoComplete", "zAllowClear", "zAutoSizeContent", "zRows", "zResize", "zMaxLength", "zAutoSuggest", "zColorConfig"], outputs: ["zOnSearch", "zOnChange", "zOnBlur", "zOnFocus", "zOnKeydown", "zOnEnter", "zOnColorCollapse", "zControl", "zEvent"], exportAs: ["zInput"] }, { kind: "component", type: ZSelectComponent, selector: "z-select", inputs: ["class", "zMode", "zSize", "zLabel", "zLabelClass", "zPlaceholder", "zRequired", "zDisabled", "zReadonly", "zLoading", "zPrefix", "zAllowClear", "zWrap", "zShowSearch", "zPlaceholderSearch", "zDebounce", "zNotFoundText", "zEmptyText", "zEmptyIcon", "zMaxTagCount", "zDropdownMaxHeight", "zOptionHeight", "zVirtualScroll", "zShowAction", "zOptions", "zConfig", "zTranslateLabels", "zKey", "zSearchServer", "zLoadingMore", "zEnableLoadMore", "zScrollDistance", "zMaxVisible", "zScrollClose", "zPosition", "zSelectedTemplate", "zOptionTemplate", "zActionTemplate", "zAsyncValidators", "zAsyncDebounce", "zAsyncValidateOn", "zValidators"], outputs: ["zOnSearch", "zOnLoadMore", "zOnBlur", "zOnFocus", "zControl", "zEvent"], exportAs: ["zSelect"] }, { kind: "pipe", type: TranslatePipe, name: "translate" }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.9", ngImport: i0, type: ZPaginationComponent, decorators: [{
            type: Component,
            args: [{ selector: 'z-pagination', imports: [
                        FormsModule,
                        ZButtonComponent,
                        ZButtonGroupComponent,
                        ZIconComponent,
                        ZInputComponent,
                        ZSelectComponent,
                        TranslatePipe,
                    ], standalone: true, changeDetection: ChangeDetectionStrategy.OnPush, host: {
                        class: 'z-pagination flex items-center gap-2',
                    }, template: "@if (zShowTotal()) {\n  <span class=\"text-muted-foreground text-sm whitespace-nowrap\">{{ totalLabelText() }}</span>\n}\n\n@if (!zSimple()) {\n  <!-- Page Size Selector -->\n  @if (zShowSizeChanger()) {\n    <z-select\n      class=\"w-fit\"\n      zSize=\"sm\"\n      [zOptions]=\"pageSizeOptions()\"\n      [ngModel]=\"zPageSize()\"\n      (ngModelChange)=\"onPageSizeChange($event)\"\n      [zDisabled]=\"zDisabled()\"\n      [zShowSearch]=\"false\" />\n  }\n\n  <z-button-group class=\"z-pagination-pages\">\n    <!-- Prev Button -->\n    <z-button zType=\"outline\" zSize=\"sm\" [zDisabled]=\"!canGoPrev() || zDisabled()\" (click)=\"goToPrev()\">\n      <z-icon zType=\"lucideChevronLeft\" zSize=\"16\" />\n    </z-button>\n\n    <!-- Page Numbers -->\n    @for (page of visiblePages(); track $index) {\n      @if (page === 'ellipsis') {\n        <span\n          class=\"z-pagination-ellipsis text-muted-foreground border-input flex h-8 w-8 items-center justify-center border-y border-r bg-transparent text-sm\">\n          ...\n        </span>\n      } @else {\n        <z-button\n          zType=\"outline\"\n          [zWave]=\"false\"\n          zSize=\"sm\"\n          [class]=\"\n            page === zPageIndex() ? 'relative min-w-8 overflow-hidden !bg-transparent hover:!bg-transparent' : 'min-w-8'\n          \"\n          [zDisabled]=\"zDisabled()\"\n          (click)=\"goToPage(page)\">\n          @if (page === zPageIndex()) {\n            <span class=\"bg-primary pointer-events-none absolute inset-[1px] rounded-[1px]\"></span>\n          }\n          <span [class]=\"page === zPageIndex() ? 'text-primary-foreground relative z-[1]' : ''\">{{ page }}</span>\n        </z-button>\n      }\n    }\n\n    <!-- Next Button -->\n    <z-button zType=\"outline\" zSize=\"sm\" [zDisabled]=\"!canGoNext() || zDisabled()\" (click)=\"goToNext()\">\n      <z-icon zType=\"lucideChevronRight\" zSize=\"16\" />\n    </z-button>\n  </z-button-group>\n\n  <!-- Quick Jumper -->\n  @if (zShowQuickJumper()) {\n    <div class=\"flex items-center gap-2 text-sm\">\n      <span class=\"text-muted-foreground whitespace-nowrap\">{{ goToLabelText() }}</span>\n      <z-input\n        zType=\"number\"\n        zSize=\"sm\"\n        class=\"w-14\"\n        [ngModel]=\"zPageIndex()\"\n        [zMin]=\"1\"\n        [zMax]=\"totalPages()\"\n        [zDisabled]=\"zDisabled()\"\n        (keydown.enter)=\"onQuickJump($event)\"\n        (blur)=\"onQuickJump($event)\" />\n    </div>\n  }\n} @else {\n  <!-- Simple Mode -->\n  <z-button-group>\n    <z-button zType=\"outline\" zSize=\"sm\" [zDisabled]=\"!canGoPrev() || zDisabled()\" (click)=\"goToPrev()\">\n      <z-icon zType=\"lucideChevronLeft\" zSize=\"16\" />\n      <span class=\"ml-1\">{{ 'i18n_z_ui_pagination_previous' | translate }}</span>\n    </z-button>\n\n    <span class=\"text-muted-foreground border-input flex h-8 items-center border-y bg-transparent px-3 text-sm\">\n      {{ zPageIndex() }} / {{ totalPages() }}\n    </span>\n\n    <z-button zType=\"outline\" zSize=\"sm\" [zDisabled]=\"!canGoNext() || zDisabled()\" (click)=\"goToNext()\">\n      <span class=\"mr-1\">{{ 'i18n_z_ui_pagination_next' | translate }}</span>\n      <z-icon zType=\"lucideChevronRight\" zSize=\"16\" />\n    </z-button>\n  </z-button-group>\n}\n" }]
        }], propDecorators: { zOnPageChange: [{ type: i0.Output, args: ["zOnPageChange"] }], zPageIndex: [{ type: i0.Input, args: [{ isSignal: true, alias: "zPageIndex", required: false }] }, { type: i0.Output, args: ["zPageIndexChange"] }], zPageSize: [{ type: i0.Input, args: [{ isSignal: true, alias: "zPageSize", required: false }] }, { type: i0.Output, args: ["zPageSizeChange"] }], zTotal: [{ type: i0.Input, args: [{ isSignal: true, alias: "zTotal", required: true }] }], zPageSizeOptions: [{ type: i0.Input, args: [{ isSignal: true, alias: "zPageSizeOptions", required: false }] }], zShowSizeChanger: [{ type: i0.Input, args: [{ isSignal: true, alias: "zShowSizeChanger", required: false }] }], zShowQuickJumper: [{ type: i0.Input, args: [{ isSignal: true, alias: "zShowQuickJumper", required: false }] }], zShowTotal: [{ type: i0.Input, args: [{ isSignal: true, alias: "zShowTotal", required: false }] }], zSimple: [{ type: i0.Input, args: [{ isSignal: true, alias: "zSimple", required: false }] }], zSize: [{ type: i0.Input, args: [{ isSignal: true, alias: "zSize", required: false }] }], zDisabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "zDisabled", required: false }] }], zTotalLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "zTotalLabel", required: false }] }], zPerPageLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "zPerPageLabel", required: false }] }], zGoToLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "zGoToLabel", required: false }] }] } });

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

export { ZPaginationComponent };
//# sourceMappingURL=shival99-z-ui-components-z-pagination.mjs.map
