import Styles from "@/constants/Styles"
import { AntDesign, MaterialCommunityIcons } from "@expo/vector-icons"
import { router } from "expo-router"
import { useState } from "react"
import { View } from "react-native"
import { useSelector } from "react-redux"
import ButtonMenuHeader from "../buttonMenuHeader"
import DrawerBottom from "../drawerBottom"
import MenuItemRow from "../menuItemRow"
import ModalFilter from "../modalFilter"

export default function HeaderRightDivisionList() {
   const [isVisible, setVisible] = useState(false)
   const [isFilter, setFilter] = useState(false)
   const entityUser = useSelector((state: any) => state.user)

   return (
      <>
         {
            entityUser.role != "user" && entityUser.role != "coadmin" &&
            <ButtonMenuHeader onPress={() => { setVisible(true) }} />
         }
         <DrawerBottom animation="slide" isVisible={isVisible} setVisible={setVisible} title="Menu">
            <View style={Styles.rowItemsCenter}>
               <MenuItemRow
                  icon={<AntDesign name="pluscircle" color="black" size={25} />}
                  title="Tambah Divisi"
                  onPress={() => {
                     setVisible(false)
                     router.push('/division/create')
                  }}
               />
               {
                  (entityUser.role == "supadmin" || entityUser.role == "developer") &&
                  <MenuItemRow
                     icon={<AntDesign name="filter" color="black" size={25} />}
                     title="Filter"
                     onPress={() => {
                        setVisible(false)
                        setTimeout(() => {
                           setFilter(true)
                        }, 600);
                     }}
                  />
               }

               {
                  (entityUser.role == "supadmin" || entityUser.role == "developer" || entityUser.role == "cosupadmin") &&
                  <MenuItemRow
                     icon={<MaterialCommunityIcons name="chart-bar" color="black" size={25} />}
                     title="Laporan"
                     onPress={() => {
                        setVisible(false)
                        router.push('/division/report')
                     }}
                  />
               }
            </View>
         </DrawerBottom>
         <ModalFilter close={() => { setFilter(false) }} open={isFilter} page="division" />
      </>
   )
}