import React from 'react';
import { __ } from '@wordpress/i18n';
import { applyFilters } from '@wordpress/hooks';
import { ArrowRight, Check, FlaskConical, Gauge, HardDrive, Search, ShieldCheck, type LucideIcon } from 'lucide-react';
import type { NavigateFunction } from 'react-router-dom';
import GradeChip from './GradeChip';
import ProPill from './ProPill';
import type { CategoryKey } from '../../api';
import type { DashboardCard, DashboardLine, DashboardModelStats } from './model';
const ICONS: Record< CategoryKey, LucideIcon > = {
speed: Gauge,
seo: Search,
storage: HardDrive,
protect: ShieldCheck,
};
function EstimateChip() {
return (
{ __( 'Estimate', 'image-sizes' ) }
);
}
function LineBody( { line, cardKey }: { line: DashboardLine; cardKey: string } ) {
return (
{ line.num
? <>{ line.num }{ ' ' }{ line.label }>
: { line.label } }
{ line.tier === 'pro' &&
}
{ line.tier === 'ok' && (
{ line.status }
) }
{ line.tier === 'free' && (
{ __( 'Free fix', 'image-sizes' ) }
) }
{ ( line.note || line.estimate ) && (
{ line.note && { line.note } }
{ line.estimate && }
) }
);
}
function Line( { line, cardKey }: { line: DashboardLine; cardKey: string } ) {
if ( line.to || line.href ) {
return (
);
}
return ;
}
/**
* One of the four category cards.
*
* A line that used to be a dashboard card still runs through that card's filter, so a Pro release
* that overrides it keeps working; the default it receives is the line itself.
*/
export default function CategoryCard( { card, stats, navigate, onScan, busy }: {
card: DashboardCard;
stats: DashboardModelStats;
navigate: NavigateFunction;
onScan: () => void;
busy: boolean;
} ) {
const Icon = ICONS[ card.key ];
const fixInner = (
<>
{ card.fix.label }
>
);
const fixClass = 'flex items-center gap-1.5 pt-3 border-t border-slate-100 font-semibold text-thumbpress-primary no-underline whitespace-nowrap cursor-pointer bg-transparent border-x-0 border-b-0 text-left disabled:opacity-60';
return (
{ card.name }
{ card.lines.map( ( line ) => {
const node = ;
return (
{ line.filter
? applyFilters( `thumbpress_dashboard_card_${ line.filter }`, node, stats, navigate ) as React.ReactNode
: node }
);
} ) }
{ card.fix.scan ? (
) : (
{ fixInner }
) }
);
}