import React, { useEffect, useRef } from 'react' import { __ } from '@wordpress/i18n' import { WithRestAPIContext } from '../../../hooks/useRestAPI' import { ScreenMetaSlot } from '../../common/ScreenMetaSlot' import { DemoCallout } from '../../common/demo/DemoCallout' import { DemoPageHeader } from '../../common/demo/DemoPageHeader' import { DemoSpotlight } from '../../common/demo/DemoSpotlight' import { useMarkDemoSeen } from '../../common/demo/useDemoSeen' import { getCallout } from './callouts' import { DemoPlanCard } from './DemoPlanCard' import { DemoPromptBox } from './DemoPromptBox' import { DemoResultCard } from './DemoResultCard' import { DemoSidebar } from './DemoSidebar' import { DemoMessage, DemoTransit, DemoTyping } from './DemoThread' import { AiAgentDemoUpsell } from './DemoUpsell' import { DEMO_EXAMPLES, DEMO_PROMPT, DEMO_REFINEMENT_REPLY } from './demoScript' import { useAiAgentDemo } from './useAiAgentDemo' import { hasReached } from './types' import type { DemoStage } from './types' /** * Only the steps that point at one particular thing are spotlit. Typing, * planning and building animate in place and need no dimming to be followed. */ const STAGE_SPOTLIGHTS: Partial> = { 'plan-ready': { target: '.ai-agent-plan', padding: 6 }, 'plan-accepted': { target: '.ai-agent-plan', padding: 6 }, 'result-ready': { target: '.ai-agent-result__rows', padding: 8 }, 'applying': { target: '.ai-agent-result__edit', padding: 6 } } /** * Text announced to assistive technology as each stage begins, so the * walkthrough is followable without watching the animation. */ const STAGE_ANNOUNCEMENTS: Partial> = { 'typing-prompt': __('Writing a prompt.', 'code-snippets'), 'prompt-sent': __('Prompt sent.', 'code-snippets'), 'planning': __('Planning your snippets.', 'code-snippets'), 'plan-ready': __('The plan is ready.', 'code-snippets'), 'plan-accepted': __('Plan accepted.', 'code-snippets'), 'building': __('Building the code.', 'code-snippets'), 'result-ready': __('Snippets created.', 'code-snippets'), 'refine-open': __('Choosing snippets to refine.', 'code-snippets'), 'typing-refinement': __('Writing a refinement.', 'code-snippets'), 'applying': __('Applying your changes.', 'code-snippets'), 'saved': __('Snippets updated and saved to your site.', 'code-snippets'), 'finished': __('Demo complete.', 'code-snippets') } // eslint-disable-next-line max-lines-per-function -- the timeline reads as one sequence. const AiAgentDemoPage: React.FC = () => { const { stage, typedPrompt, typedRefinement, snippets, hasStarted, isFinished, reducedMotion, play, skip, replay } = useAiAgentDemo() const markSeen = useMarkDemoSeen('ai-agent') const upsellRef = useRef(null) useEffect(() => { if (!isFinished) { return } markSeen() // The closing panel sits below the agent, so bring it into view rather // than leaving the walkthrough to end off screen. upsellRef.current?.scrollIntoView({ behavior: reducedMotion ? 'auto' : 'smooth', block: 'end' }) }, [isFinished, markSeen, reducedMotion]) const promptSent = hasReached(stage, 'prompt-sent') return ( <>
{STAGE_ANNOUNCEMENTS[stage]}
{!promptSent &&

{__('Start with these prompts', 'code-snippets')}

{DEMO_EXAMPLES.map(example => )}
}
{hasReached(stage, 'prompt-sent') && {DEMO_PROMPT}} {'planning' === stage && <> } {hasReached(stage, 'plan-ready') && !hasReached(stage, 'building') && } {'building' === stage && <> } {hasReached(stage, 'result-ready') && } {'applying' === stage && } {hasReached(stage, 'saved') && {DEMO_REFINEMENT_REPLY}}
{isFinished &&
}
) } export const AiAgentDemo: React.FC = () =>