"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxRuntime = require("react/jsx-runtime");
const errorMessage = require("@hookform/error-message");
const lodashEs = require("lodash-es");
const React = require("react");
const reactHookForm = require("react-hook-form");
;/* empty css                                                                                                                                                                                        */
;/* empty css                                                                                                                                                                                         */
;/* empty css                                                                                                                                                                                                 */
;/* empty css                                                                                                                                                                                            */
;/* empty css                                                                                                                                                                                            */
const Radio = require("../../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.cjs");
const Flex = require("../../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.cjs");
const Tooltip = require("../../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.cjs");
const HoverCard = require("../../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.cjs");
const Box = require("../../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.cjs");
const FormRadioGroup = ({
  name,
  rules,
  onChange,
  data,
  direction,
  gap = "md",
  ...rest
}) => {
  const { control, formState, getFieldState } = reactHookForm.useFormContext();
  const { error } = getFieldState(name, formState);
  return /* @__PURE__ */ jsxRuntime.jsx(
    reactHookForm.Controller,
    {
      control,
      name,
      rules,
      render: ({ field }) => {
        const { onChange: handleChange, ...restField } = field;
        return /* @__PURE__ */ jsxRuntime.jsx(
          Radio.Radio.Group,
          {
            ...rest,
            onChange: (value) => {
              handleChange(value);
              onChange == null ? void 0 : onChange(value);
            },
            ...restField,
            error: error ? /* @__PURE__ */ jsxRuntime.jsx(errorMessage.ErrorMessage, { errors: formState.errors, name }) : void 0,
            children: /* @__PURE__ */ jsxRuntime.jsx(Flex.Flex, { direction, gap, mt: "xs", children: data.map((i) => {
              var _a;
              const radioProps = lodashEs.omit(i, "tooltipProps", "tooltip");
              return /* @__PURE__ */ jsxRuntime.jsx(React.Fragment, { children: i.tooltip ? ((_a = i.tooltipProps) == null ? void 0 : _a.useTooltip) ? /* @__PURE__ */ jsxRuntime.jsx(Tooltip.Tooltip, { label: i.tooltip, withArrow: true, refProp: "rootRef", children: /* @__PURE__ */ jsxRuntime.jsx(Radio.Radio, { ...radioProps }) }) : /* @__PURE__ */ jsxRuntime.jsxs(HoverCard.HoverCard, { withArrow: true, shadow: "md", withinPortal: true, ...i.tooltipProps, children: [
                /* @__PURE__ */ jsxRuntime.jsx(HoverCard.HoverCard.Target, { children: /* @__PURE__ */ jsxRuntime.jsx(Box.Box, { children: /* @__PURE__ */ jsxRuntime.jsx(Radio.Radio, { ...radioProps }) }) }),
                /* @__PURE__ */ jsxRuntime.jsx(HoverCard.HoverCard.Dropdown, { maw: 400, children: i.tooltip })
              ] }) : /* @__PURE__ */ jsxRuntime.jsx(Radio.Radio, { ...radioProps }) }, i.value);
            }) })
          }
        );
      }
    }
  );
};
exports.FormRadioGroup = FormRadioGroup;
