import { __name } from './chunk-N2XQF2OL.mjs';
import { useState, useCallback, useEffect } from 'react';
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
import { CopyButton, Button } from '@djangocfg/ui-core/components';
import { Download, ChevronUp, ChevronDown, Minimize2, Maximize2 } from 'lucide-react';

var UNLOCKED_CLASS = "scroll-unlocked";
function useScrollIsolation(ref, enabled) {
  const [locked, setLocked] = useState(true);
  const unlock = useCallback(() => setLocked(false), []);
  useEffect(() => {
    if (!enabled) return;
    const handleDocClick = /* @__PURE__ */ __name((e) => {
      const el = ref.current;
      if (!el) return;
      if (!el.contains(e.target)) {
        setLocked(true);
      }
    }, "handleDocClick");
    document.addEventListener("click", handleDocClick, true);
    return () => document.removeEventListener("click", handleDocClick, true);
  }, [enabled, ref]);
  useEffect(() => {
    const el = ref.current;
    if (!el || !enabled) return;
    if (locked) {
      el.classList.remove(UNLOCKED_CLASS);
    } else {
      el.classList.add(UNLOCKED_CLASS);
    }
    return () => el.classList.remove(UNLOCKED_CLASS);
  }, [locked, enabled, ref]);
  useEffect(() => {
    if (enabled) setLocked(true);
  }, [enabled]);
  return { locked, unlock };
}
__name(useScrollIsolation, "useScrollIsolation");
var FloatingToolbar = /* @__PURE__ */ __name(({
  containerRef,
  children,
  label,
  position = "bottom-right",
  offset = 8,
  zIndex = 30,
  scrollIsolation = true
}) => {
  const { locked, unlock } = useScrollIsolation(containerRef, scrollIsolation);
  const [overlayHovered, setOverlayHovered] = useState(false);
  const overlay = scrollIsolation && locked ? /* @__PURE__ */ jsx(
    "div",
    {
      onClick: unlock,
      onMouseEnter: () => setOverlayHovered(true),
      onMouseLeave: () => setOverlayHovered(false),
      style: {
        position: "absolute",
        inset: 0,
        zIndex: zIndex - 1,
        cursor: "pointer",
        background: overlayHovered ? "rgba(0,0,0,0.04)" : "transparent",
        display: "flex",
        alignItems: "center",
        justifyContent: "center",
        transition: "background 150ms"
      },
      children: overlayHovered && /* @__PURE__ */ jsx(
        "span",
        {
          style: {
            fontSize: "0.75rem",
            padding: "0.25rem 0.625rem",
            borderRadius: "9999px",
            background: "rgba(0,0,0,0.55)",
            color: "#fff",
            pointerEvents: "none",
            userSelect: "none"
          },
          children: "Click to scroll"
        }
      )
    }
  ) : null;
  const positionStyle = position === "bottom-right" ? { bottom: offset, right: offset } : { top: offset, right: offset };
  const toolbar = /* @__PURE__ */ jsxs(
    "div",
    {
      className: "flex items-center gap-1",
      style: {
        position: "absolute",
        ...positionStyle,
        zIndex
      },
      children: [
        label && /* @__PURE__ */ jsxs(Fragment, { children: [
          label,
          /* @__PURE__ */ jsx("div", { className: "w-px h-4 bg-border/50 mx-0.5" })
        ] }),
        children
      ]
    }
  );
  return /* @__PURE__ */ jsxs(Fragment, { children: [
    overlay,
    toolbar
  ] });
}, "FloatingToolbar");
var BUTTON_CLASS = "h-6 w-6 rounded-sm bg-muted/80 hover:bg-muted border border-border/50 backdrop-blur-sm";
var CopyAction = /* @__PURE__ */ __name(({ value, title = "Copy" }) => /* @__PURE__ */ jsx(
  CopyButton,
  {
    value,
    variant: "ghost",
    size: "icon",
    className: BUTTON_CLASS,
    iconClassName: "h-3 w-3",
    title
  }
), "CopyAction");
var BUTTON_CLASS2 = "h-6 w-6 rounded-sm bg-muted/80 hover:bg-muted border border-border/50 backdrop-blur-sm";
var DownloadAction = /* @__PURE__ */ __name(({
  value,
  filename = "download.txt",
  mimeType = "text/plain",
  title = "Download"
}) => {
  const handleDownload = /* @__PURE__ */ __name(() => {
    const blob = new Blob([value], { type: mimeType });
    const url = URL.createObjectURL(blob);
    const a = document.createElement("a");
    a.href = url;
    a.download = filename;
    document.body.appendChild(a);
    a.click();
    document.body.removeChild(a);
    URL.revokeObjectURL(url);
  }, "handleDownload");
  return /* @__PURE__ */ jsx(
    Button,
    {
      variant: "ghost",
      size: "icon",
      onClick: handleDownload,
      className: BUTTON_CLASS2,
      title,
      children: /* @__PURE__ */ jsx(Download, { className: "h-3 w-3" })
    }
  );
}, "DownloadAction");
var BUTTON_CLASS3 = "h-6 w-6 rounded-sm bg-muted/80 hover:bg-muted border border-border/50 backdrop-blur-sm";
var ExpandAction = /* @__PURE__ */ __name(({ isExpanded, onToggle }) => /* @__PURE__ */ jsx(
  Button,
  {
    variant: "ghost",
    size: "icon",
    onClick: onToggle,
    className: BUTTON_CLASS3,
    title: isExpanded ? "Collapse All" : "Expand All",
    children: isExpanded ? /* @__PURE__ */ jsx(ChevronUp, { className: "h-3 w-3" }) : /* @__PURE__ */ jsx(ChevronDown, { className: "h-3 w-3" })
  }
), "ExpandAction");
var BUTTON_CLASS4 = "h-6 w-6 rounded-sm bg-muted/80 hover:bg-muted border border-border/50 backdrop-blur-sm";
var FullscreenAction = /* @__PURE__ */ __name(({
  isFullscreen = false,
  onToggle,
  title
}) => /* @__PURE__ */ jsx(
  Button,
  {
    variant: "ghost",
    size: "icon",
    onClick: onToggle,
    className: BUTTON_CLASS4,
    title: title ?? (isFullscreen ? "Exit fullscreen" : "Fullscreen"),
    children: isFullscreen ? /* @__PURE__ */ jsx(Minimize2, { className: "h-3 w-3" }) : /* @__PURE__ */ jsx(Maximize2, { className: "h-3 w-3" })
  }
), "FullscreenAction");

export { CopyAction, DownloadAction, ExpandAction, FloatingToolbar, FullscreenAction };
//# sourceMappingURL=chunk-KNEQRUBA.mjs.map
//# sourceMappingURL=chunk-KNEQRUBA.mjs.map