import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:google_fonts/google_fonts.dart';
import '../providers/user_provider.dart';
import '../theme/app_theme.dart';
import 'quick_log_dialog.dart';

class QuickLogButtons extends ConsumerWidget {
  const QuickLogButtons({super.key});

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final userProfile = ref.watch(userProfileProvider);
    final isPadTrackingEnabled = userProfile?.isPadTrackingEnabled ?? false;

    return Center(
      child: Wrap(
        spacing: 12,
        runSpacing: 12,
        alignment: WrapAlignment.center,
        children: [
          _buildQuickButton(
            context,
            icon: Icons.water_drop_outlined,
            label: 'Period',
            color: AppColors.menstrualPhase,
            onTap: () => _showQuickLogDialog(context, 'period'),
          ),
          _buildQuickButton(
            context,
            icon: Icons.emoji_emotions_outlined,
            label: 'Mood',
            color: AppColors.softGold,
            onTap: () => _showQuickLogDialog(context, 'mood'),
          ),
          _buildQuickButton(
            context,
            icon: Icons.flash_on_outlined,
            label: 'Energy',
            color: AppColors.follicularPhase,
            onTap: () => _showQuickLogDialog(context, 'energy'),
          ),
          _buildQuickButton(
            context,
            icon: Icons.healing_outlined,
            label: 'Symptoms',
            color: AppColors.rose,
            onTap: () => _showQuickLogDialog(context, 'symptoms'),
          ),
          _buildQuickButton(
            context,
            icon: Icons.fastfood_outlined,
            label: 'Cravings',
            color: AppColors.lavender,
            onTap: () => _showQuickLogDialog(context, 'cravings'),
          ),
          if (isPadTrackingEnabled)
            _buildQuickButton(
              context,
              icon: Icons.sanitizer_outlined,
              label: 'Pads',
              color: AppColors.lutealPhase,
              onTap: () => _showQuickLogDialog(context, 'pads'),
            ),
          _buildQuickButton(
            context,
            icon: Icons.church_outlined,
            label: 'Prayer',
            color: AppColors.softGold, // Or a suitable color
            onTap: () => _showQuickLogDialog(context, 'prayer'),
          ),
        ],
      ),
    );
  }

  void _showQuickLogDialog(BuildContext context, String logType) {
    showDialog(
      context: context,
      builder: (context) => QuickLogDialog(logType: logType),
    );
  }

  Widget _buildQuickButton(
    BuildContext context, {
    required IconData icon,
    required String label,
    required Color color,
    required VoidCallback onTap,
  }) {
    final isDark = Theme.of(context).brightness == Brightness.dark;

    return SizedBox(
      height: 80,
      width: 75,
      child: Material(
        color: Colors.transparent,
        child: InkWell(
          onTap: onTap,
          borderRadius: BorderRadius.circular(12),
          child: Container(
            padding: const EdgeInsets.symmetric(vertical: 16),
            decoration: BoxDecoration(
              color: color.withValues(alpha: isDark ? 0.2 : 0.15),
              borderRadius: BorderRadius.circular(12),
              border: isDark
                  ? Border.all(color: color.withValues(alpha: 0.3))
                  : null,
            ),
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                Icon(icon, color: color, size: 28), // Slightly larger icon
                const SizedBox(height: 8),
                Text(
                  label,
                  textAlign: TextAlign.center,
                  style: GoogleFonts.outfit(
                    fontSize: 12, // Slightly larger text
                    fontWeight: FontWeight.w600,
                    color: isDark ? Colors.white.withValues(alpha: 0.9) : color,
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
