// MARK: - Main Component
struct CustomAlert: View {
@Binding var isPresented: Bool
let title: String
let message: String
var action: () -> Void = {}
var secondaryAction: (() -> Void)? = nil
var tertiaryAction: (() -> Void)? = nil
var autoDismiss: Bool = false
var autoDismissDelay: Double = 3.0
var dismissible: Bool = true
@State private var dismissTimer: Timer?
var body: some View {
ZStack {
Color.black.opacity(0.3)
.ignoresSafeArea()
.blur(radius: 10)
.onTapGesture {
if dismissible {
isPresented = false
}
}
if isPresented {
VStack(spacing: 0) {
// Icon and Title
HStack(spacing: 12) {
Circle()
.fill(Color(hex: "#10b981").opacity(0.2))
.frame(width: 40, height: 40)
.overlay(
Text("✓")
.font(.system(size: 20, weight: .bold))
.foregroundColor(Color(hex: "#10b981"))
)
Text(title)
.font(.system(size: 20, weight: .bold))
.foregroundColor(Color(hex: "#000000"))
}
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.horizontal, 24)
.padding(.top, 24)
// Message
Text(message)
.font(.system(size: 14))
.foregroundColor(Color(hex: "#666666"))
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.horizontal, 24)
.padding(.top, 12)
// Buttons
HStack(spacing: 8) {
Button("OK") {
action()
isPresented = false
}
.buttonStyle(.borderedProminent)
.tint(Color(hex: "#10b981"))
}
.padding(.horizontal, 24)
.padding(.top, 20)
.padding(.bottom, 24)
}
.frame(maxWidth: 400)
.background(Color(hex: "#ffffff"))
.cornerRadius(12)
.shadow(color: Color.black.opacity(0.1), radius: 20, x: 0, y: 10)
.transition(.opacity)
.animation(.easeOut(duration: 0.3), value: isPresented)
.onAppear {
if autoDismiss {
dismissTimer = Timer.scheduledTimer(withTimeInterval: autoDismissDelay, repeats: false) { _ in
isPresented = false
}
}
}
.onDisappear {
dismissTimer?.invalidate()
}
}
}
}
}