import { useState } from 'react'
import { ConfigProvider } from '@arco-design/web-react'
import '@arco-design/web-react/dist/css/arco.css'
import '../App.css'
import { LoginPage } from '../pages/login'
import { ProjectPage } from '../pages/project'
import { projects } from '../pages/projects/project-data'
import type { ChannelKey, Screen, Theme, WorkbenchView } from '../pages/projects/project-types'

function App() {
  const [screen, setScreen] = useState<Screen>('login')
  const [theme, setTheme] = useState<Theme>('light')
  const [activeView, setActiveView] = useState<WorkbenchView>('workspace')
  const [activeProject, setActiveProject] = useState(projects[0])
  const [activeChannel, setActiveChannel] = useState<ChannelKey>('overview')
  const [selectedItem, setSelectedItem] = useState('Inbox 待处理（36）')

  const dark = theme === 'dark'

  return (
    <ConfigProvider>
      <main className={dark ? 'app theme-dark' : 'app'}>
        {screen === 'login' ? (
          <LoginPage onLogin={() => setScreen('workbench')} />
        ) : (
          <ProjectPage
            activeView={activeView}
            activeProject={activeProject}
            activeChannel={activeChannel}
            selectedItem={selectedItem}
            theme={theme}
            onSelectWorkspace={() => setActiveView('workspace')}
            onSelectProject={(project) => {
              setActiveProject(project)
              setActiveView('project')
            }}
            onSelectChannel={setActiveChannel}
            onSelectItem={setSelectedItem}
            onToggleTheme={() => setTheme(dark ? 'light' : 'dark')}
          />
        )}
      </main>
    </ConfigProvider>
  )
}

export default App
