import React, { useEffect, useState } from 'react';
import { __ } from '@wordpress/i18n';
import { api } from '../api';
import { Button, Badge, Notice, Spinner, Bar, ScoreRing } from '../components/ui';
import { IconSparkle } from '../components/icons';
import KeywordSuggest from '../components/KeywordSuggest';
/**
* The AI setup wizard.
*
* The standard wizard gets a site ready for search: licence, import, profile,
* one key, discovery files, crawlers, first analysis. This one picks up where
* it stops and puts the AI to work — in the order that pays off soonest, with
* the AI doing the typing at each step and the person only choosing.
*
* Every step is backed by an endpoint that exists today, and every step is
* skippable, so the wizard can never strand someone on a stage their site does
* not need. It writes nothing until a step's own button is pressed.
*/
const STEPS = [
{ id: 'engine', label: __('Engine', 'ai-rank-suite') },
{ id: 'brief', label: __('Brief the AI', 'ai-rank-suite') },
{ id: 'score', label: __('Score', 'ai-rank-suite') },
{ id: 'describe', label: __('Descriptions', 'ai-rank-suite') },
{ id: 'faq', label: __('FAQs', 'ai-rank-suite') },
{ id: 'keywords', label: __('Keywords', 'ai-rank-suite') },
{ id: 'prompts', label: __('AI prompts', 'ai-rank-suite') },
{ id: 'routing', label: __('Routing', 'ai-rank-suite') },
{ id: 'done', label: __('Done', 'ai-rank-suite') },
];
function Shell({ title, lede, children }) {
return (
<>
{title}
{lede && (
{lede}
)}
{children}
>
);
}
/** Drive one bulk job to completion from here, with a live bar. */
function BulkStep({ action, label, openCount, onDone }) {
const [status, setStatus] = useState(null);
const [busy, setBusy] = useState(false);
const [error, setError] = useState(null);
const run = async () => {
setBusy(true);
setError(null);
try {
let s = await api.post('/bulk/start', { action, scope: 'missing' });
setStatus(s);
s = await api.post('/bulk/tick');
setStatus(s);
while (s.state === 'running') {
s = await api.post('/bulk/tick');
setStatus(s);
}
onDone(s);
} catch (e) {
// "Nothing to process" is the server saying this step is already
// done — a success in a 400's clothing.
if (/nothing to process/i.test(e.message)) {
setStatus({ state: 'done', done: 0, total: 0, progress: 100 });
onDone({ state: 'done', done: 0 });
} else {
setError(e.message);
}
} finally {
setBusy(false);
}
};
const finished = status?.state === 'done';
return (
) : (
{__('Only one engine has a key, so every job already runs on it. Add a second key on the AI Engine screen to route jobs between them.', 'ai-rank-suite')}
)}
{routing?._draft ? (
) : (
)}
)}
{step === 'done' && (
{did.brief ? '✓ ' : '– '}
{__('Briefing saved — every engine reads it before every task.', 'ai-rank-suite')} {__('AI Engine → Knowledge base', 'ai-rank-suite')}