import { p as t, H as a, c as i, h as n, F as e, t as o } from './p-BfLQgzDX.js';
import { c as s } from './p-D7YaJBkB.js';
import { g as r } from './p-Dpaq_7dX.js';
import { d as p } from './p-5F1gBr3j.js';
import { d as l } from './p-f9tCETeY.js';
import { d as g } from './p-dR-hNm6x.js';
import { d as c } from './p-BpML1w-i.js';
import { d as k } from './p-CE6EHX9u.js';
import { d } from './p-BQ5SoHuZ.js';
import { d as h } from './p-C6qt54JA.js';
function f(t, a) {
  return t.replace(/\{(\w+)\}/g, (t, i) => {
    var n;
    return (null === (n = a[i]) || void 0 === n ? void 0 : n.toString()) || t;
  });
}
function m(t, a, i, n) {
  return { currentPage: t, totalPages: n, startItem: (t - 1) * a + 1, endItem: Math.min(t * a, i), totalItems: i };
}
const b = t(
  class extends a {
    constructor(t) {
      (super(),
        !1 !== t && this.__registerHost(),
        (this.tkNextPage = i(this, 'tk-next-page', 7)),
        (this.tkPageChange = i(this, 'tk-page-change', 7)),
        (this.tkPrevPage = i(this, 'tk-prev-page', 7)),
        (this.tkRowsPerPageChange = i(this, 'tk-rows-per-page-change', 7)),
        (this.ellipsis = '...'),
        (this.internalCurrentPage = 1),
        (this.rounded = !1),
        (this.rowsPerPage = 10),
        (this.totalItems = 0),
        (this.rowsPerPageOptions = [5, 10, 20, 50]),
        (this.type = 'outlined'),
        (this.pageReportTemplate = 'page: {currentPage} of {totalPages}'),
        (this.itemsReportTemplate = 'item: {startItem}-{endItem} of {totalItems}'),
        (this.currentPage = 1),
        (this.handlePageClick = t => {
          t >= 1 && t <= this.getTotalPages() && (this.internalCurrentPage = t);
        }),
        (this.handlePrevClick = () => {
          this.internalCurrentPage > 1 && (this.internalCurrentPage--, this.tkPrevPage.emit({ page: this.internalCurrentPage }));
        }),
        (this.handleNextClick = () => {
          this.internalCurrentPage < this.getTotalPages() && (this.internalCurrentPage++, this.tkNextPage.emit({ page: this.internalCurrentPage }));
        }));
    }
    internalCurrentPageChanged(t) {
      ((this.currentPage = t), this.updateInputValue(t), this.emitPageChangeEvents());
    }
    currentPageChanged(t) {
      ((this.internalCurrentPage = t), this.updateInputValue(t));
    }
    componentWillLoad() {
      ((this.internalCurrentPage = this.currentPage), this.updateInputValue(this.currentPage));
    }
    updateInputValue(t) {
      this.inputValue = t.toString();
    }
    getTotalPages() {
      return Math.ceil(this.totalItems / this.rowsPerPage);
    }
    getPageNumbers() {
      const t = this.getTotalPages(),
        a = this.internalCurrentPage,
        i = [];
      if (t <= 5) for (let a = 1; a <= t; a++) i.push(a);
      else t <= 7 ? this.generatePageNumbersForMediumRange(i, a, t) : this.generatePageNumbersForLargeRange(i, a, t);
      return i;
    }
    generatePageNumbersForMediumRange(t, a, i) {
      if ((t.push(1), a <= 3)) {
        for (let a = 2; a <= 5; a++) t.push(a);
        t.push(this.ellipsis);
      } else if (a >= i - 2) {
        t.push(this.ellipsis);
        for (let a = i - 4; a < i; a++) t.push(a);
      } else {
        t.push(this.ellipsis);
        for (let i = a - 1; i <= a + 1; i++) t.push(i);
        t.push(this.ellipsis);
      }
      t.push(i);
    }
    generatePageNumbersForLargeRange(t, a, i) {
      if ((t.push(1), a <= 4)) {
        for (let a = 2; a <= 5; a++) t.push(a);
        t.push(this.ellipsis, i);
      } else if (a >= i - 3) {
        t.push(this.ellipsis);
        for (let a = i - 4; a <= i; a++) t.push(a);
      } else {
        t.push(this.ellipsis);
        for (let i = a - 2; i <= a + 2; i++) t.push(i);
        t.push(this.ellipsis, i);
      }
    }
    validateAndUpdatePage() {
      const t = parseInt(this.inputValue, 10),
        a = this.getTotalPages();
      !isNaN(t) && t >= 1 && t <= a ? this.handlePageClick(t) : this.updateInputValue(this.internalCurrentPage);
    }
    emitPageChangeEvents() {
      const t = this.getTotalPages(),
        a = (this.internalCurrentPage - 1) * this.rowsPerPage + 1,
        i = Math.min(this.internalCurrentPage * this.rowsPerPage, this.totalItems);
      this.tkPageChange.emit({ page: this.internalCurrentPage, totalPages: t, startItem: a, endItem: i });
    }
    handlePageInputChange(t) {
      this.inputValue = t.replace(/[^0-9]/g, '');
    }
    createPageNumbers() {
      return this.getPageNumbers().map(t =>
        t === this.ellipsis
          ? n('span', { class: 'tk-pagination-ellipsis tk-pagination-cell' }, '...')
          : n(
              'button',
              {
                class: s('tk-pagination-cell tk-pagination-page', { 'tk-pagination-page-active': t === this.internalCurrentPage }),
                type: 'button',
                onClick: () => this.handlePageClick(t),
              },
              n('span', { class: 'tk-pagination-page-label' }, t),
            ),
      );
    }
    renderTag(t) {
      if ('compact' !== this.mode) {
        let a;
        const i = m(this.internalCurrentPage, this.rowsPerPage, this.totalItems, t);
        if ('compact-expanded' === this.mode) {
          const t = f(this.itemsReportTemplate, i);
          a = n('span', { class: 'tk-pagination-tag-label' }, t);
        } else {
          const o = f(this.pageReportTemplate, i),
            s = f(this.itemsReportTemplate, i);
          a = t > 0 && n(e, null, n('span', { class: 'tk-pagination-tag-label' }, o), n('span', { class: 'tk-pagination-tag-label' }, s));
        }
        return n('div', { class: 'tk-pagination-tag' }, a);
      }
      return null;
    }
    renderContent(t) {
      const a = 'compact' === this.mode || 'compact-expanded' === this.mode ? 'div' : 'nav',
        i = s('tk-pagination', `tk-pagination-${this.mode || this.type}`, { 'tk-pagination-rounded': this.rounded });
      let o;
      if ('compact' === this.mode) {
        const a = m(this.internalCurrentPage, this.rowsPerPage, this.totalItems, t),
          i = f(this.pageReportTemplate, a);
        o = n(
          e,
          null,
          n(
            'button',
            { class: 'tk-pagination-cell tk-pagination-prev', type: 'button', onClick: this.handlePrevClick, disabled: 1 === this.internalCurrentPage },
            n('tk-icon', Object.assign({}, r('chevron_left', { color: 'var(--icon-base)' }))),
          ),
          n('tk-input', {
            'mode': 'text',
            'value': this.inputValue,
            'onTk-change': t => this.handlePageInputChange(t.detail.toString()),
            'onTk-blur': () => this.validateAndUpdatePage(),
            'min': 1,
            'max': t,
          }),
          n('span', { class: 'tk-pagination-current-label' }, i),
          n(
            'button',
            { class: 'tk-pagination-cell tk-pagination-next', type: 'button', onClick: this.handleNextClick, disabled: this.internalCurrentPage === t },
            n('tk-icon', Object.assign({}, r('chevron_right', { color: 'var(--icon-base)' }))),
          ),
        );
      } else
        o = n(
          e,
          null,
          n(
            'div',
            { class: 'tk-pagination-prev-actions' },
            n(
              'button',
              { class: 'tk-pagination-cell tk-pagination-first', type: 'button', onClick: () => this.handlePageClick(1), disabled: 1 === this.internalCurrentPage },
              n('tk-icon', Object.assign({}, r('keyboard_double_arrow_left', { color: 'var(--icon-base)' }))),
            ),
            'grouped' === this.type && n('span', { class: 'tk-pagination-divider' }),
            n(
              'button',
              { class: 'tk-pagination-cell tk-pagination-prev', type: 'button', onClick: this.handlePrevClick, disabled: 1 === this.internalCurrentPage },
              n('tk-icon', Object.assign({}, r('chevron_left', { color: 'var(--icon-base)' }))),
              ' ',
            ),
          ),
          this.createPageNumbers(),
          n(
            'div',
            { class: 'tk-pagination-next-actions' },
            n(
              'button',
              { class: 'tk-pagination-cell tk-pagination-next', type: 'button', onClick: this.handleNextClick, disabled: this.internalCurrentPage === t },
              n('tk-icon', Object.assign({}, r('chevron_right', { color: 'var(--icon-base)' }))),
            ),
            'grouped' === this.type && n('span', { class: 'tk-pagination-divider' }),
            n(
              'button',
              { class: 'tk-pagination-cell tk-pagination-last', type: 'button', onClick: () => this.handlePageClick(t), disabled: this.internalCurrentPage === t },
              n('tk-icon', Object.assign({}, r('keyboard_double_arrow_right', { color: 'var(--icon-base)' }))),
            ),
          ),
        );
      return n(a, { class: i }, o);
    }
    renderSelect() {
      return n('tk-select', {
        'style': { width: '75px' },
        'value': this.rowsPerPage,
        'options': this.rowsPerPageOptions,
        'onTk-change': t => {
          t.detail !== this.rowsPerPage && ((this.rowsPerPage = t.detail), this.tkRowsPerPageChange.emit(t.detail));
        },
      });
    }
    renderInput(t) {
      return n('tk-input', {
        'style': { width: '70px' },
        'mode': 'text',
        'min': 1,
        'max': t,
        'value': this.inputValue,
        'icon': 'chevron_right',
        'iconPosition': 'right',
        'onTk-change': t => {
          this.handlePageInputChange(t.detail.toString());
        },
        'onTk-blur': () => this.validateAndUpdatePage(),
      });
    }
    render() {
      const t = this.getTotalPages();
      return n(
        'div',
        { key: 'ffc6159bb2ead21b8e793abe3e72abc5c33a62bb', class: 'tk-pagination-container' },
        n('div', { key: '64c521213434bc4a3164f0a04cddc7237a8b3e98', class: 'tk-pagination-start' }, this.renderTag(t)),
        this.renderContent(t),
        n('div', { key: 'c26ec2ec063ccbd2c3f84c6c6eb92ea27ee801c0', class: 'tk-pagination-end' }, this.renderSelect(), this.renderInput(t)),
      );
    }
    static get watchers() {
      return { internalCurrentPage: [{ internalCurrentPageChanged: 0 }], currentPage: [{ currentPageChanged: 0 }] };
    }
    static get style() {
      return '@font-face{font-family:"Material Symbols Outlined";src:url("./assets/fonts/material-symbols/Material-Symbols-Outlined.woff2") format("woff2");font-weight:400;font-style:normal;font-display:swap}.material-symbols-outlined{font-family:"Material Symbols Outlined";font-weight:normal;font-style:normal;font-size:24px;line-height:1;letter-spacing:normal;text-transform:none;display:inline-block;white-space:nowrap;word-wrap:normal;direction:ltr;-webkit-font-feature-settings:"liga";-webkit-font-smoothing:antialiased}.material-symbols-outlined{font-variation-settings:"FILL" 0}.material-symbols-outlined.fill{font-variation-settings:"FILL" 1}@font-face{font-family:"Material Symbols Rounded";src:url("./assets/fonts/material-symbols/Material-Symbols-Rounded.woff2") format("woff2");font-weight:400;font-style:normal;font-display:swap}.material-symbols-rounded{font-family:"Material Symbols Rounded";font-weight:normal;font-style:normal;font-size:24px;line-height:1;letter-spacing:normal;text-transform:none;display:inline-block;white-space:nowrap;word-wrap:normal;direction:ltr;-webkit-font-feature-settings:"liga";-webkit-font-smoothing:antialiased}.material-symbols-rounded{font-variation-settings:"FILL" 0}.material-symbols-rounded.fill{font-variation-settings:"FILL" 1}@font-face{font-family:"Material Symbols Sharp";src:url("./assets/fonts/material-symbols/Material-Symbols-Sharp.woff2") format("woff2");font-weight:400;font-style:normal;font-display:swap}.material-symbols-sharp{font-family:"Material Symbols Sharp";font-weight:normal;font-style:normal;font-size:24px;line-height:1;letter-spacing:normal;text-transform:none;display:inline-block;white-space:nowrap;word-wrap:normal;direction:ltr;-webkit-font-feature-settings:"liga";-webkit-font-smoothing:antialiased}.material-symbols-sharp{font-variation-settings:"FILL" 0}.material-symbols-sharp.fill{font-variation-settings:"FILL" 1}tk-pagination{display:block}.tk-pagination-container{display:flex;justify-content:space-between;align-items:center;flex-wrap:wrap;font-family:var(--family-body)}.tk-pagination-container .tk-pagination-start{margin-right:auto}.tk-pagination-container .tk-pagination-end{margin-left:auto;display:flex;gap:var(--pagination-base-right-gap, 12px)}.tk-pagination-container .tk-pagination-tag{display:flex;flex-direction:column;justify-content:center;align-items:flex-start;gap:var(--pagination-base-tag-gap, 0px)}.tk-pagination-container .tk-pagination-tag .tk-pagination-tag-label{color:var(--text-base, #717784);font-family:var(--desktop-body-xs-font);font-size:var(--desktop-body-xs-size, 12px);font-style:normal;font-weight:400;line-height:var(--desktop-body-xs-line-height, 18px);}.tk-pagination-container .tk-pagination{display:flex;align-items:center;flex-wrap:wrap;gap:var(--pagination-base-gap, 6px)}.tk-pagination-container .tk-pagination .tk-pagination-prev-actions,.tk-pagination-container .tk-pagination .tk-pagination-next-actions{display:flex;align-items:center;gap:var(--pagination-base-arrow-gap, 4px)}.tk-pagination-container .tk-pagination .tk-pagination-cell{display:flex;min-width:32px;height:32px;padding:6px 11px;justify-content:center;align-items:center;border-radius:8px;background:none;border:none;cursor:pointer;color:var(--text-darkest, #222530);font-family:var(--desktop-body-s-font);font-size:var(--desktop-body-s-size, 14px);font-style:normal;font-weight:400;line-height:var(--desktop-body-s-line-height, 20px);}.tk-pagination-container .tk-pagination .tk-pagination-cell .tk-pagination-page-label{color:var(--text-darkest)}.tk-pagination-container .tk-pagination .tk-pagination-cell:hover:not(:disabled):not(.tk-pagination-ellipsis){background:var(--background-lightest, #f9fafc)}.tk-pagination-container .tk-pagination .tk-pagination-cell:focus-visible{border:var(--spacing-px, 1px) solid var(--states-info-base, #3b82f6)}.tk-pagination-container .tk-pagination .tk-pagination-cell:disabled{pointer-events:none}.tk-pagination-container .tk-pagination .tk-pagination-cell:disabled .tk-pagination-page-label{color:var(--text-sub-base, #99a0ae)}.tk-pagination-container .tk-pagination.tk-pagination-rounded:not(.tk-pagination-compact-expanded) .tk-pagination-page{border-radius:var(--radius-full)}.tk-pagination-container .tk-pagination.tk-pagination-outlined .tk-pagination-page{border:var(--spacing-px, 1px) solid var(--border-light, #e1e4ea)}.tk-pagination-container .tk-pagination.tk-pagination-grouped{display:inline-flex;align-items:center;padding:var(--pagination-base-container-v-padding, 2px) 0px;border-radius:8px;border:var(--spacing-px, 1px) solid var(--border-light, #e1e4ea);background:var(--static-light, #fff);overflow:hidden}.tk-pagination-container .tk-pagination.tk-pagination-grouped .tk-pagination-divider{width:1px;height:16px;background-color:var(--border-light, #e1e4ea)}.tk-pagination-container .tk-pagination.tk-pagination-compact .tk-pagination-cell{width:36px;height:36px}.tk-pagination-container .tk-pagination.tk-pagination-compact .tk-pagination-current-label{color:var(--text-base, #717784);font-family:var(--desktop-body-s-font);font-size:var(--desktop-body-s-size, 14px);font-style:normal;font-weight:400;line-height:var(--desktop-body-s-line-height, 20px);}.tk-pagination-container .tk-pagination.tk-pagination-compact .tk-pagination-first,.tk-pagination-container .tk-pagination.tk-pagination-compact .tk-pagination-prev,.tk-pagination-container .tk-pagination.tk-pagination-compact .tk-pagination-next,.tk-pagination-container .tk-pagination.tk-pagination-compact .tk-pagination-last{border:var(--spacing-px, 1px) solid var(--border-light, #e1e4ea)}.tk-pagination-container .tk-pagination.tk-pagination-compact.tk-pagination-rounded .tk-pagination-first,.tk-pagination-container .tk-pagination.tk-pagination-compact.tk-pagination-rounded .tk-pagination-prev,.tk-pagination-container .tk-pagination.tk-pagination-compact.tk-pagination-rounded .tk-pagination-next,.tk-pagination-container .tk-pagination.tk-pagination-compact.tk-pagination-rounded .tk-pagination-last{border-radius:var(--radius-full)}.tk-pagination-container .tk-pagination.tk-pagination-compact tk-input{width:48px;height:40px}.tk-pagination-container .tk-pagination .tk-pagination-page.tk-pagination-page-active{border:var(--spacing-px, 1px) solid var(--states-info-sub-base);background:var(--background-lightest, #f9fafc)}.tk-pagination-container .tk-pagination .tk-pagination-last:focus-visible,.tk-pagination-container .tk-pagination .tk-pagination-prev:focus-visible,.tk-pagination-container .tk-pagination .tk-pagination-page:focus-visible,.tk-pagination-container .tk-pagination .tk-pagination-next:focus-visible,.tk-pagination-container .tk-pagination .tk-pagination-first:focus-visible{border:var(--spacing-px, 1px) solid var(--states-info-base, #3b82f6);outline:none}@media (max-width: 600px){.tk-pagination-container{display:grid;gap:8px;grid-template-columns:1fr}.tk-pagination-container .tk-pagination-start{display:none}.tk-pagination-container .tk-pagination,.tk-pagination-container .tk-pagination-end{width:100%;justify-content:center}}';
    }
  },
  [
    0,
    'tk-pagination',
    {
      rounded: [4],
      rowsPerPage: [1026, 'rows-per-page'],
      totalItems: [2, 'total-items'],
      rowsPerPageOptions: [16],
      type: [1],
      mode: [1],
      pageReportTemplate: [1, 'page-report-template'],
      itemsReportTemplate: [1, 'items-report-template'],
      currentPage: [2, 'current-page'],
      inputValue: [32],
      internalCurrentPage: [32],
    },
    void 0,
    { internalCurrentPage: [{ internalCurrentPageChanged: 0 }], currentPage: [{ currentPageChanged: 0 }] },
  ],
);
function u() {
  'undefined' != typeof customElements &&
    ['tk-pagination', 'tk-checkbox', 'tk-chips', 'tk-divider', 'tk-icon', 'tk-input', 'tk-select', 'tk-spinner'].forEach(t => {
      switch (t) {
        case 'tk-pagination':
          customElements.get(o(t)) || customElements.define(o(t), b);
          break;
        case 'tk-checkbox':
          customElements.get(o(t)) || p();
          break;
        case 'tk-chips':
          customElements.get(o(t)) || l();
          break;
        case 'tk-divider':
          customElements.get(o(t)) || g();
          break;
        case 'tk-icon':
          customElements.get(o(t)) || c();
          break;
        case 'tk-input':
          customElements.get(o(t)) || k();
          break;
        case 'tk-select':
          customElements.get(o(t)) || d();
          break;
        case 'tk-spinner':
          customElements.get(o(t)) || h();
      }
    });
}
export { b as T, u as d };
