import React, { useEffect, useState } from 'react';
import { __ } from '@wordpress/i18n';
import { api } from '../api';
import { Card, Button, Badge, Notice, Segmented } from './ui';
import { IconDoc } from './icons';
/**
* The knowledge base: what every AI call — on every engine — is briefed with.
*
* Two layers, shown as two tabs. The template is fixed and identical for all
* providers: what this plugin is, what GEO means, the house rules, and the
* live facts about this site. The owner's layer is free text, appended after
* it. "Preview" shows the assembled briefing exactly as the model receives
* it, because a summary of what is being said on your behalf is not the same
* as reading it.
*/
export default function KnowledgeBase() {
const [data, setData] = useState(null);
const [draft, setDraft] = useState(null);
const [tab, setTab] = useState('custom');
const [busy, setBusy] = useState(false);
const [saved, setSaved] = useState(false);
const [error, setError] = useState(null);
useEffect(() => {
api
.get('/ai/knowledge')
.then(setData)
.catch((e) => setError(e.message));
}, []);
if (!data) {
return (
{__( 'Tell the writer what a new colleague would need to know: what you sell, to whom, where, in which languages, what you never claim, and how you sound. Plain text; the fixed template already covers SEO and GEO rules.', 'ai-rank-suite' )}
{__( 'Fixed for every engine and every task. The site facts in it are read live from WordPress and from the Schema → Identity settings, so filling those in makes every AI output better.', 'ai-rank-suite' )}
{fixed}
{__('The complete briefing, verbatim, as the next AI call will receive it. Each task then adds its own instructions after this.', 'ai-rank-suite')}
{briefing}
{dirty && (