import { h, r as registerInstance, H as Host, g as getElement } from './index-090d31ca.js';
import { c as MapToComponentField, V as VegaSlimmer, I as InjectVegaSlimmer } from './global-slimmer-registry-17c4efd4.js';
import { V as VegaComponentUsageRuntimeMetricsSlimmer, I as InjectVegaGlobalSlimmer } from './component-usage-runtime-metrics-4b1afd04.js';
import { s as sanitizeVegaComponent } from './component-7d906393.js';
import { T as TranslationSlimmer } from './translation-slimmer-32353a1c.js';
import { V as VegaInternalTranslation } from './internal-translation-controller-d8217d93.js';
import { D as DomNodeSubjectObserverFactory, d as domNodeSubjectFactory } from './dom-node-subject-observer-factory-3897e95b.js';
import { V as VegaDropdownClick } from './vega-event-id-578c6c6d.js';
import { f as findParent } from './ui-64815a12.js';
import { C as ChangeManager } from './change-manager-6a7eb88c.js';
import { t as VegaInternalPaginationPageSizeChange } from './vega-internal-event-id-913e8be6.js';
import { i as includesPageSize, n as normalizePageSizeOption, s as sortPageSizeOptions, P as PAGE_SIZE_ALL } from './page-size-option-utils-50afc81a.js';
import './static-subject-title-52f93124.js';
import './observer-3959f9dd.js';

var __decorate$2 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  return c > 3 && r && Object.defineProperty(target, key, r), r;
};
class PageSizeSelectorMobileRenderer extends VegaSlimmer {
  render() {
    if (this.type === 'pageSizeSelectorMobile') {
      return this.renderPageSizeSelectorMobile();
    }
    else {
      return this.renderPageSizeSelectorMobileAndCurrentPageLabel();
    }
  }
  renderPageSizeSelectorMobile() {
    const preservedTranslationOutput = VegaInternalTranslation.tWithPreservedBlocks('Show [{0} items / page]', PageSizeSelectorMobileRenderer.clickableReg, this.pageSize);
    return this.renderTranslatedMessage(preservedTranslationOutput);
  }
  renderPageSizeSelectorMobileAndCurrentPageLabel() {
    const rangeFrom = this.total > 0 ? this.pageSize * (this.current - 1) + 1 : 0;
    const rangeTo = Math.min(this.current * this.pageSize, this.total);
    const preservedTranslationOutput = VegaInternalTranslation.tWithPreservedBlocks('Viewing [{0}-{1}] of {2}', PageSizeSelectorMobileRenderer.clickableReg, rangeFrom, rangeTo, this.total);
    return this.renderTranslatedMessage(preservedTranslationOutput);
  }
  renderTranslatedMessage(preservedTranslationOutput) {
    return (h("vega-flex", { alignItems: "center", justifyContent: "center", gap: "size-4" }, preservedTranslationOutput.map((outPut) => {
      if (outPut.isPreserved) {
        return this.pageSizeSelectorMobileDropdownRenderer.render(h("vega-button-link", { label: outPut.content }));
      }
      else {
        return (h("vega-font", { variant: "font-field-label", color: "text-primary" }, outPut.content));
      }
    })));
  }
}
PageSizeSelectorMobileRenderer.clickableReg = /(\[[^\]]*\])/g;
__decorate$2([
  MapToComponentField()
], PageSizeSelectorMobileRenderer.prototype, "translationSlimmer", void 0);
__decorate$2([
  MapToComponentField()
], PageSizeSelectorMobileRenderer.prototype, "type", void 0);
__decorate$2([
  MapToComponentField()
], PageSizeSelectorMobileRenderer.prototype, "pageSize", void 0);
__decorate$2([
  MapToComponentField()
], PageSizeSelectorMobileRenderer.prototype, "total", void 0);
__decorate$2([
  MapToComponentField()
], PageSizeSelectorMobileRenderer.prototype, "current", void 0);
__decorate$2([
  MapToComponentField()
], PageSizeSelectorMobileRenderer.prototype, "pageSizeSelectorMobileDropdownRenderer", void 0);

