import { B as b } from "./Button-lr02bh_m.js";
import { I } from "./CopyButton-DPBgL0K8.js";
import { C as jo } from "./CopyButton-DPBgL0K8.js";
import { jsxs as f, Fragment as z, jsx as o } from "react/jsx-runtime";
import { useState as k, useRef as B, useCallback as j } from "react";
import G from "@mui/material/Popover";
import g from "@mui/material/Box";
import M from "@mui/material/Typography";
import R from "@mui/material/Menu";
import w from "@mui/material/MenuItem";
import L from "@mui/material/ListItemIcon";
import N from "@mui/material/ListItemText";
import O from "@mui/material/Divider";
import E from "@mui/icons-material/MoreVert";
import $ from "@mui/material/ButtonGroup";
import { toMuiColor as D, toMuiVariant as K, toMuiSize as C, toCssColor as S } from "./types.js";
import v from "@mui/material/IconButton";
import y from "@mui/material/Tooltip";
import W from "@mui/material/ToggleButton";
import U from "@mui/material/ToggleButtonGroup";
import V from "@mui/material/InputBase";
import F from "@mui/icons-material/Search";
import { LuCaseSensitive as _, LuRegex as q, LuChevronUp as H, LuChevronDown as J } from "react-icons/lu";
function P({
  onConfirm: n,
  confirmMessage: e = "Are you sure?",
  children: c,
  ...t
}) {
  const [i, a] = k(!1), l = B(null);
  return /* @__PURE__ */ f(z, { children: [
    /* @__PURE__ */ o(g, { component: "span", ref: l, sx: { display: "inline-flex" }, children: /* @__PURE__ */ o(b, { ...t, onClick: () => a(!0), children: c }) }),
    /* @__PURE__ */ f(
      G,
      {
        open: i,
        anchorEl: l.current,
        onClose: () => a(!1),
        anchorOrigin: { vertical: "bottom", horizontal: "center" },
        transformOrigin: { vertical: "top", horizontal: "center" },
        slotProps: {
          paper: {
            sx: {
              p: 2,
              mt: 0.5,
              minWidth: 200,
              bgcolor: "var(--ov-bg-surface)",
              border: "1px solid var(--ov-border-default)"
            }
          }
        },
        children: [
          /* @__PURE__ */ o(
            M,
            {
              variant: "body2",
              sx: { color: "var(--ov-fg-default)", mb: 1.5 },
              children: e
            }
          ),
          /* @__PURE__ */ f(g, { sx: { display: "flex", gap: 1, justifyContent: "flex-end" }, children: [
            /* @__PURE__ */ o(
              b,
              {
                size: "xs",
                emphasis: "ghost",
                color: "neutral",
                onClick: () => a(!1),
                children: "Cancel"
              }
            ),
            /* @__PURE__ */ o(
              b,
              {
                size: "xs",
                emphasis: "solid",
                color: "danger",
                onClick: () => {
                  a(!1), n();
                },
                children: "Confirm"
              }
            )
          ] })
        ]
      }
    )
  ] });
}
P.displayName = "ConfirmButton";
function Q({
  items: n,
  trigger: e,
  size: c = "sm"
}) {
  const [t, i] = k(!1), a = B(null), l = () => i(!1);
  return /* @__PURE__ */ f(z, { children: [
    /* @__PURE__ */ o("span", { ref: a, children: e ? /* @__PURE__ */ o("span", { onClick: () => i(!0), style: { cursor: "pointer" }, children: e }) : /* @__PURE__ */ o(
      I,
      {
        size: c,
        color: "neutral",
        onClick: () => i(!0),
        "aria-label": "Actions",
        children: /* @__PURE__ */ o(E, { fontSize: "inherit" })
      }
    ) }),
    /* @__PURE__ */ o(
      R,
      {
        open: t,
        anchorEl: a.current,
        onClose: l,
        anchorOrigin: { vertical: "bottom", horizontal: "right" },
        transformOrigin: { vertical: "top", horizontal: "right" },
        slotProps: {
          paper: {
            sx: {
              minWidth: 160,
              bgcolor: "var(--ov-bg-surface)",
              border: "1px solid var(--ov-border-default)"
            }
          }
        },
        children: n.map((r) => [
          /* @__PURE__ */ f(
            w,
            {
              disabled: r.disabled,
              onClick: () => {
                l(), r.onClick();
              },
              sx: {
                fontSize: "var(--ov-text-sm)",
                color: r.color === "danger" || r.color === "error" ? "var(--ov-danger-default)" : "var(--ov-fg-default)"
              },
              children: [
                r.icon && /* @__PURE__ */ o(L, { sx: { color: "inherit", minWidth: 28 }, children: r.icon }),
                /* @__PURE__ */ o(N, { children: r.label })
              ]
            },
            r.key
          ),
          r.dividerAfter && /* @__PURE__ */ o(O, {}, `${r.key}-divider`)
        ])
      }
    )
  ] });
}
Q.displayName = "ActionMenu";
function X({
  children: n,
  emphasis: e = "outline",
  size: c = "sm",
  color: t = "neutral",
  fullWidth: i,
  orientation: a = "horizontal",
  disabled: l,
  sx: r
}) {
  const u = D(t), p = K(e), s = C(c);
  return /* @__PURE__ */ o(
    $,
    {
      color: u,
      variant: p,
      size: s,
      fullWidth: i,
      orientation: a,
      disabled: l,
      sx: r,
      children: n
    }
  );
}
X.displayName = "ButtonGroup";
const Y = {
  default: 36,
  dense: 28
};
function Z({
  children: n,
  variant: e = "default",
  dividers: c = !1,
  sx: t
}) {
  const i = Y[e];
  return /* @__PURE__ */ o(
    g,
    {
      sx: {
        display: "flex",
        alignItems: "center",
        height: i,
        gap: c ? 0 : 0.5,
        px: 0.5,
        bgcolor: "var(--ov-bg-surface)",
        ...c && {
          "& > *:not(:last-child)::after": {
            content: '""',
            display: "block",
            width: "1px",
            height: "60%",
            bgcolor: "var(--ov-border-muted)",
            ml: 0.5,
            mr: 0.5,
            flexShrink: 0
          }
        },
        ...typeof t == "object" && !Array.isArray(t) ? t : {}
      },
      children: n
    }
  );
}
Z.displayName = "Toolbar";
function oo({ children: n, sx: e }) {
  return /* @__PURE__ */ o(
    g,
    {
      sx: {
        display: "flex",
        alignItems: "center",
        gap: "2px",
        ...typeof e == "object" && !Array.isArray(e) ? e : {}
      },
      children: n
    }
  );
}
oo.displayName = "ToolbarGroup";
function ro({
  selected: n,
  onChange: e,
  icon: c,
  label: t,
  size: i = "sm",
  color: a = "primary",
  disabled: l,
  sx: r
}) {
  const u = C(i), p = S(a), s = /* @__PURE__ */ o(
    v,
    {
      size: u,
      disabled: l,
      onClick: () => e(!n),
      sx: {
        borderRadius: "4px",
        color: n ? p : "var(--ov-fg-muted)",
        bgcolor: n ? "var(--ov-state-hover)" : "transparent",
        "&:hover": {
          bgcolor: "var(--ov-state-hover)"
        },
        ...typeof r == "object" && !Array.isArray(r) ? r : {}
      },
      children: c
    }
  );
  return t ? /* @__PURE__ */ o(y, { title: t, children: s }) : s;
}
ro.displayName = "ToggleButton";
function eo({
  value: n,
  onChange: e,
  options: c,
  exclusive: t = !0,
  size: i = "sm",
  color: a = "primary",
  sx: l
}) {
  const r = C(i), u = S(a);
  return /* @__PURE__ */ o(
    U,
    {
      value: n,
      exclusive: t,
      onChange: (s, d) => {
        d !== null && e(d);
      },
      size: r,
      sx: {
        "& .Mui-selected": {
          color: `${u} !important`,
          bgcolor: "var(--ov-state-hover) !important"
        },
        ...typeof l == "object" && !Array.isArray(l) ? l : {}
      },
      children: c.map((s) => /* @__PURE__ */ f(
        W,
        {
          value: s.key,
          disabled: s.disabled,
          sx: {
            fontSize: "var(--ov-text-sm)",
            textTransform: "none",
            px: 1.5,
            gap: 0.5
          },
          children: [
            s.icon,
            s.label
          ]
        },
        s.key
      ))
    }
  );
}
eo.displayName = "ToggleGroup";
const to = {
  xs: 24,
  sm: 28,
  md: 32,
  lg: 36,
  xl: 40
};
function no({
  value: n,
  onChange: e,
  placeholder: c = "Search...",
  regex: t,
  caseSensitive: i,
  onRegexChange: a,
  onCaseSensitiveChange: l,
  matchCount: r,
  currentMatch: u,
  onNext: p,
  onPrev: s,
  size: d = "sm",
  sx: x
}) {
  const A = to[d], h = d === "xs" ? 12 : 14, T = j((m) => {
    m.key === "Enter" && (m.shiftKey ? s?.() : p?.()), m.key === "Escape" && m.target.blur();
  }, [p, s]);
  return /* @__PURE__ */ f(
    g,
    {
      sx: {
        display: "flex",
        alignItems: "center",
        height: A,
        border: "1px solid var(--ov-border-default)",
        borderRadius: "4px",
        bgcolor: "var(--ov-bg-surface)",
        px: 0.5,
        gap: "2px",
        "&:focus-within": {
          borderColor: "var(--ov-accent)"
        },
        ...typeof x == "object" && !Array.isArray(x) ? x : {}
      },
      children: [
        /* @__PURE__ */ o(F, { sx: { fontSize: h + 2, color: "var(--ov-fg-muted)", ml: 0.25 } }),
        /* @__PURE__ */ o(
          V,
          {
            value: n,
            onChange: (m) => e(m.target.value),
            onKeyDown: T,
            placeholder: c,
            sx: {
              flex: 1,
              fontSize: d === "xs" ? "var(--ov-text-xs)" : "var(--ov-text-sm)",
              color: "var(--ov-fg-default)",
              "& input": { py: 0, px: 0.5 },
              "& input::placeholder": { color: "var(--ov-fg-faint)", opacity: 1 }
            }
          }
        ),
        l && /* @__PURE__ */ o(y, { title: "Match Case", children: /* @__PURE__ */ o(
          v,
          {
            size: "small",
            onClick: () => l(!i),
            sx: {
              borderRadius: "3px",
              p: "2px",
              color: i ? "var(--ov-accent-fg)" : "var(--ov-fg-faint)",
              bgcolor: i ? "var(--ov-accent-subtle)" : "transparent"
            },
            children: /* @__PURE__ */ o(_, { size: h })
          }
        ) }),
        a && /* @__PURE__ */ o(y, { title: "Use Regular Expression", children: /* @__PURE__ */ o(
          v,
          {
            size: "small",
            onClick: () => a(!t),
            sx: {
              borderRadius: "3px",
              p: "2px",
              color: t ? "var(--ov-accent-fg)" : "var(--ov-fg-faint)",
              bgcolor: t ? "var(--ov-accent-subtle)" : "transparent"
            },
            children: /* @__PURE__ */ o(q, { size: h })
          }
        ) }),
        r !== void 0 && /* @__PURE__ */ o(
          M,
          {
            sx: {
              fontSize: "var(--ov-text-xs)",
              color: "var(--ov-fg-muted)",
              whiteSpace: "nowrap",
              px: 0.5
            },
            children: r === 0 ? "No results" : `${(u ?? 0) + 1}/${r}`
          }
        ),
        s && /* @__PURE__ */ o(v, { size: "small", onClick: s, sx: { p: "2px" }, children: /* @__PURE__ */ o(H, { size: h }) }),
        p && /* @__PURE__ */ o(v, { size: "small", onClick: p, sx: { p: "2px" }, children: /* @__PURE__ */ o(J, { size: h }) })
      ]
    }
  );
}
no.displayName = "SearchBar";
export {
  Q as ActionMenu,
  b as Button,
  X as ButtonGroup,
  P as ConfirmButton,
  jo as CopyButton,
  I as IconButton,
  no as SearchBar,
  ro as ToggleButton,
  eo as ToggleGroup,
  Z as Toolbar,
  oo as ToolbarGroup
};
