import { h, r as registerInstance, H as Host, g as getElement } from './index-090d31ca.js';
import { c as MapToComponentField, V as VegaSlimmer } from './global-slimmer-registry-0a7aa308.js';
import { I as InjectVegaSlimmer } from './inject-vega-slimmer-caffc2aa.js';
import { V as VegaComponentUsageRuntimeMetricsSlimmer, I as InjectVegaGlobalSlimmer } from './component-usage-runtime-metrics-4202784a.js';
import { s as sanitizeVegaComponent } from './component-d58ca1d0.js';
import { D as DomNodeSubjectObserverFactory } from './dom-node-subject-observer-factory-61fda003.js';
import { B as VegaFormSubmit, H as VegaBlur, c as VegaClick, h as VegaChange } from './vega-event-id-1b737ae8.js';
import { n as normalizeNumberByRanger, c as convertToNumber } from './number-4398f2e1.js';
import { f as findParent } from './ui-6dd51115.js';
import { C as ChangeManager } from './change-manager-ecbd3a2a.js';
import { d as domNodeSubjectFactory } from './dom-node-subject-factory-6894df15.js';
import { u as VegaInternalPaginationCurrentChange } from './vega-internal-event-id-a2d4c714.js';
import { C as ChildNodesEventPreventSlimmer } from './child-nodes-event-prevent-slimmer-08e29cdd.js';
import './observer-3959f9dd.js';
import './internal-vega-event-manager-a19d633d.js';
import './vega-env-manager-8f8dc473.js';
import './feature-flag-controller-b7e7da75.js';
import './index-bfc6dfa2.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 PageSelectorMobileRenderer extends VegaSlimmer {
  constructor() {
    super(...arguments);
    this.handleChange = () => {
      if (this.inputRef.value) {
        const goToPage = normalizeNumberByRanger(convertToNumber(this.inputRef.value, 1), 1, this.pageCount);
        this.inputRef.value = goToPage.toString();
        this.prevAndNextButtonRenderer.notifyParentPagination(goToPage.toString());
      }
    };
  }
  render() {
    if (this.type === 'pageSelectorMobile') {
      return this.renderPageSelectorMobile();
    }
    else {
      return this.renderPageSelectorMobileAndGoTo();
    }
  }
  renderPageSelectorMobile() {
    return (h("vega-flex", { alignItems: "center", justifyContent: "center", gap: "size-8" },
      this.prevAndNextButtonRenderer.render('prev'),
      h("vega-font", { variant: "font-field-label", color: "text-primary" }, this.current.toString()),
      h("vega-font", { variant: "font-field-label", color: "text-primary" }, "/"),
      h("vega-font", { variant: "font-field-label", color: "text-primary" }, this.pageCount.toString()),
      this.prevAndNextButtonRenderer.render('next')));
  }
  renderPageSelectorMobileAndGoTo() {
    return (h("vega-flex", { alignItems: "center", justifyContent: "center", gap: "size-8" },
      this.prevAndNextButtonRenderer.render('prev'),
      h("vega-form", { ref: (ref) => {
          DomNodeSubjectObserverFactory.addUniqueObserverToNode(ref, VegaFormSubmit, this.handleChange);
        } },
        h("vega-input", { "data-vega-form": "pageSelectorMobile_goTo", size: "small", autocomplete: "on", showClearIcon: false, style: { width: '54px' }, maskConfig: {
            type: 'number',
            options: {
              allowNegative: false,
              precision: 0,
            },
          }, value: this.current.toString(), ref: (ref) => {
            this.inputRef = ref;
            DomNodeSubjectObserverFactory.addUniqueObserverToNode(ref, VegaBlur, this.handleChange);
          } })),
      h("vega-font", { variant: "font-field-label", color: "text-primary" }, "/"),
      h("vega-font", { variant: "font-field-label", color: "text-primary" }, this.pageCount.toString()),
      this.prevAndNextButtonRenderer.render('next')));
  }
}
__decorate$2([
  MapToComponentField()
], PageSelectorMobileRenderer.prototype, "host", void 0);
__decorate$2([
  MapToComponentField()
], PageSelectorMobileRenderer.prototype, "type", void 0);
__decorate$2([
  MapToComponentField()
], PageSelectorMobileRenderer.prototype, "current", void 0);
__decorate$2([
  MapToComponentField()
], PageSelectorMobileRenderer.prototype, "pageCount", void 0);
__decorate$2([
  MapToComponentField()
], PageSelectorMobileRenderer.prototype, "prevAndNextButtonRenderer", 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 PrevAndNextButtonRenderer extends VegaSlimmer {
  constructor() {
    super(...arguments);
    this.pagerButton = (icon, isDisabled, handleClick) => {
      return (h("vega-button-circle", { variant: "icon-only", icon: icon, iconColor: "text-link", size: "small", disabled: isDisabled, 
        /* eslint-disable-next-line react/jsx-no-bind */
        ref: (ref) => {
          DomNodeSubjectObserverFactory.addUniqueObserverToNode(ref, VegaClick, handleClick);
        } }));
    };
    /** Render the prev button of the page selector mobile **/
    this.renderPrevButton = () => {
      const isDisabled = this.total === 0 || this.current === 1;
      return this.pagerButton('chevron-left', isDisabled, () => {
        this.notifyParentPagination((this.current - 1).toString());
      });
    };
    /** Render the next button of the page selector mobile **/
    this.renderNextButton = () => {
      const isDisabled = this.total === 0 || this.current === this.pageCount;
      return this.pagerButton('chevron-right', isDisabled, () => {
        this.notifyParentPagination((this.current + 1).toString());
      });
    };
  }
  notifyParentPagination(detail) {
    const pagination = findParent(this.host, 'vega-pagination');
    if (pagination) {
      ChangeManager.notify(domNodeSubjectFactory.getSubject(pagination, VegaInternalPaginationCurrentChange), {
        host: this.host,
        detail,
      });
    }
  }
  render(buttonType) {
    if (buttonType === 'prev') {
      return this.renderPrevButton();
    }
    else {
      return this.renderNextButton();
    }
  }
}
__decorate$1([
  MapToComponentField()
], PrevAndNextButtonRenderer.prototype, "host", void 0);
__decorate$1([
  MapToComponentField()
], PrevAndNextButtonRenderer.prototype, "current", void 0);
__decorate$1([
  MapToComponentField()
], PrevAndNextButtonRenderer.prototype, "total", void 0);
__decorate$1([
  MapToComponentField()
], PrevAndNextButtonRenderer.prototype, "pageCount", void 0);

const vegaPaginationPageSelectorMobileCss = ":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 VegaPaginationPageSelectorMobile = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.globalSlimmers = {};
    this.vegaComponentUsageRuntimeMetricsSlimmer = new VegaComponentUsageRuntimeMetricsSlimmer();
    this.childEventPrevent = new ChildNodesEventPreventSlimmer([VegaChange], () => this.host);
    this.pageSelectorMobileRenderer = new PageSelectorMobileRenderer();
    this.prevAndNextButtonRenderer = new PrevAndNextButtonRenderer();
    /**
     * Total number of pages.
     *
     * @vegaVersion 2.42.0
     */
    this.pageCount = 0;
    /**
     * Specifies the current page number
     *
     * @vegaVersion 2.42.0
     */
    /* eslint-disable-next-line @stencil/strict-mutable */
    this.current = 1;
    /**
     * Specifies the total number of data items
     *
     * @vegaVersion 2.42.0
     */
    this.total = 0;
  }
  render() {
    return sanitizeVegaComponent(h(Host, null, this.pageSelectorMobileRenderer.render()), this.host);
  }
  get host() { return getElement(this); }
};
__decorate([
  InjectVegaGlobalSlimmer()
], VegaPaginationPageSelectorMobile.prototype, "globalSlimmers", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaPaginationPageSelectorMobile.prototype, "vegaComponentUsageRuntimeMetricsSlimmer", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaPaginationPageSelectorMobile.prototype, "childEventPrevent", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaPaginationPageSelectorMobile.prototype, "pageSelectorMobileRenderer", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaPaginationPageSelectorMobile.prototype, "prevAndNextButtonRenderer", void 0);
VegaPaginationPageSelectorMobile.style = vegaPaginationPageSelectorMobileCss;

export { VegaPaginationPageSelectorMobile as vega_pagination_page_selector_mobile };
