//
//  RingLightOverlay.swift
//  CameraTester
//
//  Created by Matt Bruce on 1/2/26.
//

import SwiftUI

// MARK: - Ring Light Overlay

struct RingLightOverlay: View {
    let color: Color
    let width: CGFloat
    let opacity: Double
    var cornerRadius: CGFloat = 24

    var body: some View {
        // Use a filled rectangle with rounded rectangle cutout
        // This ensures the inner edge has visible rounded corners
        Rectangle()
            .fill(color.opacity(opacity))
            .reverseMask {
                RoundedRectangle(cornerRadius: cornerRadius)
                    .padding(width) // Inset by the border width to create the ring effect
            }
            .ignoresSafeArea()
    }
}

// MARK: - Corner Mask Overlay
/// Creates a black overlay with a rounded rectangle cutout to mask camera preview corners

struct CornerMaskOverlay: View {
    let cornerRadius: CGFloat
    var maskColor: Color = .black
    
    var body: some View {
        Rectangle()
            .fill(maskColor)
            .reverseMask {
                RoundedRectangle(cornerRadius: cornerRadius)
            }
    }
}

// MARK: - Reverse Mask Extension

extension View {
    @ViewBuilder
    func reverseMask<Mask: View>(@ViewBuilder _ mask: () -> Mask) -> some View {
        self.mask(
            Rectangle()
                .overlay(
                    mask()
                        .blendMode(.destinationOut)
                )
                .compositingGroup()
        )
    }
}
