import Styles from "@/constants/Styles"
import { useTheme } from "@/providers/ThemeProvider"
import { AntDesign } from "@expo/vector-icons"
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"
import ModalFormCreatePosition from "./modalFormCreatePosition"

export default function HeaderRightPositionList() {
   const entityUser = useSelector((state: any) => state.user)
   const [isVisible, setVisible] = useState(false)
   const [isVisibleTambah, setVisibleTambah] = useState(false)
   const [isFilter, setFilter] = useState(false)
   const { colors } = useTheme()

   return (
      <>
         {entityUser.role != 'user' ? <ButtonMenuHeader onPress={() => { setVisible(true) }} /> : <></>}
         <DrawerBottom animation="slide" isVisible={isVisible} setVisible={setVisible} title="Menu">
            <View style={Styles.rowItemsCenter}>
               <MenuItemRow
                  icon={<AntDesign name="pluscircleo" color={colors.text} size={25} />}
                  title="Tambah Jabatan"
                  onPress={() => {
                     setVisible(false)
                     setTimeout(() => {
                        setVisibleTambah(true)
                     }, 600)
                  }}
               />
               {
                  (entityUser.role == 'supadmin' || entityUser.role == 'developer') &&
                  <MenuItemRow
                     icon={<AntDesign name="filter" color={colors.text} size={25} />}
                     title="Filter"
                     onPress={() => {
                        setVisible(false)
                        setTimeout(() => {
                           setFilter(true)
                        }, 600)
                     }}
                  />
               }
            </View>
         </DrawerBottom>

         <DrawerBottom animation="slide" height={45} keyboard isVisible={isVisibleTambah} setVisible={() => setVisibleTambah(false)} title="Tambah Jabatan">
            <ModalFormCreatePosition onClose={() => setVisibleTambah(false)} />
         </DrawerBottom>

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