import { r as registerInstance, c as createEvent, h } from './index-148a7577.js';
import { r as randomIdGenerator } from './randomIdGenerator.util-56406f2e.js';
import './badge-notification-shape.enum-e15a6245.js';
import './typography-variation.enum-531cdf64.js';
import './badge-status-variation.enum-8d6370ff.js';
import './code-example-variation.enum-e656d235.js';
import './form-input-search-variation.enum-6d8dc10a.js';
import { B as ButtonVariation } from './button-variation.enum-94fffdd6.js';
import './calendar-week-view-heading-level.enum-6774297c.js';
import './code-variation.enum-1eee7c7a.js';
import './expandable-accordion-header-level.enum-85681e2f.js';
import './expandable-faq-item-variation.enum-a8cb225b.js';
import './expandable-faq-variation.enum-6934c367.js';
import './footer-card-variation.enum-cc732148.js';
import './form-checkbox-variation.enum-83e906fc.js';
import './form-file-upload-variation.enum-9c49ec5e.js';
import './form-input-type.enum-3da3db27.js';
import './form-input-variation.enum-64d9450f.js';
import './form-select-variation.enum-f2f6098d.js';
import './form-textarea-variation.enum-05017e8e.js';
import './form-validation-message-variation.enum-bcef8a9d.js';
import './info-card-multi-type.enum-07ee124f.js';
import './info-card-variation.enum-2ccc52c1.js';
import './layout-block-variation.enum-b7a20db4.js';
import './layout-columns-variation.enum-34f7754e.js';
import './link-button-variation.enum-84d4976f.js';
import './list-type.enum-fbb331ad.js';
import './loader-skeleton-variation.enum-f9f867b4.js';
import './loader-spinner-size.enum-0b246fa0.js';
import './logo-variation.enum-5b68b79f.js';
import './media-figure-alignment.enum-a1d36567.js';
import './navigation-sidebar-variation.enum-8fead764.js';
import './progress-indicator-variation.enum-b12ba50a.js';
import './progress-list-item-variation.enum-384b9a3a.js';
import './progress-list-variation.enum-300bd89d.js';
import './progressbar-variation.enum-40adaab4.js';
import './quote-image-inner-position.enum-8e9b1e65.js';
import './table-variation.enum-dd9366b6.js';
import './tag-media-icon.enum-fefa191c.js';
import './tag-size.enum-403e0cd8.js';
import './tools-feedback-banner-type.enum-74b4e580.js';
import './tools-feedback-rating-variation.enum-29058ff2.js';
import './tools-theme-provider.brand.enum-8c5a98c9.js';
import './typography-heading-jumbo-variation.enum-eb737f1b.js';
import './typography-meta-variation.enum-1f7c2878.js';
import './typography-time-variation.enum-34c830ef.js';
import './util-breakpoint-observer-breakpoints.enum-6d004731.js';

