'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index = require('./index-58ea899e.js');
const globalSlimmerRegistry = require('./global-slimmer-registry-b3bce7e0.js');
const componentUsageRuntimeMetrics = require('./component-usage-runtime-metrics-4572c5b7.js');
const component = require('./component-1e352960.js');
const translationSlimmer = require('./translation-slimmer-d0c77ad2.js');
const internalTranslationController = require('./internal-translation-controller-fb1532f4.js');
const domNodeSubjectObserverFactory = require('./dom-node-subject-observer-factory-9110cb94.js');
const vegaEventId = require('./vega-event-id-c08ce3d3.js');
const ui = require('./ui-ae4ee13d.js');
const changeManager = require('./change-manager-a297e4d2.js');
const vegaInternalEventId = require('./vega-internal-event-id-87014e4f.js');
const pageSizeOptionUtils = require('./page-size-option-utils-d038dd3a.js');
require('./static-subject-title-5829a298.js');
require('./observer-f49483e8.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 globalSlimmerRegistry.VegaSlimmer {
  render() {
    if (this.type === 'pageSizeSelectorMobile') {
      return this.renderPageSizeSelectorMobile();
    }
    else {
      return this.renderPageSizeSelectorMobileAndCurrentPageLabel();
    }
  }
  renderPageSizeSelectorMobile() {
    const preservedTranslationOutput = internalTranslationController.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 = internalTranslationController.VegaInternalTranslation.tWithPreservedBlocks('Viewing [{0}-{1}] of {2}', PageSizeSelectorMobileRenderer.clickableReg, rangeFrom, rangeTo, this.total);
    return this.renderTranslatedMessage(preservedTranslationOutput);
  }
  renderTranslatedMessage(preservedTranslationOutput) {
    return (index.h("vega-flex", { alignItems: "center", justifyContent: "center", gap: "size-4" }, preservedTranslationOutput.map((outPut) => {
      if (outPut.isPreserved) {
        return this.pageSizeSelectorMobileDropdownRenderer.render(index.h("vega-button-link", { label: outPut.content }));
      }
      else {
        return (index.h("vega-font", { variant: "font-field-label", color: "text-primary" }, outPut.content));
      }
    })));
  }
}
PageSizeSelectorMobileRenderer.clickableReg = /(\[[^\]]*\])/g;
__decorate$2([
  globalSlimmerRegistry.MapToComponentField()
], PageSizeSelectorMobileRenderer.prototype, "translationSlimmer", void 0);
__decorate$2([
  globalSlimmerRegistry.MapToComponentField()
], PageSizeSelectorMobileRenderer.prototype, "type", void 0);
__decorate$2([
  globalSlimmerRegistry.MapToComponentField()
], PageSizeSelectorMobileRenderer.prototype, "pageSize", void 0);
__decorate$2([
  globalSlimmerRegistry.MapToComponentField()
], PageSizeSelectorMobileRenderer.prototype, "total", void 0);
__decorate$2([
  globalSlimmerRegistry.MapToComponentField()
], PageSizeSelectorMobileRenderer.prototype, "current", void 0);
__decorate$2([
  globalSlimmerRegistry.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 globalSlimmerRegistry.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 || pageSizeOptionUtils.includesPageSize(this.pageSizeSelectorOptions, this.pageSize)
      ? this.pageSizeSelectorOptions
      : [...this.pageSizeSelectorOptions, this.pageSize];
    const normalized = options.map(pageSizeOptionUtils.normalizePageSizeOption);
    const mergedPageSizeOptions = pageSizeOptionUtils.sortPageSizeOptions(normalized);
    const itemsPerPageLabel = this.translationSlimmer.t('Items Per Page');
    const selectedValue = this.isAllActive ? pageSizeOptionUtils.PAGE_SIZE_ALL : this.pageSize;
    return (index.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.DomNodeSubjectObserverFactory.addUniqueObserverToNode(node, vegaEventId.VegaDropdownClick, (payload) => {
          this.notifyParentPagination(payload.detail);
        });
      }, isScreenPosition: (_a = this.dropdownProps) === null || _a === void 0 ? void 0 : _a.isScreenPosition }, children));
  }
  notifyParentPagination(detail) {
    const pagination = ui.findParent(this.host, 'vega-pagination');
    if (pagination) {
      changeManager.ChangeManager.notify(domNodeSubjectObserverFactory.domNodeSubjectFactory.getSubject(pagination, vegaInternalEventId.VegaInternalPaginationPageSizeChange), {
        host: this.host,
        detail,
      });
    }
  }
}
__decorate$1([
  globalSlimmerRegistry.MapToComponentField()
], PageSizeSelectorMobileDropdownRenderer.prototype, "host", void 0);
__decorate$1([
  globalSlimmerRegistry.MapToComponentField()
], PageSizeSelectorMobileDropdownRenderer.prototype, "translationSlimmer", void 0);
__decorate$1([
  globalSlimmerRegistry.MapToComponentField()
], PageSizeSelectorMobileDropdownRenderer.prototype, "pageSizeSelectorOptions", void 0);
__decorate$1([
  globalSlimmerRegistry.MapToComponentField({ writable: true })
], PageSizeSelectorMobileDropdownRenderer.prototype, "pageSize", void 0);
__decorate$1([
  globalSlimmerRegistry.MapToComponentField()
], PageSizeSelectorMobileDropdownRenderer.prototype, "dropdownProps", void 0);
__decorate$1([
  globalSlimmerRegistry.MapToComponentField()
], PageSizeSelectorMobileDropdownRenderer.prototype, "total", void 0);
__decorate$1([
  globalSlimmerRegistry.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) {
    index.registerInstance(this, hostRef);
    this.globalSlimmers = {};
    this.translationSlimmer = new translationSlimmer.TranslationSlimmer();
    this.vegaComponentUsageRuntimeMetricsSlimmer = new componentUsageRuntimeMetrics.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 component.sanitizeVegaComponent(index.h(index.Host, null, this.pageSizeSelectorMobileRenderer.render()), this.host);
  }
  get host() { return index.getElement(this); }
};
__decorate([
  componentUsageRuntimeMetrics.InjectVegaGlobalSlimmer()
], VegaPaginationPageSizeSelectorMobile.prototype, "globalSlimmers", void 0);
__decorate([
  globalSlimmerRegistry.InjectVegaSlimmer()
], VegaPaginationPageSizeSelectorMobile.prototype, "translationSlimmer", void 0);
__decorate([
  globalSlimmerRegistry.InjectVegaSlimmer()
], VegaPaginationPageSizeSelectorMobile.prototype, "vegaComponentUsageRuntimeMetricsSlimmer", void 0);
__decorate([
  globalSlimmerRegistry.InjectVegaSlimmer()
], VegaPaginationPageSizeSelectorMobile.prototype, "pageSizeSelectorMobileRenderer", void 0);
__decorate([
  globalSlimmerRegistry.InjectVegaSlimmer()
], VegaPaginationPageSizeSelectorMobile.prototype, "pageSizeSelectorMobileDropdownRenderer", void 0);
VegaPaginationPageSizeSelectorMobile.style = vegaPaginationPageSizeSelectorMobileCss;

exports.vega_pagination_page_size_selector_mobile = VegaPaginationPageSizeSelectorMobile;
