import { B as b } from "./Button-lr02bh_m.js";
import { I } from "./CopyButton-DWVcqdPe.js";
import { C as jo } from "./CopyButton-DWVcqdPe.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: r = "Are you sure?",
  children: c,
  ...e
}) {
  const [s, i] = k(!1), a = B(null);
  return /* @__PURE__ */ f(z, { children: [
    /* @__PURE__ */ o(g, { component: "span", ref: a, sx: { display: "inline-flex" }, children: /* @__PURE__ */ o(b, { ...e, onClick: () => i(!0), children: c }) }),
    /* @__PURE__ */ f(
      G,
      {
        open: s,
        anchorEl: a.current,
        onClose: () => i(!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: r
            }
          ),
          /* @__PURE__ */ f(g, { sx: { display: "flex", gap: 1, justifyContent: "flex-end" }, children: [
            /* @__PURE__ */ o(
              b,
              {
                size: "xs",
                emphasis: "ghost",
                color: "neutral",
                onClick: () => i(!1),
                children: "Cancel"
              }
            ),
            /* @__PURE__ */ o(
              b,
              {
                size: "xs",
                emphasis: "solid",
                color: "danger",
                onClick: () => {
                  i(!1), n();
                },
                children: "Confirm"
              }
            )
          ] })
        ]
      }
    )
  ] });
}
P.displayName = "ConfirmButton";
function Q({
  items: n,
  trigger: r,
  size: c = "sm",
  label: e = "Actions"
}) {
  const [s, i] = k(!1), a = B(null), p = () => i(!1);
  return /* @__PURE__ */ f(z, { children: [
    /* @__PURE__ */ o("span", { ref: a, children: r ? /* @__PURE__ */ o("span", { onClick: () => i(!0), style: { cursor: "pointer" }, children: r }) : /* @__PURE__ */ o(
      I,
      {
        size: c,
        color: "neutral",
        onClick: () => i(!0),
        "aria-label": e,
        children: /* @__PURE__ */ o(E, { fontSize: "inherit" })
      }
    ) }),
    /* @__PURE__ */ o(
      R,
      {
        open: s,
        anchorEl: a.current,
        onClose: p,
        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((t) => [
          /* @__PURE__ */ f(
            w,
            {
              disabled: t.disabled,
              onClick: () => {
                p(), t.onClick();
              },
              sx: {
                fontSize: "var(--ov-text-sm)",
                color: t.color === "danger" || t.color === "error" ? "var(--ov-danger-default)" : "var(--ov-fg-default)"
              },
              children: [
                t.icon && /* @__PURE__ */ o(L, { sx: { color: "inherit", minWidth: 28 }, children: t.icon }),
                /* @__PURE__ */ o(N, { children: t.label })
              ]
            },
            t.key
          ),
          t.dividerAfter && /* @__PURE__ */ o(O, {}, `${t.key}-divider`)
        ])
      }
    )
  ] });
}
Q.displayName = "ActionMenu";
function X({
  children: n,
  emphasis: r = "outline",
  size: c = "sm",
  color: e = "neutral",
  fullWidth: s,
  orientation: i = "horizontal",
  disabled: a,
  sx: p
}) {
  const t = D(e), u = K(r), l = C(c);
  return /* @__PURE__ */ o(
    $,
    {
      color: t,
      variant: u,
      size: l,
      fullWidth: s,
      orientation: i,
      disabled: a,
      sx: p,
      children: n
    }
  );
}
X.displayName = "ButtonGroup";
const Y = {
  default: 36,
  dense: 28
};
function Z({
  children: n,
  variant: r = "default",
  dividers: c = !1,
  sx: e
}) {
  const s = Y[r];
  return /* @__PURE__ */ o(
    g,
    {
      sx: {
        display: "flex",
        alignItems: "center",
        height: s,
        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 e == "object" && !Array.isArray(e) ? e : {}
      },
      children: n
    }
  );
}
Z.displayName = "Toolbar";
function oo({ children: n, sx: r }) {
  return /* @__PURE__ */ o(
    g,
    {
      sx: {
        display: "flex",
        alignItems: "center",
        gap: "2px",
        ...typeof r == "object" && !Array.isArray(r) ? r : {}
      },
      children: n
    }
  );
}
oo.displayName = "ToolbarGroup";
function ro({
  selected: n,
  onChange: r,
  icon: c,
  label: e,
  size: s = "sm",
  color: i = "primary",
  disabled: a,
  sx: p
}) {
  const t = C(s), u = S(i), l = /* @__PURE__ */ o(
    v,
    {
      size: t,
      disabled: a,
      onClick: () => r(!n),
      sx: {
        borderRadius: "4px",
        color: n ? u : "var(--ov-fg-muted)",
        bgcolor: n ? "var(--ov-state-hover)" : "transparent",
        "&:hover": {
          bgcolor: "var(--ov-state-hover)"
        },
        ...typeof p == "object" && !Array.isArray(p) ? p : {}
      },
      children: c
    }
  );
  return e ? /* @__PURE__ */ o(y, { title: e, children: l }) : l;
}
ro.displayName = "ToggleButton";
function eo({
  value: n,
  onChange: r,
  options: c,
  exclusive: e = !0,
  size: s = "sm",
  color: i = "primary",
  sx: a
}) {
  const p = C(s), t = S(i);
  return /* @__PURE__ */ o(
    U,
    {
      value: n,
      exclusive: e,
      onChange: (l, d) => {
        d !== null && r(d);
      },
      size: p,
      sx: {
        "& .Mui-selected": {
          color: `${t} !important`,
          bgcolor: "var(--ov-state-hover) !important"
        },
        ...typeof a == "object" && !Array.isArray(a) ? a : {}
      },
      children: c.map((l) => /* @__PURE__ */ f(
        W,
        {
          value: l.key,
          disabled: l.disabled,
          sx: {
            fontSize: "var(--ov-text-sm)",
            textTransform: "none",
            px: 1.5,
            gap: 0.5
          },
          children: [
            l.icon,
            l.label
          ]
        },
        l.key
      ))
    }
  );
}
eo.displayName = "ToggleGroup";
const to = {
  xs: 24,
  sm: 28,
  md: 32,
  lg: 36,
  xl: 40
};
function no({
  value: n,
  onChange: r,
  placeholder: c = "Search...",
  regex: e,
  caseSensitive: s,
  onRegexChange: i,
  onCaseSensitiveChange: a,
  matchCount: p,
  currentMatch: t,
  onNext: u,
  onPrev: l,
  size: d = "sm",
  sx: x
}) {
  const A = to[d], h = d === "xs" ? 12 : 14, T = j((m) => {
    m.key === "Enter" && (m.shiftKey ? l?.() : u?.()), m.key === "Escape" && m.target.blur();
  }, [u, l]);
  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) => r(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 }
            }
          }
        ),
        a && /* @__PURE__ */ o(y, { title: "Match Case", children: /* @__PURE__ */ o(
          v,
          {
            size: "small",
            onClick: () => a(!s),
            sx: {
              borderRadius: "3px",
              p: "2px",
              color: s ? "var(--ov-accent-fg)" : "var(--ov-fg-faint)",
              bgcolor: s ? "var(--ov-accent-subtle)" : "transparent"
            },
            children: /* @__PURE__ */ o(_, { size: h })
          }
        ) }),
        i && /* @__PURE__ */ o(y, { title: "Use Regular Expression", children: /* @__PURE__ */ o(
          v,
          {
            size: "small",
            onClick: () => i(!e),
            sx: {
              borderRadius: "3px",
              p: "2px",
              color: e ? "var(--ov-accent-fg)" : "var(--ov-fg-faint)",
              bgcolor: e ? "var(--ov-accent-subtle)" : "transparent"
            },
            children: /* @__PURE__ */ o(q, { size: h })
          }
        ) }),
        p !== void 0 && /* @__PURE__ */ o(
          M,
          {
            sx: {
              fontSize: "var(--ov-text-xs)",
              color: "var(--ov-fg-muted)",
              whiteSpace: "nowrap",
              px: 0.5
            },
            children: p === 0 ? "No results" : `${(t ?? 0) + 1}/${p}`
          }
        ),
        l && /* @__PURE__ */ o(v, { size: "small", onClick: l, sx: { p: "2px" }, children: /* @__PURE__ */ o(H, { size: h }) }),
        u && /* @__PURE__ */ o(v, { size: "small", onClick: u, 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
};
