import '../scss/_button-group.scss';
import CheckIcon from '../icons/CheckIcon';

/**
 * Creates a group of connected (radio) buttons
 * @param {object} props - Props: options, value, onChange
 */
const ButtonGroup = ({ options, value, onChange, className = '' }) => {

	return (
		<div className="adpresso-button-group" role="group">
			{options.map((option) => {
				const isActive = value === option.key;
				const classNames = [
					'adpresso-button-group__button',
					isActive ? 'is-active' : '',
					option.isDestructive ? 'is-destructive' : '',
					className
				].filter(Boolean).join(' ');

				return (
					<button
						key={option.key}
						type="button"
						className={classNames}
						onClick={() => onChange(option.key)}
						aria-pressed={isActive}
					>
						<CheckIcon width="13" height="13" />
						{option.label}
					</button>
				);
			})}
		</div>
	);
};

export default ButtonGroup;
