import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:sizer/sizer.dart';

import '../../../core/app_export.dart';
import '../../../models/coupon_model.dart';

class CouponDetailModal extends StatelessWidget {
  final CouponModel coupon;
  final VoidCallback? onUseCoupon;

  const CouponDetailModal({
    super.key,
    required this.coupon,
    this.onUseCoupon,
  });

  @override
  Widget build(BuildContext context) {
    final theme = Theme.of(context);

    return Dialog(
      backgroundColor: Colors.transparent,
      insetPadding: EdgeInsets.all(4.w),
      child: Container(
        constraints: BoxConstraints(
          maxHeight: 85.h,
        ),
        decoration: BoxDecoration(
          color: theme.colorScheme.surface,
          borderRadius: BorderRadius.circular(16),
        ),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            // Close Button
            Align(
              alignment: Alignment.topRight,
              child: Padding(
                padding: EdgeInsets.all(2.w),
                child: IconButton(
                  onPressed: () => Navigator.of(context).pop(),
                  icon: CustomIconWidget(
                    iconName: 'close',
                    color: theme.colorScheme.onSurface,
                    size: 24,
                  ),
                ),
              ),
            ),
            // Content
            Flexible(
              child: Padding(
                padding: EdgeInsets.fromLTRB(6.w, 0, 6.w, 6.w),
                child: Column(
                  mainAxisSize: MainAxisSize.min,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    // Full Image
                    Container(
                      width: double.infinity,
                      height: 25.h,
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(12),
                        color: theme.colorScheme.surfaceContainerHighest,
                      ),
                      child: ClipRRect(
                        borderRadius: BorderRadius.circular(12),
                        child: coupon.imageUrl != null
                            ? CustomImageWidget(
                                imageUrl: coupon.imageUrl!,
                                width: double.infinity,
                                height: double.infinity,
                                fit: BoxFit.cover,
                                semanticLabel:
                                    'Imagen de ${coupon.businessName}',
                              )
                            : Center(
                                child: Column(
                                  mainAxisAlignment: MainAxisAlignment.center,
                                  children: [
                                    CustomIconWidget(
                                      iconName: 'image',
                                      color: theme.colorScheme.onSurfaceVariant,
                                      size: 32,
                                    ),
                                    SizedBox(height: 1.h),
                                    Text(
                                      'Sin imagen',
                                      style:
                                          theme.textTheme.bodyMedium?.copyWith(
                                        color:
                                            theme.colorScheme.onSurfaceVariant,
                                      ),
                                    ),
                                  ],
                                ),
                              ),
                      ),
                    ),
                    SizedBox(height: 4.w),
                    // Business Name
                    Text(
                      coupon.businessName,
                      style: theme.textTheme.headlineSmall?.copyWith(
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                    SizedBox(height: 2.w),
                    // Title
                    Text(
                      coupon.title,
                      style: theme.textTheme.titleMedium?.copyWith(
                        color: AppTheme.accentYellow,
                        fontWeight: FontWeight.w600,
                      ),
                    ),
                    SizedBox(height: 3.w),
                    // Description
                    Text(
                      coupon.description,
                      style: theme.textTheme.bodyMedium,
                    ),
                    SizedBox(height: 3.w),
                    // Valid Until
                    Container(
                      padding: EdgeInsets.all(3.w),
                      decoration: BoxDecoration(
                        color: theme.colorScheme.surfaceContainerHighest,
                        borderRadius: BorderRadius.circular(8),
                      ),
                      child: Row(
                        children: [
                          CustomIconWidget(
                            iconName: 'access_time',
                            color: theme.colorScheme.onSurfaceVariant,
                            size: 20,
                          ),
                          SizedBox(width: 2.w),
                          Text(
                            coupon.validUntil != null
                                ? 'Válido hasta: ${coupon.validUntilFormatted}'
                                : 'Sin fecha de vencimiento',
                            style: theme.textTheme.bodyMedium?.copyWith(
                              color: coupon.isExpired
                                  ? AppTheme.errorRed
                                  : coupon.isExpiringSoon
                                      ? Colors.orange
                                      : theme.colorScheme.onSurfaceVariant,
                              fontWeight: FontWeight.w500,
                            ),
                          ),
                        ],
                      ),
                    ),
                    SizedBox(height: 4.w),
                    // Action Buttons Row
                    Row(
                      children: [
                        // Call Button (placeholder)
                        Expanded(
                          child: OutlinedButton.icon(
                            onPressed: () {
                              HapticFeedback.lightImpact();
                              // TODO: Implement call functionality
                              ScaffoldMessenger.of(context).showSnackBar(
                                const SnackBar(
                                  content:
                                      Text('Función de llamada próximamente'),
                                ),
                              );
                            },
                            icon: CustomIconWidget(
                              iconName: 'call',
                              color: theme.colorScheme.primary,
                              size: 20,
                            ),
                            label: const Text('Llamar'),
                            style: OutlinedButton.styleFrom(
                              foregroundColor: theme.colorScheme.primary,
                              side:
                                  BorderSide(color: theme.colorScheme.outline),
                            ),
                          ),
                        ),
                        SizedBox(width: 3.w),
                        // WhatsApp Button (placeholder)
                        Expanded(
                          child: OutlinedButton.icon(
                            onPressed: () {
                              HapticFeedback.lightImpact();
                              // TODO: Implement WhatsApp functionality
                              ScaffoldMessenger.of(context).showSnackBar(
                                const SnackBar(
                                  content:
                                      Text('Función de WhatsApp próximamente'),
                                ),
                              );
                            },
                            icon: CustomIconWidget(
                              iconName: 'chat',
                              color: Colors.green,
                              size: 20,
                            ),
                            label: const Text('WhatsApp'),
                            style: OutlinedButton.styleFrom(
                              foregroundColor: Colors.green,
                              side:
                                  BorderSide(color: theme.colorScheme.outline),
                            ),
                          ),
                        ),
                        SizedBox(width: 3.w),
                        // Location Button (placeholder)
                        Expanded(
                          child: OutlinedButton.icon(
                            onPressed: () {
                              HapticFeedback.lightImpact();
                              // TODO: Implement location functionality
                              ScaffoldMessenger.of(context).showSnackBar(
                                const SnackBar(
                                  content:
                                      Text('Función de ubicación próximamente'),
                                ),
                              );
                            },
                            icon: CustomIconWidget(
                              iconName: 'location_on',
                              color: AppTheme.errorRed,
                              size: 20,
                            ),
                            label: const Text('Ubicación'),
                            style: OutlinedButton.styleFrom(
                              foregroundColor: AppTheme.errorRed,
                              side:
                                  BorderSide(color: theme.colorScheme.outline),
                            ),
                          ),
                        ),
                      ],
                    ),
                  ],
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
