import 'package:digiplug/bat_theme/bat_theme.dart';
import 'package:digiplug/data/models/weather.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class SummaryHeader extends StatelessWidget {
  final Weather? weather;
  final double? energyUsed;
  const SummaryHeader({
    super.key,
    this.weather,
    this.energyUsed,
  });

  @override
  Widget build(BuildContext context) {
    var theme = BatThemeData.of(context);
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 20.w, vertical: 16.h),
      decoration: BoxDecoration(
          color: theme.colors.primary.withOpacity(0.9),
          borderRadius: BorderRadius.circular(20.r),
          boxShadow: [
            BoxShadow(
              color: theme.colors.primary.withOpacity(0.3),
              blurRadius: 15,
              offset: const Offset(0, 5),
            )
          ]),
      child: weather == null
          ? const Center(child: CircularProgressIndicator(color: Colors.white))
          : Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                _buildInfoColumn(
                  context,
                  icon: Icons.location_on_outlined,
                  title: "Lokasi Anda",
                  value: weather!.location,
                ),
                _buildInfoColumn(
                  context,
                  icon: weather!.icon,
                  title: weather!.condition,
                  value: "${weather!.temperature.toStringAsFixed(1)}°C",
                ),
                _buildInfoColumn(
                  context,
                  icon: Icons.bolt_outlined,
                  title: "Pemakaian",
                  value: "${energyUsed?.toStringAsFixed(1) ?? 'N/A'} kWh",
                ),
              ],
            ),
    );
  }

  Widget _buildInfoColumn(
    BuildContext context, {
    required IconData icon,
    required String title,
    required String value,
  }) {
    final textTheme = BatThemeData.of(context).typography;
    return Column(
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        Icon(icon, size: 28.sp, color: BatPalette.white),
        SizedBox(height: 8.h),
        Text(
          title,
          style: textTheme.subtitle.copyWith(color: BatPalette.white80),
        ),
        SizedBox(height: 2.h),
        Text(
          value,
          style: textTheme.bodyCopyMedium.copyWith(
            color: BatPalette.white,
            fontWeight: FontWeight.bold,
          ),
        ),
      ],
    );
  }
}
