import React from 'react';
import { useRouter } from 'next/navigation';

const Button = ({
  text,
  onClick,
  href,
  className,
  primary,
  icon,
  disabled,
}) => {
  const router = useRouter();
  const baseClass =
    'px-4 py-2 rounded font-label font-medium min-h-[44px] flex items-center justify-center transition-colors';
  const primaryClass = 'bg-primary hover:bg-secondary text-white';
  const secondaryClass = 'bg-gray-300 hover:bg-gray-400 text-black';
  const buttonClass = `${baseClass} ${primary && !disabled ? primaryClass : secondaryClass} ${className}`;

  const handleClick = (e) => {
    if (href) {
      router.push(href);
    } else if (onClick) {
      onClick(e);
    }
  };

  return (
    <button className={buttonClass} onClick={handleClick} disabled={disabled}>
      {icon && text && <span className="mr-2">{icon}</span>}
      {icon && !text && icon}
      {text}
    </button>
  );
};

export default Button;
