import SwiftUI

struct DropTargetData: Equatable, Sendable {
    let location: CardLocation
    let frame: CGRect
}

struct DropTargetPreferenceKey: PreferenceKey {
    nonisolated(unsafe) static var defaultValue: [DropTargetData] = []

    static func reduce(value: inout [DropTargetData], nextValue: () -> [DropTargetData]) {
        value.append(contentsOf: nextValue())
    }
}

extension View {
    func dropTarget(_ location: CardLocation) -> some View {
        background(
            GeometryReader { geometry in
                Color.clear.preference(
                    key: DropTargetPreferenceKey.self,
                    value: [DropTargetData(location: location,
                                           frame: geometry.frame(in: .named("board")))]
                )
            }
        )
    }
}
