'use strict';

const typeGuard = require('./type-guard-c1195e50.js');

/**
 * String format strategy abstract class
 */
class StringFormatStrategy {
  constructor() {
    this.overrideValue = false;
  }
  /**
   * Check if the {@link format} should be applied
   *
   * @param {FormatTrigger} triggeredBy - The trigger of the format
   * @param {FormatTarget} target - The target of the format
   * @param {InputStatus} inputStatus - The status of the input
   * @returns {boolean} - Whether the format should be applied
   */
  canFormat(triggeredBy, target, inputStatus) {
    if (triggeredBy === 'init' || triggeredBy === 'change') {
      if (target === 'component' && typeGuard.isNonNullable(inputStatus === null || inputStatus === void 0 ? void 0 : inputStatus.isBlurred)) {
        return false;
      }
      if (this.shouldTriggerAtInit()) {
        return true;
      }
    }
    if (triggeredBy === 'input' && target === 'native-input') {
      return true;
    }
    if (triggeredBy === 'change' && (target === 'component' || target === 'native-input')) {
      return true;
    }
    if (triggeredBy === 'blur' && (inputStatus === null || inputStatus === void 0 ? void 0 : inputStatus.isBlurred)) {
      if (target === 'component' && this.shouldOverrideComponentValueAfterBlur()) {
        return true;
      }
      if (target === 'native-input') {
        return true;
      }
    }
    return false;
  }
  /**
   * Determines whether a component value should be overridden based on the mask configuration.
   *
   * @returns {boolean} - Whether the component value should be overridden.
   */
  shouldOverrideComponentValueAfterBlur() {
    return this.overrideValue;
  }
  /**
   * Determines whether the format should be triggered at init.
   *
   * @returns {boolean} - Whether the format should be triggered at init.
   */
  shouldTriggerAtInit() {
    return false; // TODO: trigger at init feature is not implemented to all strategies. To keep the same behavior as before so set false here as default.
  }
}

exports.StringFormatStrategy = StringFormatStrategy;
