'use strict';

var jsxRuntime = require('react/jsx-runtime');
var React = require('react');
var utils = require('./utils-BhM0B89p.js');
var renderIcon = require('./renderIcon-BRrpZu9a.js');
var primitives_Label = require('./primitives/Label.js');
var primitives_Tooltip = require('./primitives/Tooltip.js');
var createLucideIcon = require('./createLucideIcon-D0tRgV6l.js');
var Popover = require('./Popover-Br9hkU5i.js');
var Button = require('./Button-BlNtYr1w.js');

/**
 * @license lucide-react v0.577.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */


const __iconNode = [
  ["circle", { cx: "12", cy: "12", r: "10", key: "1mglay" }],
  ["path", { d: "M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3", key: "1u773s" }],
  ["path", { d: "M12 17h.01", key: "p32p05" }]
];
const CircleQuestionMark = createLucideIcon.createLucideIcon("circle-question-mark", __iconNode);

const SIDE_MAP = {
  top: "top",
  bottom: "bottom",
  left: "left",
  right: "right",
  auto: "top"
};

const Label = React.forwardRef(
  ({ required, helpIconProps, className, children, ...otherProps }, ref) => {
    const helpIcon = helpIconProps?.icon ?? CircleQuestionMark;
    const iconElement = /* @__PURE__ */ jsxRuntime.jsx(
      "span",
      {
        className: utils.cn(
          "inline-flex cursor-help text-muted-foreground transition-colors hover:text-foreground",
          helpIconProps?.onClick && "cursor-pointer",
          helpIconProps?.className
        ),
        onClick: helpIconProps?.onClick,
        children: renderIcon.renderIcon(helpIcon, "size-3.5")
      }
    );
    const renderHelpIcon = () => {
      if (!helpIconProps) return null;
      if (helpIconProps.popoverProps) {
        const { title, description, helpLinkProps } = helpIconProps.popoverProps;
        return /* @__PURE__ */ jsxRuntime.jsxs(Popover.Popover, { trigger: iconElement, children: [
          title && /* @__PURE__ */ jsxRuntime.jsx(Popover.Popover.Title, { children: title }),
          description && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-muted-foreground", children: description }),
          helpLinkProps && /* @__PURE__ */ jsxRuntime.jsx(
            Button.Button,
            {
              variant: "link",
              size: "sm",
              className: "mt-1 h-auto self-start p-0",
              ...helpLinkProps,
              href: helpLinkProps.href
            }
          )
        ] });
      }
      if (helpIconProps.tooltipProps?.content) {
        const side = SIDE_MAP[helpIconProps.tooltipProps.position ?? "auto"] ?? "top";
        return /* @__PURE__ */ jsxRuntime.jsx(primitives_Tooltip.TooltipProvider, { children: /* @__PURE__ */ jsxRuntime.jsxs(primitives_Tooltip.Tooltip, { children: [
          /* @__PURE__ */ jsxRuntime.jsx(primitives_Tooltip.TooltipTrigger, { asChild: true, children: iconElement }),
          /* @__PURE__ */ jsxRuntime.jsx(primitives_Tooltip.TooltipContent, { side, children: helpIconProps.tooltipProps.content })
        ] }) });
      }
      return iconElement;
    };
    return /* @__PURE__ */ jsxRuntime.jsxs(primitives_Label.Label, { ref, className: utils.cn(className), ...otherProps, children: [
      children,
      required && /* @__PURE__ */ jsxRuntime.jsx("span", { "aria-hidden": "true", className: "text-destructive", children: "*" }),
      renderHelpIcon()
    ] });
  }
);
Label.displayName = "Label";

exports.Label = Label;
//# sourceMappingURL=Label-DFkiC2Jk.js.map
