import SwiftUI

// MARK: - ChangeModeAlertModifier
struct ChangeModeAlertModifier: ViewModifier {
    @Binding var isPresented: Bool
    let currentMode: Bool
    let onConfirm: () -> Void

    func body(content: Content) -> some View {
        content.alert("", isPresented: $isPresented) {
            Button("Yes") {
                onConfirm()
            }
            Button("No") {}
        } message: {
            Text("Do you change an warning mode?")
        }
    }
}

// MARK: - LocationAlertModifier
struct LocationAlertModifier: ViewModifier {
    @Binding var isPresented: Bool

    func body(content: Content) -> some View {
        content.alert("Location", isPresented: $isPresented) {
            Button("Cancel") {}
            Button("Setting") {
                guard let settingsURL = URL(string: UIApplication.openSettingsURLString) else {
                    return
                }
                UIApplication.shared.open(settingsURL, options: [:], completionHandler: nil)
            }
        } message: {
            Text("To use ECA, set the permission to use location information to ALWAYS.")
        }
    }
}

// MARK: - UpdateAlertModifier
struct UpdateAlertModifier: ViewModifier {
    @Binding var isPresented: Bool
    let appStoreURL: URL

    func body(content: Content) -> some View {
        content.alert("Update", isPresented: $isPresented) {
            Button("Go to app page") {
                UIApplication.shared.open(appStoreURL, options: [:], completionHandler: nil)
            }
        } message: {
            Text("A new version of this app is available.")
        }
    }
}

// MARK: - WarningModeAlertModifier
struct WarningModeAlertModifier: ViewModifier {
    @Binding var isPresented: Bool
    @Binding var isSignalrRestert: Bool
    let onConfirm: () -> Void

    func body(content: Content) -> some View {
        content.alert("Error", isPresented: $isPresented) {
            Button("OK") {
                onConfirm()
                isSignalrRestert = false
            }
        } message: {
            Text("The mode did not change.")
        }
    }
}
