'use client'
import { type ReactNode, useEffect } from 'react'
import {
CommandPalette,
type CommandPaletteEmptyAction,
} from './../../../components/ui/command-palette'
import { EditorCommands } from './../../../components/ui/command-palette/editor-commands'
import {
SidebarContent,
SidebarHeader,
useSidebarStore,
} from './../../../components/ui/primitives/sidebar'
import { cn } from './../../../lib/utils'
import useEditor from './../../../store/use-editor'
import { type ExtraPanel, IconRail } from './icon-rail'
import { SettingsPanel, type SettingsPanelProps } from './panels/settings-panel'
import { SitePanel, type SitePanelProps } from './panels/site-panel'
interface AppSidebarProps {
appMenuButton?: ReactNode
sidebarTop?: ReactNode
settingsPanelProps?: SettingsPanelProps
sitePanelProps?: SitePanelProps
extraPanels?: ExtraPanel[]
commandPaletteEmptyAction?: CommandPaletteEmptyAction
}
export function AppSidebar({
appMenuButton,
sidebarTop,
settingsPanelProps,
sitePanelProps,
extraPanels,
commandPaletteEmptyAction,
}: AppSidebarProps) {
const activePanel = useEditor((s) => s.activeSidebarPanel)
const setActivePanel = useEditor((s) => s.setActiveSidebarPanel)
const hasActivePanel =
activePanel === 'site' ||
activePanel === 'settings' ||
Boolean(extraPanels?.some((panel) => panel.id === activePanel))
useEffect(() => {
// Widen default sidebar (288px → 432px) for better project title visibility
const store = useSidebarStore.getState()
if (store.width <= 288) {
store.setWidth(432)
}
}, [])
useEffect(() => {
if (!hasActivePanel) {
setActivePanel('site')
}
}, [hasActivePanel, setActivePanel])
const renderPanelContent = () => {
switch (activePanel) {
case 'site':
return