/* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable react-hooks/exhaustive-deps */ 'use client' import apbdesState from '@/app/admin/(dashboard)/_state/landing-page/apbdes' import colors from '@/con/colors' import { Box, Button, Divider, Group, Select, SimpleGrid, Stack, Text, Title, LoadingOverlay, Transition, } from '@mantine/core' import { motion } from 'framer-motion' import Link from 'next/link' import { useEffect, useState } from 'react' import { useProxy } from 'valtio/utils' import { ApbdesMainSkeleton } from './components/apbdesSkeleton' import ComparisonChart from './lib/comparisonChart' import GrafikRealisasi from './lib/grafikRealisasi' import PaguTable from './lib/paguTable' import RealisasiTable from './lib/realisasiTable' const MotionStack = motion.create(Stack) function Apbdes() { const state = useProxy(apbdesState) const [selectedYear, setSelectedYear] = useState(null) const [isLoading, setIsLoading] = useState(true) const [isChangingYear, setIsChangingYear] = useState(false) const textHeading = { title: 'APBDes', des: 'Transparansi APBDes Darmasaba adalah langkah nyata menuju tata kelola desa yang bersih, terbuka, dan bertanggung jawab.', } useEffect(() => { const loadData = async () => { try { setIsLoading(true) await state.findMany.load() } catch (error) { console.error('Error loading data:', error) } finally { setIsLoading(false) } } loadData() }, []) const dataAPBDes = state.findMany.data || [] const years = Array.from( new Set( dataAPBDes .map((item: any) => item?.tahun) .filter((tahun): tahun is number => typeof tahun === 'number') ) ) .sort((a, b) => b - a) .map((year) => ({ value: year.toString(), label: `Tahun ${year}`, })) useEffect(() => { if (years.length > 0 && !selectedYear) { setSelectedYear(years[0].value) } }, [years]) const currentApbdes = dataAPBDes.length > 0 ? (dataAPBDes.find((item: any) => item?.tahun?.toString() === selectedYear) || dataAPBDes[0]) : null const handleYearChange = (value: string | null) => { if (value !== selectedYear) { setIsChangingYear(true) setSelectedYear(value) setTimeout(() => setIsChangingYear(false), 500) } } return ( {(styles) => ( {/* 📌 HEADING */} {textHeading.title} {textHeading.des} {/* Button Lihat Semua */} {/* COMBOBOX */}