import { SchemaVersion, yesNoListId, yesNoListName } from '@defra/forms-model';
import { SelectionControlField } from "./SelectionControlField.js";
import { addClassOptionIfNone } from "./helpers/index.js";
import { messageTemplate } from "../pageControllers/validationOptions.js";
import { convertToLanguageMessages } from "../../../utils/type-utils.js";

/**
 * @description
 * YesNoField is a radiosField with predefined values.
 */
export class YesNoField extends SelectionControlField {
  constructor(def, props) {
    super({
      ...def,
      list: props.model.schemaVersion === SchemaVersion.V1 ? yesNoListName : yesNoListId
    }, props);
    const {
      options
    } = def;
    let {
      formSchema
    } = this;
    addClassOptionIfNone(options, 'govuk-radios--inline');
    if (options.required === false) {
      formSchema = formSchema.optional();
    }
    formSchema = formSchema.messages(convertToLanguageMessages({
      'any.required': messageTemplate.selectYesNoRequired
    }));
    this.formSchema = formSchema;
    this.options = options;
  }

  /**
   * For error preview page that shows all possible errors on a component
   */
  getAllPossibleErrors() {
    return YesNoField.getAllPossibleErrors();
  }

  /**
   * Static version of getAllPossibleErrors that doesn't require a component instance.
   */
  static getAllPossibleErrors() {
    return {
      baseErrors: [{
        type: 'selectYesNoRequired',
        template: messageTemplate.selectYesNoRequired
      }],
      advancedSettingsErrors: []
    };
  }
}
//# sourceMappingURL=YesNoField.js.map