import { jsxs, jsx } from 'react/jsx-runtime';
import { FormItem, FormControl, FormLabel, FormMessage } from '../../form.mjs';
import { RadioGroup, RadioGroupItem } from '../../radio-group.mjs';
import AutoFormLabel from '../common/label.mjs';
import AutoFormTooltip from '../common/tooltip.mjs';
import { getBaseSchema } from '../helpers.mjs';

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,
  isRequired,
  field,
  zodItem,
  fieldProps,
  fieldConfigItem
}) {
  const baseSchema = getBaseSchema(zodItem);
  const values = getEnumValues(baseSchema);
  return /* @__PURE__ */ jsxs("div", { children: [
    /* @__PURE__ */ jsxs(FormItem, { children: [
      /* @__PURE__ */ jsx(
        AutoFormLabel,
        {
          label: fieldConfigItem?.label || label,
          isRequired
        }
      ),
      /* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsx(
        RadioGroup,
        {
          onValueChange: field.onChange,
          defaultValue: field.value,
          ...fieldProps,
          children: values?.map((value) => /* @__PURE__ */ jsxs(
            FormItem,
            {
              className: "mb-2 flex items-center gap-3 space-y-0",
              children: [
                /* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsx(RadioGroupItem, { value }) }),
                /* @__PURE__ */ jsx(FormLabel, { className: "font-normal", children: value })
              ]
            },
            value
          ))
        }
      ) }),
      /* @__PURE__ */ jsx(FormMessage, {})
    ] }),
    /* @__PURE__ */ jsx(AutoFormTooltip, { fieldConfigItem })
  ] });
}

export { AutoFormRadioGroup as default };
