import { jsx as n, jsxs as x } from "react/jsx-runtime";
import g from "react";
import c from "@mui/material/Box";
import C from "@mui/material/Typography";
import { f as m, c as A } from "./units-BuBKbqQ7.js";
import S from "@mui/material/Tooltip";
import N from "@mui/material/Chip";
import { I as p } from "./Icon-CuO9W7cA.js";
import b from "@mui/material/Checkbox";
const h = {
  bytes: (e) => A({ from: e }),
  sum: (e) => {
    let t = 0;
    if (Array.isArray(e))
      for (const r of e)
        t += Number(r);
    return typeof e == "string" && e.split(",").forEach((r) => {
      t += Number(r);
    }), typeof e == "number" && (t += e), t.toString();
  },
  count: (e) => Array.isArray(e) ? e.length.toString() : typeof e == "string" ? e.split(",").length.toString() : typeof e == "number" ? e.toString() : "",
  avg: (e) => {
    let t = 0, r = 0;
    if (Array.isArray(e))
      for (const o of e)
        t += Number(o), r++;
    return (t / r).toString();
  },
  max: (e) => {
    let t = 0;
    if (Array.isArray(e))
      for (const r of e)
        t = Math.max(t, Number(r));
    return t.toString();
  },
  min: (e) => {
    let t = Number.MAX_VALUE;
    if (Array.isArray(e))
      for (const r of e)
        t = Math.min(t, Number(r));
    return typeof e == "string" && e.split(",").forEach((r) => {
      t = Math.min(t, Number(r));
    }), typeof e == "number" && (t = Math.min(t, e)), t.toString();
  }
}, y = (e) => {
  switch (e) {
    case "success":
      return "success";
    case "warning":
      return "warning";
    case "danger":
    case "error":
      return "error";
    case "primary":
      return "primary";
    case "neutral":
      return "inherit";
    default:
      return;
  }
}, I = ({ value: e, ...t }) => {
  const r = g.useMemo(() => {
    const s = new Date(e);
    return !e || isNaN(s.getTime()) ? "0s" : m(s);
  }, [e]), [o, a] = g.useState(r);
  return g.useEffect(() => {
    const s = new Date(e);
    if (isNaN(s.getTime())) return;
    const f = setInterval(() => {
      a(m(s));
    }, 1e3);
    return () => {
      clearInterval(f);
    };
  }, [e, r]), /* @__PURE__ */ n(w, { value: o, ...t });
}, w = ({ align: e, value: t, color: r, colorMap: o, startDecorator: a, endDecorator: s, formatter: l, children: f }) => {
  const u = () => {
    if (o) {
      const d = o[t] ?? o["*"] ?? void 0;
      return y(d);
    }
    return y(r);
  };
  return /* @__PURE__ */ n(
    c,
    {
      display: "flex",
      flex: 1,
      justifyContent: (() => {
        switch (e) {
          case "left":
            return "flex-start";
          case "right":
            return "flex-end";
          case "center":
            return "center";
          default:
            return "flex-start";
        }
      })(),
      alignItems: "center",
      sx: {
        overflowY: "hidden",
        overflowX: "scroll",
        scrollbarWidth: "none",
        "&::-webkit-scrollbar": { display: "none" }
      },
      children: f ?? /* @__PURE__ */ x(c, { display: "flex", alignItems: "center", gap: 0.5, children: [
        a,
        /* @__PURE__ */ n(
          C,
          {
            variant: "caption",
            color: u(),
            noWrap: !0,
            children: l && h[l] ? h[l](t) : `${t}`
          }
        ),
        s
      ] })
    }
  );
}, B = ({ formatter: e, ...t }) => e?.toLowerCase() === "age" ? /* @__PURE__ */ n(I, { ...t }) : /* @__PURE__ */ n(w, { ...t, formatter: e?.toLowerCase() });
B.displayName = "TextCell";
const T = {
  success: "var(--ov-success-default)",
  warning: "var(--ov-warning-default)",
  danger: "var(--ov-danger-default)",
  primary: "var(--ov-accent)",
  neutral: "var(--ov-fg-muted)"
}, j = ({ align: e, values: t, colorMap: r, hoverMenu: o, hoverMenuDelay: a }) => {
  const s = (i) => T[r[i] ?? "neutral"], l = () => {
    switch (e) {
      case "left":
        return "flex-start";
      case "right":
        return "flex-end";
      case "center":
        return "center";
      case "justify":
        return "space-between";
      default:
        return "flex-start";
    }
  }, f = a ?? 200, u = ({ color: i }) => /* @__PURE__ */ n(
    c,
    {
      sx: {
        borderRadius: "2px",
        width: 12,
        height: 12,
        minWidth: 12,
        minHeight: 12,
        bgcolor: i
      }
    }
  );
  return /* @__PURE__ */ n(
    c,
    {
      display: "flex",
      flex: 1,
      justifyContent: l(),
      alignItems: "center",
      gap: 0.25,
      children: t.map((i, d) => o ? /* @__PURE__ */ n(
        S,
        {
          title: o(i),
          enterDelay: f,
          slotProps: {
            tooltip: {
              sx: {
                p: 1,
                border: "1px solid var(--ov-border-default)",
                bgcolor: "var(--ov-bg-surface-overlay)",
                color: "var(--ov-fg-default)"
              }
            }
          },
          children: /* @__PURE__ */ n(u, { color: s(i) })
        },
        `badge-${d}`
      ) : /* @__PURE__ */ n(u, { color: s(i) }, `badge-${d}`))
    }
  );
};
j.displayName = "BadgesCell";
const v = (e) => {
  switch (e) {
    case "success":
      return "success";
    case "warning":
      return "warning";
    case "danger":
      return "error";
    case "primary":
      return "primary";
    case "neutral":
      return "default";
    default:
      return "default";
  }
}, R = (e) => e === "outlined" ? "outlined" : "filled", k = ({ align: e, value: t, color: r, colorMap: o, startDecorator: a, endDecorator: s, variant: l }) => {
  const f = () => o ? o[t] || "neutral" : r ?? "neutral", u = () => {
    switch (e) {
      case "left":
        return "flex-start";
      case "right":
        return "flex-end";
      case "center":
        return "center";
      default:
        return "flex-start";
    }
  }, i = typeof a == "string" ? /* @__PURE__ */ n(p, { name: a, size: 16 }) : a, d = typeof s == "string" ? /* @__PURE__ */ n(p, { name: s, size: 16 }) : s;
  return /* @__PURE__ */ n(
    c,
    {
      display: "flex",
      flex: 1,
      justifyContent: u(),
      alignItems: "center",
      children: /* @__PURE__ */ n(
        N,
        {
          size: "small",
          color: v(f()),
          variant: R(l),
          sx: { borderRadius: "4px" },
          icon: i,
          label: d ? /* @__PURE__ */ x(c, { display: "flex", alignItems: "center", gap: 0.5, children: [
            t,
            d
          ] }) : t
        }
      )
    }
  );
};
k.displayName = "ChipCell";
const z = ({ table: e }) => /* @__PURE__ */ n(c, { sx: {
  display: "flex",
  justifyContent: "center",
  alignItems: "center",
  height: "100%",
  maxWidth: 24
}, children: /* @__PURE__ */ n(
  b,
  {
    size: "small",
    checked: e.getIsAllPageRowsSelected(),
    onChange: (t) => {
      e.toggleAllPageRowsSelected(t.target.checked);
    },
    "aria-label": "Select all rows"
  }
) });
z.displayName = "SelectBoxHeader";
const E = ({ row: e }) => /* @__PURE__ */ n(c, { sx: {
  display: "flex",
  justifyContent: "center",
  alignItems: "center",
  height: "100%",
  maxWidth: 24
}, children: /* @__PURE__ */ n(
  b,
  {
    size: "small",
    checked: e.getIsSelected(),
    onChange: (t) => {
      e.toggleSelected(t.target.checked);
    },
    "aria-label": "Select row"
  }
) });
E.displayName = "SelectBoxRow";
export {
  j as BadgesCell,
  k as ChipCell,
  z as SelectBoxHeader,
  E as SelectBoxRow,
  B as TextCell
};
