"use strict";
/**
 * useAccessibilityChecker Hook
 * Provides easy access to accessibility checking functionality
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.useAccessibilityChecker = useAccessibilityChecker;
const react_1 = require("react");
function useAccessibilityChecker({ targetElement, autoScan = true, severity = 'error', useAI = true, scanInterval, onResultsChange } = {}) {
    const [results, setResults] = (0, react_1.useState)([]);
    const [isScanning, setIsScanning] = (0, react_1.useState)(false);
    const [error, setError] = (0, react_1.useState)(null);
    const intervalRef = (0, react_1.useRef)();
    const scan = (0, react_1.useCallback)(async () => {
        if (!targetElement) {
            return;
        }
        try {
            setIsScanning(true);
            setError(null);
            const response = await fetch('/api/accessibility/check', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                },
                body: JSON.stringify({
                    element: targetElement.outerHTML,
                    options: {
                        severity,
                        useAI,
                        scanUi: true,
                        scanContent: true,
                        conformance: 'AA'
                    }
                })
            });
            if (!response.ok) {
                throw new Error('Accessibility check failed');
            }
            const data = await response.json();
            setResults(data.results);
            onResultsChange?.(data.results);
        }
        catch (err) {
            setError(err instanceof Error ? err : new Error('Unknown error occurred'));
            console.error('Accessibility scan failed:', err);
        }
        finally {
            setIsScanning(false);
        }
    }, [targetElement, severity, useAI, onResultsChange]);
    const clearResults = (0, react_1.useCallback)(() => {
        setResults([]);
        setError(null);
    }, []);
    (0, react_1.useEffect)(() => {
        if (autoScan && targetElement) {
            scan();
        }
    }, [autoScan, targetElement, scan]);
    (0, react_1.useEffect)(() => {
        if (scanInterval && targetElement) {
            // Clear any existing interval
            if (intervalRef.current) {
                clearInterval(intervalRef.current);
            }
            // Set up new interval
            intervalRef.current = setInterval(scan, scanInterval);
            // Clean up on unmount
            return () => {
                if (intervalRef.current) {
                    clearInterval(intervalRef.current);
                }
            };
        }
    }, [scanInterval, targetElement, scan]);
    return {
        results,
        isScanning,
        scan,
        clearResults,
        error
    };
}
//# sourceMappingURL=useAccessibilityChecker.js.map