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 ModalFilter from "@/components/modalFilter"
import ModalSelect from "@/components/modalSelect"
import SelectForm from "@/components/selectForm"
import { Headers } from "@/constants/Headers"
import Styles from "@/constants/Styles"
import { AntDesign } from "@expo/vector-icons"
import { router, Stack } from "expo-router"
import { useState } from "react"
import { ToastAndroid, View } from "react-native"

export default function RootLayout() {
   const [isVisible, setVisible] = useState(false)
   const [isVisibleTambah, setVisibleTambah] = useState(false)
   const [isFilter, setFilter] = useState(false)
   const [isSelect, setSelect] = useState(false)
   const [choose, setChoose] = useState({ val: '', label: '' })

   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: 'Jabatan',
               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 Jabatan"
                  onPress={() => { setVisibleTambah(true) }}
               />
               <MenuItemRow
                  icon={<AntDesign name="filter" color="black" size={25} />}
                  title="Filter"
                  onPress={() => { setFilter(true) }}
               />
            </View>
         </DrawerBottom>

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

         <ModalFilter close={() => {
            setFilter(false)
            setVisible(false)
         }} open={isFilter} page="position" />

         <ModalSelect
            category="group"
            close={setSelect}
            onSelect={(value) => {
               setChoose(value)
               setSelect(false)
            }}
            title="Lembaga Desa"
            choose={choose.val}
            open={isSelect}
         />
      </>
   )
}