import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:get/get.dart';
import 'package:qyuota/config/colors.dart';
import 'package:qyuota/config/images.dart';
import 'package:qyuota/config/text_style.dart';
import 'package:qyuota/controller/home_controller.dart';
import 'package:qyuota/view/home/home_view.dart';
import 'package:qyuota/view/profile/profile_view.dart';

class TabScreen extends StatefulWidget {
  const TabScreen({Key? key}) : super(key: key);

  @override
  State<TabScreen> createState() => _TabScreenState();
}

class _TabScreenState extends State<TabScreen> {
  final homeController = Get.put(HomeController());
  
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      bottomNavigationBar: Container(
        height: 70 + MediaQuery.of(context).padding.bottom,
        width: Get.width,
        decoration: BoxDecoration(
          color: ConstColors.whiteColor,
          boxShadow: [
            BoxShadow(
              color: const Color(0xff1E2661).withOpacity(0.06),
              blurRadius: 6,
            )
          ],
        ),
        child: Obx(
          () => Row(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            children: [
              tabCard(
                homeController.tabFlag.value == 0
                    ? DefaultImages.tab1
                    : DefaultImages.tab1Unselect,
                "Home",
                homeController.tabFlag.value == 0
                    ? ConstColors.primaryColor
                    : ConstColors.lightTextColor,
                () {
                  homeController.tabFlag.value = 0;
                },
              ),
              tabCard(
                homeController.tabFlag.value == 1
                    ? DefaultImages.tab3Select
                    : DefaultImages.tab3,
                "Profile",
                homeController.tabFlag.value == 1
                    ? ConstColors.primaryColor
                    : ConstColors.lightTextColor,
                () {
                  homeController.tabFlag.value = 1;
                },
              )
            ],
          ),
        ),
      ),
      body: Obx(
        () => homeController.tabFlag.value == 0
            ? const HomeView()
            : const ProfileView(),
      ),
    );
  }
}

Widget tabCard(String image, String text, Color color, VoidCallback onTap) {
  return InkWell(
    onTap: () {
      onTap();
    },
    child: Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        SizedBox(
          height: 24,
          width: 24,
          child: SvgPicture.asset(
            image,
            fit: BoxFit.fill,
          ),
        ),
        const SizedBox(height: 3),
        Text(
          text,
          style: pSemiBold18.copyWith(
            fontSize: 11,
            color: color,
          ),
        )
      ],
    ),
  );
}
