"use client"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/Card"; import { DataTable, Column } from "@/components/ui/DataTable"; import { useState, useEffect } from "react"; import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip as RechartsTooltip, ResponsiveContainer, PieChart, Pie, Cell } from "recharts"; import { Activity, Loader2 } from "lucide-react"; import { AppCategoryStat } from "@/lib/api"; import { useAppCategories, useContinents } from "@/lib/api-with-context"; import { fmtBytes } from "@/lib/utils"; import { UniversalFilters, useUniversalFilterState, FilterConfig } from "@/components/ui/UniversalFilters"; import { CategoryDetailPanel } from "@/components/network/CategoryDetailPanel"; import { HelpTrigger } from "@/components/help/HelpTrigger"; const COLORS = ['#58a6ff', '#3fb950', '#f0883e', '#bc8cff', '#f85149']; export default function NetworkIntelligencePage() { const [mounted, setMounted] = useState(false); const appCategories = useAppCategories(); const continents = useContinents(); const [selectedCategory, setSelectedCategory] = useState(null); const { filters, handleFilterChange, handleReset, activeCount } = useUniversalFilterState(); useEffect(() => { setMounted(true); document.title = "Traffic Categories | BackOne - Deep Package Inspection"; }, []); if (!mounted) return null; const allCategories = appCategories.data || []; const opts = (key: string) => { const raw = Array.from(new Set(allCategories.map((r: any) => String(r[key] || "")).filter(Boolean))); return raw.sort(); }; const filterConfigs: FilterConfig[] = [ { id: "category_label", label: "Category", type: "select", value: filters.category_label, options: opts("category_label") }, { 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 = allCategories.filter((row: any) => { if (filters.category_label && filters.category_label !== "All" && row.category_label !== filters.category_label) 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 appCols: Column[] = [ { header: "#", accessor: (row, i) => i + 1, className: "w-[10%] text-center" }, { header: "Category", accessor: (row) => (
{row.category_label || '-'}
), className: "w-[35%] text-center" }, { header: "Download", accessor: (row) => {fmtBytes(row.download)}, className: "w-[18%] text-center" }, { header: "Upload", accessor: (row) => {fmtBytes(row.upload)}, className: "w-[18%] text-center" }, { header: "Total", accessor: (row) => fmtBytes(row.total), className: "w-[19%] text-center" }, ]; const isLoading = appCategories.isLoading || continents.isLoading; return (

Traffic Categories {isLoading && }

{/* Mobile Actions: Inline next to Title */}

Deep packet inspection analytics and geography.

{/* Laptop/Tablet Actions: Floats on the right */}
{ 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} />
{/* Left Column: App Categories List */} App Categories List setSelectedCategory(row.category_label)} /> {/* Right Column: Graphs */}
{/* App Categories Graph */} App Categories Chart
{processedData.map((entry, index) => ( ))} fmtBytes(val as number)} />
{/* Continents Graph */} Continents (Download Volume)
`${(v/1000000000).toFixed(1)}GB`} /> fmtBytes(val as number)} />

Most of your traffic is bound for {continents.data && continents.data.length > 0 ? continents.data[0].continent_name : "unknown destinations"}. Ensure your firewall rules are optimized for latency across trans-oceanic cables.

{selectedCategory && ( setSelectedCategory(null)} /> )}
); }