'use strict';

var chunkADEN3UA4_cjs = require('./chunk-ADEN3UA4.cjs');
var chunkOLISEQHS_cjs = require('./chunk-OLISEQHS.cjs');
var lucideReact = require('lucide-react');
var hooks = require('@djangocfg/ui-core/hooks');
var lib = require('@djangocfg/ui-core/lib');
var jsxRuntime = require('react/jsx-runtime');
var React = require('react');
var components = require('@djangocfg/ui-core/components');
var i18n = require('@djangocfg/i18n');

function _interopNamespace(e) {
  if (e && e.__esModule) return e;
  var n = Object.create(null);
  if (e) {
    Object.keys(e).forEach(function (k) {
      if (k !== 'default') {
        var d = Object.getOwnPropertyDescriptor(e, k);
        Object.defineProperty(n, k, d.get ? d : {
          enumerable: true,
          get: function () { return e[k]; }
        });
      }
    });
  }
  n.default = e;
  return Object.freeze(n);
}

var React__namespace = /*#__PURE__*/_interopNamespace(React);

var SIZE_PX = { sm: 44, md: 56, lg: 64 };
var ICON_PX = { sm: 18, md: 22, lg: 26 };
function useEffectiveFABSize(size, inline) {
  const isPhone = hooks.useIsPhone();
  const isBelowDesktop = hooks.useIsTabletOrBelow();
  if (size !== "responsive") return size;
  if (inline) return "md";
  if (isPhone) return "sm";
  if (isBelowDesktop) return "md";
  return "lg";
}
chunkOLISEQHS_cjs.__name(useEffectiveFABSize, "useEffectiveFABSize");
function positionStyle(position, offset) {
  const [vert, horiz] = position.split("-");
  return { [vert]: offset, [horiz]: offset };
}
chunkOLISEQHS_cjs.__name(positionStyle, "positionStyle");
function tooltipSideClasses(position) {
  return position.endsWith("right") ? "right-full mr-3 origin-right" : "left-full ml-3 origin-left";
}
chunkOLISEQHS_cjs.__name(tooltipSideClasses, "tooltipSideClasses");
function Badge({ value }) {
  const display = value > 9 ? "9+" : String(value);
  return /* @__PURE__ */ jsxRuntime.jsx(
    "span",
    {
      "aria-hidden": "true",
      className: lib.cn(
        "absolute -right-1 -top-1 inline-flex min-w-[18px] h-[18px] items-center justify-center",
        "rounded-full bg-destructive px-1 text-[10px] font-semibold leading-none text-destructive-foreground",
        "ring-2 ring-background"
      ),
      children: display
    }
  );
}
chunkOLISEQHS_cjs.__name(Badge, "Badge");
function PulseDot() {
  return /* @__PURE__ */ jsxRuntime.jsx("span", { "aria-hidden": "true", className: "absolute right-1 top-1", children: /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "relative inline-flex h-2.5 w-2.5", children: [
    /* @__PURE__ */ jsxRuntime.jsx("span", { className: "absolute inset-0 rounded-full bg-destructive opacity-75 animate-ping" }),
    /* @__PURE__ */ jsxRuntime.jsx("span", { className: "relative inline-flex h-2.5 w-2.5 rounded-full bg-destructive ring-2 ring-background" })
  ] }) });
}
chunkOLISEQHS_cjs.__name(PulseDot, "PulseDot");
function Tooltip({ text, side }) {
  return /* @__PURE__ */ jsxRuntime.jsx(
    "span",
    {
      role: "tooltip",
      className: lib.cn(
        "pointer-events-none absolute top-1/2 -translate-y-1/2 whitespace-nowrap",
        "rounded-md bg-popover px-2.5 py-1 text-xs font-medium text-popover-foreground shadow-md",
        "border border-border opacity-0 scale-95 transition-all duration-150",
        "group-hover:opacity-100 group-hover:scale-100",
        "group-focus-within:opacity-100 group-focus-within:scale-100",
        side
      ),
      children: text
    }
  );
}
chunkOLISEQHS_cjs.__name(Tooltip, "Tooltip");
function ChatFAB({
  onClick,
  ariaLabel = "Open chat",
  icon,
  variant = "simple",
  size = "responsive",
  position = "bottom-right",
  offset = 24,
  zIndex = 9999,
  pulse = false,
  badge,
  tooltip,
  inline = false,
  className,
  style
}) {
  const effectiveSize = useEffectiveFABSize(size, inline);
  const px = SIZE_PX[effectiveSize];
  const iconPx = ICON_PX[effectiveSize];
  const renderedIcon = icon ?? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Bot, { size: iconPx });
  const baseButton = lib.cn(
    "relative grid place-items-center rounded-full focus:outline-none focus-visible:ring-2 focus-visible:ring-ring",
    "transition-transform hover:scale-105"
  );
  return /* @__PURE__ */ jsxRuntime.jsxs(
    "div",
    {
      className: lib.cn("group", inline ? "relative inline-flex" : "fixed"),
      style: inline ? void 0 : { ...positionStyle(position, offset), zIndex },
      children: [
        variant === "animated" && /* @__PURE__ */ jsxRuntime.jsx(
          AnimatedFAB,
          {
            ariaLabel,
            onClick,
            size: px,
            className,
            style,
            children: renderedIcon
          }
        ),
        variant === "glass" && /* @__PURE__ */ jsxRuntime.jsxs(
          "button",
          {
            type: "button",
            "aria-label": ariaLabel,
            onClick,
            className: lib.cn(
              baseButton,
              "border border-border/40 bg-background/60 text-foreground shadow-lg backdrop-blur-xl",
              "hover:bg-background/80",
              className
            ),
            style: { width: px, height: px, ...style },
            children: [
              renderedIcon,
              badge !== void 0 ? /* @__PURE__ */ jsxRuntime.jsx(Badge, { value: badge }) : pulse ? /* @__PURE__ */ jsxRuntime.jsx(PulseDot, {}) : null
            ]
          }
        ),
        variant === "simple" && /* @__PURE__ */ jsxRuntime.jsxs(
          "button",
          {
            type: "button",
            "aria-label": ariaLabel,
            onClick,
            className: lib.cn(
              baseButton,
              "bg-primary text-primary-foreground hover:bg-primary/90 shadow-2xl",
              className
            ),
            style: { width: px, height: px, ...style },
            children: [
              renderedIcon,
              badge !== void 0 ? /* @__PURE__ */ jsxRuntime.jsx(Badge, { value: badge }) : pulse ? /* @__PURE__ */ jsxRuntime.jsx(PulseDot, {}) : null
            ]
          }
        ),
        tooltip && /* @__PURE__ */ jsxRuntime.jsx(Tooltip, { text: tooltip, side: tooltipSideClasses(position) })
      ]
    }
  );
}
chunkOLISEQHS_cjs.__name(ChatFAB, "ChatFAB");
function AnimatedFAB({ ariaLabel, onClick, size, className, style, children }) {
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
    /* @__PURE__ */ jsxRuntime.jsx("style", { children: ANIMATED_CSS }),
    /* @__PURE__ */ jsxRuntime.jsx(
      "div",
      {
        className: lib.cn("cmdop-fab-anim", className),
        style: { width: size, height: size, ...style },
        children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cmdop-fab-anim-glow", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cmdop-fab-anim-wrap", children: [
          /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cmdop-fab-anim-grad cmdop-fab-anim-grad-1" }),
          /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cmdop-fab-anim-grad cmdop-fab-anim-grad-2" }),
          /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cmdop-fab-anim-inner" }),
          /* @__PURE__ */ jsxRuntime.jsx(
            "button",
            {
              type: "button",
              "aria-label": ariaLabel,
              onClick,
              className: "cmdop-fab-anim-btn",
              children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cmdop-fab-anim-icon", children })
            }
          )
        ] }) })
      }
    )
  ] });
}
chunkOLISEQHS_cjs.__name(AnimatedFAB, "AnimatedFAB");
var ANIMATED_CSS = `
.cmdop-fab-anim {
  position: relative;
  pointer-events: auto;
}
.cmdop-fab-anim-glow {
  width: 100%; height: 100%;
  border-radius: 50%;
  overflow: hidden;
  animation:
    cmdop-fab-entrance 0.6s cubic-bezier(0.34, 1.45, 0.64, 1) forwards,
    cmdop-fab-glow-shift 8s ease-in-out 0.6s infinite;
}
.cmdop-fab-anim-wrap {
  position: relative; width: 100%; height: 100%;
  border-radius: 50%; overflow: hidden;
}
.cmdop-fab-anim-grad { position: absolute; inset: 0; border-radius: 50%; }
.cmdop-fab-anim-grad-1 {
  background: conic-gradient(
    from 0deg,
    #fbbf24 0%, rgba(251,191,36,0) 15%,
    rgba(168,85,247,0) 20%, #a855f7 35%, rgba(168,85,247,0) 50%,
    rgba(20,184,166,0) 55%, #14b8a6 70%, rgba(20,184,166,0) 85%,
    rgba(236,72,153,0) 88%, #ec4899 97%, #fbbf24 100%
  );
  animation: cmdop-fab-rotate 7s linear infinite;
  filter: blur(1px); opacity: 0.95;
}
.cmdop-fab-anim-grad-2 {
  inset: 1px;
  background: conic-gradient(
    from 180deg,
    #a855f7 0%, rgba(168,85,247,0) 20%,
    rgba(20,184,166,0) 30%, #14b8a6 50%, rgba(20,184,166,0) 70%,
    rgba(251,191,36,0) 75%, #fbbf24 95%, #a855f7 100%
  );
  animation: cmdop-fab-rotate-rev 9s linear infinite;
  filter: blur(0.75px); opacity: 0.7;
}
.cmdop-fab-anim-inner {
  position: absolute; inset: 3px; border-radius: 50%;
  background: rgba(10, 10, 10, 0.65);
  backdrop-filter: blur(12px) saturate(1.8);
  -webkit-backdrop-filter: blur(12px) saturate(1.8);
  animation: cmdop-fab-inner-glow 5s ease-in-out infinite;
}
.cmdop-fab-anim-btn {
  position: absolute; inset: 2px;
  border-radius: 50%; border: none; background: transparent;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: transform 0.2s;
}
.cmdop-fab-anim-btn:hover { transform: scale(1.06); }
.cmdop-fab-anim-icon {
  color: #fbbf24; display: flex;
  filter: drop-shadow(0 0 6px rgba(251,191,36,0.8));
  animation: cmdop-fab-icon-pulse 2.5s ease-in-out infinite;
}
@keyframes cmdop-fab-rotate { to { transform: rotate(360deg); } }
@keyframes cmdop-fab-rotate-rev { to { transform: rotate(-360deg); } }
@keyframes cmdop-fab-entrance {
  0% { transform: scale(0); }
  50% { transform: scale(1.08); }
  70% { transform: scale(0.98); }
  100% { transform: scale(1); }
}
@keyframes cmdop-fab-glow-shift {
  0%, 100% { box-shadow: 0 0 20px rgba(251,191,36,0.5), 0 0 40px rgba(168,85,247,0.3); }
  33%      { box-shadow: 0 0 20px rgba(168,85,247,0.5), 0 0 40px rgba(20,184,166,0.3); }
  66%      { box-shadow: 0 0 20px rgba(20,184,166,0.5), 0 0 40px rgba(236,72,153,0.3); }
}
@keyframes cmdop-fab-icon-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.85; transform: scale(1.15); }
}
@keyframes cmdop-fab-inner-glow {
  0%, 100% { box-shadow: inset 0 0 20px rgba(251,191,36,0.25), inset 0 0 40px rgba(168,85,247,0.15); }
  50%      { box-shadow: inset 0 0 25px rgba(168,85,247,0.3),  inset 0 0 45px rgba(20,184,166,0.2); }
}
`;
function ChatHeader({
  title,
  icon,
  actions,
  showClose = true,
  onClose,
  closeLabel = "Close",
  closeSlot,
  className
}) {
  return /* @__PURE__ */ jsxRuntime.jsxs(
    "header",
    {
      className: lib.cn(
        "border-border bg-muted/30 flex shrink-0 items-center justify-between border-b px-4 py-2.5",
        className
      ),
      children: [
        /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex min-w-0 items-center gap-2 text-sm font-semibold", children: [
          icon ?? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Bot, { className: "text-primary h-4 w-4 shrink-0" }),
          /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: title })
        ] }),
        /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-0.5", children: [
          actions,
          closeSlot ?? (showClose && onClose && /* @__PURE__ */ jsxRuntime.jsx(
            components.Button,
            {
              variant: "ghost",
              size: "sm",
              onClick: onClose,
              "aria-label": closeLabel,
              className: "-mr-1 h-7 w-7 p-0",
              children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.X, { className: "h-4 w-4" })
            }
          ))
        ] })
      ]
    }
  );
}
chunkOLISEQHS_cjs.__name(ChatHeader, "ChatHeader");
function useChatPresence(open, exitDurationMs = 200) {
  const [phase, setPhase] = React.useState("hidden");
  const timerRef = React.useRef(null);
  React.useEffect(() => {
    if (timerRef.current) clearTimeout(timerRef.current);
    if (open) {
      setPhase("entering");
      timerRef.current = setTimeout(() => setPhase("visible"), 16);
    } else {
      setPhase("leaving");
      timerRef.current = setTimeout(() => setPhase("hidden"), exitDurationMs);
    }
    return () => {
      if (timerRef.current) clearTimeout(timerRef.current);
    };
  }, [open, exitDurationMs]);
  return phase;
}
chunkOLISEQHS_cjs.__name(useChatPresence, "useChatPresence");
function dockPositionStyle(position, horizontal, vertical) {
  const [vert, horiz] = position.split("-");
  return { [vert]: vertical, [horiz]: horizontal };
}
chunkOLISEQHS_cjs.__name(dockPositionStyle, "dockPositionStyle");
function ChatDock({
  open,
  onClose,
  children,
  mode = "popover",
  side = "right",
  title = "Chat",
  icon,
  headerActions,
  hideHeader = false,
  closeLabel,
  width,
  height = 720,
  position = "bottom-right",
  offset,
  exitDurationMs = 200,
  zIndex = 1e4,
  ariaLabel,
  className,
  mobileFullscreen = true,
  disablePortal = false,
  inline = false,
  reserveBodySpace
}) {
  const phase = useChatPresence(open, exitDurationMs);
  const isMobile = hooks.useIsMobile();
  const isBelowDesktop = hooks.useIsTabletOrBelow();
  const effectiveMode = mode === "side" && !isBelowDesktop ? "side" : "popover";
  const fullscreen = mobileFullscreen && isMobile;
  const wantsReserve = !inline && !fullscreen && effectiveMode === "side" && (reserveBodySpace ?? true);
  const resolvedSideWidth = width ?? 420;
  React.useEffect(() => {
    if (!wantsReserve || phase === "hidden") return;
    const body = document.body;
    if (!body) return;
    const cssVar = `${resolvedSideWidth}px`;
    const padKey = side === "right" ? "paddingRight" : "paddingLeft";
    const prevPad = body.style[padKey];
    const prevVar = body.style.getPropertyValue("--chat-dock-reserve");
    body.style[padKey] = cssVar;
    body.style.setProperty("--chat-dock-reserve", cssVar);
    return () => {
      body.style[padKey] = prevPad;
      if (prevVar) body.style.setProperty("--chat-dock-reserve", prevVar);
      else body.style.removeProperty("--chat-dock-reserve");
    };
  }, [wantsReserve, phase, side, resolvedSideWidth]);
  if (phase === "hidden") return null;
  const animating = phase === "entering" || phase === "leaving";
  const horizontal = offset?.horizontal ?? 24;
  const vertical = offset?.vertical ?? 96;
  const resolvedWidth = width ?? (effectiveMode === "side" ? resolvedSideWidth : 480);
  let containerStyle;
  let cornerClass;
  const dynVH = "100dvh";
  if (inline) {
    containerStyle = {
      position: "relative",
      width: resolvedWidth,
      height,
      maxHeight: `calc(${dynVH} - 16px)`,
      pointerEvents: phase === "visible" ? "auto" : "none"
    };
    cornerClass = "rounded-xl border";
  } else if (fullscreen) {
    containerStyle = {
      position: "fixed",
      top: 0,
      [side === "left" ? "left" : "right"]: 0,
      width: "100vw",
      height: dynVH,
      zIndex,
      pointerEvents: phase === "visible" ? "auto" : "none"
    };
    cornerClass = "rounded-none border-0";
  } else if (effectiveMode === "side") {
    containerStyle = {
      position: "fixed",
      top: 0,
      [side]: 0,
      height: dynVH,
      zIndex,
      width: `min(${resolvedWidth}px, 100vw)`,
      pointerEvents: phase === "visible" ? "auto" : "none"
    };
    cornerClass = side === "right" ? "rounded-none border-l" : "rounded-none border-r";
  } else {
    const heightCap = `calc(${dynVH} - ${vertical + 24}px)`;
    containerStyle = {
      position: "fixed",
      ...dockPositionStyle(position, horizontal, vertical),
      zIndex,
      width: `min(${resolvedWidth}px, calc(100vw - 32px))`,
      height: `min(${height}px, ${heightCap})`,
      minHeight: `min(320px, ${heightCap})`,
      pointerEvents: phase === "visible" ? "auto" : "none"
    };
    cornerClass = "rounded-xl border";
  }
  const enterClass = (() => {
    if (fullscreen) return "opacity-0";
    if (effectiveMode === "side") {
      return side === "right" ? "opacity-0 translate-x-4" : "opacity-0 -translate-x-4";
    }
    return "opacity-0 scale-95 translate-y-2";
  })();
  const visibleClass = "opacity-100 scale-100 translate-y-0 translate-x-0";
  return /* @__PURE__ */ jsxRuntime.jsx(components.Portal, { disablePortal: disablePortal || inline, children: /* @__PURE__ */ jsxRuntime.jsxs(
    "div",
    {
      role: "dialog",
      "aria-label": ariaLabel ?? (typeof title === "string" ? title : "Chat"),
      "aria-hidden": phase === "leaving",
      className: lib.cn(
        "bg-popover text-popover-foreground border-border",
        "flex flex-col overflow-hidden shadow-2xl",
        cornerClass,
        "transition-all duration-200 ease-out",
        animating ? enterClass : visibleClass,
        className
      ),
      style: containerStyle,
      children: [
        !hideHeader && /* @__PURE__ */ jsxRuntime.jsx(
          ChatHeader,
          {
            title,
            icon,
            actions: headerActions,
            onClose,
            closeLabel
          }
        ),
        /* @__PURE__ */ jsxRuntime.jsx("div", { className: "min-h-0 min-w-0 flex-1 overflow-hidden", children })
      ]
    }
  ) });
}
chunkOLISEQHS_cjs.__name(ChatDock, "ChatDock");
var ChatHeaderActionButton = React.forwardRef(
  /* @__PURE__ */ chunkOLISEQHS_cjs.__name(function ChatHeaderActionButton2({ icon, ariaLabel, badge, destructive, loading, disabled, className, ...rest }, ref) {
    return /* @__PURE__ */ jsxRuntime.jsxs(
      "button",
      {
        ref,
        type: "button",
        "aria-label": ariaLabel,
        title: ariaLabel,
        disabled: disabled || loading,
        className: lib.cn(
          "relative inline-flex h-7 w-7 items-center justify-center rounded-md",
          "text-muted-foreground transition-colors",
          "hover:bg-accent hover:text-foreground",
          "focus:outline-none focus-visible:ring-2 focus-visible:ring-ring",
          "disabled:opacity-50 disabled:cursor-not-allowed",
          destructive && "hover:bg-destructive/15 hover:text-destructive",
          loading && "animate-pulse",
          className
        ),
        ...rest,
        children: [
          icon,
          badge !== void 0 && /* @__PURE__ */ jsxRuntime.jsx(
            "span",
            {
              "aria-hidden": "true",
              className: "absolute -right-0.5 -top-0.5 inline-flex min-w-[14px] h-[14px] items-center justify-center rounded-full bg-destructive px-1 text-[9px] font-semibold leading-none text-destructive-foreground ring-2 ring-background",
              children: badge > 9 ? "9+" : badge
            }
          )
        ]
      }
    );
  }, "ChatHeaderActionButton")
);
function ChatHeaderModeToggle({
  mode,
  onToggle,
  expandLabel = "Dock to side",
  collapseLabel = "Back to popover",
  forceVisible = false
}) {
  const isBelowDesktop = hooks.useIsTabletOrBelow();
  if (isBelowDesktop && !forceVisible) return null;
  const isSide = mode === "side";
  return /* @__PURE__ */ jsxRuntime.jsx(
    ChatHeaderActionButton,
    {
      icon: isSide ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.PanelRightClose, { className: "h-3.5 w-3.5" }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.PanelRightOpen, { className: "h-3.5 w-3.5" }),
      ariaLabel: isSide ? collapseLabel : expandLabel,
      onClick: onToggle
    }
  );
}
chunkOLISEQHS_cjs.__name(ChatHeaderModeToggle, "ChatHeaderModeToggle");
function ChatHeaderAudioToggle({
  muted,
  onToggle,
  unmuteLabel = "Unmute notifications",
  muteLabel = "Mute notifications"
}) {
  return /* @__PURE__ */ jsxRuntime.jsx(
    ChatHeaderActionButton,
    {
      icon: muted ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.VolumeX, { className: "h-3.5 w-3.5" }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Volume2, { className: "h-3.5 w-3.5" }),
      ariaLabel: muted ? unmuteLabel : muteLabel,
      onClick: onToggle
    }
  );
}
chunkOLISEQHS_cjs.__name(ChatHeaderAudioToggle, "ChatHeaderAudioToggle");
function useChatReset(opts) {
  const { onReset, onSuccess, onError } = opts;
  const [isResetting, setIsResetting] = React.useState(false);
  const reset = React.useCallback(async () => {
    if (isResetting) return false;
    setIsResetting(true);
    try {
      const ok = await onReset();
      if (ok) onSuccess?.();
      else onError?.();
      return ok;
    } catch (err) {
      onError?.(err);
      return false;
    } finally {
      setIsResetting(false);
    }
  }, [isResetting, onReset, onSuccess, onError]);
  return { reset, isResetting };
}
chunkOLISEQHS_cjs.__name(useChatReset, "useChatReset");
var DEFAULT_TITLE = "Clear conversation?";
var DEFAULT_MESSAGE = "The assistant will forget this session and start a new one. This cannot be undone.";
var DEFAULT_LABEL = "Clear conversation";
function ChatHeaderResetButton({
  onReset,
  onSuccess,
  onError,
  confirm = true,
  confirmTitle = DEFAULT_TITLE,
  confirmMessage = DEFAULT_MESSAGE,
  ariaLabel = DEFAULT_LABEL
}) {
  const { reset, isResetting } = useChatReset({ onReset, onSuccess, onError });
  const handleClick = /* @__PURE__ */ chunkOLISEQHS_cjs.__name(async () => {
    if (confirm) {
      const api = typeof window !== "undefined" ? window.dialog : void 0;
      if (api?.confirm) {
        const ok = await api.confirm({
          title: confirmTitle,
          message: confirmMessage,
          variant: "destructive",
          confirmText: "Clear",
          cancelText: "Cancel"
        });
        if (!ok) return;
      } else if (typeof window !== "undefined" && typeof window.confirm === "function") {
        const ok = window.confirm(`${confirmTitle}

${confirmMessage}`);
        if (!ok) return;
      }
    }
    await reset();
  }, "handleClick");
  return /* @__PURE__ */ jsxRuntime.jsx(
    ChatHeaderActionButton,
    {
      icon: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.RotateCcw, { className: "h-3.5 w-3.5" }),
      ariaLabel,
      onClick: handleClick,
      loading: isResetting,
      destructive: true
    }
  );
}
chunkOLISEQHS_cjs.__name(ChatHeaderResetButton, "ChatHeaderResetButton");

