import 'package:flutter/material.dart';

import '../../../../common/theme/theme.dart';
import '../../../components/spacer/spacer.dart';

class ReportTopProduct extends StatelessWidget {
  const ReportTopProduct({super.key});

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.all(24),
      decoration: BoxDecoration(
        color: AppColor.surface,
        borderRadius: BorderRadius.circular(24),
        boxShadow: [
          BoxShadow(
            color: AppColor.textSecondary.withOpacity(0.1),
            blurRadius: 20,
            offset: const Offset(0, 8),
          ),
        ],
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    'Produk Terlaris',
                    style: AppStyle.xxl.copyWith(
                      color: AppColor.textPrimary,
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                  const SpaceHeight(4),
                  Text(
                    'Ranking penjualan tertinggi',
                    style: AppStyle.md.copyWith(color: AppColor.textSecondary),
                  ),
                ],
              ),
              Container(
                padding: const EdgeInsets.all(8),
                decoration: BoxDecoration(
                  color: AppColor.warning.withOpacity(0.1),
                  borderRadius: BorderRadius.circular(12),
                ),
                child: const Icon(
                  Icons.star,
                  color: AppColor.warning,
                  size: 24,
                ),
              ),
            ],
          ),
          const SpaceHeight(20),
          _buildEnhancedProductItem(
            'Kopi Americano',
            'Rp 25.000',
            '145 terjual',
            1,
          ),
          _buildEnhancedProductItem(
            'Nasi Goreng Spesial',
            'Rp 35.000',
            '98 terjual',
            2,
          ),
          _buildEnhancedProductItem(
            'Mie Ayam Bakso',
            'Rp 28.000',
            '87 terjual',
            3,
          ),
        ],
      ),
    );
  }

  Widget _buildEnhancedProductItem(
    String name,
    String price,
    String sold,
    int rank,
  ) {
    final isFirst = rank == 1;
    return Container(
      margin: const EdgeInsets.only(bottom: 16),
      padding: const EdgeInsets.all(16),
      decoration: BoxDecoration(
        gradient: isFirst
            ? LinearGradient(
                colors: [
                  AppColor.warning.withOpacity(0.1),
                  AppColor.warning.withOpacity(0.05),
                ],
                begin: Alignment.topLeft,
                end: Alignment.bottomRight,
              )
            : null,
        color: isFirst ? null : AppColor.backgroundLight,
        borderRadius: BorderRadius.circular(16),
        border: Border.all(
          color: isFirst ? AppColor.warning.withOpacity(0.3) : AppColor.border,
          width: isFirst ? 2 : 1,
        ),
      ),
      child: Row(
        children: [
          Container(
            width: 48,
            height: 48,
            decoration: BoxDecoration(
              gradient: isFirst
                  ? const LinearGradient(
                      colors: [AppColor.warning, Color(0xFFFFB74D)],
                      begin: Alignment.topLeft,
                      end: Alignment.bottomRight,
                    )
                  : LinearGradient(
                      colors: [
                        AppColor.primary.withOpacity(0.8),
                        AppColor.primaryLight.withOpacity(0.6),
                      ],
                    ),
              borderRadius: BorderRadius.circular(12),
              boxShadow: [
                BoxShadow(
                  color: isFirst
                      ? AppColor.warning.withOpacity(0.3)
                      : AppColor.primary.withOpacity(0.2),
                  blurRadius: 8,
                  offset: const Offset(0, 4),
                ),
              ],
            ),
            child: Center(
              child: isFirst
                  ? const Icon(
                      Icons.emoji_events,
                      color: AppColor.white,
                      size: 24,
                    )
                  : Text(
                      rank.toString(),
                      style: AppStyle.xl.copyWith(
                        color: AppColor.white,
                        fontWeight: FontWeight.bold,
                      ),
                    ),
            ),
          ),
          const SpaceWidth(16),
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  name,
                  style: AppStyle.lg.copyWith(
                    color: AppColor.textPrimary,
                    fontWeight: FontWeight.w600,
                  ),
                ),
                const SpaceHeight(4),
                Row(
                  children: [
                    Icon(
                      Icons.shopping_cart,
                      size: 14,
                      color: AppColor.textSecondary,
                    ),
                    const SpaceWidth(4),
                    Text(
                      sold,
                      style: AppStyle.sm.copyWith(
                        color: AppColor.textSecondary,
                      ),
                    ),
                  ],
                ),
              ],
            ),
          ),
          Text(
            price,
            style: AppStyle.lg.copyWith(
              color: isFirst ? AppColor.warning : AppColor.primary,
              fontSize: 16,
              fontWeight: FontWeight.bold,
            ),
          ),
        ],
      ),
    );
  }
}
