import React, { useEffect, useState } from 'react'; import { __, _n, sprintf } from '@wordpress/i18n'; import { api } from '../api'; import { Card, Button, Notice, MetricGrid, ScoreRing, Badge, SectionTitle } from '../components/ui'; import StoreAudit from '../components/StoreAudit'; /** * The shop, on one screen. * * A merchant does not think in "feeds", "schema" and "content"; they think * in products that sell and products that do not. This screen starts with * one number, how ready the catalogue is for search and for AI answers, then * the four things that number is made of, then the ten products that pull it * down, and only then the machinery: feeds, schema, the full catalogue audit. */ export default function Shop() { const [data, setData] = useState(null); const [error, setError] = useState(null); const [busy, setBusy] = useState(false); const load = (fresh = false) => { setBusy(true); api .get(`/store/overview${fresh ? '?fresh=1' : ''}`) .then(setData) .catch((e) => setError(e.message)) .finally(() => setBusy(false)); }; useEffect(() => { load(); }, []); const go = (hash) => { window.location.hash = hash; }; if (error) return {error}; if (!data) return {__('Reading the shop…', 'ai-rank-suite')}; if (!data.active) return {__('WooCommerce is not active on this site.', 'ai-rank-suite')}; const c = data.counts || {}; const tone = (v) => (v >= 80 ? 'good' : v >= 50 ? 'warn' : 'bad'); const verdict = data.readiness >= 80 ? __('Your catalogue is ready for search and for AI answers.', 'ai-rank-suite') : data.readiness >= 50 ? __('Your catalogue is findable, but a part of it is invisible where it matters.', 'ai-rank-suite') : __('Most of your catalogue cannot be shown as products by Google or quoted by an AI yet.', 'ai-rank-suite'); const gaps = [ { id: 'no_image', label: __('Without image', 'ai-rank-suite'), value: c.no_image ?? 0 }, { id: 'no_price', label: __('Without price', 'ai-rank-suite'), value: c.no_price ?? 0 }, { id: 'no_gtin', label: __('Without GTIN', 'ai-rank-suite'), value: c.no_gtin ?? 0 }, { id: 'thin', label: __('Thin description', 'ai-rank-suite'), value: c.thin ?? 0, hint: __('Under 200 characters. An AI answer has nothing to quote.', 'ai-rank-suite') }, { id: 'no_meta_desc', label: __('No meta description', 'ai-rank-suite'), value: c.no_meta_desc ?? 0 }, { id: 'stranded', label: __('Out of stock, still indexed', 'ai-rank-suite'), value: c.stranded ?? 0 }, ]; return (

{sprintf( /* translators: %s: number of products. */ _n('%s published product', '%s published products', data.products, 'ai-rank-suite'), data.products.toLocaleString() )}

{__('Shop readiness', 'ai-rank-suite')}

{verdict}

{__('Four things make the number: product data, product text, sellable pages and product schema. Each one below says what it is missing.', 'ai-rank-suite')}

{(data.pillars || []).map((p) => (
{p.score} / 100 {p.label} {p.hint}
))}
({ id: g.id, label: g.label, value: Number(g.value).toLocaleString(), sub: g.hint || (data.products ? sprintf(__('%d%% of the catalogue', 'ai-rank-suite'), Math.round((g.value / data.products) * 100)) : ''), accent: g.value === 0 ? 'var(--ars-good)' : 'var(--ars-warning)', }))} />
0 ? sprintf( /* translators: %s: number of products without a score. */ _n('%s product has no score yet; analyse it under Content.', '%s products have no score yet; analyse them under Content.', data.unscored, 'ai-rank-suite'), data.unscored.toLocaleString() ) : __('The ten lowest AI-search scores in the catalogue.', 'ai-rank-suite') } action={} > {(data.weakest || []).length === 0 ? (

{__('No product has been scored yet. Open Content and analyse the catalogue once; the queue appears here.', 'ai-rank-suite')}

) : (
    {data.weakest.map((p) => (
  • ))}
)}
go('/schema/products')}>{__('Settings', 'ai-rank-suite')}} >
{[ ['product_schema', __('Product with price and availability', 'ai-rank-suite')], ['identifiers', __('GTIN, MPN and brand', 'ai-rank-suite')], ['shipping_details', __('Shipping details', 'ai-rank-suite')], ['return_policy', __('Return policy', 'ai-rank-suite')], ['noindex_cart', __('Cart and checkout kept out of the index', 'ai-rank-suite')], ].map(([key, label]) => (
{label} {data.schema?.[key] ? __('On', 'ai-rank-suite') : __('Off', 'ai-rank-suite')}
))}
go('/feeds')}>{__('Feeds', 'ai-rank-suite')}} >
{[ ['google', __('Google Merchant', 'ai-rank-suite')], ['meta', __('Meta catalogue', 'ai-rank-suite')], ].map(([key, label]) => { const f = data.feeds?.[key] || {}; return (
{label} {f.items === null || f.items === undefined ? ( {__('Not built', 'ai-rank-suite')} ) : ( {sprintf(_n('%s item', '%s items', f.items, 'ai-rank-suite'), Number(f.items).toLocaleString())} )}
); })}
{__('Catalogue audit', 'ai-rank-suite')}
); }