import { ListFormComponent } from "./ListFormComponent.js";
import { messageTemplate } from "../pageControllers/validationOptions.js";
/**
 * "Selection controls" are checkboxes and radios (and switches), as per Material UI nomenclature.
 */
export class SelectionControlField extends ListFormComponent {
  getViewModel(payload, errors) {
    const {
      options
    } = this;
    const viewModel = super.getViewModel(payload, errors);
    let {
      fieldset,
      items,
      label
    } = viewModel;
    fieldset ??= {
      legend: {
        text: label.text,
        classes: 'govuk-fieldset__legend--m'
      }
    };
    items = items.map(item => {
      const {
        selected: checked
      } = item;
      const itemModel = {
        ...item,
        checked
      };
      if ('bold' in options && options.bold) {
        itemModel.label ??= {};
        itemModel.label.classes = 'govuk-label--s';
      }
      return itemModel;
    });
    return {
      ...viewModel,
      fieldset,
      items
    };
  }

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

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