const navigationPaginationCss = "@charset \"UTF-8\";.sc-digi-navigation-pagination-h{--digi--navigation-pagination--button--padding:calc(var(--digi--gutter--small) + 1px) var(--digi--gutter--largest-2);--digi--navigation-pagination--button--icon--width:var(--digi--gutter--medium);--digi--navigation-pagination--button--width:8.750rem;--digi--navigation-pagination--button--margin:0.125rem;--digi--navigation-pagination--button--display:flex;--digi--navigation-pagination--button--justify-content--default:center;--digi--navigation-pagination--button--keep-right--margin:8.375rem;--digi--navigation-pagination--button--previous-button--border-radius:var(--digi--global--border-radius--base) 0 0 var(--digi--global--border-radius--base);--digi--navigation-pagination--button--next-button--border-radius:0 var(--digi--global--border-radius--base) var(--digi--global--border-radius--base) 0;--digi--navigation-pagination--button--page-button--padding:calc(var(--digi--gutter--medium) - 1px) calc(var(--digi--gutter--largest) - 1px);--digi--navigation-pagination--button--page-button--padding--compressed:calc(var(--digi--gutter--medium) - 1px) calc(var(--digi--gutter--medium) - 1px);--digi--navigation-pagination--button--page-button--margin:0 2px;--digi--navigation-pagination--button--page-button--width:2.750rem;--digi--navigation-pagination--button--page-button--height:2.750rem;--digi--navigation-pagination--button--page-button--border-radius:0;--digi--navigation-pagination--pages--margin:0 0 var(--digi--global--spacing--smallest-4) 0;--digi--navigation-pagination--result--pages--margin:var(--digi--margin--smaller) 0 0 0;--digi--navigation-pagination--result--margin:0;--digi--navigation-pagination--result--strong--font-weight:600;--digi--navigation-pagination--result--text-align:center;--digi--navigation-pagination--page-list--padding:0;--digi--navigation-pagination--page-list--margin:0}.sc-digi-navigation-pagination-h .digi-navigation-pagination__result.sc-digi-navigation-pagination{font-family:var(--digi--global--typography--font-family--default);text-align:var(--digi--navigation-pagination--result--text-align);font-size:var(--digi--typography--tag--font-size--desktop);margin:var(--digi--navigation-pagination--result--margin)}.sc-digi-navigation-pagination-h .digi-navigation-pagination__result--pages.sc-digi-navigation-pagination{--digi--navigation-pagination--result--margin:var(--digi--navigation-pagination--result--pages--margin)}.sc-digi-navigation-pagination-h .digi-navigation-pagination__result.sc-digi-navigation-pagination strong.sc-digi-navigation-pagination{font-weight:var(--digi--navigation-pagination--result--strong--font-weight)}.sc-digi-navigation-pagination-h .digi-navigation-pagination__pagination.sc-digi-navigation-pagination{display:flex;flex-wrap:wrap;justify-content:center;min-width:290px;gap:4px}.sc-digi-navigation-pagination-h .digi-navigation-pagination__pagination.sc-digi-navigation-pagination .digi-navigation-pagination__pages.sc-digi-navigation-pagination{order:2}.sc-digi-navigation-pagination-h .digi-navigation-pagination__pagination.digi-navigation-pagination--two-rows.sc-digi-navigation-pagination .digi-navigation-pagination__pages.sc-digi-navigation-pagination{order:-1;flex:1 0 100%;margin:var(--digi--navigation-pagination--pages--margin);display:flex;justify-content:center}.digi-navigation-pagination__button.sc-digi-navigation-pagination{--digi--button--padding--medium:var(--digi--navigation-pagination--button--padding);--digi--button--display:var(--digi--navigation-pagination--button--display);--digi--button--width:var(--digi--navigation-pagination--button--width);--digi--button--min-height--small:var(--digi--navigation-pagination--button--page-button--height);--digi--button--justify-content--default:var(--digi--navigation-pagination--button--justify-content--default)}.digi-navigation-pagination__button--hidden.sc-digi-navigation-pagination{visibility:hidden}.digi-navigation-pagination__button--previous.sc-digi-navigation-pagination{--digi--button--border-radius--secondary--default:var(--digi--navigation-pagination--button--previous-button--border-radius);--digi--button--border-radius--secondary--hover:var(--digi--navigation-pagination--button--previous-button--border-radius);order:1}.digi-navigation-pagination__button--next.sc-digi-navigation-pagination{--digi--button--border-radius--secondary--default:var(--digi--navigation-pagination--button--next-button--border-radius);--digi--button--border-radius--secondary--hover:var(--digi--navigation-pagination--button--next-button--border-radius);order:3}.digi-navigation-pagination__button.sc-digi-navigation-pagination-s>[slot^=icon],.digi-navigation-pagination__button .sc-digi-navigation-pagination-s>[slot^=icon]{--digi--icon--width:var(--digi--navigation-pagination--button--icon--width)}.digi-navigation-pagination__page-button.sc-digi-navigation-pagination{--digi--button--border-radius--secondary--default:var(--digi--navigation-pagination--button--page-button--border-radius);--digi--button--border-radius--primary--default:var(--digi--navigation-pagination--button--page-button--border-radius);--digi--button--border-radius--secondary--hover:var(--digi--navigation-pagination--button--page-button--border-radius);--digi--button--border-radius--primary--hover:var(--digi--navigation-pagination--button--page-button--border-radius);--digi--button--width:var(--digi--navigation-pagination--button--page-button--width);--digi--button--font-size--medium:14px;--digi--button--padding--medium:calc(var(--digi--gutter--medium) - 1px) 0;--digi--button--align-items:center;display:inline-block;text-align:center;letter-spacing:-1px}.ellipsis-first.sc-digi-navigation-pagination .digi-navigation-pagination__page-button.sc-digi-navigation-pagination .digi-navigation-pagination__page-text.sc-digi-navigation-pagination:after{content:\"…\"}.ellipsis-last.sc-digi-navigation-pagination .digi-navigation-pagination__page-button.sc-digi-navigation-pagination .digi-navigation-pagination__page-text.sc-digi-navigation-pagination:before{content:\"…\"}.sc-digi-navigation-pagination-h .digi-navigation-pagination__page-list.sc-digi-navigation-pagination{display:flex;list-style:none;padding:var(--digi--navigation-pagination--page-list--padding);margin:var(--digi--navigation-pagination--page-list--margin);gap:4px}.digi-navigation-pagination__aria-label.sc-digi-navigation-pagination{clip:rect(0 0 0 0);height:1px;padding:0;white-space:nowrap;width:1px;overflow:hidden;position:absolute}";
const DigiNavigationPaginationStyle0 = navigationPaginationCss;

