import React, { useEffect, useState } from 'react';
import { __, _n, sprintf } from '@wordpress/i18n';
import { api } from '../api';
import { Notice, Button } from './ui';
import { IconRefresh } from './icons';
/**
* The full page report.
*
* Every other tab in this drawer answers part of the question. This one
* answers the whole of it — is this page done? — as a single list of
* requirements with a pass or a fail against each, weighted by how much each
* one actually costs you.
*
* The weighting is why the number at the top is worth having. A missing meta
* description and a missing twitter:card are not the same size of problem, and
* a scorecard that averages them as if they were is a scorecard nobody should
* act on.
*/
export default function ReportTab({ postId, onGoTo }) {
const [data, setData] = useState(null);
const [error, setError] = useState(null);
const [busy, setBusy] = useState(false);
const [only, setOnly] = useState(false);
const load = () => {
setBusy(true);
api
.get(`/content/${postId}/report`)
.then(setData)
.catch((e) => setError(e.message))
.finally(() => setBusy(false));
};
useEffect(() => {
setData(null);
load();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [postId]);
if (error) return
{sprintf(__('%1$s words · about %2$s min read · %3$s headings · %4$s images · %5$s internal and %6$s external links', 'ai-rank-suite'), data.words.toLocaleString(), data.reading, data.headings, data.images, data.internal, data.external)}
{sprintf(__('Weighted by consequence — %1$s of %2$s points. A missing description counts for more than a missing card type, because it costs more.', 'ai-rank-suite'), data.earned, data.possible)}
{/* * What the work did. * * Every number on this screen described the page as it is * now, which made an evening spent on it unprovable. This * is the first reading against the latest one, so a person * can see the thing they changed. It appears only once * there are two readings and the score actually moved: a * permanent "±0" is noise. */} {!!data.change && data.change.geo !== 0 && (0 ? 'ars-c-green-ink' : 'ars-c-red-ink'} style={{ fontWeight: 600 }}> {data.change.geo > 0 ? `+${data.change.geo}` : data.change.geo} {' '} {sprintf( /* translators: 1: date of the first measurement, 2: number of measurements. */ _n('on the AI score since %1$s, over %2$s measurement.', 'on the AI score since %1$s, over %2$s measurements.', data.change.points, 'ai-rank-suite'), new Date(data.change.since * 1000).toLocaleDateString(), data.change.points )}
)}{item.detail}
{item.value && (
{item.value}
)}