import React from 'react';
import PropTypes from 'prop-types';
import DialogSelect from 'Framework/Components/DialogSelect';

const OptionGroup = ({
    adjustWidth,
    dialogPositioning,
    isSelected,
    itemGroup,
    onOptionSelect,
    onToggle,
    option,
    renderOption,
    relativeTo,
    selected,
}) => {
    return (
        <DialogSelect
            onChange={onOptionSelect}
            options={itemGroup.children}
            value={selected ? option : undefined}
            label={itemGroup.title}
            valueProperty="identifier"
            relativeTo={relativeTo}
            dialogPositioning={dialogPositioning}
            adjustWidth={adjustWidth}
            isSelected={isSelected}
            renderOption={renderOption}
            onToggle={onToggle}
        />
    );
};

OptionGroup.defaultProps = {
    adjustWidth: false,
    itemGroup: {},
    onToggle: () => {},
    selected: false,
};

OptionGroup.propTypes = {
    adjustWidth: PropTypes.bool,
    itemGroup: PropTypes.object,
    onToggle: PropTypes.func,
    selected: PropTypes.bool,
};

export default OptionGroup;
