"use client";
import { jsxs as u, jsx as l, Fragment as k } from "react/jsx-runtime";
import { Root as y, Track as F, Range as M, Thumb as b } from "../../node_modules/@radix-ui/react-slider/dist/index.js";
import { cva as w } from "../../node_modules/class-variance-authority/dist/index.js";
import * as P from "react";
import { cn as c } from "../../lib/utils.js";
import { Badge as x } from "./badge.js";
const S = w(
  "relative w-full grow overflow-hidden rounded-full bg-d-primary/20",
  {
    variants: {
      size: {
        base: "h-1.5",
        medium: "h-2",
        large: "h-2.5"
      }
    },
    defaultVariants: {
      size: "base"
    }
  }
), N = w(
  c(
    "block rounded-full bg-d-background shadow transition-all duration-200 disabled:pointer-events-none disabled:opacity-50",
    // Use standard focus ring but adapted for circular slider thumb
    "focus-visible:outline-none focus-visible:ring-d-primary focus-visible:ring-[3px]",
    "border border-d-primary/50 hover:border-d-primary"
    // Added subtle border interaction
  ),
  {
    variants: {
      size: {
        base: "h-4 w-4",
        medium: "h-5 w-5",
        large: "h-6 w-6"
      }
    },
    defaultVariants: {
      size: "base"
    }
  }
), B = P.forwardRef(
  ({
    className: C,
    size: m,
    formatValue: t,
    showValues: $ = !1,
    showStickyLabel: s = !1,
    stickyLabelSuffix: h = "",
    fillOffset: o = !1,
    offsetValue: v,
    steps: d,
    showStepMarkers: z = !1,
    ...e
  }, R) => {
    const r = v !== void 0 ? v : e.min !== void 0 && e.max !== void 0 ? (e.min + e.max) / 2 : 50, f = () => {
      if (!o) return 0;
      const a = e.min || 0, i = (e.max || 100) - a;
      return (r - a) / i * 100;
    }, g = (a) => d ? d.reduce((n, i) => Math.abs(i - a) < Math.abs(n - a) ? i : n) : a, T = (a) => {
      if (!d || !e.onValueChange) {
        e.onValueChange && e.onValueChange(a);
        return;
      }
      const n = g(a[0]), i = a.length > 1 ? [n, g(a[1])] : [n];
      e.onValueChange(i);
    }, j = (a) => {
      const n = e.min || 0, i = e.max || 100;
      return (a - n) / (i - n) * 100;
    };
    return /* @__PURE__ */ u("div", { className: "flex w-full flex-col gap-1", children: [
      /* @__PURE__ */ u(
        y,
        {
          ref: R,
          className: c(
            "relative flex w-full touch-none items-center select-none",
            C
          ),
          ...e,
          onValueChange: void 0,
          onValueChange: d ? T : e.onValueChange,
          children: [
            /* @__PURE__ */ u(F, { className: c(S({ size: m })), children: [
              d && z && /* @__PURE__ */ l("div", { className: "absolute h-full w-full", children: d.map((a, n) => /* @__PURE__ */ l(
                "div",
                {
                  className: "bg-d-muted-foreground/50 absolute -mt-1.5 h-4 w-1 rounded-full",
                  style: {
                    left: `calc(${j(a)}% - 2px)`,
                    top: "50%",
                    transform: "translateY(-50%)"
                  }
                },
                n
              )) }),
              o && e.value ? /* @__PURE__ */ u(k, { children: [
                /* @__PURE__ */ l("div", { className: "bg-d-muted/30 absolute h-full w-full" }),
                /* @__PURE__ */ l(
                  "div",
                  {
                    className: "bg-d-primary absolute h-full",
                    style: {
                      left: e.value[0] < r ? `${(e.value[0] - (e.min || 0)) / ((e.max || 100) - (e.min || 0)) * 100}%` : `${f()}%`,
                      right: e.value[0] > r ? `${100 - (e.value[0] - (e.min || 0)) / ((e.max || 100) - (e.min || 0)) * 100}%` : `${100 - f()}%`
                    }
                  }
                )
              ] }) : /* @__PURE__ */ l(M, { className: "bg-d-primary absolute h-full" })
            ] }),
            /* @__PURE__ */ l(
              b,
              {
                className: c(N({ size: m }), "relative"),
                children: s && e.value && /* @__PURE__ */ l(
                  x,
                  {
                    variant: "default",
                    className: "absolute -top-5 left-1/2 z-10 -translate-x-1/2 -translate-y-1/2",
                    children: t ? t(e.value[0]) : `${e.value[0]}${h}`
                  }
                )
              }
            ),
            e.value && e.value.length > 1 && /* @__PURE__ */ l(
              b,
              {
                className: c(N({ size: m }), "relative"),
                children: s && /* @__PURE__ */ l(
                  x,
                  {
                    variant: "default",
                    className: "absolute -top-5 left-1/2 z-10 -translate-x-1/2 -translate-y-1/2",
                    children: t ? t(e.value[1]) : `${e.value[1]}${h}`
                  }
                )
              }
            )
          ]
        }
      ),
      $ && e.value && /* @__PURE__ */ u("div", { className: "text-d-muted-foreground flex justify-between text-xs font-medium", children: [
        /* @__PURE__ */ l("span", { children: t ? t(e.value[0]) : e.value[0] }),
        e.value.length > 1 ? /* @__PURE__ */ l("span", { children: t ? t(e.value[1]) : e.value[1] }) : e.max !== void 0 ? /* @__PURE__ */ l("span", { children: t ? t(e.max) : e.max }) : null
      ] })
    ] });
  }
);
B.displayName = y.displayName;
export {
  B as Slider
};
