/**
 * BlockShell — types for the panel wrapper component.
 *
 * BlockShell wraps each tool panel (trait) on the spatial workspace,
 * providing header, resize, drag, fullscreen and drop-zone capabilities.
 *
 * Ref: docs/retninger/arbeidsflaten.md
 * Ref: docs/features/universell_overfoering.md § 8.1
 */

import type { DragPayload, CompatResult, ToolType } from '$lib/transfer.js';

/** Placement intent returned by BlockReceiver.receive() */
export interface PlacementIntent {
	/** What happens on receive: new node or new edge/placement */
	mode: 'innholdstransfer' | 'lettvekts-triage';
	/** Target context ID (collection, board, calendar, channel) */
	contextId: string;
	/** Context type for placement table */
	contextType: string;
	/** Position data (column for kanban, date for calendar, etc.) */
	position?: Record<string, unknown>;
}

/** Size constraints for a panel */
export interface SizeConstraints {
	minWidth: number;
	minHeight: number;
	maxWidth: number;
	maxHeight: number;
}

/** Default size constraints */
export const DEFAULT_CONSTRAINTS: SizeConstraints = {
	minWidth: 280,
	minHeight: 200,
	maxWidth: 1600,
	maxHeight: 1200,
};

/** Mobile breakpoint — below this, panels stack vertically */
export const MOBILE_BREAKPOINT = 768;

/** Resize direction */
export type ResizeDirection =
	| 'n' | 's' | 'e' | 'w'
	| 'ne' | 'nw' | 'se' | 'sw';

/** Drop-zone state for visual feedback */
export type DropZoneState = 'idle' | 'compatible' | 'incompatible';

/**
 * BlockReceiver interface — implemented by tool panels that accept drops.
 * Ref: docs/features/universell_overfoering.md § 4.3
 *
 * - canReceive(): compatibility check (called during drag-over)
 * - receive(): creates placement/edge (called on drop)
 * - renderDropZone is handled by BlockShell (visual feedback via CSS)
 */
export interface BlockReceiver {
	/** Can this panel receive this payload? */
	canReceive(payload: DragPayload): CompatResult;
	/** Process a received drop — returns placement intent for the transfer service */
	receive?(payload: DragPayload, dropPosition?: { x: number; y: number }): PlacementIntent;
}

/** Events emitted by BlockShell */
export interface BlockShellEvents {
	/** Panel close requested */
	onClose?: () => void;
	/** Panel drag-moved (delta in world coords) */
	onDragMove?: (dx: number, dy: number) => void;
	/** Panel resized. dx/dy are position offsets for n/w edge dragging. */
	onResize?: (width: number, height: number, dx?: number, dy?: number) => void;
	/** Panel fullscreen state changed */
	onFullscreenChange?: (isFullscreen: boolean) => void;
	/** Panel minimize state changed (double-click header to toggle) */
	onMinimizeChange?: (isMinimized: boolean) => void;
	/** Drop received on this panel. shiftKey indicates Shift was held (forces innholdstransfer). */
	onDrop?: (payload: DragPayload, shiftKey: boolean) => void;
}
