"use client"; import Image from "next/image"; import Link from "next/link"; import { useEffect, useState } from "react"; import { ArrowLeft, Check, CircleOff, Eraser, Hexagon, RotateCcw, Sparkles, } from "lucide-react"; import HoneycombSection, { HONEYCOMB_DEFAULT_LAYERS, HONEYCOMB_LOGOS, PHYSICS_PRESETS, type HoneycombLayers, type HoneycombLogoPlacements, type HoneycombPlacementTool, } from "@/components/landing/HoneycombSection"; import styles from "./grid-lab.module.css"; const STORAGE_KEY = "hivegrid:playground:honeycomb-grid-lab:original:v2"; const LEGACY_STORAGE_KEY = "hivegrid:playground:honeycomb-grid-lab:v1"; type GridState = { version: 2; placements: HoneycombLogoPlacements; activeCellIds: number[]; layers: HoneycombLayers; }; const LAYER_OPTIONS: ReadonlyArray<{ key: keyof HoneycombLayers; label: string }> = [ { key: "innerRing", label: "Innerer Ring" }, { key: "outerRing", label: "Äußerer Ring" }, { key: "field", label: "Wabenfeld" }, { key: "strands", label: "Verbindungen" }, { key: "packets", label: "Datenpunkte" }, { key: "glow", label: "Glow" }, ]; function createEmptyGridState(): GridState { return { version: 2, placements: {}, activeCellIds: [], layers: { ...HONEYCOMB_DEFAULT_LAYERS, hub: true }, }; } function normalizeStoredState(value: unknown): GridState { const fallback = createEmptyGridState(); if (!value || typeof value !== "object") return fallback; const candidate = value as Partial; const placements = candidate.placements && typeof candidate.placements === "object" ? Object.fromEntries( Object.entries(candidate.placements).filter( ([cellId, label]) => Number.isInteger(Number(cellId)) && Number(cellId) > 1 && typeof label === "string" && Boolean(HONEYCOMB_LOGOS[label]) ) ) : {}; const activeCellIds = Array.isArray(candidate.activeCellIds) ? candidate.activeCellIds.filter( (cellId): cellId is number => Number.isInteger(cellId) && cellId > 1 ) : []; const storedLayers: Partial = candidate.layers && typeof candidate.layers === "object" ? candidate.layers : {}; return { version: 2, placements, activeCellIds: [...new Set(activeCellIds)].sort((a, b) => a - b), layers: { ...HONEYCOMB_DEFAULT_LAYERS, ...Object.fromEntries( LAYER_OPTIONS.map(({ key }) => [ key, typeof storedLayers[key] === "boolean" ? storedLayers[key] : HONEYCOMB_DEFAULT_LAYERS[key], ]) ), hub: true, } as HoneycombLayers, }; } export default function GridLabClient() { const [gridState, setGridState] = useState(createEmptyGridState); const [placementTool, setPlacementTool] = useState(null); const [hydrated, setHydrated] = useState(false); const [storageAvailable, setStorageAvailable] = useState(true); useEffect(() => { try { const stored = window.localStorage.getItem(STORAGE_KEY); if (stored) setGridState(normalizeStoredState(JSON.parse(stored))); window.localStorage.removeItem(LEGACY_STORAGE_KEY); } catch { setStorageAvailable(false); } finally { setHydrated(true); } }, []); useEffect(() => { if (!hydrated || !storageAvailable) return; try { window.localStorage.setItem(STORAGE_KEY, JSON.stringify(gridState)); } catch { setStorageAvailable(false); } }, [gridState, hydrated, storageAvailable]); const updateGrid = (update: (current: GridState) => GridState) => { setGridState(update); }; const resetGrid = () => { if (!window.confirm("Das Grid leeren und auf das mittlere G zurücksetzen?")) return; setGridState(createEmptyGridState()); setPlacementTool(null); }; return (
Originalversion

Original Solid

{placementTool === null ? "Waben anklicken, um sie ein- oder auszuschalten. Bereits gesetzte Logos können verschoben werden." : placementTool === "__erase__" ? "Auf eine belegte Wabe klicken, um das Logo zu entfernen." : `${placementTool} ist ausgewählt – jetzt die gewünschte Wabe anklicken.`}

updateGrid((current) => ({ ...current, placements }))} activeCellIds={gridState.activeCellIds} onActiveCellIdsChange={(activeCellIds) => updateGrid((current) => ({ ...current, activeCellIds }))} editorMode placementTool={placementTool} />
); }