import 'package:siro_driver/constant/currency.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:siro_driver/controller/home/captin/home_captain_controller.dart';
import '../../../../constant/finance_design_system.dart';

class TodayChartWidget extends StatelessWidget {
  TodayChartWidget({super.key});

  @override
  Widget build(BuildContext context) {
    return GetBuilder<HomeCaptainController>(
      builder: (hc) {
        return Container(
          padding: const EdgeInsets.all(20),
          decoration: BoxDecoration(
            color: FinanceDesignSystem.cardColor,
            borderRadius: BorderRadius.circular(FinanceDesignSystem.cardRadius),
            boxShadow: [
              BoxShadow(
                  color: Colors.black.withOpacity(0.03),
                  blurRadius: 10,
                  offset: const Offset(0, 4)),
            ],
          ),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text('Today Overview'.tr,
                  style: TextStyle(
                      fontSize: 16,
                      fontWeight: FontWeight.bold,
                      color: FinanceDesignSystem.primaryDark)),
              const SizedBox(height: 4),
              Text('Summary of your daily activity'.tr,
                  style: TextStyle(
                      fontSize: 11, color: FinanceDesignSystem.textSecondary)),
              const SizedBox(height: 20),
              _buildRow(
                  Icons.monetization_on_rounded,
                  'Earnings'.tr,
                  '${hc.totalMoneyToday} ${CurrencyHelper.currency}',
                  FinanceDesignSystem.successGreen),
              const Divider(height: 24),
              _buildRow(Icons.local_taxi_rounded, 'Rides'.tr, hc.countRideToday,
                  FinanceDesignSystem.accentBlue),
              const Divider(height: 24),
              Obx(() => _buildRow(Icons.timer_rounded, 'Online Duration'.tr,
                  hc.totalDurationDisplay.value, const Color(0xFFFF9800))),
              const Divider(height: 24),
              _buildRow(Icons.cancel_outlined, 'Refused'.tr, hc.countRefuse,
                  FinanceDesignSystem.dangerRed),
            ],
          ),
        );
      },
    );
  }

  Widget _buildRow(IconData icon, String label, String value, Color color) {
    return Row(
      children: [
        Container(
          padding: const EdgeInsets.all(8),
          decoration: BoxDecoration(
              color: color.withOpacity(0.1),
              borderRadius: BorderRadius.circular(10)),
          child: Icon(icon, color: color, size: 20),
        ),
        const SizedBox(width: 14),
        Expanded(
            child: Text(label,
                style: TextStyle(
                    fontSize: 14,
                    fontWeight: FontWeight.w500,
                    color: FinanceDesignSystem.primaryDark))),
        Text(value,
            style: TextStyle(
                fontSize: 16,
                fontWeight: FontWeight.w800,
                color: FinanceDesignSystem.primaryDark,
                fontFamily: 'digit')),
      ],
    );
  }
}
