import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_web/pages/analytics/modules/analytics/blocs/analytics_tab/analytics_tab_bloc.dart';
import 'package:syncrow_web/pages/analytics/modules/analytics/enums/analytics_page_tab.dart';
import 'package:syncrow_web/pages/analytics/modules/analytics/strategies/analytics_data_loading_strategy_factory.dart';
import 'package:syncrow_web/utils/color_manager.dart';

class AnalyticsPageTabButton extends StatelessWidget {
  const AnalyticsPageTabButton({
    super.key,
    required this.tab,
    required this.isSelected,
  });

  final AnalyticsPageTab tab;
  final bool isSelected;

  @override
  Widget build(BuildContext context) {
    return TextButton(
      onPressed: () {
        AnalyticsDataLoadingStrategyFactory.getStrategy(tab).clearData(context);
        context.read<AnalyticsTabBloc>().add(
            UpdateAnalyticsTabEvent(tab),
          );
      },
      child: Text(
        tab.title,
        textAlign: TextAlign.center,
        maxLines: 1,
        softWrap: false,
        overflow: TextOverflow.ellipsis,
        style: TextStyle(
          fontWeight: isSelected ? FontWeight.w700 : FontWeight.w400,
          fontSize: 16,
          color:
              isSelected ? ColorsManager.slidingBlueColor : ColorsManager.textGray,
        ),
      ),
    );
  }
}
