'use strict';

const internalFormFieldValidationRule_abstract = require('./internal-form-field-validation-rule.abstract-07cdff46.js');

/**
 * A rule that checks if a string is empty or not
 *
 * @augments {InternalFormFieldValidationRule<string>}
 */
class CheckBoxRequiredRule extends internalFormFieldValidationRule_abstract.InternalFormFieldValidationRule {
  /**
   * If the input is a boolean, return a boolean. If the input is a string, return a boolean. If the
   * input is anything else, return false
   *
   * @param {string | boolean} input - The input to be evaluated.
   * @returns {EvaluateResult} - An object with two properties: isValid and message.
   */
  evaluate(input) {
    if (typeof input === 'boolean') {
      return {
        isValid: input,
        message: input ? '' : 'This field is required',
      };
    }
    else if (typeof input === 'string') {
      return {
        isValid: input !== '',
        message: input !== '' ? '' : 'This field is required',
      };
    }
    else {
      return {
        isValid: false,
        message: 'This field is required',
      };
    }
  }
  /**
   * If the input is accepted and the status is not disabled and visible, then return true
   *
   * @param {unknown} input - The input to be evaluated.
   * @param {FormFieldStatusMeta} [status] - FormFieldStatusMeta
   * @returns {boolean} The return value is a boolean that indicates whether the input can be evaluated.
   */
  canEvaluate(input, status) {
    return status
      ? this.isAcceptedInputType(input) && !status.disabled && status.visible
      : this.isAcceptedInputType(input);
  }
  /**
   * If the field is not disabled, visible, and has been touched or modified, then show the error
   *
   * @param {FormFieldStatusMeta} status - FormFieldStatusMeta
   * @returns {boolean} A boolean value.
   */
  shouldShowError(status) {
    return !status.disabled && status.visible && (status.touched || status.modified);
  }
  /**
   * If the input is a string, number, boolean, or null, return true, otherwise return false.
   *
   * @param {unknown} input - The input value to be validated.
   * @returns {boolean} a boolean value.
   */
  isAcceptedInputType(input) {
    return typeof input === 'string' || typeof input === 'boolean' || input === null;
  }
}

exports.CheckBoxRequiredRule = CheckBoxRequiredRule;
