// Questo file fa parte di MyTown.
// MyTown è software libero: puoi ridistribuirlo e/o modificarlo secondo
// i termini della GNU Affero General Public License come pubblicata dalla
// Free Software Foundation, versione 3.
// Distribuito senza ALCUNA GARANZIA; vedi la GNU AGPL v3 per i dettagli.
// Copyright (C) Kondor Consulting & Services S.r.l.
// SPDX-License-Identifier: AGPL-3.0-or-later

declare namespace fabric {
	type TEvent<T = Event> = { e: T };
	type TPointerEvent = MouseEvent;

	class BaseBrush {
		color: string;
		width: number;
		onMouseDown(pointer: Point): void;
		onMouseMove(pointer: Point): void;
		onMouseUp(pointer: Point): void;
	}

	class PencilBrush extends BaseBrush {
		constructor(canvas: Canvas);
	}

	class EraserBrush extends BaseBrush {
		constructor(canvas: Canvas);
	}

	class Canvas {
		constructor(element: HTMLCanvasElement | string, options?: any);
		isDrawingMode: boolean;
		freeDrawingBrush: BaseBrush | PencilBrush | EraserBrush;
		backgroundColor: string | Pattern;
		backgroundImage?: Image;
		clipPath?: Object;
		width: number;
		height: number;
		getWidth(): number;
		getHeight(): number;
		setDimensions(dimensions: { width: number; height: number }): void;
		setZoom(zoom: number): void;
		setViewportTransform(vpt: number[]): void;
		getObjects(type?: string): Object[];
		add(...objects: Object[]): this;
		remove(object: Object): this;
		clear(): this;
		renderAll(): this;
		dispose(): void;
		on(event: string, handler: (e: any) => void): void;
	}

	class Object {
		type: string;
		group?: Group;
		getBoundingRect(): { left: number; top: number; width: number; height: number };
		selectable: boolean;
		evented: boolean;
		erasable: boolean;
	}

	class Group extends Object {
		constructor(objects: Object[], options?: any);
	}

	class Rect extends Object {
		constructor(options?: any);
	}

	class Image extends Object {
		width: number;
		height: number;
		static fromURL(url: string, callback: (img: Image) => void, options?: any): void;
		set(options: any): Image;
		getElement(): HTMLImageElement;
	}

	class Pattern {
		constructor(options: { source: HTMLImageElement | HTMLCanvasElement; repeat: string; offsetX?: number; offsetY?: number });
	}

	class Point {
		x: number;
		y: number;
	}

	class Line extends Object {
		constructor(points: number[], options?: any);
	}

	// Utility functions (add more as needed from your code)
	class util {
		static degreesToRadians(degrees: number): number;
		// etc., if used
	}
}
