import { useState, useEffect } from "react"; import { useQuery } from "@tanstack/react-query"; import { Shield, User, Search, ClipboardList } from "lucide-react"; import { getThreatActors, type ThreatActorSummary } from "../../api/threat-actors"; import { listCampaigns, type CampaignSummary } from "../../api/campaigns"; export type LayerType = "coverage" | "threat-actor" | "detection-rules" | "campaign"; interface HeatmapLayerSelectorProps { activeLayer: LayerType; onLayerChange: (layer: LayerType) => void; selectedActorId: string | null; onActorChange: (actorId: string | null) => void; selectedCampaignId: string | null; onCampaignChange: (campaignId: string | null) => void; } const LAYERS: { id: LayerType; label: string; icon: React.FC<{ className?: string }>; }[] = [ { id: "coverage", label: "Coverage", icon: Shield }, { id: "threat-actor", label: "Threat Actor", icon: User }, { id: "detection-rules", label: "Detection Rules", icon: Search }, { id: "campaign", label: "Campaign", icon: ClipboardList }, ]; export default function HeatmapLayerSelector({ activeLayer, onLayerChange, selectedActorId, onActorChange, selectedCampaignId, onCampaignChange, }: HeatmapLayerSelectorProps) { // Fetch actors for dropdown const { data: actorsData } = useQuery({ queryKey: ["threat-actors-selector"], queryFn: () => getThreatActors({ limit: 200 }), enabled: activeLayer === "threat-actor", }); // Fetch campaigns for dropdown const { data: campaignsData } = useQuery({ queryKey: ["campaigns-selector"], queryFn: () => listCampaigns({ limit: 200 }), enabled: activeLayer === "campaign", }); const actors: ThreatActorSummary[] = actorsData?.items || []; const campaigns: CampaignSummary[] = campaignsData?.items || []; // Auto-select first actor/campaign if none selected useEffect(() => { if (activeLayer === "threat-actor" && !selectedActorId && actors.length > 0) { onActorChange(actors[0].id); } }, [activeLayer, actors, selectedActorId, onActorChange]); useEffect(() => { if (activeLayer === "campaign" && !selectedCampaignId && campaigns.length > 0) { onCampaignChange(campaigns[0].id); } }, [activeLayer, campaigns, selectedCampaignId, onCampaignChange]); return (