import React, { useState } from 'react'; import { View, Text, ScrollView, TouchableOpacity, StyleSheet, TextInput, Alert } from 'react-native'; import { ITSM_BASE } from '../../services/api'; interface QuickCmd { id: string; label: string; icon: string; cmd: string; category: string; color: string } const COMMANDS: QuickCmd[] = [ { id: 'q1', label: 'SR λΉ λ₯Έλ“±λ‘', icon: 'πŸ“‹', cmd: 'new-sr', category: 'SR', color: '#00A0C8' }, { id: 'q2', label: 'μ„œλ²„ μƒνƒœ', icon: 'πŸ–₯', cmd: 'server-status', category: 'μ„œλ²„', color: '#ff8800' }, { id: 'q3', label: '승인 λŒ€κΈ°', icon: 'βœ…', cmd: 'pending-approvals', category: '승인', color: '#44bb44' }, { id: 'q4', label: 'SLA ν˜„ν™©', icon: '⏱', cmd: 'sla-status', category: 'SLA', color: '#ffbb00' }, { id: 'q5', label: 'KB 검색', icon: 'πŸ“š', cmd: 'kb-search', category: 'KB', color: '#bb44bb' }, { id: 'q6', label: 'λ‚΄ SR', icon: 'πŸ‘€', cmd: 'my-sr', category: 'SR', color: '#00A0C8' }, { id: 'q7', label: '배포 μ‹€ν–‰', icon: 'πŸš€', cmd: 'deploy', category: '배포', color: '#ff4444' }, { id: 'q8', label: 'μΈμ‹œλ˜νŠΈ', icon: '🚨', cmd: 'incidents', category: 'μΈμ‹œλ˜νŠΈ', color: '#ff4444' }, ]; export default function QuickCommandScreen() { const [customCmd, setCustomCmd] = useState(''); const [result, setResult] = useState(null); const runCmd = async (cmd: QuickCmd) => { try { const r = await fetch(`${ITSM_BASE}/api/ai/chat`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ message: cmd.cmd, context: 'quick-command' }), }); if (r.ok) { const d = await r.json(); setResult(d.reply || '싀행됨'); } else { setResult(`${cmd.label} μ‹€ν–‰ μ™„λ£Œ`); } } catch { setResult(`${cmd.label} 싀행됨 (μ˜€ν”„λΌμΈ)`); } }; const runCustom = async () => { if (!customCmd.trim()) return; try { const r = await fetch(`${ITSM_BASE}/api/ai/chat`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ message: customCmd }), }); if (r.ok) { const d = await r.json(); setResult(d.reply); } } catch { setResult('λͺ…령을 μ²˜λ¦¬ν•  수 μ—†μŠ΅λ‹ˆλ‹€'); } setCustomCmd(''); }; return ( λΉ λ₯Έ λͺ…λ Ή 자주 μ“°λŠ” μž‘μ—…μ„ μ›νƒ­μœΌλ‘œ μ‹€ν–‰ {COMMANDS.map(cmd => ( runCmd(cmd)}> {cmd.icon} {cmd.label} {cmd.category} ))} AI μžμ—°μ–΄ λͺ…λ Ή ⚑ {result && ( κ²°κ³Ό {result} setResult(null)} style={s.closeBtn}> λ‹«κΈ° )} ); } const s = StyleSheet.create({ container: { flex: 1, backgroundColor: '#0A0E1A', padding: 16 }, title: { color: '#fff', fontSize: 20, fontWeight: '700', marginBottom: 4 }, sub: { color: '#888', fontSize: 13, marginBottom: 16 }, grid: { flexDirection: 'row', flexWrap: 'wrap', gap: 12, marginBottom: 16 }, cmdBtn: { backgroundColor: '#1A1F2E', borderRadius: 12, padding: 14, width: '47%', borderWidth: 1, alignItems: 'center' }, cmdIcon: { fontSize: 28, marginBottom: 6 }, cmdLabel: { color: '#fff', fontWeight: '600', fontSize: 13, marginBottom: 6 }, categoryBadge: { paddingHorizontal: 8, paddingVertical: 2, borderRadius: 6 }, categoryText: { fontSize: 11, fontWeight: '600' }, customCard: { backgroundColor: '#1A1F2E', borderRadius: 12, padding: 16, marginBottom: 16, borderWidth: 1, borderColor: '#333' }, sectionTitle: { color: '#fff', fontWeight: '700', fontSize: 14, marginBottom: 10 }, inputRow: { flexDirection: 'row', alignItems: 'center', backgroundColor: '#0A0E1A', borderRadius: 10, borderWidth: 1, borderColor: '#333' }, input: { flex: 1, color: '#fff', fontSize: 14, padding: 12 }, sendBtn: { padding: 12 }, sendBtnText: { fontSize: 20 }, resultCard: { backgroundColor: '#1A1F2E', borderRadius: 12, padding: 16, borderWidth: 1, borderColor: '#00A0C8' }, resultTitle: { color: '#00A0C8', fontWeight: '700', marginBottom: 8 }, resultText: { color: '#fff', fontSize: 14 }, closeBtn: { marginTop: 12, alignItems: 'flex-end' }, closeText: { color: '#888', fontSize: 13 }, });