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, 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('/group?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('/group?active=false') }}
                     label="Tidak Aktif"
                     icon={<AntDesign name="closecircleo" color={active == "false" ? 'white' : 'black'} size={20} />}
                     n={2} />
               </View>
               <InputSearch />
               <View>
                  <BorderBottomItem
                     onPress={() => { setModal(true) }}
                     borderType="all"
                     icon={
                        <View style={[Styles.iconContent, ColorsStatus.lightGreen]}>
                           <MaterialCommunityIcons name="office-building-outline" size={25} color={'#384288'} />
                        </View>
                     }
                     title="Adat"
                  />
                  <BorderBottomItem
                     onPress={() => { setModal(true) }}
                     borderType="all"
                     icon={
                        <View style={[Styles.iconContent, ColorsStatus.lightGreen]}>
                           <MaterialCommunityIcons name="office-building-outline" size={25} color={'#384288'} />
                        </View>
                     }
                     title="Dinas"
                  />
                  <BorderBottomItem
                     onPress={() => { setModal(true) }}
                     borderType="all"
                     icon={
                        <View style={[Styles.iconContent, ColorsStatus.lightGreen]}>
                           <MaterialCommunityIcons name="office-building-outline" size={25} color={'#384288'} />
                        </View>
                     }
                     title="PKK"
                  />
                  <BorderBottomItem
                     onPress={() => { setModal(true) }}
                     borderType="all"
                     icon={
                        <View style={[Styles.iconContent, ColorsStatus.lightGreen]}>
                           <MaterialCommunityIcons name="office-building-outline" size={25} color={'#384288'} />
                        </View>
                     }
                     title="Karang Taruna"
                  />
                  <BorderBottomItem
                     onPress={() => { setModal(true) }}
                     borderType="all"
                     icon={
                        <View style={[Styles.iconContent, ColorsStatus.lightGreen]}>
                           <MaterialCommunityIcons name="office-building-outline" size={25} color={'#384288'} />
                        </View>
                     }
                     title="Koperasi"
                  />
               </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 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={() => { handleEdit() }} />
               </View>
            </View>
         </DrawerBottom>


      </SafeAreaView>
   )
}