import { useState, useEffect } from 'react'; import { __ } from '@wordpress/i18n'; import { getDebugInfo, DebugInfo } from '../../api'; interface DebugProps { onDataLoaded?: (info: DebugInfo) => void; } function Badge({ ok }: { ok: boolean }) { return ( {ok ? __( 'Enabled', 'image-sizes' ) : __( 'Disabled', 'image-sizes' )} ); } function StatusBadge({ status }: { status: string | null }) { if (!status) return ; const ok = status.toLowerCase() === 'active' || status.toLowerCase() === 'valid'; return ( {status} ); } function Row({ label, value }: { label: string; value: React.ReactNode }) { return ( {label} {value} ); } function Section({ title, children }: { title: string; children: React.ReactNode }) { return (

{title}

{children}
); } const P = ({ w, h = 'h-3' }: { w: string; h?: string }) => (
); function DebugLoadingSkeleton() { type Sec = { hw: string; rows: Array<[string, string]> }; const sections: Sec[] = [ { hw: 'w-16', rows: [ ['w-24', 'w-16'], ['w-8', 'w-12'], ['w-14', 'w-16'], ['w-12', 'w-24'], ['w-32', 'w-12'], ['w-28', 'w-8' ], ['w-36', 'w-16'], ['w-40', 'w-10'], ['w-24', 'w-16'], ], }, { hw: 'w-36', rows: [['w-20', 'w-20'], ['w-32', 'w-20'], ['w-28', 'w-20']], }, { hw: 'w-28', rows: [ ['w-16', 'w-12'], ['w-20', 'w-20'], ['w-28', 'w-20'], ['w-24', 'w-12'], ['w-20', 'w-20'], ['w-36', 'w-20'], ['w-24', 'w-20'], ['w-28', 'w-20'], ['w-24', 'w-16'], ['w-32', 'w-20'], ['w-36', 'w-48'], ], }, { hw: 'w-28', rows: [['w-12', 'w-36'], ['w-16', 'w-8']], }, { hw: 'w-32', rows: [['w-24', 'w-20'], ['w-32', 'w-8']], }, ]; return (
{sections.map((sec, si) => (

{sec.rows.map(([lw, vw], ri) => ( ))}

))}
); } export default function Debug({ onDataLoaded }: DebugProps) { const [info, setInfo] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(''); useEffect(() => { getDebugInfo() .then((res) => { if (res.success && res.data) { setInfo(res.data); onDataLoaded?.(res.data); } else { setError(__( 'Failed to load debug info.', 'image-sizes' )); } }) .catch(() => setError(__( 'Failed to load debug info.', 'image-sizes' ))) .finally(() => setLoading(false)); }, []); if (loading) { return ; } if (error || !info) { return
{error || __( 'No data.', 'image-sizes' )}
; } const tp = info.thumbpress; return (
} /> } /> } />
{tp.pro_version && ( v{tp.pro_version} )} ) : ( ) } /> } /> } /> } /> } /> } /> } /> 0 ? ( {tp.disabled_sizes.join(', ')} ) : ( {__( 'None', 'image-sizes' )} ) } />
{info.active_theme.parent && ( )}
{info.active_plugins.map((plugin) => ( v{plugin.version}} /> ))}
); }