import ButtonBackHeader from "@/components/buttonBackHeader";
import { ButtonForm } from "@/components/buttonForm";
import ButtonMenuHeader from "@/components/buttonMenuHeader";
import DrawerBottom from "@/components/drawerBottom";
import { InputForm } from "@/components/inputForm";
import MenuItemRow from "@/components/menuItemRow";
import { Headers } from "@/constants/Headers";
import Styles from "@/constants/Styles";
import AntDesign from "@expo/vector-icons/AntDesign";
import { router, Stack } from "expo-router";
import React, { useState } from "react";
import { ToastAndroid, View } from "react-native";

export default function RootLayout() {
   const [isVisible, setVisible] = useState(false)
   const [isVisibleTambah, setVisibleTambah] = useState(false)

   function handleTambah() {
      setVisibleTambah(false)
      setVisible(false)
      ToastAndroid.show('Berhasil menambahkan data', ToastAndroid.SHORT)
   }

   return (
      <>
         <Stack screenOptions={Headers.shadow}>
            <Stack.Screen name="index" options={{
               headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
               headerTitle: 'Lembaga Desa',
               headerTitleAlign: 'center',
               headerRight: () => <ButtonMenuHeader onPress={() => { setVisible(true) }} />
            }} />
         </Stack>

         <DrawerBottom animation="slide" isVisible={isVisible} setVisible={setVisible} title="Menu">
            <View style={Styles.rowItemsCenter}>
               <MenuItemRow
                  icon={<AntDesign name="pluscircle" color="black" size={25} />}
                  title="Tambah Lembaga"
                  onPress={() => {
                     setVisible(false);
                     setTimeout(
                        () => {
                           setVisibleTambah(true)
                        },
                        100,
                     );

                  }}
               />
            </View>
         </DrawerBottom>

         <DrawerBottom animation="none" isVisible={isVisibleTambah} setVisible={setVisibleTambah} title="Tambah Lembaga Desa">
            <View style={{ justifyContent: 'space-between', flex: 1 }}>
               <View>
                  <InputForm type="default" placeholder="Nama Lembaga Desa" required label="Lembaga Desa" />
               </View>
               <View>
                  <ButtonForm text="SIMPAN" onPress={() => { handleTambah() }} />
               </View>
            </View>
         </DrawerBottom>
      </>
   )
}