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')}
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')}