import { useScene, type ZoneNode } from "@pascal-app/core"; import { useViewer } from "@pascal-app/viewer"; import { Hexagon, Trash2 } from "lucide-react"; import { cn } from "@/lib/utils"; import useEditor from "@/store/use-editor"; import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/primitives/popover"; // Preset colors for zones const PRESET_COLORS = [ "#3b82f6", // blue "#22c55e", // green "#eab308", // yellow "#f97316", // orange "#ef4444", // red "#a855f7", // purple "#ec4899", // pink "#06b6d4", // cyan ]; function ZoneItem({ zone }: { zone: ZoneNode }) { const deleteNode = useScene((state) => state.deleteNode); const updateNode = useScene((state) => state.updateNode); const selectedZoneId = useViewer((state) => state.selection.zoneId); const setSelection = useViewer((state) => state.setSelection); const isSelected = selectedZoneId === zone.id; const handleClick = () => { setSelection({ zoneId: zone.id }); }; const handleDelete = (e: React.MouseEvent) => { e.stopPropagation(); deleteNode(zone.id); if (isSelected) { setSelection({ zoneId: null }); } }; const handleColorChange = (color: string) => { updateNode(zone.id, { color }); }; return (
{zone.name} ); } export function ZonePanel() { const nodes = useScene((state) => state.nodes); const currentLevelId = useViewer((state) => state.selection.levelId); const setPhase = useEditor((state) => state.setPhase); const setMode = useEditor((state) => state.setMode); const setTool = useEditor((state) => state.setTool); // Filter nodes to get zones for the current level const levelZones = Object.values(nodes).filter( (node): node is ZoneNode => node.type === "zone" && node.parentId === currentLevelId ); const handleAddZone = () => { if (currentLevelId) { setPhase("structure"); setMode("build"); setTool("zone"); } }; if (!currentLevelId) { return (
Select a level to view and create zones
); } return (
{levelZones.length === 0 ? (
No zones on this level.{" "}
) : ( levelZones.map((zone) => ) )}
); }