'use strict';

var chunkWGEGR3DF_cjs = require('./chunk-WGEGR3DF.cjs');
var react = require('react');
var jsxRuntime = require('react/jsx-runtime');
var components = require('@djangocfg/ui-core/components');
var lucideReact = require('lucide-react');

var UNLOCKED_CLASS = "scroll-unlocked";
function useScrollIsolation(ref, enabled) {
  const [locked, setLocked] = react.useState(true);
  const unlock = react.useCallback(() => setLocked(false), []);
  react.useEffect(() => {
    if (!enabled) return;
    const handleDocClick = /* @__PURE__ */ chunkWGEGR3DF_cjs.__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]);
  react.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]);
  react.useEffect(() => {
    if (enabled) setLocked(true);
  }, [enabled]);
  return { locked, unlock };
}
chunkWGEGR3DF_cjs.__name(useScrollIsolation, "useScrollIsolation");
var FloatingToolbar = /* @__PURE__ */ chunkWGEGR3DF_cjs.__name(({
  containerRef,
  children,
  label,
  position = "bottom-right",
  offset = 8,
  zIndex = 30,
  scrollIsolation = true
}) => {
  const { locked, unlock } = useScrollIsolation(containerRef, scrollIsolation);
  const [overlayHovered, setOverlayHovered] = react.useState(false);
  const overlay = scrollIsolation && locked ? /* @__PURE__ */ jsxRuntime.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__ */ jsxRuntime.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__ */ jsxRuntime.jsxs(
    "div",
    {
      className: "flex items-center gap-1",
      style: {
        position: "absolute",
        ...positionStyle,
        zIndex
      },
      children: [
        label && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
          label,
          /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-px h-4 bg-border/50 mx-0.5" })
        ] }),
        children
      ]
    }
  );
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.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__ */ chunkWGEGR3DF_cjs.__name(({ value, title = "Copy" }) => /* @__PURE__ */ jsxRuntime.jsx(
  components.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__ */ chunkWGEGR3DF_cjs.__name(({
  value,
  filename = "download.txt",
  mimeType = "text/plain",
  title = "Download"
}) => {
  const handleDownload = /* @__PURE__ */ chunkWGEGR3DF_cjs.__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__ */ jsxRuntime.jsx(
    components.Button,
    {
      variant: "ghost",
      size: "icon",
      onClick: handleDownload,
      className: BUTTON_CLASS2,
      title,
      children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.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__ */ chunkWGEGR3DF_cjs.__name(({ isExpanded, onToggle }) => /* @__PURE__ */ jsxRuntime.jsx(
  components.Button,
  {
    variant: "ghost",
    size: "icon",
    onClick: onToggle,
    className: BUTTON_CLASS3,
    title: isExpanded ? "Collapse All" : "Expand All",
    children: isExpanded ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronUp, { className: "h-3 w-3" }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.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__ */ chunkWGEGR3DF_cjs.__name(({
  isFullscreen = false,
  onToggle,
  title
}) => /* @__PURE__ */ jsxRuntime.jsx(
  components.Button,
  {
    variant: "ghost",
    size: "icon",
    onClick: onToggle,
    className: BUTTON_CLASS4,
    title: title ?? (isFullscreen ? "Exit fullscreen" : "Fullscreen"),
    children: isFullscreen ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Minimize2, { className: "h-3 w-3" }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Maximize2, { className: "h-3 w-3" })
  }
), "FullscreenAction");

exports.CopyAction = CopyAction;
exports.DownloadAction = DownloadAction;
exports.ExpandAction = ExpandAction;
exports.FloatingToolbar = FloatingToolbar;
exports.FullscreenAction = FullscreenAction;
//# sourceMappingURL=chunk-2SMCH62O.cjs.map
//# sourceMappingURL=chunk-2SMCH62O.cjs.map