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 { parsePixelStringToNumber } from '../../../../../utils/pixel';
/**
 * The `VegaCalendarTitleMaxHeightController` class in TypeScript sets the maximum height for
 * a vertical title element based on its line height and current height.
 */
export class VegaCalendarTitleMaxHeightController extends VegaSlimmer {
  /*
   * The below method is e2e-test covered in
   * @see{module:vega-calendar-event-title-max-height-e2e}
   */
  /* istanbul ignore next */
  /**
   * The function sets the maximum height of a vertical title element based on its line height and
   * current height.
   */
  setVerticalTitleMaxHeight() {
    const title = this.renderer.getEventTitleContainerRef();
    if (title && title.classList.contains('title-word-wrap')) {
      const styles = window.getComputedStyle(title);
      const height = parsePixelStringToNumber(styles.height);
      const lineHeight = parsePixelStringToNumber(styles.lineHeight);
      // We need to ensure that at least one line is displayed
      const maxLines = Math.max(Math.floor(height / lineHeight), 1);
      title.style.maxHeight = `${maxLines * lineHeight}px`;
    }
  }
}
__decorate([
  MapToComponentField()
], VegaCalendarTitleMaxHeightController.prototype, "renderer", void 0);
