import React from "react"; import { useState, useEffect, useRef } from "@wordpress/element"; import { __, _n, sprintf } from "@wordpress/i18n"; import { decodeEntities } from "@wordpress/html-entities"; import { Sparkle, Spinner, IconClose, IconCheck, IconDoc } from "./icons"; import { IconDrag } from "../../icons"; /* ---------- AI badge ---------- */ export const AiBadge = ({ label }) => ( {label || __("AI-powered — no API key needed", "betterdocs")} ); /* ---------- "Generate Sample Docs" sparkle pill ---------- */ export const GenerateBtn = ({ children, onClick, disabled, block }) => ( ); /* ---------- Detecting view ---------- */ export const DetectingView = ({ title, sub }) => (
{title || __("Analyzing your site…", "betterdocs")}
{sub || __("Detecting your site type and the topics your visitors ask about.", "betterdocs")}
{[0, 1, 2].map((i) => ( ))}
); /* ---------- Editable category chips ---------- */ export function CategoryChips({ cats, setCats, emptyText }) { const remove = (id) => setCats((cs) => cs.filter((c) => c.id !== id)); if (!cats.length) { return (

{emptyText || __("All suggestions removed. Reload this page to start over with a fresh set.", "betterdocs")}

); } return (
{cats.map((c) => ( {decodeEntities(c.name)} ))}
); } /* ---------- Quota note ---------- */ export const QuotaNote = () => (
{__("You've used your free AI generation. Add your OpenAI API key in Settings to generate more — your suggested categories are saved below.", "betterdocs")}
); /* ---------- Detected profile ---------- */ export function ProfileBody({ profile, cats, setCats, quota, contentType = "docs", intent = "", setIntent }) { const site = profile?.site || {}; // Prefer the server's content-aware niche label (e.g. "AI / LLM platform"); // fall back to the plugin-type label for older profiles. const typeLabel = decodeEntities((profile?.niche_label && String(profile.niche_label)) || humanType(profile?.type)); const signals = (profile?.signals?.active_plugins || []).slice(0, 5); const storeName = decodeEntities(site.title || __("your site", "betterdocs")); // Content-type-specific scan blurb: docs vs FAQ vs WooCommerce product FAQ. const blurb = contentType === "product_faq" ? __("We scanned %s and prepared starter FAQs for your product categories, from what your products actually say.", "betterdocs") : contentType === "faq" ? __("We scanned %s and prepared a starter list of FAQs tailored to what your visitors usually ask.", "betterdocs") : __("We scanned %s and prepared a starter knowledge base tailored to what your visitors usually ask.", "betterdocs"); // Both FAQ tabs now work the same way: real detected topics as chips (the General // tab's site subjects, the WooCommerce tab's product categories), with the AI // designing the groups and writing the questions. Only docs differs. const isGeneralFaq = contentType !== "docs"; const showIntent = !!setIntent && (contentType === "docs" || isGeneralFaq); const intentCopy = isGeneralFaq ? contentType === "product_faq" ? { label: __("What should these product FAQs answer? (optional)", "betterdocs"), placeholder: __("e.g. Sizing and care questions shoppers ask before buying our apparel.", "betterdocs"), hint: __("BetterDocs AI writes an FAQ for each product category, from your real products — and attaches it to that category so it shows on those product pages.", "betterdocs"), } : { label: __("What should these FAQs answer? (optional)", "betterdocs"), placeholder: __("e.g. Questions advertisers ask before signing up — pricing, billing, campaign limits.", "betterdocs"), hint: __("BetterDocs AI groups the questions by subject the way a real FAQ page does, and answers each in a few sentences. Add a line to steer it.", "betterdocs"), } : { label: __("What should this knowledge base be about? (optional)", "betterdocs"), placeholder: __("e.g. A knowledge base for our billboard advertising platform, for both advertisers and operators.", "betterdocs"), hint: __("BetterDocs AI designs the full structure — an Introduction, a Quickstart, and in-depth guides — from your site content. Add a sentence to steer it.", "betterdocs"), }; // Count of detected subjects (chips). Docs used to also show an article count // ("3 categories, 9 docs"), but those were placeholder seed articles — the deep // outline flow right-sizes the real KB, so the number never matched. All three tabs // now show just the detected-topic count. const catCount = sprintf(_n("%d topic", "%d topics", cats.length, "betterdocs"), cats.length); return (

{sprintf(__("We detected %s", "betterdocs"), withArticle(typeLabel))}

{sprintf(blurb, storeName)}

{signals.length > 0 && (
{signals.map((s) => ( {s} ))}
)}
{showIntent && (