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 { ElementAppenderSlimmer } from '../../../../helpers/slimmers/element-appender/element-appender-slimmer';
import { LogUtility } from '../../../../utils/log';
import { pad } from '../../../../utils/date';
import { ClickOutsideOnlyToDismissStrategy } from '../../../../helpers/slimmers/element-appender/trigger-strategies/click-outside-only-to-dismiss-strategy';
/** The `VegaTimePickerDropdownController` class is responsible for managing the dropdown functionality of the VegaTimePicker component in a TypeScript application. */
export class VegaTimePickerSingleDropdownController extends ElementAppenderSlimmer {
  /**
   * The constructor initializes a custom dropdown component with specific configuration options.
   */
  constructor() {
    super(
    /* istanbul ignore next */
    // eslint-disable-next-line jsdoc/require-jsdoc
    () => ({
      target: this.singleInputRenderer.getInputRef(),
      appendableElement: this.singleDropdownRenderer.getDropdownRef(),
      positionRelativeTo: this.positionRelativeTo,
      translocation: { X: 0, Y: 8 },
      placement: ['bottom', 'top'],
    }), () => new ClickOutsideOnlyToDismissStrategy());
  }
  /**
   * The function initializes a value controller and dropdown source.
   */
  initValueAndDropdownSource() {
    this.valueController.resetValue();
    this.initDropdownSource();
  }
  /**
   * The function initializes the dropdown source and input mask configuration, resetting the value
   * controller, initializing the dropdown source, and initializing the input mask configuration.
   */
  initDropdownSourceAndInputMaskConfig() {
    this.valueController.resetValue();
    this.initDropdownSource();
    this.inputMaskController.initInputMask();
  }
  /**
   * The function initializes the dropdown source and sets the selected items based on a given value.
   */
  initDropdownSourceAndSelectedItems() {
    this.initDropdownSource();
    if (this.mode === 'single') {
      this.dropdownSelectedItemsController.initSelectedItemsByString(this.value);
    }
  }
  /**
   * The function hides a dropdown when it is disabled.
   */
  hideDropdownWhenDisabled() {
    if (this.mode === 'single') {
      this.hide();
    }
  }
  /**
   * The function initializes the dropdownSource object with hours and minutes strings.
   */
  initDropdownSource() {
    this.dropdownSource = {
      hours: this.getSourceHoursStrings(),
      minutes: this.getSourceMinutesStrings(),
    };
  }
  /**
   * The function `getSourceMinutesStrings` generates an array of strings representing minutes in increments specified by the `increments` variable.
   *
   * @returns {string[]} an array of strings.
   */
  getSourceMinutesStrings() {
    if (this.increments < 1 || this.increments > 59 || isNaN(Number(this.increments))) {
      LogUtility.warn('The increments should be between 1 and 59.');
      this.increments = 1;
    }
    const sourceMinutesStrings = [];
    for (let i = 0; i < 60; i = i + this.increments) {
      sourceMinutesStrings.push(pad(i));
    }
    return sourceMinutesStrings;
  }
  /**
   * The function `getSourceHoursStrings` returns an array of strings representing the hours in either 12-hour or 24-hour format.
   *
   * @returns {string[]} The function `getSourceHoursStrings` returns an array of strings.
   */
  getSourceHoursStrings() {
    const sourceHoursStrings = [];
    if (this.timeFormat === '12-hour') {
      sourceHoursStrings.push('12');
      for (let i = 1; i < 12; i++) {
        sourceHoursStrings.push(pad(i));
      }
    }
    else {
      for (let i = 0; i < 24; i++) {
        sourceHoursStrings.push(pad(i));
      }
    }
    return sourceHoursStrings;
  }
}
__decorate([
  MapToComponentField({ writable: true })
], VegaTimePickerSingleDropdownController.prototype, "isDropdownShow", void 0);
__decorate([
  MapToComponentField({ writable: true })
], VegaTimePickerSingleDropdownController.prototype, "dropdownSource", void 0);
__decorate([
  MapToComponentField()
], VegaTimePickerSingleDropdownController.prototype, "mode", void 0);
__decorate([
  MapToComponentField({ writable: true })
], VegaTimePickerSingleDropdownController.prototype, "increments", void 0);
__decorate([
  MapToComponentField()
], VegaTimePickerSingleDropdownController.prototype, "timeFormat", void 0);
__decorate([
  MapToComponentField()
], VegaTimePickerSingleDropdownController.prototype, "value", void 0);
__decorate([
  MapToComponentField()
], VegaTimePickerSingleDropdownController.prototype, "positionRelativeTo", void 0);
__decorate([
  MapToComponentField()
], VegaTimePickerSingleDropdownController.prototype, "selectedTimeValue", void 0);
__decorate([
  MapToComponentField()
], VegaTimePickerSingleDropdownController.prototype, "singleInputRenderer", void 0);
__decorate([
  MapToComponentField()
], VegaTimePickerSingleDropdownController.prototype, "rangeInputRenderer", void 0);
__decorate([
  MapToComponentField()
], VegaTimePickerSingleDropdownController.prototype, "singleDropdownRenderer", void 0);
__decorate([
  MapToComponentField()
], VegaTimePickerSingleDropdownController.prototype, "valueController", void 0);
__decorate([
  MapToComponentField()
], VegaTimePickerSingleDropdownController.prototype, "dropdownSelectedItemsController", void 0);
__decorate([
  MapToComponentField()
], VegaTimePickerSingleDropdownController.prototype, "inputMaskController", void 0);
__decorate([
  MapToComponentMethod('watchIncrements')
], VegaTimePickerSingleDropdownController.prototype, "initValueAndDropdownSource", null);
__decorate([
  MapToComponentMethod('watchTimeFormat')
], VegaTimePickerSingleDropdownController.prototype, "initDropdownSourceAndInputMaskConfig", null);
__decorate([
  MapToComponentMethod('componentWillLoad')
], VegaTimePickerSingleDropdownController.prototype, "initDropdownSourceAndSelectedItems", null);
__decorate([
  MapToComponentMethod('watchDisabled')
], VegaTimePickerSingleDropdownController.prototype, "hideDropdownWhenDisabled", null);
