<template>
  <view
    :class="classNames(bem.b(), bem.m(direction), rootClass)"
    :style="stringifyStyle(rootStyle)"
  >
    <slot
      v-if="$slots.custom"
      name="custom"
      :toggle="toggle"
      :value="innerValue"
    ></slot>
    <slot v-else></slot>
  </view>
</template>

<script lang="ts">
import { defineComponent as _defineComponent } from "vue";
import { ref, watch, provide, toRef, reactive } from "vue";
import {
  radioContextSymbol,
  radioGroupProps
} from "../radio/common";
import { classNames, stringifyStyle, createBem } from "../utils";
import { useFormItemContext } from "../form/common";
const __default__ = {
  options: {
    virtualHost: true,
    styleIsolation: "shared"
  }
};
export default /* @__PURE__ */ _defineComponent({
  ...__default__,
  __name: "radio-group",
  props: radioGroupProps,
  emits: ["update:model-value"],
  setup(__props, { expose: __expose, emit: __emit }) {
    __expose();
    const props = __props;
    const emit = __emit;
    const bem = createBem("radio-group");
    const formItemContext = useFormItemContext();
    const innerValue = ref(props.modelValue);
    watch(
      () => props.modelValue,
      () => {
        innerValue.value = props.modelValue;
        if (props.validateEvent) {
          formItemContext?.onChange();
        }
      }
    );
    const toggle = (value) => {
      emit("update:model-value", value);
    };
    provide(
      radioContextSymbol,
      reactive({
        disabled: toRef(props, "disabled"),
        readonly: toRef(props, "readonly"),
        size: toRef(props, "size"),
        type: toRef(props, "type"),
        checkedColor: toRef(props, "checkedColor"),
        value: innerValue,
        toggle
      })
    );
    const __returned__ = { props, emit, bem, formItemContext, innerValue, toggle, get classNames() {
      return classNames;
    }, get stringifyStyle() {
      return stringifyStyle;
    } };
    return __returned__;
  }
});
</script>

<style lang="scss">
@use './index.scss';
</style>