"use client"; import { useState, useEffect, useMemo } from "react"; import { useCountries } from "@/lib/api-with-context"; import { DataTable, Column } from "@/components/ui/DataTable"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/Card"; import { Loader2 } from "lucide-react"; import { fmtBytes } from "@/lib/utils"; import { WorldMap } from "@/components/ui/WorldMap"; import { UniversalFilters, useUniversalFilterState, FilterConfig } from "@/components/ui/UniversalFilters"; import { HelpTrigger } from "@/components/help/HelpTrigger"; export default function GeographyPage() { const [mounted, setMounted] = useState(false); const [showMap, setShowMap] = useState(false); const { data, isLoading } = useCountries(); const { filters, handleFilterChange, handleReset, activeCount } = useUniversalFilterState(); const mapData = useMemo(() => { if (!data) return []; return data.map((row) => ({ countryCode: row.country_code, value: row.download + row.upload, download: row.download, upload: row.upload, label: row.country_name, })); }, [data]); useEffect(() => { setMounted(true); document.title = "Geo Traffic | BackOne - Deep Package Inspection"; }, []); if (!mounted) return null; const all = data || []; const opts = (key: string) => { const raw = Array.from(new Set(all.map((r: any) => String(r[key] || "")).filter(Boolean))); return raw.sort(); }; const filterConfigs: FilterConfig[] = [ { id: "country_name", label: "Country", type: "select", value: filters.country_name, options: opts("country_name") }, { id: "sort_download", label: "Sort Download", type: "select", value: filters.sort_download, options: ["Descending", "Ascending"] }, { id: "sort_upload", label: "Sort Upload", type: "select", value: filters.sort_upload, options: ["Descending", "Ascending"] }, ]; const filteredData = all.filter((row: any) => { if (filters.country_name && filters.country_name !== "All" && row.country_name !== filters.country_name) return false; return true; }); let processedData = [...filteredData]; const sortUpload = filters.sort_upload || "All"; const sortDownload = filters.sort_download || "All"; if (sortUpload !== "All") { processedData.sort((a, b) => sortUpload === "Descending" ? b.upload - a.upload : a.upload - b.upload); } else if (sortDownload !== "All") { processedData.sort((a, b) => sortDownload === "Descending" ? b.download - a.download : a.download - b.download); } const columns: Column[] = [ { header: "#", accessor: (row, i) => i + 1 }, { header: "Country", accessor: (row) => (
{row.country_code && ( {row.country_code} { e.currentTarget.style.display = 'none'; }} /> )} {row.country_name}
) }, { header: "Country Code", accessor: (row) => row.country_code }, { header: "Download", accessor: (row) => {fmtBytes(row.download)} }, { header: "Upload", accessor: (row) => {fmtBytes(row.upload)} }, { header: "Total Data", accessor: (row) => {fmtBytes(row.download + row.upload)} } ]; return (

Geo Traffic {isLoading && }

Visualize data flow and activity across the globe.

{ if (id === 'sort_download') { handleFilterChange('sort_download', val); handleFilterChange('sort_upload', 'All'); } else if (id === 'sort_upload') { handleFilterChange('sort_upload', val); handleFilterChange('sort_download', 'All'); } else { handleFilterChange(id, val); } }} showDateRange={false} activeFilterCount={activeCount} onReset={handleReset} /> {showMap && ( Heatmap Visualization )} Traffic by Country ({processedData.length}) {!showMap && ( )} { const q = query.toLowerCase(); return (row.country_name || "").toLowerCase().includes(q); }} />
); }