import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

import '../../../cubit/menu_history_cubit.dart';
import '../../../utils/U.dart';
import '../../../utils/extensions.dart';

class BuildTab extends StatelessWidget {
  final TabController controller;
  const BuildTab({super.key, required this.controller});

  @override
  Widget build(BuildContext context) {
    return BlocBuilder<MenuHistoryCubit, MenuHistoryState>(
        builder: (context, state) {
          return Row(
            children: [
              GestureDetector(
                child: Container(
                  margin: EdgeInsets.only(left: 16),
                  padding: EdgeInsets.symmetric(vertical: 5, horizontal: 16),
                  decoration: BoxDecoration(
                      color: Colors.white,
                      border: Border(bottom: BorderSide(
                          color: state.activeTab.name == "ongoing"
                              ? primaryColor
                              : primaryColor.withValues(alpha: 0.3),
                          width: state.activeTab.name == "ongoing" ? 2 : 1))),
                  child: Text('ongoing'.tr(), style: TextStyle(
                      color: state.activeTab.name == "ongoing"
                          ? textColor
                          : textColor.withValues(alpha: 0.65), fontSize: 16)),
                ),
                onTap: () {
                  controller.animateTo(0);
                  context.read<MenuHistoryCubit>().setActiveTab(HistoryTab.ongoing);
                },
              ).withHover(),
              GestureDetector(
                child: Container(
                  padding: EdgeInsets.symmetric(vertical: 5, horizontal: 16),
                  decoration: BoxDecoration(color: Colors.white,
                      border: Border(bottom: BorderSide(
                          color: state.activeTab.name == "done"
                              ? primaryColor
                              : primaryColor.withValues(alpha: 0.3),
                          width: state.activeTab.name == "done" ? 2 : 1))),
                  child: Text('done'.tr(), style: TextStyle(
                      color: state.activeTab.name == "done"
                          ? textColor
                          : textColor.withValues(alpha: 0.65), fontSize: 16)),
                ),
                onTap: () {
                  controller.animateTo(1);
                  context.read<MenuHistoryCubit>().setActiveTab(HistoryTab.done);
                },
              ).withHover(),
            ],
          );;
        });
  }
}