import SwiftUI
import VNCCore

struct TrackpadCursorOverlay: View {
    let normalizedPosition: CGPoint
    let framebufferSize: CGSize
    let isVisible: Bool

    var body: some View {
        GeometryReader { proxy in
            let mapper = InputMapper()
            if isVisible,
               let displayed = mapper.displayedRect(for: framebufferSize, in: proxy.size),
               displayed.width > 0 && displayed.height > 0 {
                let x = displayed.origin.x + normalizedPosition.x * displayed.width
                let y = displayed.origin.y + normalizedPosition.y * displayed.height
                Image(systemName: "cursorarrow")
                    .font(.system(size: 22, weight: .bold))
                    .foregroundStyle(.white, .black)
                    .shadow(radius: 1)
                    .position(x: x, y: y)
                    .allowsHitTesting(false)
                    .accessibilityHidden(true)
                    .transition(.opacity)
            }
        }
        .ignoresSafeArea()
    }
}
