"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Select = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("@chakra-ui/react");
const icons_1 = require("@chakra-ui/icons");
/**
 * Select component using Chakra UI's Select with BFUI theme customizations
 */
const Select = ({ label, error, helperText, size = 'md', isRequired = false, options, placeholder = 'Select an option', isClearable = false, isSearchable = false, icon = (0, jsx_runtime_1.jsx)(icons_1.ChevronDownIcon, {}), id, ...rest }) => {
    const inputId = id || label?.toLowerCase().replace(/\s+/g, '-');
    const bg = (0, react_1.useColorModeValue)('white', 'gray.800');
    const borderColor = (0, react_1.useColorModeValue)('gray.200', 'gray.600');
    // Group options if any have group property
    const hasGroups = options.some(option => option.group);
    const groupedOptions = hasGroups
        ? options.reduce((acc, option) => {
            const group = option.group || 'Other';
            if (!acc[group]) {
                acc[group] = [];
            }
            acc[group].push(option);
            return acc;
        }, {})
        : null;
    return ((0, jsx_runtime_1.jsxs)(react_1.FormControl, { isInvalid: !!error, isRequired: isRequired, children: [label && (0, jsx_runtime_1.jsx)(react_1.FormLabel, { htmlFor: inputId, children: label }), (0, jsx_runtime_1.jsx)(react_1.Select, { id: inputId, size: size, bg: bg, borderColor: borderColor, placeholder: placeholder, icon: icon, _hover: {
                    borderColor: (0, react_1.useColorModeValue)('gray.300', 'gray.500'),
                }, _focus: {
                    borderColor: 'blue.500',
                    boxShadow: 'outline',
                }, ...rest, children: groupedOptions
                    ? Object.entries(groupedOptions).map(([group, groupOptions]) => ((0, jsx_runtime_1.jsx)("optgroup", { label: group, children: groupOptions.map(option => ((0, jsx_runtime_1.jsx)("option", { value: option.value, disabled: !!option.isDisabled, children: option.label }, option.value))) }, group)))
                    : options.map(option => ((0, jsx_runtime_1.jsx)("option", { value: option.value, disabled: !!option.isDisabled, children: option.label }, 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.Select = Select;
exports.default = exports.Select;
//# sourceMappingURL=Select.js.map