'use client';

import { useEffect, useState } from 'react';
import { useRouter } from 'next/navigation';
import Shell from '../../components/Shell';

export default function WaitingPage() {
  const [progress, setProgress] = useState(8);
  const router = useRouter();

  useEffect(() => {
    const t = setInterval(() => {
      setProgress((p) => Math.min(p + 12, 100));
    }, 600);
    const done = setTimeout(() => {
      const sid = typeof window !== 'undefined' ? localStorage.getItem('lingjing_sid') : '';
      router.push(`/report-preview?sid=${encodeURIComponent(sid || '')}`);
    }, 5000);
    return () => {
      clearInterval(t);
      clearTimeout(done);
    };
  }, [router]);

  return (
    <Shell title="正在生成你的灵镜报告" subtitle="正在整理你的回答与关键线索，请稍候。">
      <div className="card p-6">
        <div className="h-2 w-full overflow-hidden rounded-full bg-neutral-200">
          <div className="h-full rounded-full bg-black transition-all" style={{ width: `${progress}%` }} />
        </div>
        <p className="mt-3 text-sm text-neutral-600">{progress}%</p>
      </div>
    </Shell>
  );
}
