import { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import Layout from './components/Layout'
import Login from './pages/Login'
import Signup from './pages/Signup'
import FindId from './pages/FindId'
import ResetPw from './pages/ResetPw'
import Dashboard from './pages/Dashboard'
import StoreList from './pages/StoreList'
import TemplateList from './pages/TemplateList'
import PosCvtList from './pages/PosCvtList'
import AlarmList from './pages/AlarmList'
import HCoreStatus from './pages/HCoreStatus'
import WorkHistory from './pages/WorkHistory'
import FirmwareList from './pages/FirmwareList'
import UserList from './pages/UserList'
import ProductList from './pages/ProductList'
import TenantAdmin from './pages/TenantAdmin'
import AiAnalysis from './pages/AiAnalysis'
import TagBindingList from './pages/TagBindingList'
import UpdateQueueList from './pages/UpdateQueueList'
import MobileApp from './pages/MobileApp'
// UIWS(UIMS) 이식: 업무일지·일정·쪽지·통계
import WorklogList from './pages/uiws/WorklogList'
import ScheduleCalendar from './pages/uiws/ScheduleCalendar'
import MessageBox from './pages/uiws/MessageBox'
import StatsPivot from './pages/uiws/StatsPivot'
// UIWS system(권한관리) 이식: 역할/역할-메뉴/공통코드/메뉴/부서/거래처 (관리자 전용)
import RoleManagement from './pages/uiws/system/RoleManagement'
import RoleMenuManagement from './pages/uiws/system/RoleMenuManagement'
import CodeManagement from './pages/uiws/system/CodeManagement'
import MenuManagement from './pages/uiws/system/MenuManagement'
import DeptManagement from './pages/uiws/system/DeptManagement'
import CompanyManagement from './pages/uiws/system/CompanyManagement'
// Claude AI 전환: AI 플랫폼 설정(ADMIN)
import AiPlatformSettings from './pages/AiPlatformSettings'

const qc = new QueryClient()

export default function App() {
  return (
    <QueryClientProvider client={qc}>
      <BrowserRouter>
        <Routes>
          <Route path="/login"    element={<Login />} />
          {/* UIWS 로그인 보조 3종 — 비인증(Layout 밖) */}
          <Route path="/signup"   element={<Signup />} />
          <Route path="/find-id"  element={<FindId />} />
          <Route path="/reset-pw" element={<ResetPw />} />
          <Route element={<Layout />}>
            <Route path="/dashboard"    element={<Dashboard />} />
            <Route path="/stores"       element={<StoreList />} />
            <Route path="/templates"    element={<TemplateList />} />
            <Route path="/pos-cvt"      element={<PosCvtList />} />
            <Route path="/tag-binding"  element={<TagBindingList />} />
            <Route path="/update-queue" element={<UpdateQueueList />} />
            <Route path="/alarms"       element={<AlarmList />} />
            <Route path="/hcore"        element={<HCoreStatus />} />
            <Route path="/works"        element={<WorkHistory />} />
            <Route path="/firmware"     element={<FirmwareList />} />
            <Route path="/products"     element={<ProductList />} />
            <Route path="/users"        element={<UserList />} />
            <Route path="/tenants"      element={<TenantAdmin />} />
            <Route path="/ai"           element={<AiAnalysis />} />
            {/* 통합 메신저 앱 다운로드 QR (ITSM 중앙 APK 저장소 공개 엔드포인트 재사용·읽기전용) */}
            <Route path="/mobile-app"   element={<MobileApp />} />
            {/* UIWS(UIMS) 이식: 공통 업무협업 레이어 */}
            <Route path="/worklogs"     element={<WorklogList />} />
            <Route path="/schedules"    element={<ScheduleCalendar />} />
            <Route path="/messages"     element={<MessageBox />} />
            <Route path="/work-stats"   element={<StatsPivot />} />
            {/* UIWS 시스템관리(권한) — 관리자 전용(AdminGate + 백엔드 403) */}
            <Route path="/system/roles"      element={<RoleManagement />} />
            <Route path="/system/role-menus" element={<RoleMenuManagement />} />
            <Route path="/system/codes"      element={<CodeManagement />} />
            <Route path="/system/menus"      element={<MenuManagement />} />
            <Route path="/system/depts"      element={<DeptManagement />} />
            <Route path="/system/companies"  element={<CompanyManagement />} />
            {/* AI 플랫폼 설정 — 관리자 전용(백엔드 /api/admin/** ADMIN 게이트) */}
            <Route path="/system/ai-config"  element={<AiPlatformSettings />} />
          </Route>
          <Route path="*" element={<Navigate to="/dashboard" replace />} />
        </Routes>
      </BrowserRouter>
    </QueryClientProvider>
  )
}
