// Shared bridge between the ship-class calculator (sidebar) and the map
// view: the calculator publishes the selected planet's origin and the
// current design's loaded speed here, and the map reads it to draw reach
// circles. A module singleton keeps the two siblings decoupled — neither
// imports the other — and survives sidebar tab switches. The store is
// cleared whenever the calculator has no valid design or no selected
// planet, which makes the map drop the rings.

class ReachStore {
	origin: { x: number; y: number } | null = $state(null);
	speedPerTurn = $state(0);

	set(origin: { x: number; y: number }, speedPerTurn: number): void {
		this.origin = origin;
		this.speedPerTurn = speedPerTurn;
	}

	clear(): void {
		this.origin = null;
		this.speedPerTurn = 0;
	}
}

export const reachStore = new ReachStore();
