'use strict';

const jsxRuntime = require('react/jsx-runtime');
const form = require('../../form.cjs');
const radioGroup = require('../../radio-group.cjs');
const label = require('../common/label.cjs');
const tooltip = require('../common/tooltip.cjs');
const helpers = require('../helpers.cjs');

function getEnumValues(schema) {
  if (Array.isArray(schema.options)) {
    return schema.options;
  }
  if (schema.enum) {
    return Object.values(schema.enum);
  }
  const def = schema._zod?.def;
  if (def?.entries) {
    return Object.values(def.entries);
  }
  return [];
}
function AutoFormRadioGroup({
  label: label$1,
  isRequired,
  field,
  zodItem,
  fieldProps,
  fieldConfigItem
}) {
  const baseSchema = helpers.getBaseSchema(zodItem);
  const values = getEnumValues(baseSchema);
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
    /* @__PURE__ */ jsxRuntime.jsxs(form.FormItem, { children: [
      /* @__PURE__ */ jsxRuntime.jsx(
        label,
        {
          label: fieldConfigItem?.label || label$1,
          isRequired
        }
      ),
      /* @__PURE__ */ jsxRuntime.jsx(form.FormControl, { children: /* @__PURE__ */ jsxRuntime.jsx(
        radioGroup.RadioGroup,
        {
          onValueChange: field.onChange,
          defaultValue: field.value,
          ...fieldProps,
          children: values?.map((value) => /* @__PURE__ */ jsxRuntime.jsxs(
            form.FormItem,
            {
              className: "mb-2 flex items-center gap-3 space-y-0",
              children: [
                /* @__PURE__ */ jsxRuntime.jsx(form.FormControl, { children: /* @__PURE__ */ jsxRuntime.jsx(radioGroup.RadioGroupItem, { value }) }),
                /* @__PURE__ */ jsxRuntime.jsx(form.FormLabel, { className: "font-normal", children: value })
              ]
            },
            value
          ))
        }
      ) }),
      /* @__PURE__ */ jsxRuntime.jsx(form.FormMessage, {})
    ] }),
    /* @__PURE__ */ jsxRuntime.jsx(tooltip, { fieldConfigItem })
  ] });
}

module.exports = AutoFormRadioGroup;
