import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
import { defineComponent, computed, resolveComponent, openBlock, createElementBlock, normalizeClass, renderSlot, Fragment, renderList, createBlock } from 'vue';
import getPrefixCls from '../_util/getPrefixCls';
import { CHANGE_EVENT, UPDATE_MODEL_EVENT } from '../_util/constants';
import { useTheme } from '../_theme/useTheme';
import FRadio from '../radio';
import RadioButton from '../radio-button';
import { useRadioGroup } from './useRadioGroup';
import { COMPONENT_NAME } from './const';
import { radioGroupProps } from './props';

function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
const prefixCls = getPrefixCls('radio-group');
var script = defineComponent({
  name: COMPONENT_NAME,
  components: {
    FRadio,
    RadioButton
  },
  props: radioGroupProps,
  emits: [CHANGE_EVENT, UPDATE_MODEL_EVENT],
  setup(props, _ref) {
    let {
      emit
    } = _ref;
    useTheme();
    const {
      isFormDisabled
    } = useRadioGroup(props, emit);
    const classList = computed(() => [prefixCls, props.vertical && 'is-vertical', props.fullLine && 'is-full-line', (props.disabled || isFormDisabled.value) && 'is-disabled']);
    const optionsRef = computed(() => props.options ? props.options.map(opt => {
      return _objectSpread(_objectSpread({}, opt), {}, {
        value: opt[props.valueField],
        label: opt[props.labelField]
      });
    }) : []);
    return {
      classList,
      optionsRef,
      isFormDisabled
    };
  }
});

function render(_ctx, _cache, $props, $setup, $data, $options) {
  const _component_FRadio = resolveComponent("FRadio");
  const _component_RadioButton = resolveComponent("RadioButton");
  return openBlock(), createElementBlock("div", {
    class: normalizeClass(_ctx.classList)
  }, [renderSlot(_ctx.$slots, "default"), _ctx.optionType === 'default' ? (openBlock(true), createElementBlock(Fragment, {
    key: 0
  }, renderList(_ctx.optionsRef, opt => {
    return openBlock(), createBlock(_component_FRadio, {
      key: opt.value,
      value: opt.value,
      label: opt.label,
      disabled: opt.disabled || _ctx.isFormDisabled
    }, null, 8 /* PROPS */, ["value", "label", "disabled"]);
  }), 128 /* KEYED_FRAGMENT */)) : (openBlock(true), createElementBlock(Fragment, {
    key: 1
  }, renderList(_ctx.optionsRef, opt => {
    return openBlock(), createBlock(_component_RadioButton, {
      key: opt.value,
      value: opt.value,
      label: opt.label,
      disabled: opt.disabled || _ctx.isFormDisabled
    }, null, 8 /* PROPS */, ["value", "label", "disabled"]);
  }), 128 /* KEYED_FRAGMENT */))], 2 /* CLASS */);
}

script.render = render;
script.__file = "components/radio-group/radio-group.vue";

export { script as default };
