// 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 };
use crate::tree::find_handlers;

use super::super::gesture::SwipeConfig;

/// Pointer-side helpers on `AppData`. Split out so touch can call the
/// same swipe-config factory; `apply_*` helpers live in `dispatch.rs`
/// because they are shared.
impl<A: App> AppData<A>
{
	/// Snapshot the swipe thresholds + surface dimensions into a
	/// [`SwipeConfig`] for the gesture machine. Called once per
	/// motion / release event.
	pub( crate ) fn swipe_config( &self, focus: SurfaceFocus ) -> SwipeConfig
	{
		let ss = self.surface( focus );
		SwipeConfig
		{
			up_thresh:         self.app.swipe_threshold(),
			down_thresh:       self.app.swipe_down_threshold(),
			down_edge:         self.app.swipe_down_edge(),
			horizontal_thresh: self.app.swipe_horizontal_threshold(),
			overscroll_thresh: self.app.overscroll_dismiss_threshold(),
			surface_width:     ss.physical_width(),
			surface_height:    ss.physical_height(),
		}
	}
}

pub( crate ) fn hover_affects_paint<Msg: Clone>(
	widget_rects: &[crate::widget::LaidOutWidget<Msg>],
	idx:          Option<usize>,
) -> bool
{
	idx.and_then( |i| find_handlers( widget_rects, i ) )
		.map( |h| !h.is_slider() )
		.unwrap_or( false )
}
