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'; // A job normally starts within a few seconds. If it is still only queued, nothing is picking it up. const waitingTooLong = generation.status === 'queued' && elapsed > 20; 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}”

)} {waitingTooLong ? (

This has not started yet. The background worker may not be running. On a development machine, start it with “composer run dev”.

) : (

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

)}
); }