import SwiftUI
import SFSafeSymbols

struct ColoredButton: View {

    let icon: SFSymbol

    let text: LocalizedStringKey

    let fillColor: Color

    let textColor: Color

    let action: () -> Void

    init(icon: SFSymbol, text: LocalizedStringKey, fillColor: Color = .blue, textColor: Color = .white, action: @escaping () -> Void) {
        self.icon = icon
        self.text = text
        self.fillColor = fillColor
        self.textColor = textColor
        self.action = action
    }

    init(delete: @escaping () -> Void) {
        self.icon = .trash
        self.text = "Delete"
        self.fillColor = .red
        self.textColor = .white
        self.action = delete
    }

    var body: some View {
        Button(action: action) {
            HStack {
                Spacer()
                Image(systemSymbol: icon)
                Text(text)
                    .padding(.vertical, 8)
                Spacer()
            }
            .foregroundStyle(textColor)
            .background(RoundedRectangle(cornerRadius: 8).fill(fillColor))
        }.buttonStyle(.plain)
    }
}
