import { writable, derived } from 'svelte/store';

export interface CanvasPosition {
	lat: number;
	lng: number;
	zoom: number;
}

export interface SelectedPixel {
	tileX: number;
	tileY: number;
	x: number;
	y: number;
}

// Canvas state
export const selectedColor = writable<number>(1);
export const canvasPosition = writable<CanvasPosition>({
	lat: 0,
	lng: 0,
	zoom: 3
});

export const selectedPixel = writable<SelectedPixel | null>(null);
export const visibleTiles = writable<Set<string>>(new Set());

// Brush/tool state
export const brushSize = writable<number>(1);
export const toolMode = writable<'paint' | 'eyedropper'>('paint');

// Pixel info modal
export const pixelInfoOpen = writable(false);

// Helper to add visible tile
export function addVisibleTile(tileX: number, tileY: number) {
	visibleTiles.update((tiles) => {
		tiles.add(`${tileX},${tileY}`);
		return tiles;
	});
}

// Helper to clear visible tiles
export function clearVisibleTiles() {
	visibleTiles.set(new Set());
}
