import { forwardRef, useState } from 'react' import { Button } from '../index' import { ButtonType, ButtonSize, ButtonSubType } from '../types' import { Save, Download, Trash2, Check } from 'lucide-react' import { buttonAccessibilityReport } from './ButtonAccessibilityReport' import { generateAccessibilityReport, downloadReport, getMimeType, getFileExtension, type ReportFormat, } from '../../shared/accessibility/reportGenerator' import { Download as DownloadIcon } from 'lucide-react' export type ButtonAccessibilityProps = { className?: string } const ButtonAccessibility = forwardRef< HTMLDivElement, ButtonAccessibilityProps >(({ className }, ref) => { const [selectedFormat, setSelectedFormat] = useState('markdown') const [includeTestResults, setIncludeTestResults] = useState(true) const [includeRecommendations, setIncludeRecommendations] = useState(true) const [togglePressed, setTogglePressed] = useState(false) const [loadingButton, setLoadingButton] = useState(false) const [reportHtmlContent, setReportHtmlContent] = useState( null ) const [showFullReport, setShowFullReport] = useState(false) const handleLoadingDemo = () => { setLoadingButton(true) setTimeout(() => setLoadingButton(false), 3000) } const handleDownload = () => { try { const content = generateAccessibilityReport( buttonAccessibilityReport, { format: selectedFormat, includeTestResults, includeRecommendations, } ) const filename = `button-accessibility-report-${buttonAccessibilityReport.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( buttonAccessibilityReport, { 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 = buttonAccessibilityReport 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 (

Button Component Accessibility

WCAG {report.wcagVersion} • {report.conformanceLevel} • {report.reportDate}
Evaluates: WCAG 2.0, 2.1, 2.2
{report.overallStatus.toUpperCase()}
{compliantCount}
Compliant ✅
Verified & tested
{nonCompliantCount}
Non-Compliant ❌
Issues found
{unsureCount}
Unsure ⚠️
Needs verification
{complianceRate}%
Compliance Rate
Based on verified items
{/* Unsure Items Warning */} {unsureCount > 0 && (
⚠️

Manual Verification Required

{unsureCount} criterion/criteria marked as "unsure" require manual verification. These items need testing with contrast checkers, screen readers, or depend on application context. See verification instructions below.

)} {/* Summary & Download */}

Summary

{report.summary}

Download Report

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

Full Accessibility Report

Interactive HTML report (same as downloaded version)