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, VegaSlimmer } from 'vega-slimmer/core';
import responsiveFormatFacade from '../../../../helpers/formatter/responsive-map-formatter/responsive-format-facade';
import { Spacing } from '../../../../constants/public-api';
/**
 * The divider size controller.
 */
export class VegaDividerSizeController extends VegaSlimmer {
  /**
   * The function `getSize` adjusts the height or width of an element based on its
   * direction.
   *
   * @returns {VegaDividerSizeType} The current size value.
   */
  getSize() {
    const size = {};
    const direction = responsiveFormatFacade.formatCustom(this.direction);
    const margin = responsiveFormatFacade.formatCustom(this.margin);
    if (direction === 'vertical') {
      size.height = `calc(100% - ${this.getDirectionMargin(margin, 'top')}px - ${this.getDirectionMargin(margin, 'bottom')}px)`;
    }
    else {
      size.width = `calc(100% - ${this.getDirectionMargin(margin, 'left')}px - ${this.getDirectionMargin(margin, 'right')}px)`;
    }
    return size;
  }
  /*
   * The below method is e2e-test covered in
   * @see{module:vega-divider-size-in-horizontal-e2e}
   * @see{module:vega-divider-size-in-vertical-e2e}
   */
  /* istanbul ignore next */
  /**
   * Get the direction margin.
   *
   * @param {MarginType} margin - The current margin of divider.
   * @param {SpacingDirection} direction - The direction of margin.
   * @returns {number} The current margin value.
   */
  getDirectionMargin(margin, direction) {
    const directionMargin = typeof margin === 'string'
      ? margin
      : ['top', 'bottom'].includes(direction)
        ? margin.y || margin[direction]
        : margin.x || margin[direction];
    return directionMargin && directionMargin !== 'auto' ? Spacing[directionMargin] : 0;
  }
}
__decorate([
  MapToComponentField()
], VegaDividerSizeController.prototype, "host", void 0);
__decorate([
  MapToComponentField()
], VegaDividerSizeController.prototype, "direction", void 0);
__decorate([
  MapToComponentField()
], VegaDividerSizeController.prototype, "margin", void 0);
