import { describe, it, expect, beforeEach, vi } from 'vitest'
import { render, screen } from '@/test/test-utils'

vi.mock('zustand/middleware', async () => {
  const actual = await vi.importActual('zustand/middleware')
  return { ...actual, persist: (fn: any) => fn }
})

vi.mock('@tanstack/react-router', async () => {
  const actual = await vi.importActual('@tanstack/react-router')
  return {
    ...actual,
    createFileRoute: (_path: string) => (opts: any) => ({ ...opts, path: _path }),
    Link: ({ children, to, ...props }: any) => <a href={to} {...props}>{children}</a>,
    useNavigate: () => vi.fn(),
    useLocation: () => ({ pathname: '/chat' }),
  }
})

vi.mock('@/hooks/use-chat', () => ({
  useSendMessage: () => vi.fn(),
  useChatConfig: () => ({ data: { model: 'claude-sonnet-4-20250514', enabled: true } }),
}))

vi.mock('sonner', () => ({ toast: { success: vi.fn(), error: vi.fn() } }))

import { useUIStore } from '@/stores/ui'
import { useAuthStore } from '@/stores/auth'
import { useChatStore } from '@/stores/chat'
import { Route } from './chat'

describe('chat route', () => {
  beforeEach(() => {
    useUIStore.setState({ namespace: 'default', sidebarCollapsed: false, theme: 'light' })
    useAuthStore.setState({ token: 'test-token' })
    useChatStore.setState({ messages: [], currentSessionId: null, isStreaming: false })
  })

  it('exports Route with component', () => {
    expect(Route).toBeDefined()
    expect(Route.component).toBeDefined()
    expect(Route.path).toBe('/chat')
  })

  it('renders ChatPage component', () => {
    const ChatComponent = Route.component!
    render(<ChatComponent />)
    // ChatPage renders a message input area
    expect(screen.getByPlaceholderText(/message/i)).toBeInTheDocument()
  })
})
