import { ColorsStatus } from "@/constants/ColorsStatus"
import Styles from "@/constants/Styles"
import { apiGetDivisionOneFeature } from "@/lib/api"
import { useAuthSession } from "@/providers/AuthProvider"
import { AntDesign, MaterialIcons, SimpleLineIcons } from "@expo/vector-icons"
import { router, useLocalSearchParams } from "expo-router"
import { useEffect, useState } from "react"
import { View } from "react-native"
import BorderBottomItem from "../borderBottomItem"
import Text from "../Text"

type Props = {
   tugas: number
   dokumen: number
   diskusi: number
   kalender: number
}

export default function FiturDivisionDetail({ refreshing }: { refreshing: boolean }) {
   const { token, decryptToken } = useAuthSession()
   const { id } = useLocalSearchParams<{ id: string }>()
   const [data, setData] = useState<Props>({
      tugas: 0,
      dokumen: 0,
      diskusi: 0,
      kalender: 0,
   })

   async function handleLoad() {
      try {
         const hasil = await decryptToken(String(token?.current))
         const response = await apiGetDivisionOneFeature({ user: hasil, id, cat: 'jumlah' })
         setData(response.data)
      } catch (error) {
         console.error(error)
      }
   }

   useEffect(() => {
      if (refreshing)
         handleLoad()
   }, [refreshing])

   useEffect(() => {
      handleLoad()
   }, [])

   return (
      <View style={[Styles.mb15]}>
         <Text style={[Styles.textDefaultSemiBold, Styles.mv05]}>Fitur</Text>
         <View>
            <View style={[Styles.rowSpaceBetween]}>
               <BorderBottomItem
                  bgColor="white"
                  borderType="all"
                  icon={
                     <View style={[Styles.iconContent, ColorsStatus.lightGreen]}>
                        <AntDesign name="filetext1" size={25} color={'#384288'} />
                     </View>
                  }
                  title="Tugas"
                  subtitle={`${data.tugas} Tugas`}
                  width={28}
                  onPress={() => { router.push(`/division/${id}/task?status=0`) }}
               />

               <BorderBottomItem
                  bgColor="white"
                  borderType="all"
                  icon={
                     <View style={[Styles.iconContent, ColorsStatus.lightGreen]}>
                        <MaterialIcons name="attach-file" size={25} color={'#384288'} />
                     </View>
                  }
                  title="Dokumen"
                  subtitle={`${data.dokumen} File`}
                  width={28}
                  onPress={() => { router.push(`/division/${id}/document`) }}
               />
            </View>

            <View style={[Styles.rowSpaceBetween]}>
               <BorderBottomItem
                  bgColor="white"
                  borderType="all"
                  icon={
                     <View style={[Styles.iconContent, ColorsStatus.lightGreen]}>
                        <SimpleLineIcons name="bubbles" size={25} color={'#384288'} />
                     </View>
                  }
                  title="Diskusi"
                  subtitle={`${data.diskusi} Diskusi`}
                  width={28}
                  onPress={() => { router.push(`/division/${id}/discussion?active=true`) }}
               />

               <BorderBottomItem
                  bgColor="white"
                  borderType="all"
                  icon={
                     <View style={[Styles.iconContent, ColorsStatus.lightGreen]}>
                        <AntDesign name="calendar" size={25} color={'#384288'} />
                     </View>
                  }
                  title="Kalender"
                  subtitle={`${data.kalender} Acara`}
                  width={28}
                  onPress={() => { router.push(`/division/${id}/calendar`) }}
               />
            </View>
         </View>
      </View>
   )
}