"use client"; import { useMemo } from "react"; import { X, ArrowRight } from "lucide-react"; import { EdgeType } from "@/app/types/council"; import { useCouncilStore } from "@/app/store/council-store"; // Right-side panel shown when a canvas edge is selected export function EdgeSettingsPanel() { const selectedEdgeId = useCouncilStore((s) => s.selectedEdgeId); const edges = useCouncilStore((s) => s.edges); const nodes = useCouncilStore((s) => s.nodes); const updateEdgeData = useCouncilStore((s) => s.updateEdgeData); const selectEdge = useCouncilStore((s) => s.selectEdge); const edge = edges.find((e) => e.id === selectedEdgeId); // Derive state directly from the store instead of syncing via useEffect const edgeType = useMemo( () => (edge?.data?.type as EdgeType) ?? "linear", [edge?.data?.type] ); const condition = useMemo( () => (edge?.data?.condition as string) ?? "", [edge?.data?.condition] ); if (!selectedEdgeId || !edge) return null; const sourceNode = nodes.find((n) => n.id === edge.source); const targetNode = nodes.find((n) => n.id === edge.target); const handleTypeChange = (newType: EdgeType) => { updateEdgeData(selectedEdgeId, newType, newType === "conditional" ? condition : undefined); }; const handleConditionChange = (value: string) => { updateEdgeData(selectedEdgeId, edgeType, value); }; return ( ); }