import React from 'react';
import type { ReactNode } from 'react';

interface ButtonOption {
  value: string;
  label: string;
  icon?: ReactNode;
}

interface ButtonGroupProps {
  options: ButtonOption[];
  value: string;
  onChange: (value: string) => void;
}

const ButtonGroup: React.FC<ButtonGroupProps> = ({ options, value, onChange }) => {
  return (
    <div className="inline-flex p-1 bg-gray-100 rounded-lg border border-gray-200">
      {options.map((option, index) => {
        const isActive = value === option.value;
        
        return (
          <button
            key={option.value}
            onClick={() => onChange(option.value)}
            className={`
              flex items-center gap-2 px-3 py-1.5 text-sm font-medium transition-all rounded-md
              ${index !== 0 ? 'border-l border-gray-300' : ''}
              ${isActive 
                ? 'bg-blue-100 text-blue-700 border-blue-500 shadow-sm' 
                : 'bg-transparent text-gray-600 hover:text-gray-900 hover:bg-gray-200'
              }
              ${isActive ? 'ring-1 ring-blue-500' : ''}
            `}
          >
            {option.icon && <span className="flex-shrink-0">{option.icon}</span>}
            <span>{option.label}</span>
          </button>
        );
      })}
    </div>
  );
};

export default ButtonGroup;