import { jsx, jsxs } from "react/jsx-runtime";
import * as React from "react";
import * as ProgressPrimitive from "@radix-ui/react-progress";
import { XCircle, CircleCheck } from "lucide-react";
import { cn } from "../../lib/utils.js";
const DEFAULT_TRACK_H = 4;
const STATUS_FILL = {
  inProgress: "bg-info",
  success: "bg-success",
  error: "bg-error"
};
const STATUS_ICON = {
  success: { Icon: CircleCheck, className: "text-success" },
  error: { Icon: XCircle, className: "text-error" }
};
const ProgressBar = React.forwardRef(
  ({
    value,
    status = "inProgress",
    affix,
    height,
    className,
    ...props
  }, ref) => {
    const clampedValue = Math.max(0, Math.min(100, value));
    const fillColor = STATUS_FILL[status];
    const trackH = height ?? DEFAULT_TRACK_H;
    let affixNode = null;
    if (affix === "value") {
      affixNode = /* @__PURE__ */ jsxs("span", { className: "text-caption text-foreground tabular-nums shrink-0", children: [
        Math.round(clampedValue),
        "%"
      ] });
    } else if (affix === "status-icon") {
      const s = status !== "inProgress" ? STATUS_ICON[status] : null;
      if (s) affixNode = /* @__PURE__ */ jsx(s.Icon, { size: 16, className: cn("shrink-0", s.className), "aria-hidden": true });
    } else if (React.isValidElement(affix) || typeof affix === "string" || typeof affix === "number") {
      affixNode = affix;
    }
    const bar = /* @__PURE__ */ jsx(
      ProgressPrimitive.Root,
      {
        ref,
        value: clampedValue,
        max: 100,
        className: cn(
          "relative overflow-hidden rounded-full bg-secondary w-full",
          className
        ),
        style: { height: trackH },
        ...props,
        children: /* @__PURE__ */ jsx(
          ProgressPrimitive.Indicator,
          {
            className: cn("h-full rounded-full transition-all duration-300", fillColor),
            style: { width: `${clampedValue}%` }
          }
        )
      }
    );
    if (!affixNode) return bar;
    return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 w-full", children: [
      /* @__PURE__ */ jsx("div", { className: "flex-1 min-w-0", children: bar }),
      affixNode
    ] });
  }
);
ProgressBar.displayName = "ProgressBar";
const progressBarMeta = {
  component: "ProgressBar",
  family: null,
  // non-family composite / overlay / layout
  variants: {},
  sizes: {},
  states: ["default"],
  tokens: {
    bg: ["bg-error", "bg-info", "bg-secondary", "bg-success"],
    fg: ["text-foreground"],
    ring: []
  }
};
export {
  ProgressBar,
  progressBarMeta
};
//# sourceMappingURL=progress-bar.js.map
