import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:syncrow_web/common/widgets/app_loading_indicator.dart';
import 'package:syncrow_web/utils/color_manager.dart';
import 'package:syncrow_web/utils/extension/build_context_x.dart';

class AnalyticsChartEmptyStateWidget extends StatelessWidget {
  const AnalyticsChartEmptyStateWidget({
    required this.iconPath,
    this.isLoading = false,
    this.isError = false,
    this.isInitial = false,
    this.errorMessage,
    this.noDataMessage = 'No data to display',
    this.initialMessage = 'Please select a space to see data',
    super.key,
  });

  final bool isLoading;
  final bool isError;
  final bool isInitial;
  final String? errorMessage;
  final String noDataMessage;
  final String initialMessage;
  final String iconPath;

  @override
  Widget build(BuildContext context) {
    return Expanded(
      child: _buildWidgetBasedOnState(context),
    );
  }

  Widget _buildWidgetBasedOnState(BuildContext context) {
    final widgetsMap = {
      isLoading: const AppLoadingIndicator(),
      isInitial: _buildState(context, initialMessage),
      isError: _buildState(context, errorMessage ?? 'Something went wrong'),
    };

    return widgetsMap[true] ?? _buildState(context, noDataMessage);
  }

  Widget _buildState(BuildContext context, String message) {
    return Center(
      child: Column(
        spacing: 16,
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          const SizedBox(height: 16),
          Expanded(child: SvgPicture.asset(iconPath, fit: BoxFit.contain)),
          SelectableText(
            message,
            style: isError
                ? context.textTheme.bodyMedium?.copyWith(
                    color: ColorsManager.red,
                    fontSize: 16,
                    fontWeight: FontWeight.w700,
                  )
                : null,
            textAlign: TextAlign.center,
          ),
          const SizedBox(height: 16),
        ],
      ),
    );
  }
}
