import ComponentLibrary
import ComposableArchitecture
import Foundation
import Localization
import SwiftUI

@Reducer
public struct ForceUpdate {
    @ObservableState
    public struct State: Equatable {}

    public enum Action: Equatable {
        case openAppStore
    }

    @Dependency(\.openURL) var openURL

    public var body: some ReducerOf<Self> {
        Reduce { _, action in
            switch action {
            case .openAppStore:
                let url = URL(string: "https://www.suno.com/ios")!
                return .run { _ in
                    await openURL(url)
                }
            }
        }
    }
}

public struct ForceUpdateScreen: View {
    let store: StoreOf<ForceUpdate>

    public var body: some View {
        FailedView(
            title: L10n.FeatureApp.forceUpdateTitle,
            message: L10n.FeatureApp.forceUpdateMessage,
            buttonTitle: L10n.FeatureApp.forceUpdateButton,
            action: { store.send(.openAppStore) }
        )
    }
}
