import { useEffect } from 'react'
import { useWaste } from './store'
import { Onboarding } from './pages/Onboarding'
import { Chat } from './pages/Chat'
import './App.css'

// Default to local daemon WS IPC. Override with VITE_DAEMON_WS env var.
const DAEMON_WS = import.meta.env.VITE_DAEMON_WS ?? 'ws://127.0.0.1:17338'

export default function App() {
  const { connect, daemonStatus, localPeer } = useWaste()

  useEffect(() => {
    connect(DAEMON_WS)
  }, [connect])

  if (daemonStatus !== 'connected' || !localPeer) {
    return <Onboarding status={daemonStatus} />
  }

  return <Chat />
}
