import { Layout } from '@arco-design/web-react'
import { WorkspacePage } from './workspace'
import { ProjectOverview } from './projects/project-overview'
import { ProjectInspector } from './projects/project-inspector'
import { ProjectRail } from './projects/project-rail'
import { ProjectSidebar } from './projects/project-sidebar'
import { ProjectStatusbar } from './projects/project-statusbar'
import { ProjectTopbar } from './projects/project-topbar'
import type { ChannelKey, Project, Theme, WorkbenchView } from './projects/project-types'

const { Content } = Layout

export function ProjectPage({
  activeView,
  activeProject,
  activeChannel,
  selectedItem,
  theme,
  onSelectProject,
  onSelectWorkspace,
  onSelectChannel,
  onSelectItem,
  onToggleTheme,
}: {
  activeView: WorkbenchView
  activeProject: Project
  activeChannel: ChannelKey
  selectedItem: string
  theme: Theme
  onSelectProject: (project: Project) => void
  onSelectWorkspace: () => void
  onSelectChannel: (key: ChannelKey) => void
  onSelectItem: (title: string) => void
  onToggleTheme: () => void
}) {
  const isWorkspace = activeView === 'workspace'

  return (
    <Layout className="workbench-shell">
      <ProjectTopbar theme={theme} onToggleTheme={onToggleTheme} />

      <Layout className="workbench-main" hasSider>
        <ProjectRail
          activeProject={activeProject}
          activeView={activeView}
          onSelectWorkspace={onSelectWorkspace}
          onSelectProject={onSelectProject}
        />

        {!isWorkspace && (
          <ProjectSidebar
            activeView={activeView}
            activeProject={activeProject}
            activeChannel={activeChannel}
            onSelectChannel={onSelectChannel}
            onSelectItem={onSelectItem}
          />
        )}

        <Content className="stage">
          {isWorkspace ? (
            <WorkspacePage onSelectProject={onSelectProject} />
          ) : (
            <ProjectOverview onSelectItem={onSelectItem} />
          )}
        </Content>

        {!isWorkspace && (
          <ProjectInspector
            activeView={activeView}
            activeProject={activeProject}
            activeChannel={activeChannel}
            selectedItem={selectedItem}
          />
        )}
      </Layout>

      <ProjectStatusbar />
    </Layout>
  )
}
