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: 'd8d99fb4bbc03f2dfba8295cf3ec8ee84bb26fce', class: "digi-navigation-pagination" }, h("digi-util-resize-observer", { key: '27084b1d413219aa3f2468beba86a5b4faf1cb75', onAfOnChange: (e) => {
                this.handleResizeObserver(e);
            } }), h("span", { key: '84e82c3caca5d9f4bcd36e132df10570f3ec431a', id: `${this.afId}-aria-label`, "aria-hidden": "true", class: "digi-navigation-pagination__aria-label" }, "Paginering"), h("nav", { key: 'e39ba4dc3ed4deb579aed3d212ef7f3310c8e9e4', "aria-labelledby": this.labelledby(), class: `digi-navigation-pagination__pagination ${this.twoRows ? 'digi-navigation-pagination--two-rows' : ''}` }, h("digi-button", { key: '684389743487f33f9a29ca418d0f1bf9a792063f', 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: 'c24a7960db56dde692e5c93ec08104ba706967ef', slot: "icon" }), h("span", { key: 'a71caf869f9567c1118f00a3212497410b7b43bf' }, "F\u00F6reg\u00E5ende")), h("digi-button", { key: '9ed520e00f4e5cbc1c8996ca93f2346bedefa378', 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: '9562e882499f2e0be5ea5b3dc55922ba7d49282a', slot: "icon-secondary" }), h("span", { key: '5f3234984162cc2524521606a0fb2ab645c6fb15' }, "N\u00E4sta")), h("div", { key: 'c2860112360036941893e2a5f76ab8ada71d99ff', class: "digi-navigation-pagination__pages" }, h("ol", { key: 'a7ff7c808e75ff7f60cc5e6d7a457d34ab00e49f', 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: '5e6ca5150d25cbf7b2dfbd0ee9f2cfaee505d806', 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: '5b068f6c49f07a653e0779ebb1d940b54713c8fd' }, h("span", { key: '904012c7fd0cd8e7a51d2f721484c6535b69fa1e', id: `${this.afId}-result-show` }, "Visar "), h("strong", { key: 'e2bb68ef9f625cdd204732eb1015d719e859a8e2', id: `${this.afId}-result-current` }, this.afCurrentResultStart, "-", this.afCurrentResultEnd), h("span", { key: '35f11256b8a1d8478c5706f63cad06c624442305', id: `${this.afId}-result-of` }, " av "), h("strong", { key: '0b03d745dac18a6a23f7197fedc24b3d666a18db', id: `${this.afId}-result-total` }, this.afTotalResults), this.afResultName && (h("span", { key: '785a668f07a32716e5d52bf34a17e50817764212', id: `${this.afId}-result-name` }, ` ${this.afResultName}`)))))));
    }
};
NavigationPagination.style = DigiNavigationPaginationStyle0;

export { NavigationPagination as digi_navigation_pagination };