var __decorate$1 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  return c > 3 && r && Object.defineProperty(target, key, r), r;
};
class PageSizeSelectorMobileDropdownRenderer extends VegaSlimmer {
  /**
   * Renders the dropdown component with the provided children.
   *
   * @param {HTMLElement} children HTML element children to be rendered inside the dropdown.
   * @returns {HTMLElement} The rendered dropdown component.
   */
  render(children) {
    var _a;
    /* istanbul ignore next */
    const options = this.isAllActive || includesPageSize(this.pageSizeSelectorOptions, this.pageSize)
      ? this.pageSizeSelectorOptions
      : [...this.pageSizeSelectorOptions, this.pageSize];
    const normalized = options.map(normalizePageSizeOption);
    const mergedPageSizeOptions = sortPageSizeOptions(normalized);
    const itemsPerPageLabel = this.translationSlimmer.t('Items Per Page');
    const selectedValue = this.isAllActive ? PAGE_SIZE_ALL : this.pageSize;
    return (h("vega-dropdown", { trigger: "click", selectType: "single", alignment: "center", minWidth: 160, selectedSourceKey: selectedValue.toString(), source: [
        {
          key: 'items-per-page',
          label: itemsPerPageLabel,
          children: [
            ...mergedPageSizeOptions.map((option) => ({
              key: option.value.toString(),
              label: option.label,
            })),
          ],
        },
      ], ref: (node) => {
        DomNodeSubjectObserverFactory.addUniqueObserverToNode(node, VegaDropdownClick, (payload) => {
          this.notifyParentPagination(payload.detail);
        });
      }, isScreenPosition: (_a = this.dropdownProps) === null || _a === void 0 ? void 0 : _a.isScreenPosition }, children));
  }
  notifyParentPagination(detail) {
    const pagination = findParent(this.host, 'vega-pagination');
    if (pagination) {
      ChangeManager.notify(domNodeSubjectFactory.getSubject(pagination, VegaInternalPaginationPageSizeChange), {
        host: this.host,
        detail,
      });
    }
  }
}
__decorate$1([
  MapToComponentField()
], PageSizeSelectorMobileDropdownRenderer.prototype, "host", void 0);
__decorate$1([
  MapToComponentField()
], PageSizeSelectorMobileDropdownRenderer.prototype, "translationSlimmer", void 0);
__decorate$1([
  MapToComponentField()
], PageSizeSelectorMobileDropdownRenderer.prototype, "pageSizeSelectorOptions", void 0);
__decorate$1([
  MapToComponentField({ writable: true })
], PageSizeSelectorMobileDropdownRenderer.prototype, "pageSize", void 0);
__decorate$1([
  MapToComponentField()
], PageSizeSelectorMobileDropdownRenderer.prototype, "dropdownProps", void 0);
__decorate$1([
  MapToComponentField()
], PageSizeSelectorMobileDropdownRenderer.prototype, "total", void 0);
__decorate$1([
  MapToComponentField()
], PageSizeSelectorMobileDropdownRenderer.prototype, "isAllActive", void 0);

const vegaPaginationPageSizeSelectorMobileCss = ":host{display:inline-block}";

var __decorate = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
    r = Reflect.decorate(decorators, target, key, desc);
  else
    for (var i = decorators.length - 1; i >= 0; i--)
      if (d = decorators[i])
        r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  return c > 3 && r && Object.defineProperty(target, key, r), r;
};
const VegaPaginationPageSizeSelectorMobile = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.globalSlimmers = {};
    this.translationSlimmer = new TranslationSlimmer();
    this.vegaComponentUsageRuntimeMetricsSlimmer = new VegaComponentUsageRuntimeMetricsSlimmer();
    this.pageSizeSelectorMobileRenderer = new PageSizeSelectorMobileRenderer();
    this.pageSizeSelectorMobileDropdownRenderer = new PageSizeSelectorMobileDropdownRenderer();
    /**
     * Specifies the number of data items to be displayed per page
     *
     * @vegaVersion 2.42.0
     */
    /* eslint-disable-next-line @stencil/strict-mutable */
    this.pageSize = 10;
    /**
     * Specifies the options available for the page size selector
     *
     * @vegaVersion 2.42.0
     */
    /* eslint-disable-next-line @stencil/strict-mutable */
    this.pageSizeSelectorOptions = [10, 20, 50, 100];
    /**
     * Specifies the total number of data items
     *
     * @vegaVersion 2.42.0
     */
    this.total = 0;
    /**
     * Specifies the current page number
     *
     * @vegaVersion 2.42.0
     */
    /* eslint-disable-next-line @stencil/strict-mutable */
    this.current = 1;
    /**
     * @internal
     * Tracks whether "All" page size option is currently active.
     *
     * @vegaVersion 2.81.0
     */
    this.isAllActive = false;
  }
  render() {
    return sanitizeVegaComponent(h(Host, null, this.pageSizeSelectorMobileRenderer.render()), this.host);
  }
  get host() { return getElement(this); }
};
__decorate([
  InjectVegaGlobalSlimmer()
], VegaPaginationPageSizeSelectorMobile.prototype, "globalSlimmers", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaPaginationPageSizeSelectorMobile.prototype, "translationSlimmer", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaPaginationPageSizeSelectorMobile.prototype, "vegaComponentUsageRuntimeMetricsSlimmer", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaPaginationPageSizeSelectorMobile.prototype, "pageSizeSelectorMobileRenderer", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaPaginationPageSizeSelectorMobile.prototype, "pageSizeSelectorMobileDropdownRenderer", void 0);
VegaPaginationPageSizeSelectorMobile.style = vegaPaginationPageSizeSelectorMobileCss;

export { VegaPaginationPageSizeSelectorMobile as vega_pagination_page_size_selector_mobile };
