import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_web/pages/analytics/modules/air_quality/blocs/range_of_aqi/range_of_aqi_bloc.dart';
import 'package:syncrow_web/pages/analytics/modules/air_quality/widgets/range_of_aqi_chart.dart';
import 'package:syncrow_web/pages/analytics/modules/air_quality/widgets/range_of_aqi_chart_title.dart';
import 'package:syncrow_web/pages/analytics/widgets/analytics_chart_empty_state_widget.dart';
import 'package:syncrow_web/pages/analytics/widgets/analytics_error_widget.dart';
import 'package:syncrow_web/utils/constants/assets.dart';
import 'package:syncrow_web/utils/style.dart';

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

  @override
  Widget build(BuildContext context) {
    return BlocBuilder<RangeOfAqiBloc, RangeOfAqiState>(
      builder: (context, state) {
        return Container(
          padding: const EdgeInsetsDirectional.all(30),
          decoration: subSectionContainerDecoration.copyWith(
            borderRadius: BorderRadius.circular(30),
          ),
          child: Column(
            mainAxisSize: MainAxisSize.min,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              if (state.errorMessage != null) ...[
                AnalyticsErrorWidget(state.errorMessage),
                const SizedBox(height: 10),
              ],
              RangeOfAqiChartTitle(
                isLoading: state.status == RangeOfAqiStatus.loading,
              ),
              const SizedBox(height: 10),
              const Divider(),
              const SizedBox(height: 20),
              Visibility(
                visible: state.filteredRangeOfAqi.isNotEmpty,
                replacement: AnalyticsChartEmptyStateWidget(
                  isLoading: state.status == RangeOfAqiStatus.loading,
                  isError: state.status == RangeOfAqiStatus.failure,
                  isInitial: state.status == RangeOfAqiStatus.initial,
                  errorMessage: state.errorMessage,
                  iconPath: Assets.emptyRangeOfAqi,
                ),
                child: Expanded(
                  child: RangeOfAqiChart(
                    chartData: state.filteredRangeOfAqi,
                    selectedAqiType: state.selectedAqiType,
                  ),
                ),
              ),
            ],
          ),
        );
      },
    );
  }
}
