import { forwardRef, useState } from 'react' import { Button } from '../../../Button' import { ButtonType, ButtonSize } from '../../../Button/types' import UnitInput from '../UnitInput' import { UnitInputSize, UnitPosition } from '../types' import { unitInputAccessibilityReport } from './UnitInputAccessibilityReport' import { generateAccessibilityReport, downloadReport, getMimeType, getFileExtension, type ReportFormat, } from '../../../shared/accessibility/reportGenerator' import { Download as DownloadIcon } from 'lucide-react' export type UnitInputAccessibilityProps = { className?: string } const UnitInputAccessibility = forwardRef< HTMLDivElement, UnitInputAccessibilityProps >(({ 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) // Demo state const [price, setPrice] = useState(undefined) const [discount, setDiscount] = useState(undefined) const [weight, setWeight] = useState(undefined) const discountError = discount !== undefined && (discount < 0 || discount > 100) ? 'Discount must be between 0% and 100%' : '' const handleDownload = () => { try { const content = generateAccessibilityReport( unitInputAccessibilityReport, { format: selectedFormat, includeTestResults, includeRecommendations, } ) const filename = `unitinput-accessibility-report-${unitInputAccessibilityReport.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( unitInputAccessibilityReport, { 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 = unitInputAccessibilityReport 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 (

UnitInput Component Accessibility

WCAG {report.wcagVersion} • {report.conformanceLevel} • {report.reportDate}
Evaluates: WCAG 2.0, 2.1, 2.2
{/* Download Options */}

Download Report

{/* Summary Cards */}
{compliantCount}
Compliant ✅
Verified & tested
{nonCompliantCount}
Non-Compliant ❌
Issues found
{unsureCount}
Unsure ⚠️
Needs verification
{complianceRate}%
Compliance Rate
Based on verified items
{/* Full Report Viewer */} {showFullReport && reportHtmlContent && (

Full Accessibility Report

Interactive HTML report (same as downloaded version)