// SPDX-License-Identifier: LGPL-2.1-only
// Copyright (C) 2026 Liberux Labs, S. L. <info@liberux.net>

use crate::app::App;
use crate::event_loop::{ AppData, SurfaceFocus };

impl<A: App> AppData<A>
{
	/// Top-left of `focus` in main-surface (global) coordinates. Used to
	/// translate per-surface pointer coords into a single coordinate
	/// space the app can reason about during drag-and-drop across
	/// surfaces.
	pub( crate ) fn surface_offset_for( &self, focus: SurfaceFocus ) -> ( f32, f32 )
	{
		let SurfaceFocus::Overlay( id ) = focus else { return ( 0.0, 0.0 ); };
		let Some( ss ) = self.overlays.get( &id ) else { return ( 0.0, 0.0 ); };
		let Some( anchor ) = ss.layer_anchor else { return ( 0.0, 0.0 ); };
		let ( sw, sh ) = ( self.main.width as f32, self.main.height as f32 );
		let ( w, h )   = ( ss.width as f32, ss.height as f32 );
		let x = if anchor.left  { 0.0 }
			else if anchor.right { sw - w }
			else                 { ( sw - w ) / 2.0 };
		let y = if anchor.top    { 0.0 }
			else if anchor.bottom { sh - h }
			else                  { ( sh - h ) / 2.0 };
		( x, y )
	}
}
