"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.RadioGroup = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("@chakra-ui/react");
const FormGroup_js_1 = __importDefault(require("./FormGroup.js"));
/**
 * Custom radio card component
 */
const RadioCard = ({ option, isChecked, isDisabled = false, onClick }) => {
    const bg = (0, react_1.useColorModeValue)('white', 'gray.800');
    const borderColor = (0, react_1.useColorModeValue)('gray.200', 'gray.600');
    const checkedBg = (0, react_1.useColorModeValue)('blue.50', 'blue.900');
    const checkedBorder = 'blue.500';
    // Manage hover style conditionally without passing undefined
    const hoverProps = !isDisabled && !isChecked
        ? {
            _hover: {
                bg: (0, react_1.useColorModeValue)('gray.50', 'gray.700'),
                borderColor: (0, react_1.useColorModeValue)('gray.300', 'gray.500'),
            },
        }
        : {};
    return ((0, jsx_runtime_1.jsx)(react_1.Box, { as: "label", cursor: isDisabled ? 'not-allowed' : 'pointer', borderWidth: "1px", borderRadius: "md", borderColor: isChecked ? checkedBorder : borderColor, bg: isChecked ? checkedBg : bg, px: 5, py: 3, onClick: !isDisabled ? onClick : undefined, opacity: isDisabled ? 0.6 : 1, ...hoverProps, children: (0, jsx_runtime_1.jsxs)(react_1.Stack, { direction: "row", align: "center", spacing: 4, children: [option.icon && (0, jsx_runtime_1.jsx)(react_1.Box, { color: isChecked ? 'blue.500' : 'gray.400', children: option.icon }), (0, jsx_runtime_1.jsxs)(react_1.Stack, { spacing: 0, children: [(0, jsx_runtime_1.jsx)(react_1.Box, { fontWeight: "semibold", children: option.label }), option.description && ((0, jsx_runtime_1.jsx)(react_1.Box, { fontSize: "sm", color: (0, react_1.useColorModeValue)('gray.600', 'gray.400'), children: option.description }))] })] }) }));
};
/**
 * RadioGroup component using Chakra UI's RadioGroup with BFUI theme customizations
 */
const RadioGroup = ({ label, error, helperText, isRequired = false, options, direction = 'vertical', spacing = 4, size = 'md', isCard = false, colorScheme = 'blue', onChange, value, defaultValue, name, formGroupProps, ...rest }) => {
    // Build hook props without undefined values
    const radioHookProps = { name: name ?? '' };
    if (onChange)
        radioHookProps.onChange = onChange;
    if (value !== undefined)
        radioHookProps.value = value;
    if (defaultValue !== undefined)
        radioHookProps.defaultValue = defaultValue;
    const { getRootProps, getRadioProps } = (0, react_1.useRadioGroup)(radioHookProps);
    // Build FormGroup props conditionally to avoid undefined
    const groupProps = {
        ...(label !== undefined ? { label } : {}),
        isRequired,
        ...(error !== undefined ? { isInvalid: true, errorMessage: error } : {}),
        ...(helperText !== undefined ? { helperText } : {}),
        ...formGroupProps,
    };
    return ((0, jsx_runtime_1.jsx)(FormGroup_js_1.default, { ...groupProps, children: (0, jsx_runtime_1.jsxs)(react_1.FormControl, { children: [label && (0, jsx_runtime_1.jsx)(react_1.FormLabel, { children: label }), (0, jsx_runtime_1.jsx)(react_1.Stack, { ...getRootProps(), direction: direction === 'horizontal' ? 'row' : 'column', spacing: spacing, ...rest, children: options.map(option => {
                        const radioProps = getRadioProps({ value: option.value });
                        const isChecked = radioProps.isChecked;
                        if (isCard) {
                            return ((0, jsx_runtime_1.jsx)(RadioCard, { option: option, isChecked: isChecked, isDisabled: !!option.isDisabled, onClick: () => {
                                    if (!option.isDisabled && onChange) {
                                        onChange(option.value);
                                    }
                                } }, option.value));
                        }
                        return ((0, jsx_runtime_1.jsx)(react_1.Radio, { ...radioProps, size: size, colorScheme: colorScheme, isDisabled: !!option.isDisabled, children: (0, jsx_runtime_1.jsxs)(react_1.Stack, { direction: "row", align: "center", spacing: 2, children: [option.icon, (0, jsx_runtime_1.jsxs)(react_1.Stack, { spacing: 0, children: [(0, jsx_runtime_1.jsx)(react_1.Box, { children: option.label }), option.description && ((0, jsx_runtime_1.jsx)(react_1.Box, { fontSize: "sm", color: (0, react_1.useColorModeValue)('gray.600', 'gray.400'), children: option.description }))] })] }) }, option.value));
                    }) }), error ? ((0, jsx_runtime_1.jsx)(react_1.FormErrorMessage, { children: error })) : helperText ? ((0, jsx_runtime_1.jsx)(react_1.FormHelperText, { children: helperText })) : null] }) }));
};
exports.RadioGroup = RadioGroup;
exports.default = exports.RadioGroup;
//# sourceMappingURL=RadioGroup.js.map