import { useEffect, useState } from 'react'; import { Spinner } from '@/components/ui/spinner'; import type { StoreGeneration } from '@/types'; const generateSteps = [ 'Reading your brand description', 'Choosing colours and fonts', 'Picking the right sections', 'Writing your store text', 'Checking the design', ]; const secondsPerStep = 12; /** * Shown while the AI is working in the background. * The steps are a friendly estimate based on time passed, not exact progress. */ export default function DesignProgress({ generation, }: { generation: StoreGeneration; }) { const startedAt = generation.created_at ? new Date(generation.created_at).getTime() : null; const [now, setNow] = useState(() => Date.now()); useEffect(() => { const timer = setInterval(() => setNow(Date.now()), 1000); return () => clearInterval(timer); }, []); const elapsed = startedAt ? Math.max(0, Math.floor((now - startedAt) / 1000)) : 0; const step = Math.min( generateSteps.length - 1, Math.floor(elapsed / secondsPerStep), ); const isEdit = generation.type === 'edit'; return (

{isEdit ? 'Making your change' : 'Designing your store'}

{isEdit ? 'This usually takes a few seconds.' : `${generateSteps[step]}… This usually takes about a minute.`}

{isEdit && generation.instruction && (

“{generation.instruction}”

)}

You can leave this page. The work continues in the background.

); }