// src/tools/SpeechRecognition/core/languages-catalog.ts
var WEB_SPEECH_LANGUAGES = [
  { name: "Afrikaans", iso: "af", englishName: "afrikaans", dialects: [{ code: "af-ZA", region: "South Africa" }] },
  { name: "\u12A0\u121B\u122D\u129B", iso: "am", englishName: "amharic", dialects: [{ code: "am-ET", region: "Ethiopia" }] },
  { name: "Az\u0259rbaycanca", iso: "az", englishName: "azerbaijani", dialects: [{ code: "az-AZ", region: "Azerbaijan" }] },
  {
    name: "\u09AC\u09BE\u0982\u09B2\u09BE",
    iso: "bn",
    englishName: "bengali",
    dialects: [
      { code: "bn-BD", region: "Bangladesh" },
      { code: "bn-IN", region: "India" }
    ]
  },
  { name: "Bahasa Indonesia", iso: "id", englishName: "indonesian", dialects: [{ code: "id-ID", region: "Indonesia" }] },
  { name: "Bahasa Melayu", iso: "ms", englishName: "malay", dialects: [{ code: "ms-MY", region: "Malaysia" }] },
  { name: "Catal\xE0", iso: "ca", englishName: "catalan", dialects: [{ code: "ca-ES", region: "Spain" }] },
  { name: "\u010Ce\u0161tina", iso: "cs", englishName: "czech", dialects: [{ code: "cs-CZ", region: "Czechia" }] },
  { name: "Dansk", iso: "da", englishName: "danish", dialects: [{ code: "da-DK", region: "Denmark" }] },
  { name: "Deutsch", iso: "de", englishName: "german", dialects: [{ code: "de-DE", region: "Germany" }] },
  {
    name: "English",
    iso: "en",
    englishName: "english",
    dialects: [
      { code: "en-US", region: "United States" },
      { code: "en-GB", region: "United Kingdom" },
      { code: "en-AU", region: "Australia" },
      { code: "en-CA", region: "Canada" },
      { code: "en-IN", region: "India" },
      { code: "en-NZ", region: "New Zealand" },
      { code: "en-PH", region: "Philippines" },
      { code: "en-ZA", region: "South Africa" },
      { code: "en-NG", region: "Nigeria" },
      { code: "en-GH", region: "Ghana" },
      { code: "en-KE", region: "Kenya" },
      { code: "en-TZ", region: "Tanzania" }
    ]
  },
  {
    name: "Espa\xF1ol",
    iso: "es",
    englishName: "spanish",
    dialects: [
      { code: "es-ES", region: "Espa\xF1a" },
      { code: "es-MX", region: "M\xE9xico" },
      { code: "es-US", region: "Estados Unidos" },
      { code: "es-AR", region: "Argentina" },
      { code: "es-CL", region: "Chile" },
      { code: "es-CO", region: "Colombia" },
      { code: "es-PE", region: "Per\xFA" },
      { code: "es-VE", region: "Venezuela" },
      { code: "es-EC", region: "Ecuador" },
      { code: "es-GT", region: "Guatemala" },
      { code: "es-CR", region: "Costa Rica" },
      { code: "es-PA", region: "Panam\xE1" },
      { code: "es-DO", region: "Rep. Dominicana" },
      { code: "es-UY", region: "Uruguay" },
      { code: "es-PY", region: "Paraguay" },
      { code: "es-BO", region: "Bolivia" },
      { code: "es-SV", region: "El Salvador" },
      { code: "es-HN", region: "Honduras" },
      { code: "es-NI", region: "Nicaragua" },
      { code: "es-PR", region: "Puerto Rico" }
    ]
  },
  { name: "Euskara", iso: "eu", englishName: "basque", dialects: [{ code: "eu-ES", region: "Spain" }] },
  { name: "Filipino", iso: "fil", englishName: "filipino tagalog", dialects: [{ code: "fil-PH", region: "Philippines" }] },
  { name: "Fran\xE7ais", iso: "fr", englishName: "french", dialects: [{ code: "fr-FR", region: "France" }] },
  { name: "Basa Jawa", iso: "jv", englishName: "javanese", dialects: [{ code: "jv-ID", region: "Indonesia" }] },
  { name: "Galego", iso: "gl", englishName: "galician", dialects: [{ code: "gl-ES", region: "Spain" }] },
  { name: "\u0A97\u0AC1\u0A9C\u0AB0\u0ABE\u0AA4\u0AC0", iso: "gu", englishName: "gujarati", dialects: [{ code: "gu-IN", region: "India" }] },
  { name: "Hrvatski", iso: "hr", englishName: "croatian", dialects: [{ code: "hr-HR", region: "Croatia" }] },
  { name: "IsiZulu", iso: "zu", englishName: "zulu", dialects: [{ code: "zu-ZA", region: "South Africa" }] },
  { name: "\xCDslenska", iso: "is", englishName: "icelandic", dialects: [{ code: "is-IS", region: "Iceland" }] },
  {
    name: "Italiano",
    iso: "it",
    englishName: "italian",
    dialects: [
      { code: "it-IT", region: "Italia" },
      { code: "it-CH", region: "Svizzera" }
    ]
  },
  { name: "\u0C95\u0CA8\u0CCD\u0CA8\u0CA1", iso: "kn", englishName: "kannada", dialects: [{ code: "kn-IN", region: "India" }] },
  { name: "\u1797\u17B6\u179F\u17B6\u1781\u17D2\u1798\u17C2\u179A", iso: "km", englishName: "khmer cambodian", dialects: [{ code: "km-KH", region: "Cambodia" }] },
  { name: "Latvie\u0161u", iso: "lv", englishName: "latvian", dialects: [{ code: "lv-LV", region: "Latvia" }] },
  { name: "Lietuvi\u0173", iso: "lt", englishName: "lithuanian", dialects: [{ code: "lt-LT", region: "Lithuania" }] },
  { name: "\u0D2E\u0D32\u0D2F\u0D3E\u0D33\u0D02", iso: "ml", englishName: "malayalam", dialects: [{ code: "ml-IN", region: "India" }] },
  { name: "\u092E\u0930\u093E\u0920\u0940", iso: "mr", englishName: "marathi", dialects: [{ code: "mr-IN", region: "India" }] },
  { name: "Magyar", iso: "hu", englishName: "hungarian", dialects: [{ code: "hu-HU", region: "Hungary" }] },
  { name: "\u0EA5\u0EB2\u0EA7", iso: "lo", englishName: "lao laotian", dialects: [{ code: "lo-LA", region: "Laos" }] },
  { name: "Nederlands", iso: "nl", englishName: "dutch", dialects: [{ code: "nl-NL", region: "Netherlands" }] },
  { name: "\u0928\u0947\u092A\u093E\u0932\u0940 \u092D\u093E\u0937\u093E", iso: "ne", englishName: "nepali", dialects: [{ code: "ne-NP", region: "Nepal" }] },
  { name: "Norsk bokm\xE5l", iso: "nb", englishName: "norwegian bokmal", dialects: [{ code: "nb-NO", region: "Norway" }] },
  { name: "Polski", iso: "pl", englishName: "polish", dialects: [{ code: "pl-PL", region: "Poland" }] },
  {
    name: "Portugu\xEAs",
    iso: "pt",
    englishName: "portuguese",
    dialects: [
      { code: "pt-BR", region: "Brasil" },
      { code: "pt-PT", region: "Portugal" }
    ]
  },
  { name: "Rom\xE2n\u0103", iso: "ro", englishName: "romanian", dialects: [{ code: "ro-RO", region: "Romania" }] },
  { name: "\u0DC3\u0DD2\u0D82\u0DC4\u0DBD", iso: "si", englishName: "sinhala sinhalese", dialects: [{ code: "si-LK", region: "Sri Lanka" }] },
  { name: "Sloven\u0161\u010Dina", iso: "sl", englishName: "slovenian", dialects: [{ code: "sl-SI", region: "Slovenia" }] },
  { name: "Basa Sunda", iso: "su", englishName: "sundanese", dialects: [{ code: "su-ID", region: "Indonesia" }] },
  { name: "Sloven\u010Dina", iso: "sk", englishName: "slovak", dialects: [{ code: "sk-SK", region: "Slovakia" }] },
  { name: "Suomi", iso: "fi", englishName: "finnish", dialects: [{ code: "fi-FI", region: "Finland" }] },
  { name: "Svenska", iso: "sv", englishName: "swedish", dialects: [{ code: "sv-SE", region: "Sweden" }] },
  {
    name: "Kiswahili",
    iso: "sw",
    englishName: "swahili",
    dialects: [
      { code: "sw-TZ", region: "Tanzania" },
      { code: "sw-KE", region: "Kenya" }
    ]
  },
  { name: "\u10E5\u10D0\u10E0\u10D7\u10E3\u10DA\u10D8", iso: "ka", englishName: "georgian", dialects: [{ code: "ka-GE", region: "Georgia" }] },
  { name: "\u0540\u0561\u0575\u0565\u0580\u0565\u0576", iso: "hy", englishName: "armenian", dialects: [{ code: "hy-AM", region: "Armenia" }] },
  {
    name: "\u0BA4\u0BAE\u0BBF\u0BB4\u0BCD",
    iso: "ta",
    englishName: "tamil",
    dialects: [
      { code: "ta-IN", region: "\u0B87\u0BA8\u0BCD\u0BA4\u0BBF\u0BAF\u0BBE" },
      { code: "ta-SG", region: "\u0B9A\u0BBF\u0B99\u0BCD\u0B95\u0BAA\u0BCD\u0BAA\u0BC2\u0BB0\u0BCD" },
      { code: "ta-LK", region: "\u0B87\u0BB2\u0B99\u0BCD\u0B95\u0BC8" },
      { code: "ta-MY", region: "\u0BAE\u0BB2\u0BC7\u0B9A\u0BBF\u0BAF\u0BBE" }
    ]
  },
  { name: "\u0C24\u0C46\u0C32\u0C41\u0C17\u0C41", iso: "te", englishName: "telugu", dialects: [{ code: "te-IN", region: "India" }] },
  { name: "Ti\u1EBFng Vi\u1EC7t", iso: "vi", englishName: "vietnamese", dialects: [{ code: "vi-VN", region: "Vietnam" }] },
  { name: "T\xFCrk\xE7e", iso: "tr", englishName: "turkish", dialects: [{ code: "tr-TR", region: "T\xFCrkiye" }] },
  {
    name: "\u0627\u064F\u0631\u062F\u064F\u0648",
    iso: "ur",
    englishName: "urdu",
    dialects: [
      { code: "ur-PK", region: "\u067E\u0627\u06A9\u0633\u062A\u0627\u0646" },
      { code: "ur-IN", region: "\u0628\u06BE\u0627\u0631\u062A" }
    ]
  },
  { name: "\u0395\u03BB\u03BB\u03B7\u03BD\u03B9\u03BA\u03AC", iso: "el", englishName: "greek", dialects: [{ code: "el-GR", region: "Greece" }] },
  { name: "\u0431\u044A\u043B\u0433\u0430\u0440\u0441\u043A\u0438", iso: "bg", englishName: "bulgarian", dialects: [{ code: "bg-BG", region: "Bulgaria" }] },
  { name: "\u0420\u0443\u0441\u0441\u043A\u0438\u0439", iso: "ru", englishName: "russian", dialects: [{ code: "ru-RU", region: "Russia" }] },
  { name: "\u0421\u0440\u043F\u0441\u043A\u0438", iso: "sr", englishName: "serbian", dialects: [{ code: "sr-RS", region: "Serbia" }] },
  { name: "\u0423\u043A\u0440\u0430\u0457\u043D\u0441\u044C\u043A\u0430", iso: "uk", englishName: "ukrainian", dialects: [{ code: "uk-UA", region: "Ukraine" }] },
  { name: "\uD55C\uAD6D\uC5B4", iso: "ko", englishName: "korean", dialects: [{ code: "ko-KR", region: "Korea" }] },
  {
    name: "\u4E2D\u6587",
    iso: "cmn",
    englishName: "chinese mandarin cantonese",
    dialects: [
      { code: "cmn-Hans-CN", region: "\u666E\u901A\u8BDD (\u4E2D\u56FD\u5927\u9646)" },
      { code: "cmn-Hans-HK", region: "\u666E\u901A\u8BDD (\u9999\u6E2F)" },
      { code: "cmn-Hant-TW", region: "\u4E2D\u6587 (\u53F0\u7063)" },
      { code: "yue-Hant-HK", region: "\u7CB5\u8A9E (\u9999\u6E2F)" }
    ]
  },
  { name: "\u65E5\u672C\u8A9E", iso: "ja", englishName: "japanese", dialects: [{ code: "ja-JP", region: "Japan" }] },
  { name: "\u0939\u093F\u0928\u094D\u0926\u0940", iso: "hi", englishName: "hindi", dialects: [{ code: "hi-IN", region: "India" }] },
  { name: "\u0E20\u0E32\u0E29\u0E32\u0E44\u0E17\u0E22", iso: "th", englishName: "thai", dialects: [{ code: "th-TH", region: "Thailand" }] }
];
WEB_SPEECH_LANGUAGES.flatMap(
  (l) => l.dialects.map((d) => d.code)
);
function findSpeechLanguage(tag) {
  if (!tag) return null;
  const lower = tag.toLowerCase();
  for (const language of WEB_SPEECH_LANGUAGES) {
    for (const dialect of language.dialects) {
      if (dialect.code.toLowerCase() === lower) return { language, dialect };
    }
  }
  return null;
}
chunkOLISEQHS_cjs.__name(findSpeechLanguage, "findSpeechLanguage");
function countryFromTag(tag) {
  if (!tag) return null;
  const parts = tag.split("-");
  for (let i = parts.length - 1; i >= 0; i -= 1) {
    const p = parts[i];
    if (p.length === 2 && /^[A-Za-z]{2}$/.test(p)) return p.toUpperCase();
  }
  return null;
}
chunkOLISEQHS_cjs.__name(countryFromTag, "countryFromTag");
chunkADEN3UA4_cjs.getSpeechLogger();
React.createContext(null);
function Spinner({ className }) {
  const t = i18n.useAppT();
  const loadingLabel = t("ui.states.loading");
  return /* @__PURE__ */ jsxRuntime.jsx(
    "div",
    {
      className: lib.cn(
        "inline-block h-8 w-8 animate-spin rounded-full",
        "border-4 border-solid border-current border-r-transparent",
        "align-[-0.125em] motion-reduce:animate-[spin_1.5s_linear_infinite]",
        className
      ),
      role: "status",
      "aria-label": loadingLabel
    }
  );
}
chunkOLISEQHS_cjs.__name(Spinner, "Spinner");
function LoadingFallback({
  minHeight = 200,
  showText = true,
  text,
  className
}) {
  const t = i18n.useAppT();
  const loadingText = text ?? t("ui.form.loading");
  const height = typeof minHeight === "number" ? `${minHeight}px` : minHeight;
  return /* @__PURE__ */ jsxRuntime.jsx(
    "div",
    {
      className: lib.cn(
        "flex items-center justify-center bg-muted/30 rounded-lg",
        className
      ),
      style: { minHeight: height },
      children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-center", children: [
        /* @__PURE__ */ jsxRuntime.jsx(Spinner, { className: "text-primary" }),
        showText && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mt-3 text-sm text-muted-foreground", children: loadingText })
      ] })
    }
  );
}
chunkOLISEQHS_cjs.__name(LoadingFallback, "LoadingFallback");
function CardLoadingFallback({
  title,
  description,
  minHeight = 200,
  className
}) {
  const t = i18n.useAppT();
  const cardTitle = title ?? t("ui.states.loading");
  const height = typeof minHeight === "number" ? `${minHeight}px` : minHeight;
  return /* @__PURE__ */ jsxRuntime.jsxs(
    "div",
    {
      className: lib.cn(
        "relative bg-card rounded-lg border border-border overflow-hidden",
        className
      ),
      children: [
        /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "p-4 border-b border-border bg-muted/50", children: [
          /* @__PURE__ */ jsxRuntime.jsx("h6", { className: "text-sm font-semibold text-foreground", children: cardTitle }),
          description && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-muted-foreground mt-1", children: description })
        ] }),
        /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-4", children: /* @__PURE__ */ jsxRuntime.jsx(
          "div",
          {
            className: "flex justify-center items-center",
            style: { minHeight: height },
            children: /* @__PURE__ */ jsxRuntime.jsx(Spinner, { className: "text-primary" })
          }
        ) })
      ]
    }
  );
}
chunkOLISEQHS_cjs.__name(CardLoadingFallback, "CardLoadingFallback");
function MapLoadingFallback({
  minHeight = 400,
  className
}) {
  const t = i18n.useAppT();
  const loadingText = t("ui.form.loading");
  const height = typeof minHeight === "number" ? `${minHeight}px` : minHeight;
  return /* @__PURE__ */ jsxRuntime.jsx(
    "div",
    {
      className: lib.cn(
        "relative bg-muted/50 rounded-lg overflow-hidden",
        "flex items-center justify-center",
        className
      ),
      style: { minHeight: height },
      children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-center", children: [
        /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative", children: [
          /* @__PURE__ */ jsxRuntime.jsx(Spinner, { className: "text-primary h-10 w-10" }),
          /* @__PURE__ */ jsxRuntime.jsx("div", { className: "absolute inset-0 flex items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsxs(
            "svg",
            {
              className: "h-5 w-5 text-muted-foreground",
              fill: "none",
              viewBox: "0 0 24 24",
              stroke: "currentColor",
              children: [
                /* @__PURE__ */ jsxRuntime.jsx(
                  "path",
                  {
                    strokeLinecap: "round",
                    strokeLinejoin: "round",
                    strokeWidth: 2,
                    d: "M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z"
                  }
                ),
                /* @__PURE__ */ jsxRuntime.jsx(
                  "path",
                  {
                    strokeLinecap: "round",
                    strokeLinejoin: "round",
                    strokeWidth: 2,
                    d: "M15 11a3 3 0 11-6 0 3 3 0 016 0z"
                  }
                )
              ]
            }
          ) })
        ] }),
        /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mt-3 text-sm text-muted-foreground", children: loadingText })
      ] })
    }
  );
}
chunkOLISEQHS_cjs.__name(MapLoadingFallback, "MapLoadingFallback");
function LazyWrapper({
  children,
  fallback,
  card = false,
  cardTitle,
  cardDescription,
  minHeight = 200,
  className
}) {
  const defaultFallback = card ? /* @__PURE__ */ jsxRuntime.jsx(
    CardLoadingFallback,
    {
      title: cardTitle,
      description: cardDescription,
      minHeight,
      className
    }
  ) : /* @__PURE__ */ jsxRuntime.jsx(LoadingFallback, { minHeight, className });
  return /* @__PURE__ */ jsxRuntime.jsx(React.Suspense, { fallback: fallback ?? defaultFallback, children });
}
chunkOLISEQHS_cjs.__name(LazyWrapper, "LazyWrapper");
function createLazyComponent(loader, options = {}) {
  const LazyComponent = React__namespace.lazy(loader);
  const WrappedComponent = /* @__PURE__ */ chunkOLISEQHS_cjs.__name((props) => {
    const fallback = typeof options.fallback === "function" ? options.fallback(props) : options.fallback ?? /* @__PURE__ */ jsxRuntime.jsx(LoadingFallback, {});
    return /* @__PURE__ */ jsxRuntime.jsx(React.Suspense, { fallback, children: /* @__PURE__ */ jsxRuntime.jsx(LazyComponent, { ...props }) });
  }, "WrappedComponent");
  WrappedComponent.displayName = options.displayName ?? "LazyComponent";
  return WrappedComponent;
}
chunkOLISEQHS_cjs.__name(createLazyComponent, "createLazyComponent");
createLazyComponent(
  () => import('./DictationField-AS2F33WI.cjs').then((mod) => ({
    default: mod.DictationField
  })),
  {
    displayName: "LazyDictationField",
    fallback: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-lg border border-border/60 bg-card px-3 py-2 text-xs text-muted-foreground", children: "Loading dictation\u2026" })
  }
);
function ChatHeaderLanguageButton({
  ariaLabel = "Speech language",
  allowedTags,
  hideFallbackIcon,
  className
}) {
  const prefs = chunkADEN3UA4_cjs.useSpeechPrefs();
  const active = chunkADEN3UA4_cjs.useResolvedLanguage();
  const options = React.useMemo(() => {
    const allow = allowedTags ? new Set(allowedTags) : null;
    const out = [];
    for (const lang of WEB_SPEECH_LANGUAGES) {
      for (const d of lang.dialects) {
        if (allow && !allow.has(d.code)) continue;
        out.push({
          value: d.code,
          // "Русский" / "Español — Argentina" / "English — United States"
          label: lang.dialects.length === 1 ? lang.name : `${lang.name} \u2014 ${d.region}`,
          // Search-only index: English name, BCP-47 tag, ISO, region.
          // Lets users type "russian" / "ru-RU" / "ru" / "argentina"
          // and still find the row regardless of native script.
          description: `${lang.englishName} ${d.code} ${lang.iso} ${d.region}`.toLowerCase()
        });
      }
    }
    return out;
  }, [allowedTags]);
  return /* @__PURE__ */ jsxRuntime.jsx(
    components.Combobox,
    {
      options,
      value: prefs.language ?? active,
      onValueChange: (v) => prefs.setLanguage(v || null),
      placeholder: ariaLabel,
      searchPlaceholder: "Search language\u2026",
      filterFunction: (opt, search) => {
        const s = search.toLowerCase();
        return opt.label.toLowerCase().includes(s) || opt.value.toLowerCase().includes(s) || (opt.description?.includes(s) ?? false);
      },
      contentClassName: "w-[280px]",
      contentStyle: { zIndex: 10001 },
      renderOption: (option) => {
        const country = countryFromTag(option.value);
        return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex min-w-0 flex-1 items-center gap-2", children: [
          country ? /* @__PURE__ */ jsxRuntime.jsx(
            components.Flag,
            {
              countryCode: country,
              className: "h-4 w-5 shrink-0 overflow-hidden rounded-[2px] border border-border/60 ring-1 ring-black/5"
            }
          ) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Globe, { className: "h-4 w-4 shrink-0 text-muted-foreground", "aria-hidden": true }),
          /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate text-sm", children: option.label })
        ] });
      },
      renderTrigger: (selected, open) => {
        const tag = selected?.value ?? active;
        const country = countryFromTag(tag);
        const found = findSpeechLanguage(tag);
        const tooltipLabel = found ? `${found.language.name}${found.language.dialects.length > 1 ? ` \u2014 ${found.dialect.region}` : ""} \xB7 ${tag}` : tag;
        return /* @__PURE__ */ jsxRuntime.jsx(
          "button",
          {
            type: "button",
            "aria-label": `${ariaLabel}: ${tooltipLabel}`,
            "aria-expanded": open,
            title: tooltipLabel,
            className: lib.cn(
              "inline-flex h-7 w-7 items-center justify-center rounded-md",
              "text-muted-foreground transition-colors",
              "hover:bg-accent hover:text-foreground",
              "focus:outline-none focus-visible:ring-2 focus-visible:ring-ring",
              className
            ),
            children: country ? /* @__PURE__ */ jsxRuntime.jsx(
              components.Flag,
              {
                countryCode: country,
                className: "h-4 w-5 overflow-hidden rounded-[2px] border border-border/60 ring-1 ring-black/5"
              }
            ) : hideFallbackIcon ? null : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Globe, { className: "h-3.5 w-3.5", "aria-hidden": true })
          }
        );
      }
    }
  );
}
chunkOLISEQHS_cjs.__name(ChatHeaderLanguageButton, "ChatHeaderLanguageButton");
function anchorStyle(position, fabOffset, fabClearance) {
  const [vert, horiz] = position.split("-");
  return { [vert]: fabClearance, [horiz]: fabOffset };
}
chunkOLISEQHS_cjs.__name(anchorStyle, "anchorStyle");
function originClass(position) {
  if (position === "bottom-right") return "origin-bottom-right";
  if (position === "bottom-left") return "origin-bottom-left";
  if (position === "top-right") return "origin-top-right";
  return "origin-top-left";
}
chunkOLISEQHS_cjs.__name(originClass, "originClass");
function ChatGreeting({
  open,
  children,
  onClick,
  onDismiss,
  position = "bottom-right",
  fabOffset = 24,
  fabClearance = 96,
  delayMs = 1500,
  zIndex = 9998,
  className,
  style,
  avatar,
  senderName,
  dismissLabel = "Dismiss",
  inline = false
}) {
  const [delayed, setDelayed] = React.useState(delayMs <= 0);
  React.useEffect(() => {
    if (!open || delayMs <= 0) return;
    const t = setTimeout(() => setDelayed(true), delayMs);
    return () => clearTimeout(t);
  }, [open, delayMs]);
  const shouldShow = open && delayed;
  const phase = useChatPresence(shouldShow, 220);
  if (phase === "hidden") return null;
  const animating = phase === "entering" || phase === "leaving";
  const clickable = !!onClick;
  return /* @__PURE__ */ jsxRuntime.jsxs(
    "div",
    {
      role: clickable ? "button" : "status",
      "aria-live": "polite",
      tabIndex: clickable ? 0 : -1,
      onClick: clickable ? onClick : void 0,
      onKeyDown: clickable ? (e) => {
        if (e.key === "Enter" || e.key === " ") {
          e.preventDefault();
          onClick?.();
        }
      } : void 0,
      className: lib.cn(
        inline ? "relative inline-flex" : "fixed",
        "flex items-start gap-2.5 max-w-[280px]",
        "rounded-2xl border border-border bg-popover text-popover-foreground",
        "px-3.5 py-2.5 shadow-2xl transition-all duration-200 ease-out",
        clickable && "cursor-pointer hover:bg-accent/40 focus:outline-none focus-visible:ring-2 focus-visible:ring-ring",
        originClass(position),
        animating ? "opacity-0 scale-95 translate-y-1" : "opacity-100 scale-100 translate-y-0",
        className
      ),
      style: {
        ...inline ? {} : anchorStyle(position, fabOffset, fabClearance),
        ...inline ? {} : { zIndex },
        pointerEvents: phase === "visible" ? "auto" : "none",
        ...style
      },
      children: [
        avatar && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-0.5 shrink-0", children: avatar }),
        /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "min-w-0 flex-1 text-sm leading-snug", children: [
          senderName && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mb-0.5 text-[11px] font-medium text-muted-foreground", children: senderName }),
          /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-foreground", children })
        ] }),
        onDismiss && /* @__PURE__ */ jsxRuntime.jsx(
          "button",
          {
            type: "button",
            "aria-label": dismissLabel,
            onClick: (e) => {
              e.stopPropagation();
              onDismiss();
            },
            className: lib.cn(
              "-mr-1 -mt-1 flex h-6 w-6 shrink-0 items-center justify-center rounded-full",
              "text-muted-foreground transition-colors hover:bg-accent hover:text-foreground",
              "focus:outline-none focus-visible:ring-2 focus-visible:ring-ring"
            ),
            children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.X, { className: "h-3.5 w-3.5" })
          }
        )
      ]
    }
  );
}
chunkOLISEQHS_cjs.__name(ChatGreeting, "ChatGreeting");
var TIME_FORMAT = new Intl.DateTimeFormat(void 0, {
  hour: "2-digit",
  minute: "2-digit"
});
function anchorStyle2(position, fabOffset, fabClearance) {
  const [vert, horiz] = position.split("-");
  return { [vert]: fabClearance, [horiz]: fabOffset };
}
chunkOLISEQHS_cjs.__name(anchorStyle2, "anchorStyle");
function originClass2(position) {
  if (position === "bottom-right") return "origin-bottom-right";
  if (position === "bottom-left") return "origin-bottom-left";
  if (position === "top-right") return "origin-top-right";
  return "origin-top-left";
}
chunkOLISEQHS_cjs.__name(originClass2, "originClass");
function deriveAvatar(persona, name) {
  const initials = persona?.initials ?? (name ?? persona?.name ?? "?").split(/\s+/).map((p) => p[0]).filter(Boolean).slice(0, 2).join("").toUpperCase();
  return /* @__PURE__ */ jsxRuntime.jsxs(components.Avatar, { className: "h-9 w-9", children: [
    persona?.avatarUrl ? /* @__PURE__ */ jsxRuntime.jsx(components.AvatarImage, { src: persona.avatarUrl }) : null,
    /* @__PURE__ */ jsxRuntime.jsx(components.AvatarFallback, { children: initials || "?" })
  ] });
}
chunkOLISEQHS_cjs.__name(deriveAvatar, "deriveAvatar");
function ChatUnreadPreview({
  open,
  message,
  onClick,
  onDismiss,
  position = "bottom-right",
  fabOffset = 24,
  fabClearance = 96,
  truncate = 2,
  zIndex = 9998,
  inline = false,
  className,
  style,
  dismissLabel = "Mark as read",
  avatar,
  senderName
}) {
  const shouldShow = open && !!message;
  const phase = useChatPresence(shouldShow, 200);
  if (phase === "hidden" || !message) return null;
  const animating = phase === "entering" || phase === "leaving";
  const clickable = !!onClick;
  const displayName = senderName ?? message.sender?.name ?? "New message";
  const stamp = TIME_FORMAT.format(new Date(message.createdAt));
  return /* @__PURE__ */ jsxRuntime.jsxs(
    "div",
    {
      role: clickable ? "button" : "status",
      "aria-live": "polite",
      tabIndex: clickable ? 0 : -1,
      onClick: clickable ? onClick : void 0,
      onKeyDown: clickable ? (e) => {
        if (e.key === "Enter" || e.key === " ") {
          e.preventDefault();
          onClick?.();
        }
      } : void 0,
      className: lib.cn(
        inline ? "relative inline-flex" : "fixed",
        "flex items-start gap-2.5 max-w-[300px]",
        "rounded-2xl border border-border bg-popover text-popover-foreground",
        "px-3.5 py-2.5 shadow-2xl transition-all duration-200 ease-out",
        clickable && "cursor-pointer hover:bg-accent/40 focus:outline-none focus-visible:ring-2 focus-visible:ring-ring",
        originClass2(position),
        animating ? "opacity-0 scale-95 translate-y-1" : "opacity-100 scale-100 translate-y-0",
        className
      ),
      style: {
        ...inline ? {} : anchorStyle2(position, fabOffset, fabClearance),
        ...inline ? {} : { zIndex },
        pointerEvents: phase === "visible" ? "auto" : "none",
        ...style
      },
      children: [
        /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-0.5 shrink-0", children: avatar ?? deriveAvatar(message.sender, displayName) }),
        /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "min-w-0 flex-1 text-sm leading-snug", children: [
          /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-baseline justify-between gap-2", children: [
            /* @__PURE__ */ jsxRuntime.jsx("div", { className: "truncate text-[12px] font-semibold text-foreground", children: displayName }),
            /* @__PURE__ */ jsxRuntime.jsx("div", { className: "shrink-0 text-[10px] text-muted-foreground", children: stamp })
          ] }),
          /* @__PURE__ */ jsxRuntime.jsx(
            "div",
            {
              className: "text-foreground/90 mt-0.5 break-words",
              style: {
                display: "-webkit-box",
                WebkitLineClamp: truncate,
                WebkitBoxOrient: "vertical",
                overflow: "hidden"
              },
              children: message.content
            }
          )
        ] }),
        onDismiss ? /* @__PURE__ */ jsxRuntime.jsx(
          "button",
          {
            type: "button",
            "aria-label": dismissLabel,
            onClick: (e) => {
              e.stopPropagation();
              onDismiss();
            },
            className: lib.cn(
              "-mr-1 -mt-1 flex h-6 w-6 shrink-0 items-center justify-center rounded-full",
              "text-muted-foreground transition-colors hover:bg-accent hover:text-foreground",
              "focus:outline-none focus-visible:ring-2 focus-visible:ring-ring"
            ),
            children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.X, { className: "h-3.5 w-3.5" })
          }
        ) : null
      ]
    }
  );
}
chunkOLISEQHS_cjs.__name(ChatUnreadPreview, "ChatUnreadPreview");
function readDismissed(storageKey) {
  if (!storageKey) return false;
  if (typeof window === "undefined") return false;
  try {
    return window.localStorage.getItem(storageKey) === "1";
  } catch {
    return false;
  }
}
chunkOLISEQHS_cjs.__name(readDismissed, "readDismissed");
function writeDismissed(storageKey) {
  if (!storageKey) return;
  if (typeof window === "undefined") return;
  try {
    window.localStorage.setItem(storageKey, "1");
  } catch {
  }
}
chunkOLISEQHS_cjs.__name(writeDismissed, "writeDismissed");
function ChatLauncher({
  children,
  fab,
  dock,
  greeting,
  hotkey,
  defaultOpen = false,
  open: controlledOpen,
  onOpenChange,
  autoFocusComposerOnOpen = true,
  closeOnEscape = true,
  unreadMessage,
  onMarkRead,
  unreadPreview,
  audio,
  hideAudioToggle = false
}) {
  const [uncontrolledOpen, setUncontrolledOpen] = React.useState(defaultOpen);
  const isControlled = controlledOpen !== void 0;
  const open = isControlled ? controlledOpen : uncontrolledOpen;
  const dockContentRef = React.useRef(null);
  React.useEffect(() => {
    if (!autoFocusComposerOnOpen || !open) return;
    const t = setTimeout(() => {
      const root = dockContentRef.current;
      if (!root) return;
      const target = root.querySelector(
        'textarea:not([disabled]):not([readonly]), input[type="text"]:not([disabled]):not([readonly])'
      );
      target?.focus();
    }, 120);
    return () => clearTimeout(t);
  }, [open, autoFocusComposerOnOpen]);
  const setOpen = React.useCallback(
    (next) => {
      if (!isControlled) setUncontrolledOpen(next);
      onOpenChange?.(next);
    },
    [isControlled, onOpenChange]
  );
  const toggleOpen = React.useCallback(() => setOpen(!open), [open, setOpen]);
  hooks.useHotkey(
    "escape",
    (e) => {
      const target = e?.target ?? null;
      const inEditable = !!target && (target.matches?.('input, textarea, [contenteditable="true"]') ?? false);
      if (inEditable) {
        target.blur();
        return;
      }
      setOpen(false);
    },
    { enabled: closeOnEscape && open }
  );
  const greetingConfig = greeting === void 0 ? null : typeof greeting === "string" ? { content: greeting } : greeting;
  const [dismissed, setDismissed] = React.useState(
    () => readDismissed(greetingConfig?.dismissStorageKey)
  );
  React.useEffect(() => {
    if (!hotkey) return;
    const handler = /* @__PURE__ */ chunkOLISEQHS_cjs.__name((e) => {
      const metaOk = hotkey.meta ? e.metaKey || e.ctrlKey : !e.metaKey && !e.ctrlKey;
      const shiftOk = hotkey.shift ? e.shiftKey : !e.shiftKey;
      const altOk = hotkey.alt ? e.altKey : !e.altKey;
      if (!metaOk || !shiftOk || !altOk) return;
      if (e.key !== hotkey.key) return;
      e.preventDefault();
      setOpen(!open);
    }, "handler");
    window.addEventListener("keydown", handler);
    return () => window.removeEventListener("keydown", handler);
  }, [hotkey?.key, hotkey?.meta, hotkey?.shift, hotkey?.alt, open, setOpen, hotkey]);
  const greetingOpen = !!greetingConfig && !dismissed && (greetingConfig.hideOnOpen === false || !open);
  const fabPosition = fab?.position ?? "bottom-right";
  const fabOffset = fab?.offset ?? 24;
  const handleGreetingDismiss = /* @__PURE__ */ chunkOLISEQHS_cjs.__name(() => {
    setDismissed(true);
    writeDismissed(greetingConfig?.dismissStorageKey);
  }, "handleGreetingDismiss");
  const handleGreetingClick = /* @__PURE__ */ chunkOLISEQHS_cjs.__name(() => {
    setOpen(true);
    setDismissed(true);
    writeDismissed(greetingConfig?.dismissStorageKey);
  }, "handleGreetingClick");
  React.useEffect(() => {
    if (open && unreadMessage) onMarkRead?.();
  }, [open, unreadMessage, onMarkRead]);
  const unreadOpen = !open && !!unreadMessage;
  const handleUnreadClick = /* @__PURE__ */ chunkOLISEQHS_cjs.__name(() => {
    setOpen(true);
    onMarkRead?.();
  }, "handleUnreadClick");
  const handleUnreadDismiss = /* @__PURE__ */ chunkOLISEQHS_cjs.__name(() => {
    onMarkRead?.();
  }, "handleUnreadDismiss");
  const resolvedFab = unreadMessage && fab?.badge === void 0 ? { ...fab, badge: 1 } : fab;
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
    /* @__PURE__ */ jsxRuntime.jsx(ChatFAB, { ...resolvedFab, onClick: toggleOpen }),
    unreadMessage ? /* @__PURE__ */ jsxRuntime.jsx(
      ChatUnreadPreview,
      {
        ...unreadPreview,
        open: unreadOpen,
        message: unreadMessage,
        onClick: handleUnreadClick,
        onDismiss: handleUnreadDismiss,
        position: fabPosition,
        fabOffset
      }
    ) : greetingConfig ? /* @__PURE__ */ jsxRuntime.jsx(
      ChatGreeting,
      {
        ...greetingConfig,
        open: greetingOpen,
        onClick: handleGreetingClick,
        onDismiss: handleGreetingDismiss,
        position: fabPosition,
        fabOffset,
        children: greetingConfig.content
      }
    ) : null,
    /* @__PURE__ */ jsxRuntime.jsx(
      ChatDock,
      {
        ...dock,
        open,
        onClose: () => setOpen(false),
        headerActions: audio && !audio.isSilent && !hideAudioToggle || dock?.headerActions ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
          dock?.headerActions,
          audio && !audio.isSilent && !hideAudioToggle ? /* @__PURE__ */ jsxRuntime.jsx(ChatHeaderAudioToggle, { muted: audio.muted, onToggle: audio.toggleMute }) : null
        ] }) : void 0,
        children: /* @__PURE__ */ jsxRuntime.jsx("div", { ref: dockContentRef, className: "flex h-full min-h-0 min-w-0 flex-col", children })
      }
    )
  ] });
}
chunkOLISEQHS_cjs.__name(ChatLauncher, "ChatLauncher");

exports.CardLoadingFallback = CardLoadingFallback;
exports.ChatDock = ChatDock;
exports.ChatFAB = ChatFAB;
exports.ChatGreeting = ChatGreeting;
exports.ChatHeader = ChatHeader;
exports.ChatHeaderActionButton = ChatHeaderActionButton;
exports.ChatHeaderAudioToggle = ChatHeaderAudioToggle;
exports.ChatHeaderLanguageButton = ChatHeaderLanguageButton;
exports.ChatHeaderModeToggle = ChatHeaderModeToggle;
exports.ChatHeaderResetButton = ChatHeaderResetButton;
exports.ChatLauncher = ChatLauncher;
exports.ChatUnreadPreview = ChatUnreadPreview;
exports.LazyWrapper = LazyWrapper;
exports.LoadingFallback = LoadingFallback;
exports.MapLoadingFallback = MapLoadingFallback;
exports.Spinner = Spinner;
exports.createLazyComponent = createLazyComponent;
exports.useChatPresence = useChatPresence;
exports.useChatReset = useChatReset;
//# sourceMappingURL=chunk-W75B7Y6C.cjs.map
//# sourceMappingURL=chunk-W75B7Y6C.cjs.map