const NavigationPagination = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.afOnPageChange = createEvent(this, "afOnPageChange", 7);
        this.afOnReady = createEvent(this, "afOnReady", 3);
        this.currentPage = undefined;
        this.twoRows = undefined;
        this.limit = 6;
        this.afInitActivePage = 1;
        this.afTotalPages = undefined;
        this.afCurrentResultStart = undefined;
        this.afId = randomIdGenerator('digi-navigation-pagination');
        this.afCurrentResultEnd = undefined;
        this.afTotalResults = 0;
        this.afResultName = '';
        this.afLimit = 6;
    }
    setTwoRows(value) {
        this.twoRows = value;
    }
    setLimit(value) {
        this.limit = value;
    }
    /**
     * Kan användas för att manuellt sätta om den aktiva sidan.
     * @en Can be used to set the active page.
     */
    async afMSetCurrentPage(pageNumber) {
        this.setCurrentPage(pageNumber, false);
    }
    /**
     * Handles which pages to display when the total amount of pages exceeds 6
     */
    getPagination(currentPage, numPages, maxLength) {
        let startPage = Math.max(currentPage - Math.floor(maxLength / 2), 1);
        let endPage = startPage + maxLength - 1;
        if (endPage > numPages) {
            endPage = numPages;
            startPage = Math.max(endPage - maxLength + 1, 1);
        }
        const pages = [];
        for (let i = startPage; i <= endPage; i++) {
            pages.push(i);
        }
        if (startPage > 1) {
            pages.shift(); //remove first array item
            pages.unshift('1…'); //add first
        }
        if (endPage < numPages) {
            pages.pop(); //remove last array item
            pages.push('…' + numPages); //add last
        }
        return pages;
    }
    get currentInterval() {
        return this.getPagination(this.currentPage, this.afTotalPages, this.limit);
    }
    prevPage() {
        this.setCurrentPage(this.currentPage - 1, true);
    }
    nextPage() {
        this.setCurrentPage(this.currentPage + 1, true);
    }
    setCurrentPage(pageToSet = this.currentPage, emitEvent = true) {
        if (pageToSet === this.currentPage) {
            return;
        }
        this.currentPage =
            pageToSet <= 1
                ? 1
                : pageToSet <= this.afTotalPages
                    ? pageToSet
                    : this.afTotalPages;
        if (emitEvent) {
            this.afOnPageChange.emit(this.currentPage);
        }
    }
    buttonAriaLabel(pageNumber) {
        return `${pageNumber}`;
    }
    handleResizeObserver(e) {
        const w = Math.round(e.detail.contentRect.width);
        if (!isNaN(w)) {
            const buttonWidth = 52;
            const minNavWidth = 570;
            if (w > minNavWidth) {
                const diff = Math.floor((w - minNavWidth) / buttonWidth);
                const minLimit = 6;
                this.setLimit(Math.min(minLimit + diff, this.afLimit));
                this.setTwoRows(false);
            }
            else {
                this.setTwoRows(true);
            }
        }
    }
    componentDidLoad() {
        this.afOnReady.emit();
    }
    componentWillLoad() {
        this.setCurrentPage(this.afInitActivePage, false);
    }
    isCurrentPage(currentPage, page) {
        if (currentPage === page || null) {
            return 'page';
        }
    }
    labelledby() {
        if (this.afTotalResults > 0) {
            return `
        ${this.afId}-aria-label
        ${this.afId}-result-show
        ${this.afId}-result-current
        ${this.afId}-result-of
        ${this.afId}-result-total
        ${this.afId}-result-name
      `;
        }
        else {
            return `${this.afId}-aria-label`;
        }
    }
    render() {
        return (h("div", { key: 'f2e28d3e529f4020243c07f29de63516e93214e4', class: "digi-navigation-pagination" }, h("digi-util-resize-observer", { key: 'cc3b66a9ed04a216097cd9828ea6385ac5047aeb', onAfOnChange: (e) => {
                this.handleResizeObserver(e);
            } }), h("span", { key: 'bac9929a11d0067fe8caf84a672da89ef3ad4aae', id: `${this.afId}-aria-label`, "aria-hidden": "true", class: "digi-navigation-pagination__aria-label" }, "Paginering"), h("nav", { key: '2737a921d418e5da0673dbab894ecfc8ad123acf', "aria-labelledby": this.labelledby(), class: `digi-navigation-pagination__pagination ${this.twoRows ? 'digi-navigation-pagination--two-rows' : ''}` }, h("digi-button", { key: '472ca42ce075e8aa10c1c8eaebe424d999185b4e', onClick: () => this.prevPage(), class: {
                'digi-navigation-pagination__button digi-navigation-pagination__button--previous': true,
                'digi-navigation-pagination__button--hidden': this.currentPage === 1
            }, afVariation: "secondary", afAriaLabel: "F\u00F6reg\u00E5ende" }, h("digi-icon-chevron-left", { key: '3225507e8b69efc3c598f7c05187816474b61dc4', slot: "icon" }), h("span", { key: 'ecd596ac495c5edec01acf93d2ce5456398931b4' }, "F\u00F6reg\u00E5ende")), h("digi-button", { key: '4720a2d4b836b9898e9716d022b1427e559db789', onClick: () => this.nextPage(), class: {
                'digi-navigation-pagination__button digi-navigation-pagination__button--next': true,
                'digi-navigation-pagination__button--hidden': this.currentPage === this.afTotalPages
            }, afVariation: "secondary", afAriaLabel: "N\u00E4sta" }, h("digi-icon-chevron-right", { key: 'e3d86e3f4cfd8572f3d10758134a2050abfd1fd6', slot: "icon-secondary" }), h("span", { key: '6a0d762c6c46b961ead3f8ab931de007538fc887' }, "N\u00E4sta")), h("div", { key: '89fc1a2596097283ffbe64a934c6fadb2c9fbcc3', class: "digi-navigation-pagination__pages" }, h("ol", { key: '6540d8b7340b28a33510b1b08497cf1da6dc0764', class: "digi-navigation-pagination__page-list" }, this.currentInterval.map((pageValue) => {
            const page = isNaN(pageValue)
                ? parseInt(pageValue.replace('…', ''))
                : pageValue;
            return (h("li", { class: `digi-navigation-pagination__page-list-item ${isNaN(pageValue) ? (page === 1 ? 'ellipsis-first' : 'ellipsis-last') : ''}` }, h("digi-button", { onClick: () => this.setCurrentPage(page), afAriaLabel: this.buttonAriaLabel(page), afAriaCurrent: this.isCurrentPage(this.currentPage, page), class: {
                    'digi-navigation-pagination__button': true,
                    'digi-navigation-pagination__page-button': true,
                    'digi-navigation-pagination__page-button--active': this.currentPage === page
                }, afVariation: this.currentPage === page
                    ? ButtonVariation.PRIMARY
                    : ButtonVariation.SECONDARY }, h("span", { class: `digi-navigation-pagination__page-text` }, page))));
        })))), this.afTotalResults > 0 && (h("div", { key: 'b91ec2afc620c6c3c31ff71758d9a1359313ab45', class: {
                'digi-navigation-pagination__result': true,
                'digi-navigation-pagination__result--pages': this.afTotalPages > 1
            }, "aria-hidden": this.afTotalPages > 1 ? 'true' : 'false', id: `${this.afId}-result` }, h("digi-typography", { key: 'e648fb8e0cf7320664760e3c4af25eac6922332f' }, h("span", { key: '2d14913e9f62fc02656e48eaa4061196cba2048a', id: `${this.afId}-result-show` }, "Visar "), h("strong", { key: '2c33cc8ae5dd40125fc6e0f6d78c7cec7610628b', id: `${this.afId}-result-current` }, this.afCurrentResultStart, "-", this.afCurrentResultEnd), h("span", { key: '75476de666cb33b05371d06a253d57cf2bb7b54b', id: `${this.afId}-result-of` }, " av "), h("strong", { key: '2a53e018958c26b5b87e13db724ba955720449aa', id: `${this.afId}-result-total` }, this.afTotalResults), this.afResultName && (h("span", { key: '2fd196e20cb4c6069192dce4caff7336531f7c6f', id: `${this.afId}-result-name` }, ` ${this.afResultName}`)))))));
    }
};
NavigationPagination.style = DigiNavigationPaginationStyle0;

export { NavigationPagination as digi_navigation_pagination };
