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 { MapToComponentMethod, MapToComponentField, VegaSlimmer } from 'vega-slimmer/core';
export class VegaSegmentOverflowController extends VegaSlimmer {
  watchSegments() {
    this.setIsOverflowBlockSegments();
  }
  /** The below method is e2e-test covered in
   *  @see{module:vega-segment-control-set-block-e2e}
   *  @see{module:vega-segment-control-set-block-resize-screen-e2e}
   */
  /* istanbul ignore next */
  watchBlock() {
    this.setIsOverflowBlockSegments();
  }
  watchSize() {
    this.setIsOverflowBlockSegments();
  }
  setIsOverflowBlockSegments() {
    this.isOverflowBlockSegments = this.isExceedContainerWidth();
  }
  /**
   * The below method is e2e-test covered in
   * @see{module:vega-segment-control-set-block-e2e}
   * @see{module:vega-segment-control-set-block-resize-screen-e2e}
   */
  /* istanbul ignore next */
  isExceedContainerWidth() {
    if (this.block) {
      const container = this.host.shadowRoot.querySelector('.vega-segment-control-container');
      const childrenWidth = container.children.length *
        VegaSegmentOverflowController.SEGMENTS_OVERFLOW_THRESHOLD[this.size] +
        4 * (container.children.length - 1) +
        5;
      return container.clientWidth < childrenWidth ? true : false;
    }
    return false;
  }
}
VegaSegmentOverflowController.SEGMENTS_OVERFLOW_THRESHOLD = {
  medium: 101.9,
  small: 82,
};
__decorate([
  MapToComponentField()
], VegaSegmentOverflowController.prototype, "host", void 0);
__decorate([
  MapToComponentField()
], VegaSegmentOverflowController.prototype, "block", void 0);
__decorate([
  MapToComponentField()
], VegaSegmentOverflowController.prototype, "size", void 0);
__decorate([
  MapToComponentField({ writable: true })
], VegaSegmentOverflowController.prototype, "isOverflowBlockSegments", void 0);
__decorate([
  MapToComponentMethod('watchSegments')
], VegaSegmentOverflowController.prototype, "watchSegments", null);
__decorate([
  MapToComponentMethod('watchBlock')
], VegaSegmentOverflowController.prototype, "watchBlock", null);
__decorate([
  MapToComponentMethod('watchSize')
], VegaSegmentOverflowController.prototype, "watchSize", null);
