138 lines
5.9 KiB
TypeScript
138 lines
5.9 KiB
TypeScript
"use client";
|
|
|
|
import React from "react";
|
|
import { X, MapPin, ArrowDownLeft, ArrowUpRight, Activity, Globe, Server } from "lucide-react";
|
|
import { fmtBytes } from "@/lib/utils";
|
|
import { formatAppLabel } from "@/lib/domainUtils";
|
|
import { GlobePointData } from "./useGlobeData";
|
|
|
|
interface GlobePointPopupProps {
|
|
point: GlobePointData;
|
|
onClose: () => void;
|
|
}
|
|
|
|
export const GlobePointPopup = ({ point, onClose }: GlobePointPopupProps) => {
|
|
const topIps = point.topIps || [];
|
|
const topDomains = point.topDomains || [];
|
|
|
|
return (
|
|
<div
|
|
className="absolute top-3 right-3 z-30 w-72 max-h-[460px] flex flex-col rounded-xl border border-white/15 bg-slate-950/95 p-3 text-slate-200 shadow-2xl backdrop-blur-md animate-fade-in cursor-default"
|
|
onClick={(e) => e.stopPropagation()}
|
|
>
|
|
<div className="flex items-start justify-between gap-2 border-b border-white/10 pb-2 shrink-0">
|
|
<div className="min-w-0">
|
|
<span
|
|
className={`inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-[9px] font-bold uppercase tracking-wider ${
|
|
point.isOrigin
|
|
? "bg-rose-500/20 text-rose-400 border border-rose-500/30"
|
|
: "bg-sky-500/20 text-sky-400 border border-sky-500/30"
|
|
}`}
|
|
>
|
|
<MapPin className="h-2.5 w-2.5" />
|
|
{point.isOrigin ? "Lokasi Server Agent" : "Negara Tujuan / Luar"}
|
|
</span>
|
|
<h4 className="mt-1 text-xs font-bold text-white break-words">{point.name}</h4>
|
|
<p className="text-[9px] font-mono text-slate-400">
|
|
Lat: {point.lat.toFixed(6)}, Lng: {point.lng.toFixed(6)}
|
|
</p>
|
|
</div>
|
|
<button
|
|
type="button"
|
|
onClick={onClose}
|
|
className="rounded-lg p-1 text-slate-400 hover:bg-white/10 hover:text-white transition-colors"
|
|
aria-label="Close detail"
|
|
>
|
|
<X className="h-3.5 w-3.5" />
|
|
</button>
|
|
</div>
|
|
|
|
<div className="mt-2 space-y-1 text-[10px] shrink-0">
|
|
<div className="flex items-center justify-between">
|
|
<span className="flex items-center gap-1 text-emerald-400">
|
|
<ArrowDownLeft className="h-3 w-3" /> Download (Luar → Agent)
|
|
</span>
|
|
<span className="font-mono font-semibold text-emerald-400">{fmtBytes(point.download || 0)}</span>
|
|
</div>
|
|
<div className="flex items-center justify-between">
|
|
<span className="flex items-center gap-1 text-sky-400">
|
|
<ArrowUpRight className="h-3 w-3" /> Upload (Agent → Luar)
|
|
</span>
|
|
<span className="font-mono font-semibold text-sky-400">{fmtBytes(point.upload || 0)}</span>
|
|
</div>
|
|
<div className="flex items-center justify-between border-t border-white/10 pt-1">
|
|
<span className="flex items-center gap-1 text-slate-300 font-medium">
|
|
<Activity className="h-3 w-3 text-purple-400" /> Total Trafik
|
|
</span>
|
|
<span className="font-mono font-bold text-white">
|
|
{fmtBytes((point.download || 0) + (point.upload || 0))}
|
|
</span>
|
|
</div>
|
|
</div>
|
|
|
|
{(topIps.length > 0 || topDomains.length > 0) && (
|
|
<div className="mt-2.5 pt-2 border-t border-white/10 overflow-y-auto space-y-2.5 pr-1 custom-scrollbar">
|
|
{topIps.length > 0 && (
|
|
<div>
|
|
<div className="flex items-center gap-1 text-[9px] font-bold uppercase tracking-wider text-sky-400 mb-1">
|
|
<Server className="h-2.5 w-2.5" />
|
|
<span>Daftar IP ({topIps.length})</span>
|
|
</div>
|
|
<div className="space-y-1">
|
|
{topIps.map((item, idx) => {
|
|
const hostLabel = item.domain
|
|
? formatAppLabel(item.domain)
|
|
: item.app_label
|
|
? formatAppLabel(item.app_label)
|
|
: null;
|
|
return (
|
|
<div
|
|
key={`${item.ip}-${idx}`}
|
|
className="rounded-md bg-white/[0.04] border border-white/5 px-2 py-1 text-[9px]"
|
|
>
|
|
<div className="flex items-center justify-between gap-2">
|
|
<span className="font-mono font-semibold text-slate-100 truncate">{item.ip}</span>
|
|
<span className="font-mono text-sky-300 shrink-0">{fmtBytes(item.total || 0)}</span>
|
|
</div>
|
|
{hostLabel && (
|
|
<div className="text-[8.5px] text-slate-400 truncate mt-0.5" title={hostLabel}>
|
|
{hostLabel}
|
|
</div>
|
|
)}
|
|
</div>
|
|
);
|
|
})}
|
|
</div>
|
|
</div>
|
|
)}
|
|
|
|
{topDomains.length > 0 && (
|
|
<div>
|
|
<div className="flex items-center gap-1 text-[9px] font-bold uppercase tracking-wider text-emerald-400 mb-1">
|
|
<Globe className="h-2.5 w-2.5" />
|
|
<span>Domain / Aplikasi ({topDomains.length})</span>
|
|
</div>
|
|
<div className="space-y-1">
|
|
{topDomains.map((item, idx) => {
|
|
const label = formatAppLabel(item.domain);
|
|
return (
|
|
<div
|
|
key={`${item.domain}-${idx}`}
|
|
className="flex items-center justify-between gap-2 rounded-md bg-white/[0.04] border border-white/5 px-2 py-1 text-[9px]"
|
|
>
|
|
<span className="text-slate-200 truncate" title={label}>
|
|
{label}
|
|
</span>
|
|
<span className="font-mono text-emerald-300 shrink-0">{fmtBytes(item.total || 0)}</span>
|
|
</div>
|
|
);
|
|
})}
|
|
</div>
|
|
</div>
|
|
)}
|
|
</div>
|
|
)}
|
|
</div>
|
|
);
|
|
};
|