var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { MapToComponentField, MapToComponentMethod, VegaSlimmer } from 'vega-slimmer/core';
/** The class `VegaRadioGroupRadioItemsController` manages a group of radio items within a VegaRadioGroup component in TypeScript. */
export class VegaRadioGroupRadioItemsController extends VegaSlimmer {
  constructor() {
    super(...arguments);
    this.vegaRadioArray = [];
  }
  /**
   * The function `queryRadioItemsAndSetValue` retrieves all `vega-radio` elements and sets the default value based on the checked item.
   */
  componentWillLoad() {
    this.syncRadioArrayAndValue();
  }
  /**
   * The function `setRadioItemName` assigns a name to each radio item in the `vegaRadioArray` based on the component's `name` property or the `name` attribute of the radio item.
   */
  setRadioItemName() {
    this.vegaRadioArray.forEach((vegaRadio) => {
      if (this.name) {
        vegaRadio.name = this.name;
      }
      else {
        vegaRadio.name = vegaRadio.getAttribute('name');
      }
    });
  }
  /**
   * The function sets the checked property of a radio item in an array based on a specified value.
   *
   * @param {string} newValue - The `newValue` parameter in the `setRadioItemCheckedByValue` method is a
   * string value that represents the value of the radio item that you want to set as checked in a group
   * of radio items. The method iterates over an array of radio elements (`vegaRadioArray`) and sets
   */
  setRadioItemCheckedByValue(newValue) {
    this.vegaRadioArray.forEach((vegaRadio) => {
      vegaRadio.checked = vegaRadio.value === newValue;
    });
  }
  /**
   * The function syncs the status of radio items based on a specified value.
   */
  syncRadioItemsStatus() {
    this.setRadioItemCheckedByValue(this.value);
    this.setRadioItemName();
  }
  /**
   * The function returns an array of HTMLVegaRadioElement objects.
   *
   * @returns {HTMLVegaRadioElement[]} An array of HTMLVegaRadioElement objects is being returned.
   */
  getRadioItemsArray() {
    return this.vegaRadioArray;
  }
  /**
   * The function collect radio items and sync the radio group value.
   */
  syncRadioArrayAndValue() {
    this.vegaRadioArray = Array.from(this.host.querySelectorAll('vega-radio'));
    this.vegaRadioArray.forEach((vegaRadio) => {
      if (vegaRadio.checked) {
        this.valueController.setValue(vegaRadio.value);
      }
    });
  }
}
__decorate([
  MapToComponentField()
], VegaRadioGroupRadioItemsController.prototype, "host", void 0);
__decorate([
  MapToComponentField()
], VegaRadioGroupRadioItemsController.prototype, "value", void 0);
__decorate([
  MapToComponentField()
], VegaRadioGroupRadioItemsController.prototype, "name", void 0);
__decorate([
  MapToComponentField()
], VegaRadioGroupRadioItemsController.prototype, "valueController", void 0);
__decorate([
  MapToComponentMethod('componentWillLoad')
], VegaRadioGroupRadioItemsController.prototype, "componentWillLoad", null);
__decorate([
  MapToComponentMethod('watchName')
], VegaRadioGroupRadioItemsController.prototype, "setRadioItemName", null);
__decorate([
  MapToComponentMethod('watchValue')
], VegaRadioGroupRadioItemsController.prototype, "setRadioItemCheckedByValue", null);
__decorate([
  MapToComponentMethod('componentDidLoad')
], VegaRadioGroupRadioItemsController.prototype, "syncRadioItemsStatus", null);
