"use client" import * as React from "react" import { useLocation, useNavigate } from "react-router-dom" import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu" import { Tooltip, TooltipContent, TooltipTrigger, } from "@/components/ui/tooltip" import { useAskLeo } from "@/components/ask-leo-context" import { useProduct } from "@/contexts/product-context" import { useProductDashboardHref } from "@/contexts/product-route-sync" import { productSlug } from "@/stores/app-store" import { cn } from "@/lib/utils" type AskLeoViewMode = "panel" | "fullscreen" function isLeoLandingPath(pathname: string, leoHref: string) { return pathname === leoHref || pathname.startsWith(`${leoHref}/`) } function useAskLeoViewMode(): AskLeoViewMode { const { pathname } = useLocation() const { product } = useProduct() const leoHref = `/${productSlug(product)}/leo` return isLeoLandingPath(pathname, leoHref) ? "fullscreen" : "panel" } /** * Panel <-> full-screen Leo view switcher. Kept separate from the heavy * sidebar panel so the landing route can render it without pulling the panel * implementation into the app shell chunk. */ export function AskLeoViewToggle({ className }: { className?: string }) { const navigate = useNavigate() const { open, setOpen } = useAskLeo() const { product } = useProduct() const dashboardHref = useProductDashboardHref() const leoHref = `/${productSlug(product)}/leo` const viewMode = useAskLeoViewMode() const handleViewChange = React.useCallback( (next: AskLeoViewMode) => { if (next === viewMode) return if (next === "fullscreen") { setOpen(false) navigate(leoHref) return } if (viewMode === "fullscreen") { navigate(dashboardHref) queueMicrotask(() => setOpen(true)) return } if (!open) setOpen(true) }, [dashboardHref, leoHref, navigate, open, setOpen, viewMode], ) return (