import AlertKonfirmasi from "@/components/alertKonfirmasi";
import BorderBottomItem from "@/components/borderBottomItem";
import { ButtonForm } from "@/components/buttonForm";
import ButtonTab from "@/components/buttonTab";
import DrawerBottom from "@/components/drawerBottom";
import { InputForm } from "@/components/inputForm";
import InputSearch from "@/components/inputSearch";
import MenuItemRow from "@/components/menuItemRow";
import { ColorsStatus } from "@/constants/ColorsStatus";
import Styles from "@/constants/Styles";
import { AntDesign, Feather, MaterialCommunityIcons } from "@expo/vector-icons";
import { router, useLocalSearchParams } from "expo-router";
import { useState } from "react";
import { SafeAreaView, ScrollView, Text, ToastAndroid, View } from "react-native";

export default function Index() {
   const { active } = useLocalSearchParams<{ active?: string }>()
   const [isModal, setModal] = useState(false)
   const [isVisibleEdit, setVisibleEdit] = useState(false)

   function handleEdit() {
      setVisibleEdit(false)
      setModal(false)
      ToastAndroid.show('Berhasil mengupdate data', ToastAndroid.SHORT)
   }

   return (
      <SafeAreaView>
         <ScrollView>
            <View style={[Styles.p15]}>
               <View style={[Styles.wrapBtnTab]}>
                  <ButtonTab
                     active={active == "false" ? "false" : "true"}
                     value="true"
                     onPress={() => { router.push('/position?active=true') }}
                     label="Aktif"
                     icon={<Feather name="check-circle" color={active == "true" ? 'white' : 'black'} size={20} />}
                     n={2} />
                  <ButtonTab
                     active={active == "false" ? "false" : "true"}
                     value="false"
                     onPress={() => { router.push('/position?active=false') }}
                     label="Tidak Aktif"
                     icon={<AntDesign name="closecircleo" color={active == "false" ? 'white' : 'black'} size={20} />}
                     n={2} />
               </View>
               <InputSearch />
               <View style={[Styles.mv05]}>
                  <Text>Filter : Dinas</Text>
               </View>
               <View>
                  <BorderBottomItem
                     onPress={() => { setModal(true) }}
                     borderType="all"
                     icon={
                        <View style={[Styles.iconContent, ColorsStatus.lightGreen]}>
                           <MaterialCommunityIcons name="account-tie" size={25} color={'#384288'} />
                        </View>
                     }
                     title="Anggota"
                     subtitle="Dinas"
                  />
                  <BorderBottomItem
                     onPress={() => { setModal(true) }}
                     borderType="all"
                     icon={
                        <View style={[Styles.iconContent, ColorsStatus.lightGreen]}>
                           <MaterialCommunityIcons name="account-tie" size={25} color={'#384288'} />
                        </View>
                     }
                     title="Bendahara"
                     subtitle="Dinas"
                  />
                  <BorderBottomItem
                     onPress={() => { setModal(true) }}
                     borderType="all"
                     icon={
                        <View style={[Styles.iconContent, ColorsStatus.lightGreen]}>
                           <MaterialCommunityIcons name="account-tie" size={25} color={'#384288'} />
                        </View>
                     }
                     title="Ketua"
                     subtitle="Dinas"
                  />
                  <BorderBottomItem
                     onPress={() => { setModal(true) }}
                     borderType="all"
                     icon={
                        <View style={[Styles.iconContent, ColorsStatus.lightGreen]}>
                           <MaterialCommunityIcons name="account-tie" size={25} color={'#384288'} />
                        </View>
                     }
                     title="Sekretaris"
                     subtitle="Dinas"
                  />
                  <BorderBottomItem
                     onPress={() => { setModal(true) }}
                     borderType="all"
                     icon={
                        <View style={[Styles.iconContent, ColorsStatus.lightGreen]}>
                           <MaterialCommunityIcons name="account-tie" size={25} color={'#384288'} />
                        </View>
                     }
                     title="Kepala TU"
                     subtitle="Dinas"
                  />
                  <BorderBottomItem
                     onPress={() => { setModal(true) }}
                     borderType="all"
                     icon={
                        <View style={[Styles.iconContent, ColorsStatus.lightGreen]}>
                           <MaterialCommunityIcons name="account-tie" size={25} color={'#384288'} />
                        </View>
                     }
                     title="Wakil Kepala TU"
                     subtitle="Dinas"
                  />
               </View>
            </View>
         </ScrollView>

         <DrawerBottom animation="slide" isVisible={isModal} setVisible={setModal} title="Menu">
            <View style={Styles.rowItemsCenter}>
               <MenuItemRow
                  icon={<MaterialCommunityIcons name="toggle-switch-off-outline" color="black" size={25} />}
                  title="Non Aktifkan"
                  onPress={() => {
                     AlertKonfirmasi({
                        title: 'Konfirmasi',
                        desc: 'Apakah anda yakin ingin menonaktifkan data?',
                        onPress: () => { handleEdit() }
                     })
                  }}
               />
               <MenuItemRow
                  icon={<MaterialCommunityIcons name="pencil-outline" color="black" size={25} />}
                  title="Edit"
                  onPress={() => { setVisibleEdit(true) }}
               />
            </View>
         </DrawerBottom>


         <DrawerBottom animation="none" isVisible={isVisibleEdit} setVisible={setVisibleEdit} title="Edit Jabatan">
            <View style={{ justifyContent: 'space-between', flex: 1 }}>
               <View>
                  <InputForm type="default" placeholder="Nama Jabatan" required label="Jabatan" />
               </View>
               <View>
                  <ButtonForm text="SIMPAN" onPress={() => { handleEdit() }} />
               </View>
            </View>
         </DrawerBottom>

      </SafeAreaView>
   )
}