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 { VegaClick } from '../../../../../helpers/event-manager/event-id/vega-event-id';
import { findParent } from '../../../../../utils/ui';
import changeManager from '../../../../../helpers/change-manager/change-manager';
import domNodeSubjectFactory from '../../../../../helpers/change-manager/subject/dom-node-subject/dom-node-subject-factory';
import { VegaInternalPaginationCurrentChange } from '../../../../../helpers/event-manager/event-id/vega-internal-event-id';
export 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([
  MapToComponentField()
], PrevAndNextButtonRenderer.prototype, "host", void 0);
__decorate([
  MapToComponentField()
], PrevAndNextButtonRenderer.prototype, "current", void 0);
__decorate([
  MapToComponentField()
], PrevAndNextButtonRenderer.prototype, "total", void 0);
__decorate([
  MapToComponentField()
], PrevAndNextButtonRenderer.prototype, "pageCount", void 0);
