import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:syncrow_app/features/devices/model/smart_door_model.dart';
import 'package:syncrow_app/generated/assets.dart';

class SosStatusBar extends StatelessWidget {
  const SosStatusBar({
    required this.smartDoorModel,
    super.key,
  });

  final SmartDoorModel smartDoorModel;

  @override
  Widget build(BuildContext context) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        SvgPicture.asset(Assets.assetsIconsWifi),
        Transform.rotate(
          angle: 1.5708, // 90 degrees in radians (π/2 or 1.5708)
          child: Icon(
            _getBatteryIcon(smartDoorModel.residualElectricity),
            color: _getBatteryColor(smartDoorModel.residualElectricity),
            size: 30,
          ),
        ),
      ],
    );
  }

  IconData _getBatteryIcon(int batteryLevel) {
    // if (batteryState == BatteryState.charging) {
    //   return Icons.battery_charging_full;
    // } else
    if (batteryLevel >= 80) {
      return Icons.battery_full;
    } else if (batteryLevel >= 60) {
      return Icons.battery_4_bar;
    } else if (batteryLevel >= 40) {
      return Icons.battery_3_bar;
    } else if (batteryLevel >= 20) {
      return Icons.battery_2_bar;
    } else {
      return Icons.battery_alert;
    }
  }

  Color _getBatteryColor(int batteryLevel) {
    if (batteryLevel >= 80) {
      return Colors.green;
    } else if (batteryLevel >= 40) {
      return Colors.yellowAccent;
    } else {
      return Colors.red;
    }
  }
}
