import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_web/pages/analytics/modules/energy_management/blocs/energy_consumption_by_phases/energy_consumption_by_phases_bloc.dart';
import 'package:syncrow_web/pages/analytics/modules/energy_management/widgets/energy_consumption_by_phases_chart.dart';
import 'package:syncrow_web/pages/analytics/modules/energy_management/widgets/energy_consumption_by_phases_title.dart';
import 'package:syncrow_web/pages/analytics/widgets/analytics_error_widget.dart';
import 'package:syncrow_web/utils/style.dart';

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

  @override
  Widget build(BuildContext context) {
    return BlocBuilder<EnergyConsumptionByPhasesBloc,
        EnergyConsumptionByPhasesState>(
      builder: (context, state) {
        return Container(
          padding: const EdgeInsetsDirectional.all(20),
          decoration: secondarySection,
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              AnalyticsErrorWidget(state.errorMessage),
              EnergyConsumptionByPhasesTitle(
                isLoading: state.status == EnergyConsumptionByPhasesStatus.loading,
              ),
              const SizedBox(height: 20),
              Expanded(
                child: EnergyConsumptionByPhasesChart(
                  energyData: state.chartData,
                ),
              ),
            ],
          ),
        );
      },
    );
  }
}
