import SwiftUI

// This is a custom button style that changes its background color when hovered
public struct HoverButtonStyle: ButtonStyle {
    @State private var isHovered: Bool
    private var padding: CGFloat
    private var hoverColor: Color
    private var backgroundColor: Color
    private var cornerRadius: CGFloat
    
    public init(
        isHovered: Bool = false,
        padding: CGFloat = 4,
        hoverColor: Color = .hoverColor,
        backgroundColor: Color = .clear,
        cornerRadius: CGFloat = 4
    ) {
        self.isHovered = isHovered
        self.padding = padding
        self.hoverColor = hoverColor
        self.backgroundColor = backgroundColor
        self.cornerRadius = cornerRadius
    }

    public func makeBody(configuration: Configuration) -> some View {
        configuration.label
            .scaledPadding(padding)
            .background(
                configuration.isPressed
                ? Color.gray.opacity(0.2)
                    : isHovered
                        ? hoverColor
                : backgroundColor
            )
            .cornerRadius(cornerRadius)
            .onHover { hover in
                isHovered = hover
            }
    }
}
