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 { Component, Host, h, Element, Prop, Event, Watch } from '@stencil/core';
import { sanitizeVegaComponent } from '../../../utils/component';
import { RequiredFieldRule } from '../../../helpers/validator/rules/required-field-rule';
import { ComponentLoadRequired } from '../../../decorators/method-decorators/component-load-required';
import ChangeManager from '../../../helpers/change-manager/change-manager';
import { RADIO_GROUP_DISABLED_CHANGE, RADIO_VALUE_CHANGE, } from '../../../helpers/change-manager/subject/static-subject/static-subject-title';
import { FormFieldControllerSlimmer } from '../../../helpers/slimmers/form-field-controller-slimmer';
import { InjectVegaGlobalSlimmer, InjectVegaSlimmer, methodPlaceholder, } from 'vega-slimmer/core';
import { ChildNodesNotifyObserverSlimmer, } from '../../../helpers/event-manager/slimmers/child-nodes-notify-observer-slimmer';
import { ChildNodesEventPreventSlimmer } from '../../../helpers/event-manager/slimmers/child-nodes-event-prevent-slimmer';
import { VegaChange } from '../../../helpers/event-manager/event-id/vega-event-id';
import { createEventEmitSlimmer, } from '../../../helpers/event-manager/slimmers/event-emit-slimmer';
import { VegaRadioGroupKeyboardController } from './slimmers/controllers/vega-radio-group-keyboard-controller';
import { VegaRadioGroupValueController } from './slimmers/controllers/vega-radio-group-value-controller';
import { VegaRadioGroupRadioItemsController } from './slimmers/controllers/vega-radio-group-radio-items-controller';
import { MutationObserverSlimmer } from '../../../helpers/slimmers/mutation-observer/mutation-observer-slimmer';
import { TagNameMutationFilter } from '../../../helpers/slimmers/mutation-observer/mutation-observer-filters';
import { VegaComponentUsageRuntimeMetricsSlimmer } from '../../../helpers/slimmers/component-usage-runtime-metrics';
/**
 * @vegaVersion 1.0.7
 */
