import SwiftUI

public struct GlassButtonStyle<S: InsettableShape>: ButtonStyle {
    private let shape: S
    private let strokeWidth: CGFloat
    private let padding: EdgeInsets

    public init(
        _ shape: S,
        strokeWidth: CGFloat = 1.0,
        padding: EdgeInsets
    ) {
        self.shape = shape
        self.padding = padding
        self.strokeWidth = strokeWidth
    }

    public init(
        _ shape: S,
        strokeWidth: CGFloat = 1.0,
        padding: CGFloat = 1.0
    ) {
        self.shape = shape
        self.padding = EdgeInsets(all: padding)
        self.strokeWidth = strokeWidth
    }

    public func makeBody(configuration: Configuration) -> some View {
        configuration.label
            .typographyV1(.button)
            .foregroundStyle(.white)
            .padding(.vertical, 12)
            .padding(.horizontal, 12)
            .background(Color.SemanticV2.backgroundFogThick)
            .clipShape(shape)
            .opacity(configuration.isPressed ? 0.5 : 1.0)
            .overlay(
                shape
                    .inset(by: strokeWidth / 2)
                    .stroke(Color.SemanticV2.borderPrimary, lineWidth: strokeWidth)
                    .colorScheme(.dark)
            )
    }
}
