import 'package:flutter/material.dart';
import 'package:syncrow_web/pages/analytics/modules/air_quality/widgets/air_quality_end_side_widget.dart';
import 'package:syncrow_web/pages/analytics/modules/air_quality/widgets/aqi_distribution_chart_box.dart';
import 'package:syncrow_web/pages/analytics/modules/air_quality/widgets/aqi_legend.dart';
import 'package:syncrow_web/pages/analytics/modules/air_quality/widgets/range_of_aqi_chart_box.dart';

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

  static const _padding = EdgeInsetsDirectional.all(32);

  @override
  Widget build(BuildContext context) {
    return LayoutBuilder(
      builder: (context, constraints) {
        final isMediumOrLess = constraints.maxWidth <= 900;
        final height = MediaQuery.sizeOf(context).height;
        if (isMediumOrLess) {
          return SingleChildScrollView(
            padding: _padding,
            child: Column(
              spacing: 32,
              children: [
                SizedBox(
                  height: height * 0.1,
                  child: const AqiLegend(),
                ),
                SizedBox(
                  height: height * 1.2,
                  child: const AirQualityEndSideWidget(),
                ),
                SizedBox(
                  height: height * 0.5,
                  child: const RangeOfAqiChartBox(),
                ),
                SizedBox(
                  height: height * 0.5,
                  child: const AqiDistributionChartBox(),
                ),
              ],
            ),
          );
        }

        return SingleChildScrollView(
          child: Container(
            padding: _padding,
            height: height * 1.2,
            child: const Column(
              children: [
                Expanded(
                  child: Row(
                    spacing: 32,
                    children: [
                      Expanded(
                        flex: 10,
                        child: Column(
                          spacing: 20,
                          children: [
                            Expanded(flex: 2, child: AqiLegend()),
                            Expanded(flex: 12, child: RangeOfAqiChartBox()),
                            Expanded(flex: 12, child: AqiDistributionChartBox()),
                          ],
                        ),
                      ),
                      Expanded(flex: 6, child: AirQualityEndSideWidget()),
                    ],
                  ),
                ),
              ],
            ),
          ),
        );
      },
    );
  }
}
