import React from 'react'; import { Globe, GitMerge, ShieldAlert } from '../../icons'; import type { Net } from './types'; import type { ResizeHandle } from './useMazeInteraction'; interface Props { net: Net; selected: boolean; dropTarget: boolean; inactive: boolean; deployed?: boolean; onSelect?: (id: string) => void; onHeaderMouseDown?: (id: string) => (e: React.MouseEvent) => void; onResizeMouseDown?: (id: string, handle: ResizeHandle) => (e: React.MouseEvent) => void; onContextMenu?: (e: React.MouseEvent) => void; children?: React.ReactNode; } const NetBox: React.FC = ({ net, selected, dropTarget, inactive, deployed, onSelect, onHeaderMouseDown, onResizeMouseDown, onContextMenu, children, }) => { const classes = [ 'maze-net-box', net.kind === 'internet' ? 'internet' : '', net.kind === 'dmz' ? 'dmz' : '', selected ? 'selected' : '', dropTarget ? 'drop-target' : '', inactive ? 'inactive' : '', deployed ? 'deployed' : '', net.pending ? 'pending' : '', ].filter(Boolean).join(' '); const Icon = net.kind === 'internet' ? Globe : net.kind === 'dmz' ? ShieldAlert : GitMerge; const resizable = net.kind !== 'internet'; const handleBoxDown = (e: React.MouseEvent) => { if (e.target !== e.currentTarget) return; onSelect?.(net.id); }; const handleHeadDown = (e: React.MouseEvent) => { onSelect?.(net.id); onHeaderMouseDown?.(net.id)(e); }; return (
{net.label} {inactive && !net.pending && ( INACTIVE )} {net.pending && ( PENDING )}
{net.cidr}
{resizable && onResizeMouseDown && ( <>
)} {children}
); }; export default React.memo(NetBox);