import { useState, useEffect, useMemo } from 'react' import { useQuery, useMutation } from '@tanstack/react-query' import { api } from '../../api/client' import { useLayout } from '../../components/Layout' import Select from '../../components/Select' import { useSymbolStore } from './store' const TYPE_ORDER = ['아케인', '어센틱', '그랜드 어센틱'] function CharacterCard({ char, active, onSelect, onRemove }) { return (
{ if (e.target.closest('button')) return onSelect() }} className={`group relative shrink-0 w-36 rounded-xl border cursor-pointer select-none transition ${ active ? 'border-emerald-500/40 bg-emerald-500/[0.08]' : 'border-white/5 hover:border-white/15 bg-gray-950/40 hover:bg-gray-950/60' }`} > {/* 삭제 (우상단) */} {/* 내용 */}
{char.character_image ? ( ) : ( ? )}
{char.character_name}
Lv.{char.character_level} · {char.job_name}
) } function SymbolCard({ symbol, equipped, charId }) { const progress = useSymbolStore((s) => s.progress?.[charId]?.[symbol.id]) const updateSymbol = useSymbolStore((s) => s.updateSymbol) const dailyDone = progress?.dailyDone ?? false const weeklyCount = progress?.weeklyCount ?? 3 const daily = progress?.daily ?? symbol.daily_default const extra = progress?.extra ?? 0 const patch = (p) => charId && updateSymbol(charId, symbol.id, p) // 임시 목업 값 (계산 기능 미구현) const level = progress?.level ?? 0 const growth = progress?.growth ?? 0 const requireGrowth = symbol.levels?.[0]?.required_count || 0 const remainingSymbols = '-' const remainingMeso = '-' const daysLeft = '-' const completeDate = '-' return (
{symbol.image_url && ( {symbol.region} )}
{symbol.region}
Lv.{level} / {symbol.max_level}
{/* 진행도 바 */}
성장치 {growth} / {requireGrowth} {requireGrowth ? Math.min(Math.floor((growth / requireGrowth) * 100), 100) : 0}%
{/* 획득량 입력 */}
0 ? '0.7fr 1.3fr 1fr' : '1fr 1fr' }} >
patch({ daily: Number(e.target.value.replace(/[^\d]/g, '')) || 0 })} disabled={!equipped} className="w-full h-10 rounded-md border border-white/10 bg-gray-950 px-3 text-base text-right tabular-nums outline-none focus:border-emerald-500/50 hover:border-white/20 disabled:opacity-50 transition" />
{symbol.weekly_default > 0 && (
patch({ extra: Number(e.target.value.replace(/[^\d]/g, '')) || 0 })} disabled={!equipped} className="w-full h-10 rounded-md border border-white/10 bg-gray-950 px-3 text-base text-right tabular-nums outline-none focus:border-emerald-500/50 hover:border-white/20 disabled:opacity-50 transition" />
{/* 정보 */}
남은 심볼 {remainingSymbols}
필요 메소 {remainingMeso}
체납 메소 -
남은 일수 {typeof daysLeft === 'number' ? `${daysLeft}일` : daysLeft}
예상 완료일 {completeDate}
) } export default function Symbol() { const { setFullscreen } = useLayout() useEffect(() => { setFullscreen(true) return () => setFullscreen(false) }, [setFullscreen]) // 심볼 목록 (DB에서 로드) const { data: allSymbols = [] } = useQuery({ queryKey: ['symbol', 'symbols'], queryFn: () => api('/api/symbols').catch(() => []), staleTime: 5 * 60 * 1000, }) const tabs = useMemo(() => { const groups = {} for (const s of allSymbols) { if (!groups[s.type]) groups[s.type] = s } return TYPE_ORDER .filter((t) => groups[t]) .map((t) => ({ key: t, label: `${t} 심볼`, image_url: groups[t].image_url })) }, [allSymbols]) const [tab, setTab] = useState(null) useEffect(() => { if (!tab && tabs.length) setTab(tabs[0].key) }, [tabs, tab]) const characters = useSymbolStore((s) => s.characters) const selectedCharId = useSymbolStore((s) => s.selectedCharId) const addCharacter = useSymbolStore((s) => s.addCharacter) const removeCharacter = useSymbolStore((s) => s.removeCharacter) const selectCharacter = useSymbolStore((s) => s.selectCharacter) const [addName, setAddName] = useState('') const [addError, setAddError] = useState('') const symbols = allSymbols.filter((s) => s.type === tab) const tabInfo = tabs.find((t) => t.key === tab) const searchMutation = useMutation({ mutationFn: (name) => api(`/api/character/search?name=${encodeURIComponent(name)}`), onSuccess: (data) => { if (characters.find((c) => c.character_name === data.character_name)) { setAddError('이미 추가된 캐릭터입니다') return } setAddError('') setAddName('') addCharacter(data) }, onError: (err) => setAddError(err.message || '조회 실패'), }) const handleSearch = (e) => { e.preventDefault() const n = addName.trim() if (!n) return setAddError('') searchMutation.mutate(n) } // 임시: 첫 번째 심볼만 장착된 것으로 표시 const isEquipped = (i) => i === 0 return (
{/* 캐릭터 조회 */}
{ setAddName(e.target.value); if (addError) setAddError('') }} placeholder="캐릭터 닉네임으로 장착 심볼 불러오기" className="w-full h-12 box-border rounded-lg border border-white/10 bg-gray-950 pl-10 pr-4 text-base outline-none focus:border-emerald-500/60 hover:border-white/20 transition" />
{addError &&

{addError}

} {/* 캐릭터 목록 */} {characters.length > 0 && (
{characters.map((c) => ( selectCharacter(c.id)} onRemove={() => removeCharacter(c.id)} /> ))}
)}
{/* 심볼 타입 탭 */}
{tabs.map((t) => ( ))}
{/* 심볼 카드 그리드 */}
{symbols.map((s, i) => ( ))}
{/* 전체 요약 */}
{tabInfo?.label} 전체 만렙 완료 예상일
2026년 09월 12일 (토)
누적 체납 메소
108,000,000
누적 필요 메소
768,000,000
) }