import { jsx, jsxs } from "react/jsx-runtime";
import { ErrorMessage } from "@hookform/error-message";
import { omit } from "lodash-es";
import { Fragment } from "react";
import { useFormContext, Controller } from "react-hook-form";
/* empty css                                                                                                                                                                                       */
/* empty css                                                                                                                                                                                        */
/* empty css                                                                                                                                                                                                */
/* empty css                                                                                                                                                                                           */
/* empty css                                                                                                                                                                                           */
import { Radio } from "../../node_modules/.pnpm/@mantine_core@7.15.2_patch_hash_jclkxeaefn6uz54h34k3r3yjsq_@mantine_hooks@7.15.2_react@18.3.1_szqfuioo5damkjdixckhzmwycq/node_modules/@mantine/core/esm/components/Radio/Radio.mjs";
import { Flex } from "../../node_modules/.pnpm/@mantine_core@7.15.2_patch_hash_jclkxeaefn6uz54h34k3r3yjsq_@mantine_hooks@7.15.2_react@18.3.1_szqfuioo5damkjdixckhzmwycq/node_modules/@mantine/core/esm/components/Flex/Flex.mjs";
import { Tooltip } from "../../node_modules/.pnpm/@mantine_core@7.15.2_patch_hash_jclkxeaefn6uz54h34k3r3yjsq_@mantine_hooks@7.15.2_react@18.3.1_szqfuioo5damkjdixckhzmwycq/node_modules/@mantine/core/esm/components/Tooltip/Tooltip.mjs";
import { HoverCard } from "../../node_modules/.pnpm/@mantine_core@7.15.2_patch_hash_jclkxeaefn6uz54h34k3r3yjsq_@mantine_hooks@7.15.2_react@18.3.1_szqfuioo5damkjdixckhzmwycq/node_modules/@mantine/core/esm/components/HoverCard/HoverCard.mjs";
import { Box } from "../../node_modules/.pnpm/@mantine_core@7.15.2_patch_hash_jclkxeaefn6uz54h34k3r3yjsq_@mantine_hooks@7.15.2_react@18.3.1_szqfuioo5damkjdixckhzmwycq/node_modules/@mantine/core/esm/core/Box/Box.mjs";
const FormRadioGroup = ({
  name,
  rules,
  onChange,
  data,
  direction,
  gap = "md",
  ...rest
}) => {
  const { control, formState, getFieldState } = useFormContext();
  const { error } = getFieldState(name, formState);
  return /* @__PURE__ */ jsx(
    Controller,
    {
      control,
      name,
      rules,
      render: ({ field }) => {
        const { onChange: handleChange, ...restField } = field;
        return /* @__PURE__ */ jsx(
          Radio.Group,
          {
            ...rest,
            onChange: (value) => {
              handleChange(value);
              onChange == null ? void 0 : onChange(value);
            },
            ...restField,
            error: error ? /* @__PURE__ */ jsx(ErrorMessage, { errors: formState.errors, name }) : void 0,
            children: /* @__PURE__ */ jsx(Flex, { direction, gap, mt: "xs", children: data.map((i) => {
              var _a;
              const radioProps = omit(i, "tooltipProps", "tooltip");
              return /* @__PURE__ */ jsx(Fragment, { children: i.tooltip ? ((_a = i.tooltipProps) == null ? void 0 : _a.useTooltip) ? /* @__PURE__ */ jsx(Tooltip, { label: i.tooltip, withArrow: true, refProp: "rootRef", children: /* @__PURE__ */ jsx(Radio, { ...radioProps }) }) : /* @__PURE__ */ jsxs(HoverCard, { withArrow: true, shadow: "md", withinPortal: true, ...i.tooltipProps, children: [
                /* @__PURE__ */ jsx(HoverCard.Target, { children: /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(Radio, { ...radioProps }) }) }),
                /* @__PURE__ */ jsx(HoverCard.Dropdown, { maw: 400, children: i.tooltip })
              ] }) : /* @__PURE__ */ jsx(Radio, { ...radioProps }) }, i.value);
            }) })
          }
        );
      }
    }
  );
};
export {
  FormRadioGroup
};
