"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AccessibleRadio = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const AccessibleRadio = ({ label, name, options = [], value, defaultValue, helperText, error, isRequired = false, isDisabled = false, isHorizontal = false, showDescriptions = false, onChange, className = '', optionsClassName = '', optionClassName = '', ariaLabel, ariaDescribedby, showAccessibilityIssues = false, ...props }) => {
    // Generate an ID if not provided
    const radioGroupId = name || `radio-group-${Math.random().toString(36).substring(2, 9)}`;
    const hasError = !!error;
    const helperTextId = helperText ? `${radioGroupId}-helper-text` : undefined;
    const errorId = error ? `${radioGroupId}-error` : undefined;
    const describedBy = [helperTextId, errorId, ariaDescribedby].filter(Boolean).join(' ') || undefined;
    // Ensure options have the right format
    const formattedOptions = options.map((option, index) => {
        if (typeof option === 'string') {
            return { label: option, value: option };
        }
        return option;
    });
    // Styling classes
    const radioGroupClasses = [
        'radio-group',
        className
    ].filter(Boolean).join(' ');
    const labelClasses = [
        'block mb-2 text-sm font-medium text-gray-700',
        isRequired ? 'required' : '',
    ].filter(Boolean).join(' ');
    const optionsContainerClasses = [
        isHorizontal ? 'flex flex-wrap gap-4' : 'space-y-2',
        optionsClassName
    ].filter(Boolean).join(' ');
    const optionContainerClasses = [
        'flex items-start',
        optionClassName
    ].filter(Boolean).join(' ');
    const radioClasses = [
        'h-4 w-4 mt-1 border focus:ring-2 focus:ring-blue-500',
        hasError ? 'border-red-500 text-red-600' : 'border-gray-300 text-blue-600',
        isDisabled ? 'opacity-50 cursor-not-allowed bg-gray-100' : '',
    ].filter(Boolean).join(' ');
    const optionLabelClasses = [
        'ml-2 block text-sm font-medium text-gray-700',
        isDisabled ? 'opacity-50' : '',
    ].filter(Boolean).join(' ');
    const optionDescriptionClasses = 'ml-6 text-sm text-gray-500';
    const helperTextClasses = 'mt-1 text-sm text-gray-600';
    const errorTextClasses = 'mt-1 text-sm text-red-600';
    return ((0, jsx_runtime_1.jsxs)("div", { className: radioGroupClasses, role: "radiogroup", "aria-labelledby": `${radioGroupId}-label`, "aria-describedby": describedBy, "aria-required": isRequired, children: [label && ((0, jsx_runtime_1.jsxs)("label", { id: `${radioGroupId}-label`, className: labelClasses, children: [label, isRequired && (0, jsx_runtime_1.jsx)("span", { className: "text-red-500 ml-1", "aria-hidden": "true", children: "*" })] })), (0, jsx_runtime_1.jsx)("div", { className: optionsContainerClasses, children: formattedOptions.map((option, index) => {
                    const optionId = `${radioGroupId}-option-${index}`;
                    const isOptionDisabled = isDisabled || option.isDisabled;
                    return ((0, jsx_runtime_1.jsxs)("div", { className: optionContainerClasses, children: [(0, jsx_runtime_1.jsx)("div", { className: "flex items-center h-5", children: (0, jsx_runtime_1.jsx)("input", { type: "radio", id: optionId, name: radioGroupId, value: option.value, defaultChecked: defaultValue === option.value, checked: value === option.value, disabled: isOptionDisabled, onChange: (e) => onChange && onChange(e.target.value, e), className: radioClasses, "aria-describedby": option.description ? `${optionId}-description` : undefined, ...props }) }), (0, jsx_runtime_1.jsxs)("div", { className: "ml-2", children: [(0, jsx_runtime_1.jsx)("label", { htmlFor: optionId, className: optionLabelClasses, children: option.label }), showDescriptions && option.description && ((0, jsx_runtime_1.jsx)("p", { id: `${optionId}-description`, className: optionDescriptionClasses, children: option.description }))] })] }, optionId));
                }) }), helperText && !error && ((0, jsx_runtime_1.jsx)("div", { id: helperTextId, className: helperTextClasses, children: helperText })), error && ((0, jsx_runtime_1.jsx)("div", { id: errorId, role: "alert", className: errorTextClasses, children: error })), showAccessibilityIssues && ((0, jsx_runtime_1.jsxs)("div", { className: "mt-2 p-2 border border-yellow-400 bg-yellow-50 text-yellow-800 text-sm rounded", children: ["This is a simplified radio button group. For a fully accessible implementation, consider:", (0, jsx_runtime_1.jsxs)("ul", { className: "list-disc ml-5 mt-1", children: [(0, jsx_runtime_1.jsx)("li", { children: "Keyboard navigation between options" }), (0, jsx_runtime_1.jsx)("li", { children: "Focus management" }), (0, jsx_runtime_1.jsx)("li", { children: "Role and ARIA attributes verification" })] })] }))] }));
};
exports.AccessibleRadio = AccessibleRadio;
exports.default = exports.AccessibleRadio;
//# sourceMappingURL=AccessibleRadio.js.map