import { emitter, useScene, type ZoneNode } from "@pascal-app/core";
import { useViewer } from "@pascal-app/viewer";
import { Camera, Hexagon, Trash2 } from "lucide-react";
import { useState } from "react";
import { cn } from "@/lib/utils";
import useEditor from "@/store/use-editor";
import { ColorDot } from "@/components/ui/primitives/color-dot";
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/primitives/popover";
function ZoneItem({ zone }: { zone: ZoneNode }) {
const [cameraPopoverOpen, setCameraPopoverOpen] = useState(false);
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}
{/* Camera snapshot button */}
e.stopPropagation()}
>
{zone.camera && (
)}
{zone.camera && (
)}
);
}
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) =>
)
)}
);
}