import { forwardRef, useState } from 'react' import Avatar from '../Avatar' import { AvatarSize, AvatarShape, AvatarOnlinePosition } from '../types' import { avatarAccessibilityReport } from './AvatarAccessibilityReport' import { generateAccessibilityReport, downloadReport, getMimeType, getFileExtension, type ReportFormat, } from '../../shared/accessibility/reportGenerator' import { Download as DownloadIcon } from 'lucide-react' import { Button } from '../../Button' import { ButtonType, ButtonSize } from '../../Button/types' export type AvatarAccessibilityProps = { className?: string } const AvatarAccessibility = forwardRef< HTMLDivElement, AvatarAccessibilityProps >(({ className }, ref) => { const [selectedFormat, setSelectedFormat] = useState('markdown') const [includeTestResults, setIncludeTestResults] = useState(true) const [includeRecommendations, setIncludeRecommendations] = useState(true) const [reportHtmlContent, setReportHtmlContent] = useState( null ) const [showFullReport, setShowFullReport] = useState(false) const handleDownload = () => { try { const content = generateAccessibilityReport( avatarAccessibilityReport, { format: selectedFormat, includeTestResults, includeRecommendations, } ) const filename = `avatar-accessibility-report-${avatarAccessibilityReport.reportDate}.${getFileExtension(selectedFormat)}` const mimeType = getMimeType(selectedFormat) downloadReport(content, filename, mimeType) } catch (error) { console.error('Error generating report:', error) alert('Failed to generate report. Please try again.') } } const handleViewReport = () => { try { const htmlContent = generateAccessibilityReport( avatarAccessibilityReport, { format: 'html', includeTestResults, includeRecommendations, } ) setReportHtmlContent(htmlContent) setShowFullReport(true) } catch (error) { console.error('Error generating report:', error) alert('Failed to generate report. Please try again.') } } const report = avatarAccessibilityReport const compliantCount = report.criteria.filter( (c) => c.status === 'compliant' ).length const nonCompliantCount = report.criteria.filter( (c) => c.status === 'non-compliant' ).length const unsureCount = report.criteria.filter( (c) => c.status === 'unsure' ).length const totalApplicable = report.criteria.filter( (c) => c.status !== 'not-applicable' ).length const complianceRate = totalApplicable > 0 ? Math.round((compliantCount / totalApplicable) * 100) : 0 return (

Avatar Accessibility Report

WCAG 2.0, 2.1, 2.2 Compliance Analysis - Level AA

Report Date: {report.reportDate}

{report.overallStatus.toUpperCase()}
{/* Compliance Stats */}
{compliantCount}
Compliant
{nonCompliantCount}
Non-Compliant
{unsureCount}
Requires Verification
{complianceRate}%
Compliance Rate
{/* Summary & Download */}

Summary

{report.summary}

Download Report

{/* Full Report Viewer */} {showFullReport && reportHtmlContent && (

Full Accessibility Report

Interactive HTML report (same as downloaded version)