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 { MapToComponentField, MapToComponentMethod } from 'vega-slimmer/core';
import { PageResizeObserverSlimmer } from '../../../../helpers/slimmers/page-resize-observer-slimmer';
import ResponsiveFormatFacade from '../../../../helpers/formatter/responsive-map-formatter/responsive-format-facade';
/** Manage the layout of vega-pagination */
export class VegaPaginationLayoutController extends PageResizeObserverSlimmer {
  /**
   * Register the callback function to page resize observer slimmer
   */
  constructor() {
    super({
      // eslint-disable-next-line jsdoc/require-jsdoc
      callback: /* istanbul ignore next */ () => {
        this.calculatePaginationLayout();
      },
    });
    /** calculate the horizontal or vertical layout of vega-pagination */
    this.calculatePaginationLayout = () => {
      if (this.currentLayout === 'vertical') {
        this.host.classList.add('vega-pagination-vertical');
        this.host.classList.remove('vega-pagination-horizontal');
      }
      else {
        this.host.classList.remove('vega-pagination-vertical');
        this.host.classList.add('vega-pagination-horizontal');
        const hostOffsetHeight = this.host.offsetHeight;
        const directVegaFlexElements = Array.from(this.host.shadowRoot.children).filter((child) => child.tagName === 'VEGA-FLEX');
        const isLineWrapped = directVegaFlexElements.every((vegaFlexElement) => hostOffsetHeight > vegaFlexElement.offsetHeight);
        /*
         * The next line is covered in e2e-test
         * @see{should-render-layout-properly-when-set-responsive-prop-layout}
         */
        /* istanbul ignore next */
        if (isLineWrapped) {
          this.host.classList.add('vega-pagination-vertical');
          this.host.classList.remove('vega-pagination-horizontal');
        }
      }
    };
  }
  /** set the currentLayout when component will load */
  componentWillLoad() {
    this.setCurrentLayout();
  }
  /*
   * The next line is covered in e2e-test
   * @see{should-render-layout-properly-when-set-responsive-prop-layout}
   */
  /* istanbul ignore next */
  /** set the currentLayout when currentBreakpoint changes */
  watchCurrentBreakpoint() {
    this.setCurrentLayout();
  }
  /** set the currentLayout and calculate pagination layout when layout changes */
  watchLayout() {
    this.setCurrentLayout();
    this.calculatePaginationLayout();
  }
  /** set the value of currentLayout */
  setCurrentLayout() {
    this.currentLayout = ResponsiveFormatFacade.formatCustom(this.layout);
  }
}
__decorate([
  MapToComponentField()
], VegaPaginationLayoutController.prototype, "host", void 0);
__decorate([
  MapToComponentField()
], VegaPaginationLayoutController.prototype, "layout", void 0);
__decorate([
  MapToComponentMethod('componentWillLoad')
], VegaPaginationLayoutController.prototype, "componentWillLoad", null);
__decorate([
  MapToComponentMethod('watchCurrentBreakpoint')
], VegaPaginationLayoutController.prototype, "watchCurrentBreakpoint", null);
__decorate([
  MapToComponentMethod('watchLayout')
], VegaPaginationLayoutController.prototype, "watchLayout", null);
