import { jsxs as h, jsx as e } from "react/jsx-runtime";
import f, { useMemo as j } from "react";
import { motion as u } from "motion/react";
import n from "../../utils/classNames.js";
import { SortDirection as A } from "../../utils/SortUtils.js";
import { useSortedBars as H } from "./useSortedBars.js";
const O = {
  animate: {
    transition: {
      staggerChildren: 0.1
    }
  }
}, R = {
  initial: { width: 0 },
  animate: (o) => ({
    width: `${o}%`,
    transition: { duration: 0.8, ease: "easeOut" }
  })
}, T = 25, _ = 0.5, g = (o, v) => {
  const {
    data: y = [],
    valueFormatter: N = (a) => a.toString(),
    showAnimation: s = !1,
    onSelectRow: i,
    referenceValue: l,
    sortOrder: b = A.DESCENDING,
    barColor: w = "bg-highlight-light",
    labelColor: x = "text-color-darker",
    background: k = "bg-transparent",
    rowHeight: c = T,
    opacity: C = _,
    className: L = "",
    ...B
  } = o, r = H(y, b, (a) => a.value), [d, m] = f.useState(null), D = j(() => {
    const a = l ?? Math.max(...r.map((t) => t.value), 0);
    return r.map((t) => a === 0 || t.value === 0 ? 0 : Math.max(t.value / a * 100, 2));
  }, [r, l]);
  return /* @__PURE__ */ h(
    "div",
    {
      ...B,
      ref: v,
      className: n("display-flex justify-content-between gap-15", L),
      children: [
        /* @__PURE__ */ e(
          u.div,
          {
            variants: s ? O : void 0,
            initial: "initial",
            animate: "animate",
            className: "width-100pct space-y-5",
            children: r.map((a, t) => {
              const E = D[t], p = a.color ?? x, I = a.barColor ?? w, S = a.background ?? k;
              return /* @__PURE__ */ h(
                "div",
                {
                  onMouseEnter: () => m(t),
                  onMouseLeave: () => m(null),
                  onClick: () => i?.(a),
                  className: n(
                    "position-relative width-100pct rounded-small",
                    "transition-all transition-ease-in-out transition-duration-01",
                    S,
                    i && "cursor-pointer",
                    d === t && "bg-lightest"
                  ),
                  children: [
                    /* @__PURE__ */ e(
                      u.div,
                      {
                        custom: E,
                        variants: s ? R : void 0,
                        className: n(
                          "display-flex align-items-center rounded-small",
                          "transition-all transition-ease-in-out transition-duration-01",
                          I
                        ),
                        style: { height: `${c}px`, opacity: d === t ? 1 : C },
                        role: "presentation"
                      }
                    ),
                    /* @__PURE__ */ e("div", { className: "position-absolute left-0 top-50pct translate-y-50pct display-flex width-100pct padding-left-10", children: a.href ? /* @__PURE__ */ e(
                      "a",
                      {
                        href: a.href,
                        className: p,
                        target: "_blank",
                        rel: "noreferrer",
                        onClick: (M) => M.stopPropagation(),
                        children: a.name
                      }
                    ) : /* @__PURE__ */ e("div", { className: p, children: a.name }) })
                  ]
                },
                a.key ?? a.name
              );
            })
          }
        ),
        /* @__PURE__ */ e("div", { className: "space-y-5", children: r.map((a) => /* @__PURE__ */ e(
          "div",
          {
            className: n("display-flex align-items-center justify-content-end"),
            style: { height: `${c}px` },
            children: /* @__PURE__ */ e("div", { className: "text-color-darkest", children: N(a.value) })
          },
          a.key ?? a.name
        )) })
      ]
    }
  );
};
g.displayName = "BarList";
const W = f.forwardRef(g);
export {
  W as default
};
//# sourceMappingURL=BarList.js.map
