import 'package:flutter/material.dart';
import '../theme/app_colors.dart';
import '../theme/app_text_styles.dart';
import '../theme/app_radius.dart';

enum OptionState { idle, selected, correct, wrong }

class OptionButton extends StatelessWidget {
  final String label;
  final String text;
  final OptionState state;
  final VoidCallback? onTap;

  const OptionButton({
    super.key,
    required this.label,
    required this.text,
    this.state = OptionState.idle,
    this.onTap,
  });

  @override
  Widget build(BuildContext context) {
    final (bg, borderColor, labelColor) = switch (state) {
      OptionState.idle => (AppColors.panelLight, AppColors.border, AppColors.accentLight),
      OptionState.selected => (AppColors.accentGlow, AppColors.accent, AppColors.accentLight),
      OptionState.correct => (AppColors.successBg, AppColors.success, AppColors.success),
      OptionState.wrong => (AppColors.errorBg, AppColors.error, AppColors.error),
    };

    final trailingIcon = switch (state) {
      OptionState.correct => Icons.check_circle_rounded,
      OptionState.wrong => Icons.cancel_rounded,
      _ => null,
    };

    return Material(
      color: bg,
      borderRadius: AppRadius.smAll,
      child: InkWell(
        onTap: onTap,
        borderRadius: AppRadius.smAll,
        child: AnimatedContainer(
          duration: const Duration(milliseconds: 250),
          curve: Curves.easeInOut,
          padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 12),
          decoration: BoxDecoration(
            border: Border.all(color: borderColor, width: 2),
            borderRadius: AppRadius.smAll,
          ),
          child: Row(
            children: [
              Text(
                '$label)',
                style: AppTextStyles.titleSmall.copyWith(
                  color: labelColor,
                  fontWeight: FontWeight.w800,
                ),
              ),
              const SizedBox(width: 10),
              Expanded(
                child: Text(text, style: AppTextStyles.bodyMedium),
              ),
              if (trailingIcon != null)
                Icon(trailingIcon, color: labelColor, size: 22),
            ],
          ),
        ),
      ),
    );
  }
}