import { Tabs } from 'expo-router'
import { View, Text, StyleSheet } from 'react-native'
import { COLORS } from '../../constants/Config'

function TabIcon({ icon, label, focused }: { icon: string; label: string; focused: boolean }) {
  return (
    <View style={[tab.wrap, focused && tab.active]}>
      <Text style={tab.icon}>{icon}</Text>
      <Text style={[tab.label, focused && tab.labelActive]}>{label}</Text>
    </View>
  )
}

const tab = StyleSheet.create({
  wrap:        { alignItems: 'center', paddingTop: 4, paddingHorizontal: 2 },
  active:      {},
  icon:        { fontSize: 21 },
  label:       { fontSize: 10, color: COLORS.muted, marginTop: 2, letterSpacing: 0.2 },
  labelActive: { color: COLORS.accent, fontWeight: '700' },
})

export default function TabLayout() {
  return (
    <Tabs
      screenOptions={{
        headerStyle:        { backgroundColor: COLORS.gnbBg },
        headerTintColor:    '#fff',
        headerTitleStyle:   { fontWeight: '800', fontSize: 16, letterSpacing: -0.3 },
        tabBarStyle: {
          backgroundColor: '#fff',
          borderTopColor: COLORS.border,
          borderTopWidth: 1,
          height: 62,
          elevation: 8,
          shadowColor: '#003366',
          shadowOffset: { width: 0, height: -2 },
          shadowOpacity: 0.08,
          shadowRadius: 8,
        },
        tabBarActiveTintColor:   COLORS.accent,
        tabBarInactiveTintColor: COLORS.muted,
        tabBarShowLabel:         false,
      }}
    >
      <Tabs.Screen
        name="index"
        options={{
          title: '대시보드',
          tabBarIcon: ({ focused }) => <TabIcon icon="📊" label="대시보드" focused={focused} />,
        }}
      />
      <Tabs.Screen
        name="sr"
        options={{
          title: '서비스 요청',
          tabBarIcon: ({ focused }) => <TabIcon icon="📋" label="SR" focused={focused} />,
        }}
      />
      <Tabs.Screen
        name="chat"
        options={{
          title: 'AI 챗봇',
          tabBarIcon: ({ focused }) => <TabIcon icon="🤖" label="AI" focused={focused} />,
        }}
      />
      <Tabs.Screen
        name="notifications"
        options={{
          title: '알림',
          tabBarIcon: ({ focused }) => <TabIcon icon="🔔" label="알림" focused={focused} />,
        }}
      />
      <Tabs.Screen
        name="dr"
        options={{
          title: 'DR 관제',
          tabBarIcon: ({ focused }) => <TabIcon icon="🛡️" label="DR" focused={focused} />,
        }}
      />
      <Tabs.Screen
        name="network"
        options={{
          title: '네트워크',
          tabBarIcon: ({ focused }) => <TabIcon icon="🔀" label="네트워크" focused={focused} />,
        }}
      />
      <Tabs.Screen
        name="insights"
        options={{
          title: 'AI 인사이트',
          tabBarIcon: ({ focused }) => <TabIcon icon="🧠" label="AI" focused={focused} />,
        }}
      />
      <Tabs.Screen
        name="voice"
        options={{
          title: '음성 명령',
          tabBarIcon: ({ focused }) => <TabIcon icon="🎤" label="음성" focused={focused} />,
        }}
      />
      <Tabs.Screen
        name="meeting"
        options={{
          title: '회의 녹음',
          tabBarIcon: ({ focused }) => <TabIcon icon="🎙️" label="회의" focused={focused} />,
        }}
      />
      <Tabs.Screen
        name="meeting_sr"
        options={{
          title: '액션→SR',
          href: null,
        }}
      />
      <Tabs.Screen
        name="scan"
        options={{
          title: 'QR 스캔',
          tabBarIcon: ({ focused }) => <TabIcon icon="📷" label="QR" focused={focused} />,
        }}
      />
      <Tabs.Screen
        name="settings"
        options={{
          title: '설정',
          tabBarIcon: ({ focused }) => <TabIcon icon="⚙️" label="설정" focused={focused} />,
        }}
      />

      {/* ── 승인·워크플로우 (#63~#70) — 탭바 미노출 ── */}
      <Tabs.Screen name="approval"          options={{ title: '승인 관리',    href: null }} />
      <Tabs.Screen name="delegation"        options={{ title: '대리결재',     href: null }} />
      <Tabs.Screen name="change_calendar"   options={{ title: '변경 캘린더',  href: null }} />
      <Tabs.Screen name="automation_rules"  options={{ title: '자동화 규칙',  href: null }} />
      <Tabs.Screen name="sla_exception"     options={{ title: 'SLA 예외',     href: null }} />

      {/* ── 지식베이스·문서 (#71~#77) ── */}
      <Tabs.Screen name="kb_browser"        options={{ title: '지식베이스',   href: null }} />
      <Tabs.Screen name="meeting_minutes"   options={{ title: '회의록',       href: null }} />
      <Tabs.Screen name="release_notes"     options={{ title: '릴리즈노트',   href: null }} />

      {/* ── 준수·거버넌스 (#78~#84) ── */}
      <Tabs.Screen name="csap_dashboard"   options={{ title: 'CSAP',         href: null }} />
      <Tabs.Screen name="audit_log"        options={{ title: '감사로그',      href: null }} />
      <Tabs.Screen name="pii_status"       options={{ title: 'PII/패치',      href: null }} />
      <Tabs.Screen name="ai_soc"           options={{ title: 'AI-SOC',       href: null }} />

      {/* ── UX·접근성 (#85~#92) ── */}
      <Tabs.Screen name="theme_settings"   options={{ title: 'UX 설정',      href: null }} />
      <Tabs.Screen name="accessibility"    options={{ title: '접근성',        href: null }} />

      {/* ── 통계·보고 (#93~#97) ── */}
      <Tabs.Screen name="my_stats"          options={{ title: '나의 통계',    href: null }} />
      <Tabs.Screen name="institution_compare" options={{ title: '기관별 현황', href: null }} />
      <Tabs.Screen name="deploy_history"    options={{ title: '배포 이력',    href: null }} />
      <Tabs.Screen name="pdf_share"         options={{ title: '리포트 공유',  href: null }} />
      <Tabs.Screen name="kpi_dashboard"     options={{ title: 'KPI',         href: null }} />

      {/* ── 협업·연동 (#98~#100) ── */}
      <Tabs.Screen name="sr_chat_room"      options={{ title: 'SR 채팅',      href: null }} />
      <Tabs.Screen name="qr_apk"            options={{ title: 'APK 배포',     href: null }} />
      <Tabs.Screen name="jenkins_builds"    options={{ title: 'CI/CD',        href: null }} />

      {/* ── 2세대 AIOps / 예측 (#101~#110) ── */}
      <Tabs.Screen name="failure_prediction" options={{ title: '장애 예측',   href: null }} />
      <Tabs.Screen name="capacity_plan"      options={{ title: '용량 예측',   href: null }} />
      <Tabs.Screen name="dependency_map"     options={{ title: '의존성 맵',   href: null }} />
      <Tabs.Screen name="greenops_dashboard" options={{ title: 'GreenOps',   href: null }} />
      <Tabs.Screen name="cost_advice"        options={{ title: '비용 절감',   href: null }} />
      <Tabs.Screen name="policy_alerts"      options={{ title: '정책 위반',   href: null }} />

      {/* ── 전자서명 / 하드웨어 (#111~#120) ── */}
      <Tabs.Screen name="esignature"         options={{ title: '전자서명',    href: null }} />
      <Tabs.Screen name="hw_warranty"        options={{ title: 'HW 보증',    href: null }} />
      <Tabs.Screen name="nfc_asset"          options={{ title: 'NFC 자산',   href: null }} />

      {/* ── 보안 위협 (#131~#140) ── */}
      <Tabs.Screen name="cve_detail"         options={{ title: 'CVE',         href: null }} />
      <Tabs.Screen name="threat_feed"        options={{ title: '위협 피드',   href: null }} />
      <Tabs.Screen name="ioc_search"         options={{ title: 'IoC 검색',   href: null }} />
      <Tabs.Screen name="security_score"     options={{ title: '보안 점수',   href: null }} />

      {/* ── AI 이력 / 브리핑 (#141~#150) ── */}
      <Tabs.Screen name="ai_history"         options={{ title: 'AI 대화',     href: null }} />
      <Tabs.Screen name="ai_briefing"        options={{ title: 'AI 브리핑',   href: null }} />
      <Tabs.Screen name="ollama_status"      options={{ title: 'Ollama',      href: null }} />

      {/* ── 할 일 / 캘린더 (#151~#160) ── */}
      <Tabs.Screen name="todo_list"          options={{ title: '할 일',       href: null }} />
      <Tabs.Screen name="work_calendar"      options={{ title: '업무 캘린더', href: null }} />
      <Tabs.Screen name="maintenance_window" options={{ title: '유지보수',    href: null }} />

      {/* ── 클라우드 / 인프라 (#161~#170) ── */}
      <Tabs.Screen name="vm_status"          options={{ title: 'VM 상태',    href: null }} />
      <Tabs.Screen name="ssl_alerts"         options={{ title: 'SSL 경보',   href: null }} />
      <Tabs.Screen name="eol_alerts"         options={{ title: 'EOL 경보',   href: null }} />

      {/* ── 즐겨찾기 / 최근 (#171~#180) ── */}
      <Tabs.Screen name="favorites"          options={{ title: '즐겨찾기',    href: null }} />
      <Tabs.Screen name="recent_screens"     options={{ title: '최근 방문',   href: null }} />

      {/* ── 성과 / 분석 (#181~#190) ── */}
      <Tabs.Screen name="team_leaderboard"   options={{ title: '리더보드',    href: null }} />
      <Tabs.Screen name="sr_heatmap"         options={{ title: 'SR 히트맵',  href: null }} />
      <Tabs.Screen name="health_scorecard"   options={{ title: '건강 점수',   href: null }} />

      {/* ── 공공기관 특화 (#191~#200) ── */}
      <Tabs.Screen name="citizen_requests"   options={{ title: '민원 접수',   href: null }} />
      <Tabs.Screen name="narasajang_status"  options={{ title: '나라장터',    href: null }} />
      <Tabs.Screen name="csap_audit_prep"    options={{ title: 'CSAP 심사',  href: null }} />

      {/* ── Gen3 AI-Native (#G3-1~#G3-6) ── */}
      <Tabs.Screen name="ai_agent"           options={{ title: 'AI 에이전트', href: null }} />
      <Tabs.Screen name="multimodal"         options={{ title: '멀티모달',    href: null }} />
      <Tabs.Screen name="on_device_ai"       options={{ title: '온디바이스AI',href: null }} />
      <Tabs.Screen name="camera_ar"          options={{ title: 'AR 오버레이', href: null }} />

      {/* ── Gen4 Edge AI & Smart Notify ── */}
      <Tabs.Screen name="offline_ai"         options={{ title: '오프라인 AI', href: null }} />
      <Tabs.Screen name="predictive_alert"   options={{ title: '예측 알림',   href: null }} />

      {/* ── Gen5 Collaboration & Productivity ── */}
      <Tabs.Screen name="whiteboard"         options={{ title: '화이트보드',  href: null }} />
      <Tabs.Screen name="cowork_sr"          options={{ title: 'SR 공동대응', href: null }} />
      <Tabs.Screen name="batch_action"       options={{ title: '일괄 처리',   href: null }} />
      <Tabs.Screen name="quick_command"      options={{ title: '빠른 명령',   href: null }} />
      <Tabs.Screen name="smart_search"       options={{ title: '스마트 검색', href: null }} />

      {/* ── Gen6 Autonomous ── */}
      <Tabs.Screen name="self_healing"       options={{ title: '자가 치유',   href: null }} />
      <Tabs.Screen name="auto_sr"            options={{ title: '자율 SR',     href: null }} />
      <Tabs.Screen name="ai_decision"        options={{ title: 'AI 의사결정', href: null }} />
      <Tabs.Screen name="autonomous_ops"     options={{ title: '자율 운영',   href: null }} />

      {/* ── 나라장터 소프트웨어 사업 분석 ── */}
      <Tabs.Screen name="narasajang_sw"      options={{ title: '나라장터 SW', href: null }} />
    </Tabs>
  )
}
