var __decorate = (this && this.__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;
};
import { h } from '@stencil/core';
import { MapToComponentField, VegaSlimmer } from 'vega-slimmer/core';
import { DomNodeSubjectObserverFactory } from '../../../../../helpers/change-manager/subject/dom-node-subject/dom-node-subject-observer-factory';
import { VegaBlur, VegaFormSubmit } from '../../../../../helpers/event-manager/event-id/vega-event-id';
import { convertToNumber, normalizeNumberByRanger } from '../../../../../utils/number';
export 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([
  MapToComponentField()
], PageSelectorMobileRenderer.prototype, "host", void 0);
__decorate([
  MapToComponentField()
], PageSelectorMobileRenderer.prototype, "type", void 0);
__decorate([
  MapToComponentField()
], PageSelectorMobileRenderer.prototype, "current", void 0);
__decorate([
  MapToComponentField()
], PageSelectorMobileRenderer.prototype, "pageCount", void 0);
__decorate([
  MapToComponentField()
], PageSelectorMobileRenderer.prototype, "prevAndNextButtonRenderer", void 0);
