"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const Vue = require("vue");
const index = require("../field/index.js");
const optionUtil = require("../../../utils/optionUtil.js");
const index$1 = require("../radioGroup/index.js");
const common = require("../../../utils/common.js");
const _hoisted_1 = { key: 1 };
const _sfc_main = {
  __name: "FieldRadio",
  props: {
    modelValue: {
      type: [String, Number],
      default: ""
    },
    optionConfig: {
      type: Object,
      default: () => ({})
    },
    readonly: {
      type: Boolean,
      default: false
    },
    dataSources: {
      type: Array,
      default: () => []
    },
    formData: {
      type: Object,
      default: () => {
      }
    },
    fields: {
      type: Array,
      default: () => []
    }
  },
  emits: ["update:modelValue"],
  setup(__props, { emit: __emit }) {
    const currentInstance = Vue.getCurrentInstance();
    const ctx = currentInstance.proxy;
    const props = __props;
    Vue.useAttrs();
    const finalOptions = Vue.ref([]);
    Vue.watch(
      () => common.cloneDeep(props.optionConfig),
      (val) => {
        optionUtil.getOptions({
          ctx,
          dataSources: props.dataSources,
          formData: props.formData,
          fields: props.fields,
          ...props.optionConfig
        }).then((data) => {
          finalOptions.value = data;
        });
      },
      {
        deep: true,
        immediate: true
      }
    );
    const emit = __emit;
    const compValue = Vue.computed({
      get: () => {
        return props.modelValue;
      },
      set: (val) => {
        emit("update:modelValue", val);
      }
    });
    const fieldTextValue = Vue.computed(() => {
      const selectedOption = finalOptions.value.find(
        (option) => option.value === compValue.value
      );
      return selectedOption ? selectedOption.text : "";
    });
    return (_ctx, _cache) => {
      return Vue.openBlock(), Vue.createBlock(Vue.unref(index.MobileField), Vue.mergeProps(_ctx.$attrs, {
        readonly: __props.readonly,
        modelValue: Vue.unref(fieldTextValue),
        "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => Vue.isRef(fieldTextValue) ? fieldTextValue.value = $event : null)
      }), {
        input: Vue.withCtx(() => [
          !__props.readonly ? (Vue.openBlock(), Vue.createBlock(Vue.unref(index$1.MobileRadioGroup), Vue.mergeProps({ key: 0 }, _ctx.$attrs, {
            options: Vue.unref(finalOptions),
            modelValue: Vue.unref(compValue),
            "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => Vue.isRef(compValue) ? compValue.value = $event : null)
          }), null, 16, ["options", "modelValue"])) : (Vue.openBlock(), Vue.createElementBlock("span", _hoisted_1, Vue.toDisplayString(Vue.unref(fieldTextValue)), 1))
        ]),
        _: 1
      }, 16, ["readonly", "modelValue"]);
    };
  }
};
exports.default = _sfc_main;
