import { V as VegaRTEContent } from './content-state-afeb700d.js';
import { I as InternalFormFieldValidationRule } from './internal-form-field-validation-rule.abstract-f5b6bdbf.js';

/**
 * A rule that checks if the input range is empty or not
 *
 * @augments {InternalFormFieldValidationRule<string[]>}
 */
class RichTextEditorRequiredRule extends InternalFormFieldValidationRule {
  /**
   * It checks if the input is a valid value.
   *
   * @param {string[]} input - The value of the input field.
   * @returns {EvaluateResult} An object with two properties: isValid and message.
   */
  evaluate(input) {
    var _a, _b;
    if (!this.isAcceptedInputType(input)) {
      throw new Error(`Invalid value ${input} for rich text editor`);
    }
    const isValid = ((_a = input === null || input === void 0 ? void 0 : input.children) === null || _a === void 0 ? void 0 : _a.length) > 1 || // isValid: true when the length is greater than 1 to keep the same behavior as vega-textarea
      (((_b = input === null || input === void 0 ? void 0 : input.children) === null || _b === void 0 ? void 0 : _b.length) === 1 && input.children.some((block) => block.isNotEmpty()));
    return {
      isValid,
      message: isValid ? '' : '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} A boolean value.
   */
  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 undefined or null, return true, otherwise return true if the input is a VegaRTEContent.
   *
   * @param {unknown} input - The input value to be validated.
   * @returns {boolean} A boolean.
   */
  isAcceptedInputType(input) {
    if (input === undefined || input === null)
      return true;
    return input instanceof VegaRTEContent;
  }
}

export { RichTextEditorRequiredRule as R };
