'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 domNodeSubjectObserverFactory = require('./dom-node-subject-observer-factory-9110cb94.js');
const vegaEventId = require('./vega-event-id-c08ce3d3.js');
const number = require('./number-4816603d.js');
const ui = require('./ui-ae4ee13d.js');
const changeManager = require('./change-manager-a297e4d2.js');
const vegaInternalEventId = require('./vega-internal-event-id-87014e4f.js');
const childNodesEventPreventSlimmer = require('./child-nodes-event-prevent-slimmer-9b7095a4.js');
require('./observer-f49483e8.js');
require('./internal-vega-event-manager-fef893bf.js');
require('./vega-env-manager-23b8b23c.js');
require('./feature-flag-controller-9129ef52.js');
require('./index-f054eb5d.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 globalSlimmerRegistry.VegaSlimmer {
  constructor() {
    super(...arguments);
    this.handleChange = () => {
      if (this.inputRef.value) {
        const goToPage = number.normalizeNumberByRanger(number.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 (index.h("vega-flex", { alignItems: "center", justifyContent: "center", gap: "size-8" },
      this.prevAndNextButtonRenderer.render('prev'),
      index.h("vega-font", { variant: "font-field-label", color: "text-primary" }, this.current.toString()),
      index.h("vega-font", { variant: "font-field-label", color: "text-primary" }, "/"),
      index.h("vega-font", { variant: "font-field-label", color: "text-primary" }, this.pageCount.toString()),
      this.prevAndNextButtonRenderer.render('next')));
  }
  renderPageSelectorMobileAndGoTo() {
    return (index.h("vega-flex", { alignItems: "center", justifyContent: "center", gap: "size-8" },
      this.prevAndNextButtonRenderer.render('prev'),
      index.h("vega-form", { ref: (ref) => {
          domNodeSubjectObserverFactory.DomNodeSubjectObserverFactory.addUniqueObserverToNode(ref, vegaEventId.VegaFormSubmit, this.handleChange);
        } },
        index.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.DomNodeSubjectObserverFactory.addUniqueObserverToNode(ref, vegaEventId.VegaBlur, this.handleChange);
          } })),
      index.h("vega-font", { variant: "font-field-label", color: "text-primary" }, "/"),
      index.h("vega-font", { variant: "font-field-label", color: "text-primary" }, this.pageCount.toString()),
      this.prevAndNextButtonRenderer.render('next')));
  }
}
__decorate$2([
  globalSlimmerRegistry.MapToComponentField()
], PageSelectorMobileRenderer.prototype, "host", void 0);
__decorate$2([
  globalSlimmerRegistry.MapToComponentField()
], PageSelectorMobileRenderer.prototype, "type", void 0);
__decorate$2([
  globalSlimmerRegistry.MapToComponentField()
], PageSelectorMobileRenderer.prototype, "current", void 0);
__decorate$2([
  globalSlimmerRegistry.MapToComponentField()
], PageSelectorMobileRenderer.prototype, "pageCount", void 0);
__decorate$2([
  globalSlimmerRegistry.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 globalSlimmerRegistry.VegaSlimmer {
  constructor() {
    super(...arguments);
    this.pagerButton = (icon, isDisabled, handleClick) => {
      return (index.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.DomNodeSubjectObserverFactory.addUniqueObserverToNode(ref, vegaEventId.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 = ui.findParent(this.host, 'vega-pagination');
    if (pagination) {
      changeManager.ChangeManager.notify(domNodeSubjectObserverFactory.domNodeSubjectFactory.getSubject(pagination, vegaInternalEventId.VegaInternalPaginationCurrentChange), {
        host: this.host,
        detail,
      });
    }
  }
  render(buttonType) {
    if (buttonType === 'prev') {
      return this.renderPrevButton();
    }
    else {
      return this.renderNextButton();
    }
  }
}
__decorate$1([
  globalSlimmerRegistry.MapToComponentField()
], PrevAndNextButtonRenderer.prototype, "host", void 0);
__decorate$1([
  globalSlimmerRegistry.MapToComponentField()
], PrevAndNextButtonRenderer.prototype, "current", void 0);
__decorate$1([
  globalSlimmerRegistry.MapToComponentField()
], PrevAndNextButtonRenderer.prototype, "total", void 0);
__decorate$1([
  globalSlimmerRegistry.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) {
    index.registerInstance(this, hostRef);
    this.globalSlimmers = {};
    this.vegaComponentUsageRuntimeMetricsSlimmer = new componentUsageRuntimeMetrics.VegaComponentUsageRuntimeMetricsSlimmer();
    this.childEventPrevent = new childNodesEventPreventSlimmer.ChildNodesEventPreventSlimmer([vegaEventId.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 component.sanitizeVegaComponent(index.h(index.Host, null, this.pageSelectorMobileRenderer.render()), this.host);
  }
  get host() { return index.getElement(this); }
};
__decorate([
  componentUsageRuntimeMetrics.InjectVegaGlobalSlimmer()
], VegaPaginationPageSelectorMobile.prototype, "globalSlimmers", void 0);
__decorate([
  globalSlimmerRegistry.InjectVegaSlimmer()
], VegaPaginationPageSelectorMobile.prototype, "vegaComponentUsageRuntimeMetricsSlimmer", void 0);
__decorate([
  globalSlimmerRegistry.InjectVegaSlimmer()
], VegaPaginationPageSelectorMobile.prototype, "childEventPrevent", void 0);
__decorate([
  globalSlimmerRegistry.InjectVegaSlimmer()
], VegaPaginationPageSelectorMobile.prototype, "pageSelectorMobileRenderer", void 0);
__decorate([
  globalSlimmerRegistry.InjectVegaSlimmer()
], VegaPaginationPageSelectorMobile.prototype, "prevAndNextButtonRenderer", void 0);
VegaPaginationPageSelectorMobile.style = vegaPaginationPageSelectorMobileCss;

exports.vega_pagination_page_selector_mobile = VegaPaginationPageSelectorMobile;
