import 'package:flutter/material.dart';
import 'package:syncrow_web/pages/analytics/modules/energy_management/widgets/energy_consumption_per_device_chart_box.dart';
import 'package:syncrow_web/pages/analytics/modules/energy_management/widgets/power_clamp_energy_data_widget.dart';
import 'package:syncrow_web/pages/analytics/modules/energy_management/widgets/total_energy_consumption_chart_box.dart';

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

  static const _padding = EdgeInsetsDirectional.all(32);
  @override
  Widget build(BuildContext context) {
    return LayoutBuilder(
      builder: (context, constraints) {
        final isMediumOrLess = constraints.maxWidth <= 900;
        if (isMediumOrLess) {
          return SingleChildScrollView(
            padding: _padding,
            child: Column(
              spacing: 32,
              children: [
                SizedBox(
                  height: MediaQuery.sizeOf(context).height * 1.2,
                  child: const PowerClampEnergyDataWidget(),
                ),
                SizedBox(
                  height: MediaQuery.sizeOf(context).height * 0.5,
                  child: const TotalEnergyConsumptionChartBox(),
                ),
                SizedBox(
                  height: MediaQuery.sizeOf(context).height * 0.5,
                  child: const EnergyConsumptionPerDeviceChartBox(),
                ),
              ],
            ),
          );
        }

        return SingleChildScrollView(
          child: Container(
            padding: _padding,
            height: MediaQuery.sizeOf(context).height * 1.05,
            child: const Column(
              children: [
                Expanded(
                  child: Row(
                    spacing: 32,
                    children: [
                      Expanded(
                        flex: 7,
                        child: Column(
                          spacing: 20,
                          children: [
                            Expanded(child: TotalEnergyConsumptionChartBox()),
                            Expanded(child: EnergyConsumptionPerDeviceChartBox()),
                          ],
                        ),
                      ),
                      Expanded(flex: 4, child: PowerClampEnergyDataWidget()),
                    ],
                  ),
                ),
              ],
            ),
          ),
        );
      },
    );
  }
}
