'use client'; import React, { useState } from 'react'; import { Treemap, Tooltip as ReTooltip, ResponsiveContainer } from 'recharts'; import IconDesktop from '@/components/icon/icon-desktop'; import IconUser from '@/components/icon/icon-user'; interface ReportMobileDesktopProps { reports: { mobile: { report: any }; desktop: { report: any }; }; loading: boolean } const ReportMobileDesktop: React.FC = ({ reports, loading }) => { const [activeTab, setActiveTab] = useState<'mobile' | 'desktop'>('mobile'); const currentReport = reports?.[activeTab]?.report || { scores: {}, metrics: {}, opportunities: [], diagnostics: {}, screenshot: '', }; const parseSavings = (value: string): number => { if (!value) return 0; const val = parseFloat(value); if (value.toLowerCase().includes('ms')) return val; if (value.toLowerCase().includes('s')) return val * 1000; return val; }; const renderScoreCircle = (score: number) => { const radius = 45; // bigger circle const strokeWidth = 10; const circumference = 2 * Math.PI * radius; const progress = (score / 100) * circumference; const color = score >= 90 ? "#22c55e" : score >= 50 ? "#eab308" : "#ef4444"; // green, yellow, red const lightColor = score >= 90 ? "#bbf7d0" : score >= 50 ? "#fef9c3" : "#fecaca"; return (
{/* background light circle */} {/* progress circle */} {score}%
); }; const renderMetrics = (metrics: Record = {}) => (
{Object.entries(metrics).map(([key, value]) => (

{key.replace(/([A-Z])/g, ' $1').replace(/^./, str => str.toUpperCase())}

{value ?? '-'}

))}
); const renderOpportunities = (opportunities: any[] = []) => (

Opportunities

{opportunities.length === 0 &&

No suggestions available.

} {opportunities.map((op, idx) => (

{op.title ?? '-'}

{op.description ?? '-'}

{op.estimatedSavings && (

Estimated Savings: {op.estimatedSavings}

)}
))}
); const renderTreeMap = (opportunities: any[] = []) => { if (opportunities.length === 0) return null; const data = opportunities.map(op => ({ name: op.title || 'Untitled', size: parseSavings(op.estimatedSavings) })); return (

Opportunities Tree Map

{ if (!payload || payload.length === 0) return null; const item = payload[0].payload; return (

{item.name}

{item.size} ms estimated savings

); }} />
); }; const renderDiagnostics = (diagnostics: any = {}) => (

Diagnostics

{Object.keys(diagnostics).length === 0 &&

No diagnostics available.

}
{Object.entries(diagnostics).map(([key, value]) => (

{key.replace(/([A-Z])/g, ' $1').replace(/^./, str => str.toUpperCase())}

{key === 'http2' && (

All resources should be served via HTTP/2 for better performance.

)}
{value ? 'Pass' : 'Fail'}
))}
); return (
{/* Tabs with your flex-col style */}
{ loading ? (
Loading...
) : ( < div className="w-full mt-4 border p-5"> {/* Top Scores */}

Diagnose performance issues

{['performance', 'accessibility', 'bestPractices', 'seo', 'pwa'].map((key) => { const score = currentReport.scores?.[key]; if (score === undefined || score === null) return null; return (
{renderScoreCircle(score)}

{key.charAt(0).toUpperCase() + key.slice(1)}

); })}
{/* Metrics */} {renderMetrics(currentReport.metrics)} {/* Opportunities */} {renderOpportunities(currentReport.opportunities)} {/* Tree Map */} {renderTreeMap(currentReport.opportunities)} {/* Diagnostics */} {renderDiagnostics(currentReport.diagnostics)} {/* Screenshot */} {currentReport.screenshot && (
{`${activeTab}
)}
) } ); }; export default ReportMobileDesktop;