export class VegaRadioGroup {
  constructor() {
    this.globalSlimmers = {};
    this.formFieldController = new FormFieldControllerSlimmer({
      propertyRules: [
        {
          propertyName: 'required',
          ruleFactory: (isRequired) => (isRequired ? new RequiredFieldRule() : null),
        },
      ],
      inputContainerGetter: () => this.inputContainerRef,
      touchableAreaGetter: () => this.radioItemsController
        .getRadioItemsArray()
        .map((vegaRadio) => vegaRadio.shadowRoot.querySelector('input')),
      defaultValue: '',
      attributeGetter: (propertyName) => this[propertyName],
      validationRulesName: 'validationRules',
    });
    this.radioValueChangeObserver = new ChildNodesNotifyObserverSlimmer(RADIO_VALUE_CHANGE, (payload) => this.childRadioValueChange(payload));
    this.radioEventPrevent = new ChildNodesEventPreventSlimmer([VegaChange], () => this.vegaFlexElement);
    this.slotMutationObserver = new MutationObserverSlimmer({
      options: { childList: true },
      mutationFilter: TagNameMutationFilter('VEGA-RADIO'),
      callback: 
      /*
       * The below method is e2e-test covered in
       * @see{module:vega-radio-group-slot-change-e2e}
       */
      /* istanbul ignore next */
      () => this.radioItemsController.syncRadioArrayAndValue(),
    });
    this.changeEventEmitter = createEventEmitSlimmer(VegaRadioGroup, VegaChange);
    this.keyboardController = new VegaRadioGroupKeyboardController();
    this.radioItemsController = new VegaRadioGroupRadioItemsController();
    this.valueController = new VegaRadioGroupValueController();
    this.vegaComponentUsageRuntimeMetricsSlimmer = new VegaComponentUsageRuntimeMetricsSlimmer();
    /**
     * Specifies the label or title of the radio group.
     *
     * @vegaVersion 1.3.0
     */
    this.label = '';
    /**
     * Represents the value associated with the radio button.
     *
     * @vegaVersion 1.0.7
     */
    /* eslint-disable-next-line @stencil/strict-mutable */
    this.value = '';
    /**
     * Specifies all the properties of the `vega-flex` component
     *    in the radio group.
     *
     * @vegaVersion 1.3.0
     */
    this.vegaFlexProp = {};
    /**
     * Specifies whether the radio button within the radio group
     *    must be checked to pass form validation.
     *
     * @vegaVersion 1.3.0
     */
    this.required = false;
    /**
     * Provides a supplementary prompt message that assists users
     *    in selecting the appropriate value for the radio group.
     *
     * @vegaVersion 1.3.0
     */
    this.hint = '';
    /**
     * Sets the validation status for the radio group.
     *
     * @vegaVersion 1.3.0
     */
    /* eslint-disable-next-line @stencil/strict-mutable */
    this.isValid = null;
    /**
     * Determines whether the radio group is disabled.
     *
     * @vegaVersion 1.8.0
     */
    this.disabled = false;
    /**
     * Determines whether automatic validation should be implemented for
     *    the radio group upon selection.
     *
     * @vegaVersion 2.6.0
     */
    this.autoValidation = true;
    /**
     * Defines custom validation rules for the radio group.
     *
     * @vegaVersion 2.6.0
     */
    this.validationRules = [];
    /**
     * Update radio group value when child radio is changed.
     */
    this.childRadioValueChange = (payload) => {
      if (payload.detail) {
        this.valueController.setValue(payload.host.value);
      }
    };
  }
  async watchValue(newValue) {
    methodPlaceholder(newValue);
  }
  watchName() {
    methodPlaceholder();
  }
  watchVegaFlexProp() {
    this.setVegaFlexProperty();
  }
  async watchDisabled() {
    this.notifyGroupDisabledChange();
  }
  watchValidationRules() {
    methodPlaceholder();
  }
  componentWillLoad() {
    methodPlaceholder();
  }
  componentDidLoad() {
    this.setVegaFlexProperty();
    if (this.disabled) {
      this.notifyGroupDisabledChange();
    }
  }
  render() {
    return sanitizeVegaComponent(h(Host, { role: "radiogroup" },
      this.renderLabelDom(),
      h("div", { class: "vega-radio-container", ref: (e) => (this.inputContainerRef = e) },
        h("vega-flex", { ref: (el) => {
            this.vegaFlexElement = el;
          } },
          h("slot", null))),
      this.renderHintDom()), this.host);
  }
  renderLabelDom() {
    return (this.label && (h("div", { class: "vega-label" },
      h("label", { "aria-label": this.label },
        this.label,
        this.renderRequireDom()))));
  }
  renderRequireDom() {
    return this.required ? h("span", { class: "vega-require" }, "*") : null;
  }
  renderHintDom() {
    return (this.hint && (h("div", { class: "vega-hint" },
      h("label", null, this.hint))));
  }
  setVegaFlexProperty() {
    if (this.vegaFlexProp) {
      Object.assign(this.vegaFlexElement, {
        gap: 'size-16',
        direction: 'col',
      }, this.vegaFlexProp);
    }
  }
  /**
   * This function notifies a change in the disabled state of a radio group component.
   */
  notifyGroupDisabledChange() {
    ChangeManager.notify(RADIO_GROUP_DISABLED_CHANGE, { host: this.host });
  }
  static get is() { return "vega-radio-group"; }
  static get encapsulation() { return "shadow"; }
  static get originalStyleUrls() { return {
    "$": ["vega-radio-group.scss"]
  }; }
  static get styleUrls() { return {
    "$": ["vega-radio-group.css"]
  }; }
  static get properties() { return {
    "label": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "name": "vegaVersion",
            "text": "1.3.0"
          }],
        "text": "Specifies the label or title of the radio group."
      },
      "attribute": "label",
      "reflect": false,
      "defaultValue": "''"
    },
    "value": {
      "type": "string",
      "mutable": true,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "name": "vegaVersion",
            "text": "1.0.7"
          }],
        "text": "Represents the value associated with the radio button."
      },
      "attribute": "value",
      "reflect": true,
      "defaultValue": "''"
    },
    "name": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "name": "vegaVersion",
            "text": "1.3.0"
          }],
        "text": "Specifies the name attribute for each radio button\n   in the radio group."
      },
      "attribute": "name",
      "reflect": false
    },
    "vegaFlexProp": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "VegaFlexProps",
        "resolved": "{ direction?: ResponsiveType<\"row\" | \"col\" | \"column\" | \"row-reverse\" | \"col-reverse\" | \"column-reverse\">; gap?: ResponsiveType<GapType>; alignItems?: ResponsiveType<FlexAlignItemType>; justifyContent?: ResponsiveType<FlexJustifyContentType>; margin?: ResponsiveType<MarginType>; }",
        "references": {
          "VegaFlexProps": {
            "location": "import",
            "path": "../../../types/ui.type"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "name": "vegaVersion",
            "text": "1.3.0"
          }],
        "text": "Specifies all the properties of the `vega-flex` component\n   in the radio group."
      },
      "defaultValue": "{}"
    },
    "required": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "name": "vegaVersion",
            "text": "1.3.0"
          }],
        "text": "Specifies whether the radio button within the radio group\n   must be checked to pass form validation."
      },
      "attribute": "required",
      "reflect": true,
      "defaultValue": "false"
    },
    "hint": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "name": "vegaVersion",
            "text": "1.3.0"
          }],
        "text": "Provides a supplementary prompt message that assists users\n   in selecting the appropriate value for the radio group."
      },
      "attribute": "hint",
      "reflect": false,
      "defaultValue": "''"
    },
    "isValid": {
      "type": "boolean",
      "mutable": true,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "name": "vegaVersion",
            "text": "1.3.0"
          }],
        "text": "Sets the validation status for the radio group."
      },
      "attribute": "is-valid",
      "reflect": true,
      "defaultValue": "null"
    },
    "disabled": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "name": "vegaVersion",
            "text": "1.8.0"
          }],
        "text": "Determines whether the radio group is disabled."
      },
      "attribute": "disabled",
      "reflect": true,
      "defaultValue": "false"
    },
    "autoValidation": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "name": "vegaVersion",
            "text": "2.6.0"
          }],
        "text": "Determines whether automatic validation should be implemented for\n   the radio group upon selection."
      },
      "attribute": "auto-validation",
      "reflect": true,
      "defaultValue": "true"
    },
    "validationRules": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "FormFieldValidationRule<unknown>[]",
        "resolved": "FormFieldValidationRule<unknown>[]",
        "references": {
          "FormFieldValidationRule": {
            "location": "import",
            "path": "../../../helpers/validator/rules/form-field-validation-rule"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "name": "vegaVersion",
            "text": "2.6.0"
          }],
        "text": "Defines custom validation rules for the radio group."
      },
      "defaultValue": "[]"
    }
  }; }
  static get events() { return [{
      "method": "vegaChange",
      "name": "vegaChange",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [{
            "name": "vegaVersion",
            "text": "1.0.10"
          }],
        "text": "An event emitter notifying the change of the\n   checked radio button in the radio group."
      },
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      }
    }, {
      "method": "change",
      "name": "change",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [{
            "name": "eventSemantics",
            "text": "namespace:native"
          }, {
            "name": "vegaVersion",
            "text": "2.0.0"
          }],
        "text": "An event emitter notifying the change of the\n   checked radio button in the radio group."
      },
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      }
    }]; }
  static get elementRef() { return "host"; }
  static get watchers() { return [{
      "propName": "value",
      "methodName": "watchValue"
    }, {
      "propName": "name",
      "methodName": "watchName"
    }, {
      "propName": "vegaFlexProp",
      "methodName": "watchVegaFlexProp"
    }, {
      "propName": "disabled",
      "methodName": "watchDisabled"
    }, {
      "propName": "validationRules",
      "methodName": "watchValidationRules"
    }]; }
}
__decorate([
  InjectVegaGlobalSlimmer()
], VegaRadioGroup.prototype, "globalSlimmers", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaRadioGroup.prototype, "formFieldController", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaRadioGroup.prototype, "radioValueChangeObserver", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaRadioGroup.prototype, "radioEventPrevent", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaRadioGroup.prototype, "slotMutationObserver", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaRadioGroup.prototype, "changeEventEmitter", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaRadioGroup.prototype, "keyboardController", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaRadioGroup.prototype, "radioItemsController", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaRadioGroup.prototype, "valueController", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaRadioGroup.prototype, "vegaComponentUsageRuntimeMetricsSlimmer", void 0);
__decorate([
  ComponentLoadRequired()
], VegaRadioGroup.prototype, "watchVegaFlexProp", null);
