import { InputMixin as p, CheckableMixin as h, GroupableMixin as c, MessagesMixin as g } from "../../common/mixins/input.js";
import { RADIO_INPUT_VALIDATION_CLASSES as f } from "./radio-constants.js";
import { addClassStyleAttrs as C, removeClassStyleAttrs as V, hasSlotContent as v } from "../../common/utils/index.js";
import { resolveComponent as b, createElementBlock as i, openBlock as o, mergeProps as a, createElementVNode as t, createCommentVNode as r, normalizeClass as M, toHandlers as S, renderSlot as d, createTextVNode as l, toDisplayString as n, createVNode as y } from "vue";
import { _ as k } from "../../_plugin-vue_export-helper-CHgC5LLL.js";
import A from "../validation-messages/validation-messages.js";
const D = {
  compatConfig: { MODE: 3 },
  name: "DtRadio",
  components: { DtValidationMessages: A },
  mixins: [p, h, c, g],
  inheritAttrs: !1,
  props: {
    /**
     * A provided value for the radio
     */
    value: {
      type: [String, Number],
      default: ""
    }
  },
  emits: [
    /**
     * Native input event
     *
     * @event input
     * @type {String | Number}
     */
    "input",
    /**
     * Event fired to sync the modelValue prop with the parent component
     *
     * @event input
     * @type {String | Number}
     */
    "update:modelValue",
    /**
     * Native input focus event
     *
     * @event focus
     * @type {FocusEvent}
     */
    "focus",
    /**
     * Native input focusin event
     *
     * @event focusin
     * @property {FocusEvent}
     */
    "focusin",
    /**
     * Native input focusout event
     *
     * @event focusout
     * @property {FocusEvent}
     */
    "focusout"
  ],
  data() {
    return {
      hasSlotContent: v
    };
  },
  computed: {
    inputValidationClass() {
      return f[this.internalValidationState];
    },
    radioGroupValue() {
      var e;
      return (e = this.groupContext) == null ? void 0 : e.selectedValue;
    },
    inputListeners() {
      return {
        /*
         * Override input listener to as no-op. Prevents parent input listeners from being passed through onto the input
         * element which will result in the handler being called twice
         * (once on the input element and once by the emitted input event by the change listener).
        */
        input: () => {
        },
        focusin: (e) => this.$emit("focusin", e),
        focusout: (e) => this.$emit("focusout", e),
        change: (e) => this.emitValue(e.target.value)
      };
    },
    hasMessages() {
      return this.formattedMessages.length && this.showMessages;
    }
  },
  watch: {
    radioGroupValue: {
      immediate: !0,
      handler(e) {
        this.hasGroup && (this.internalChecked = e === this.value);
      }
    }
  },
  methods: {
    removeClassStyleAttrs: V,
    addClassStyleAttrs: C,
    emitValue(e) {
      e !== this.radioGroupValue && (this.setGroupValue(e), this.$emit("input", e), this.$emit("update:modelValue", e));
    }
  }
}, N = { class: "d-radio__input" }, $ = ["checked", "name", "value", "disabled"], G = {
  key: 0,
  class: "d-radio__messages",
  "data-qa": "radio-description-messages"
};
function _(e, w, u, I, P, s) {
  const m = b("dt-validation-messages");
  return o(), i("div", a({ class: e.rootClass }, s.addClassStyleAttrs(e.$attrs)), [
    t("label", {
      class: M(["d-radio-group", { "d-radio-group--disabled": e.internalDisabled }])
    }, [
      t("div", N, [
        t("input", a({
          checked: e.internalChecked,
          name: e.internalName,
          value: u.value,
          disabled: e.internalDisabled,
          type: "radio",
          class: ["d-radio", s.inputValidationClass, e.inputClass]
        }, s.removeClassStyleAttrs(e.$attrs), S(s.inputListeners, !0)), null, 16, $)
      ]),
      t("div", a({
        class: [e.labelClass, "d-radio__copy d-radio__label"]
      }, e.labelChildProps, { "data-qa": "radio-label" }), [
        d(e.$slots, "default", {}, () => [
          l(n(e.label), 1)
        ])
      ], 16)
    ], 2),
    e.$slots.description || e.description || s.hasMessages ? (o(), i("div", G, [
      e.$slots.description || e.description ? (o(), i("div", a({
        key: 0,
        class: ["d-description", e.descriptionClass]
      }, e.descriptionChildProps, { "data-qa": "radio-description" }), [
        d(e.$slots, "description", {}, () => [
          l(n(e.description), 1)
        ])
      ], 16)) : r("", !0),
      y(m, a({
        "validation-messages": e.formattedMessages,
        "show-messages": e.showMessages,
        class: e.messagesClass
      }, e.messagesChildProps, { "data-qa": "dt-radio-validation-messages" }), null, 16, ["validation-messages", "show-messages", "class"])
    ])) : r("", !0)
  ], 16);
}
const B = /* @__PURE__ */ k(D, [["render", _]]);
export {
  B as default
};
//# sourceMappingURL=radio.js.map
