import type { CSSProperties } from 'react'
import { Badge, Button, Layout, Space } from '@arco-design/web-react'
import { IconDashboard, IconEmail, IconPlus } from '@arco-design/web-react/icon'
import type { Project, WorkbenchView } from './project-types'

const { Sider } = Layout

export function ProjectRail({
  activeProject,
  projects,
  activeView,
  onSelectWorkspace,
  onSelectWorkspaceInbox,
  onSelectProject,
}: {
  activeProject: Project
  projects: Project[]
  activeView: WorkbenchView
  onSelectWorkspace: () => void
  onSelectWorkspaceInbox: () => void
  onSelectProject: (project: Project) => void
}) {
  return (
    <Sider className="project-rail" width={96}>
      <Button
        className={activeView === 'workspace' ? 'dashboard-button active' : 'dashboard-button'}
        icon={<IconDashboard />}
        onClick={onSelectWorkspace}
        aria-label="工作台"
        title="工作台"
      />
      <Button
        className={activeView === 'workspace-inbox' ? 'dashboard-button active' : 'dashboard-button'}
        icon={<IconEmail />}
        onClick={onSelectWorkspaceInbox}
        aria-label="Inbox"
        title="Inbox"
      />
      <Space className="project-stack" direction="vertical" size={12}>
        {projects.map((project) => (
          <Badge key={project.id} count={project.badge} dot={false} className={project.urgent ? 'project-badge urgent' : 'project-badge'}>
            <button
              className={activeView === 'project' && activeProject.id === project.id ? 'project-button active' : 'project-button'}
              onClick={() => onSelectProject(project)}
              style={{ '--project-color': project.color } as CSSProperties}
              title={project.name}
            >
              {project.short}
            </button>
          </Badge>
        ))}
      </Space>
      <Button className="create-project" aria-label="新建项目" icon={<IconPlus />} title="新建项目" />
    </Sider>
  )
}
