'use client' import React, { useMemo, useState } from 'react' import { useStore } from 'zustand' import { Badge, Button, Tooltip, TooltipContent, TooltipTrigger } from '@djangocfg/ui-core/components' import { cn } from '@djangocfg/ui-core/lib' import { Bug, Maximize2, Minimize2, ScrollText, X } from 'lucide-react' import { devtoolsStore } from '../store' import type { CustomDebugTab } from '../types' import { LogsTab } from './LogsTab' export interface DevtoolsPanelProps { /** Additional app-specific tabs */ tabs?: CustomDebugTab[] position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left' defaultHeight?: number defaultWidth?: number } const POSITION_STYLES: Record, React.CSSProperties> = { 'bottom-right': { bottom: 16, right: 16 }, 'bottom-left': { bottom: 16, left: 16 }, 'top-right': { top: 16, right: 16 }, 'top-left': { top: 16, left: 16 }, } export function DevtoolsPanel({ tabs: customTabs = [], position = 'bottom-left', defaultHeight = 480, defaultWidth = 560, }: DevtoolsPanelProps) { const isOpen = useStore(devtoolsStore, (s) => s.isOpen) const activeTab = useStore(devtoolsStore, (s) => s.tab) const setTab = useStore(devtoolsStore, (s) => s.setTab) const closePanel = useStore(devtoolsStore, (s) => s.closePanel) const errorCount = useStore(devtoolsStore, (s) => s.entries.reduce((n, e) => (e.level === 'error' ? n + 1 : n), 0), ) const [isMinimized, setIsMinimized] = useState(false) const allTabs = useMemo( () => [ { id: 'logs', label: 'Logs', icon: ScrollText as React.ElementType }, ...customTabs.map((t) => ({ id: t.id, label: t.label, icon: t.icon })), ], [customTabs], ) if (!isOpen) return null return (
{/* Header */}
Devtools {errorCount > 0 && ( {errorCount} {errorCount === 1 ? 'error' : 'errors'} )} {!isMinimized && (
{allTabs.map((tab) => { const Icon = tab.icon as React.ComponentType<{ className?: string }> const isActive = activeTab === tab.id return ( ) })}
)}
{isMinimized ? 'Expand' : 'Minimize'} Close
{/* Content */} {!isMinimized && (
{activeTab === 'logs' && } {customTabs.map((tab) => { const Panel = tab.panel return (
) })}
)}
) }