"use client"; import { useState, useEffect, useMemo } from "react"; const FILTER_CATEGORIES = [ { id: "All", name: "Todos", color: "#374151" }, { id: "GND", name: "Terra (GND)", color: "#64748b" }, { id: "Power", name: "Alimentação", color: "#ef4444" }, { id: "GPIO", name: "GPIO", color: "#22c55e" }, { id: "Low Power", name: "GPIO LP", color: "#f59e0b" }, { id: "ADC", name: "ADC", color: "#ec4899" }, { id: "DAC", name: "DAC", color: "#a855f7" }, { id: "Touch", name: "Touch", color: "#06b6d4" }, { id: "UART", name: "UART", color: "#3b82f6" }, { id: "SPI", name: "SPI", color: "#ef4444" }, { id: "USB", name: "USB", color: "#8b5cf6" }, { id: "Clock", name: "Clock", color: "#eab308" }, { id: "JTAG", name: "JTAG", color: "#8b5cf6" }, { id: "Strapping", name: "Inicialização", color: "#dc2626" }, { id: "DSI", name: "Display (DSI)", color: "#f97316" }, { id: "CSI", name: "Câmera (CSI)", color: "#14b8a6" }, { id: "Ethernet", name: "Ethernet", color: "#3b82f6" }, { id: "SD", name: "Cartão SD", color: "#10b981" }, { id: "I2C", name: "I2C", color: "#f59e0b" }, { id: "Antena", name: "Antena", color: "#22d3ee" }, ]; const type_colors = { power: "#ef4444", ground: "#64748b", io: "#22c55e", analog: "#ec4899", dedicated: "#3b82f6", nc: "#9ca3af", }; export default function ConnectionsDiagram({ connections, serie }) { const [activeFilter, setActiveFilter] = useState("All"); const [selectedConnection, setSelectedConnection] = useState(null); const [hoveredConnection, setHoveredConnection] = useState(null); const [searchQuery, setSearchQuery] = useState(""); const [viewMode, setViewMode] = useState("grid"); const [showTooltip, setShowTooltip] = useState(null); const isConnectionVisible = (connection) => { const matchesFilter = activeFilter === "All" || connection.categorias.includes(activeFilter); const matchesSearch = searchQuery === "" || connection.nome.toLowerCase().includes(searchQuery.toLowerCase()) || connection.numero.toString().toLowerCase().includes(searchQuery.toLowerCase()); return matchesFilter && matchesSearch; }; const getCategoryColor = (category) => { const filter = FILTER_CATEGORIES.find((f) => f.id === category); return filter?.color || "#64748b"; }; const visibleConnections = useMemo(() => { return connections.filter(isConnectionVisible); }, [connections, activeFilter, searchQuery]); const activeCategories = useMemo(() => { if (activeFilter === "All") return []; return FILTER_CATEGORIES.filter(cat => visibleConnections.some(conn => conn.categorias.includes(cat.id)) ); }, [visibleConnections, activeFilter]); useEffect(() => { const handleEscape = (e) => { if (e.key === "Escape") { setSelectedConnection(null); setShowTooltip(null); } }; if (selectedConnection) { document.addEventListener("keydown", handleEscape); document.body.style.overflow = "hidden"; } return () => { document.removeEventListener("keydown", handleEscape); document.body.style.overflow = "unset"; }; }, [selectedConnection]); useEffect(() => { const handleKeyDown = (e) => { if (selectedConnection) return; if (e.key === "Tab") { const buttons = document.querySelectorAll('[data-connection-button]'); const currentIndex = Array.from(buttons).findIndex(btn => btn === document.activeElement); if (e.shiftKey && currentIndex > 0) { e.preventDefault(); buttons[currentIndex - 1].focus(); } else if (!e.shiftKey && currentIndex < buttons.length - 1) { e.preventDefault(); buttons[currentIndex + 1].focus(); } } }; document.addEventListener("keydown", handleKeyDown); return () => document.removeEventListener("keydown", handleKeyDown); }, [selectedConnection]); if (!connections || connections.length === 0) { return (
Diagrama de conexões indisponível
Este modelo ainda não possui dados de conexão
Explore as conexões do {serie.nome_completo}. Use a busca, filtros por função ou passe o mouse para ver detalhes rápidos.
Categorias visíveis:
Nenhuma conexão encontrada
Tente ajustar os filtros ou termo de busca
| Pin | Nome | Categorias | Funções | Avisos |
|---|---|---|---|---|
|
{typeof connection.numero === "number"
? connection.numero
: connection.numero.substring(0, 4)}
|
{connection.nome}
|
{connection.categorias.map((cat) => (
{cat === "Strapping" ? "Inicialização" : cat}
))}
|
{connection.funcoes.join(", ")}
|
{connection.avisos ? ( Sim ) : ( Não )} |
Informações Importantes
Pino {selectedConnection.numero}
Avisos Importantes
{selectedConnection.avisos.map((aviso, index) => (