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 { StringMaskStrategy } from '../../../../helpers/formatter/string-formatter/string-mask-strategy';
import { StringInputFormatterSlimmer } from '../../../../helpers/slimmers/string-input-formatter-slimmer';
import { CalendarDate } from '../../../../helpers/calendar';
/** The date picker format controller slimmer */
export class VegaDatePickerFormatController extends StringInputFormatterSlimmer {
  /**
   * The constructor function initializes an object with a specified input type in TypeScript.
   *
   * @param {InputType} inputType - The `inputType` parameter in the constructor is of type `InputType`.
   * It is being assigned to the `inputType` property of the class instance.
   */
  constructor(inputType) {
    super();
    /**
     * The code below is defining a function called `formatDate` in TypeScript. This function takes a
     *  parameter `date` of type string and returns a string.
     *
     * @param {string} date - The value of the date.
     * @returns {string} The formatted date is being returned.
     */
    this.formatDate = (date) => {
      const formattedDate = CalendarDate.fromString(date, this.format);
      return formattedDate.toString(this.format);
    };
    /**
     * This function returns a reference to an HTML input element based on the input type specified.
     *
     * @returns {HTMLInputElement|null} The single mode input ref, the start date input ref or end date input ref in range mode
     */
    this.getInputElementRef = () => {
      switch (this.inputType) {
        case 'single':
          return this.vegaDatePickerSingleInputRenderer.getSingleDateInputRef();
        case 'rangeStart':
          return this.vegaDatePickerRangeInputRenderer.getStartDateInputRef();
        case 'rangeEnd':
          return this.vegaDatePickerRangeInputRenderer.getEndDateInputRef();
      }
    };
    /**
     * Determining the string format strategy to be applied when the input field trigger is set to 'input'.
     *
     * @returns {Nullable<StringFormatStrategy>} the input mode mask strategy
     */
    this.getInputModeStrategy = () => {
      return this.datePickerFormatStrategy;
    };
    /**
     * Determining the string format strategy to be applied when the input field trigger is set to 'blur'. The date-picker don't need blur strategy, return null
     *
     * @returns {Nullable<StringFormatStrategy>} the blur mode mask strategy
     */
    this.getBlurModeStrategy = () => {
      return null;
    };
    /**
     * The code below is defining a private method called `getDateFormatMask` in a TypeScript class. This
     * method takes a `format` parameter of type `string`.
     *
     * @param {string} format - The value of the format.
     * @returns {StringMaskStrategy} - The mask of the date format.
     */
    this.getDateFormatMask = (format) => {
      const matchResult = format.match(/M/gi);
      return new StringMaskStrategy({
        mask: format.replace(/[MDY]/gi, '9'),
        slot: '9',
        accept: (matchResult && matchResult.length) > 2 ? /\w/g : /\d/g,
      });
    };
    this.inputType = inputType;
  }
  /** Set up string formatter when component did load */
  componentDidLoad() {
    this.setupStringFormatter(this.format);
  }
  /*
   * The below method is e2e-test covered in
   * @see{module:vega-date-picker-change-mask-format}
   * @see{module:vega-date-picker-range-mode-change-mask-format}
   */
  /* istanbul ignore next */
  /**
   * It is decorated with the `@MapToComponentMethod` decorator,
   * which indicates that this method should be mapped to a component method called 'format'.
   *
   * @param {string} format - The value of the format.
   */
  watchFormat(format) {
    this.setupStringFormatter(format);
  }
  /*
   * The below method is e2e-test covered in
   * @see{module:vega-date-picker-change-mask-format}
   * @see{module:vega-date-picker-range-mode-change-mask-format}
   */
  /* istanbul ignore next */
  /**
   * The function `setupStringFormatter` sets up string input formatters based on the provided format for
   * either single date or range mode.
   *
   * @param {string} format - The format parameter is a string that represents the desired format for the
   * date input. It is used to create a date format mask that is passed to the StringInputFormatter
   * constructor.
   */
  setupStringFormatter(format) {
    this.datePickerFormatStrategy = this.getDateFormatMask(format);
    this.setup();
  }
}
__decorate([
  MapToComponentField()
], VegaDatePickerFormatController.prototype, "format", void 0);
__decorate([
  MapToComponentField()
], VegaDatePickerFormatController.prototype, "mode", void 0);
__decorate([
  MapToComponentField()
], VegaDatePickerFormatController.prototype, "vegaDatePickerCalendarRenderer", void 0);
__decorate([
  MapToComponentField()
], VegaDatePickerFormatController.prototype, "vegaDatePickerSingleInputRenderer", void 0);
__decorate([
  MapToComponentField()
], VegaDatePickerFormatController.prototype, "vegaDatePickerRangeInputRenderer", void 0);
__decorate([
  MapToComponentMethod('componentDidLoad')
], VegaDatePickerFormatController.prototype, "componentDidLoad", null);
__decorate([
  MapToComponentMethod('watchFormat')
], VegaDatePickerFormatController.prototype, "watchFormat", null);
