import { useState, useEffect } from 'react'; import Icon from './Icon'; import { getPointsBalance, type PointsBalance } from '../lib/api'; interface Props { locale: string; dashboard: { brandName: string; navHome: string; navStore: string; navDivination: string; navManual: string; navAuto: string; navHistory: string; navLanguage: string; navSettings: string; logout: string }; divination: { questionTitle: string; questionPlaceholder: string; categoryLabel: string; categories: string; timeTitle: string; timeHint: string; guideTitle: string; guideAuto: string; shakeTitle: string; shakeBtn: string; hexPreview: string; summaryTitle: string; checkCategory: string; checkMethod: string; checkCost: string; submitBtn: string; progressLabel: string }; } export default function AutoDivinationPage({ locale, divination: d }: Props) { const cats = d.categories.split(','); const [category, setCategory] = useState(cats[0]); const [question, setQuestion] = useState(''); const [progress, setProgress] = useState(0); const [hexLines, setHexLines] = useState([]); const [isShaking, setIsShaking] = useState(false); const [points, setPoints] = useState(null); useEffect(() => { getPointsBalance().then(setPoints).catch(() => {}); }, []); const handleShake = () => { setIsShaking(true); setTimeout(() => { const newProgress = progress + 1; setProgress(newProgress); const line = Math.random() > 0.5; setHexLines(prev => [...prev, line]); setIsShaking(false); }, 600); }; const done = progress >= 6; return (

{locale === 'en' ? 'Auto Cast' : d.checkMethod.replace(/^.*:|^.*: /, '').replace('手动', '自动')}

{locale === 'en' ? 'Click the button or shake your device to generate six coin results.' : '点击按钮或摇动设备生成铜钱结果,连续 6 次形成完整卦象。'}

{locale === 'en' ? `Available ${points?.availableBalance ?? '...'} credits · This time ${points?.runCost ?? 20} credits` : `可用 ${points?.availableBalance ?? '...'} 积分 · 本次 ${points?.runCost ?? 20} 积分`}
{/* Left: Question + Time + Guide */}

{d.questionTitle}

{category}