import React from 'react';
import { TouchableOpacity, Text, ActivityIndicator, View } from 'react-native';

interface AppButtonProps {
  title: string;
  onPress: () => void;
  variant?: 'primary' | 'secondary' | 'danger' | 'outline';
  loading?: boolean;
  disabled?: boolean;
  className?: string;
}

export const AppButton: React.FC<AppButtonProps> = ({
  title,
  onPress,
  variant = 'primary',
  loading = false,
  disabled = false,
  className = '',
}) => {
  const baseClasses = 'flex-row items-center justify-center rounded-xl px-6 py-3.5 active:opacity-80';
  const variantClasses = {
    primary: 'bg-blue-600',
    secondary: 'bg-gray-200',
    danger: 'bg-red-600',
    outline: 'border-2 border-blue-600 bg-transparent',
  };
  const textClasses = {
    primary: 'text-white font-semibold text-base',
    secondary: 'text-gray-800 font-semibold text-base',
    danger: 'text-white font-semibold text-base',
    outline: 'text-blue-600 font-semibold text-base',
  };
  const disabledClass = disabled || loading ? 'opacity-50' : '';

  return (
    <TouchableOpacity
      onPress={onPress}
      disabled={disabled || loading}
      className={`${baseClasses} ${variantClasses[variant]} ${disabledClass} ${className}`}
    >
      {loading ? (
        <ActivityIndicator color={variant === 'outline' ? '#2563EB' : '#fff'} size="small" />
      ) : (
        <Text className={textClasses[variant]}>{title}</Text>
      )}
    </TouchableOpacity>
  );
};
