import React, { useGlobal } from "reactn";
import { StyleSheet } from "react-native";
import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";
import { Motion } from "@legendapp/motion";

import { responsiveHeight } from "../actions/responsiveSizes.js";

import useLayoutType from "../hooks/useLayoutType.js";

import { Routes } from "./Routes";
import { Palette } from "../styles";

import { tabs } from "../assets";

import TabBar from "./TabBar";

import HomeStack from "./HomeStack";
import ChatStack from "./ChatStack";
import SettingsStack from "./SettingsStack";
import Library from "../screens/Library/Library.js";
import Profile from "../screens/Profile/Profile.js";
import HitParade from "../screens/HitParade/HitParade.js";
import Playbacks from "../screens/Playbacks.js";

const bottomTabStyles = StyleSheet.create({
  icon: {
    width: responsiveHeight(5),
    height: responsiveHeight(5),
    resizeMode: "contain",
  },
});

const BottomTab = createBottomTabNavigator();

export const BottomTabScreen = () => {
  const renderIcon = (icon, focused) => (
    <Motion.Image
      resizeMode={"contain"}
      animate={{
        tintColor: focused ? Palette.white : "#8B8883",
      }}
      style={[
        bottomTabStyles.icon,
        {
          width: 24,
          height: 24,
        },
      ]}
      source={icon}
    />
  );

  return (
    <BottomTab.Navigator tabBar={(props) => <TabBar {...props} />}>
      <BottomTab.Screen
        name={Routes.HomeStack}
        component={HomeStack}
        options={{
          tabBarLabel: "Créer",
          headerShown: false,
          tabBarShowLabel: true,
          tabBarIcon: ({ focused }) => renderIcon(tabs.addTab, focused),
        }}
      />
      <BottomTab.Screen
        name={Routes.HitParade}
        component={HitParade}
        options={{
          tabBarLabel: "Hit Parade",
          headerShown: false,
          tabBarShowLabel: true,
          tabBarIcon: ({ focused }) => renderIcon(tabs.ribbon, focused),
        }}
      />
      <BottomTab.Screen
        name={Routes.Playbacks}
        component={Playbacks}
        options={{
          tabBarLabel: "Playbacks",
          headerShown: false,
          tabBarShowLabel: true,
          tabBarIcon: ({ focused }) => renderIcon(tabs.mic, focused),
        }}
      />
      <BottomTab.Screen
        name={Routes.Library}
        component={Library}
        options={{
          tabBarLabel: "Librairie",
          headerShown: false,
          tabBarShowLabel: true,
          tabBarIcon: ({ focused }) => renderIcon(tabs.albums, focused),
        }}
      />
      <BottomTab.Screen
        name={Routes.Profile}
        component={Profile}
        options={{
          tabBarLabel: "Profil",
          headerShown: false,
          tabBarShowLabel: true,
          tabBarIcon: ({ focused }) => renderIcon(tabs.person, focused),
        }}
      />
    </BottomTab.Navigator>
  );
};
