import Foundation
import SwiftUI

struct WelcomeScreen: View {
    @EnvironmentObject var store: AppStore

    var body: some View {
        VStack(spacing: 16) {
            Spacer()

            // logo
            Image.logo
                .resizable()
                .aspectRatio(contentMode: .fit)
                .frame(width: 140, height: 140)

            // text
            Text(L10n.Welcome.title)
                .font(.head1)
                .foregroundColor(.Main.black)
                .multilineTextAlignment(.center)
            Text(L10n.Welcome.subtitle)

                .multilineTextAlignment(.center)
                .padding(.horizontal, 32)
            Spacer()

            // buttons
            HStack {
                Button {
                    store.dispatch(.registrationAction(.goTo(.addExists)))
                    store.dispatch(.changeFlow(.registration))
                } label: {
                    Text(L10n.Welcome.Btn.login)
                }
                .buttonStyle(SecondaryButtonStyle())
                Spacer()
                Button {
                    store.dispatch(.registrationAction(.goTo(.addNew)))
                    store.dispatch(.changeFlow(.registration))
                } label: {
                    Text(L10n.Welcome.Btn.register)
                }
                .buttonStyle(PrimaryButtonStyle())
            }
            .padding(.horizontal, 32)
            .padding(.bottom, 60)
        }
        .frame(maxWidth: .infinity)
        .ignoresSafeArea()
        .background(Color.Main.backgroundLight)
    }
}

#if DEBUG
    struct WelcomeScreen_Previews: PreviewProvider {
        static var previews: some View {
            showPreview(stateConfig: { state in
                state.currentFlow = .welcome
                state.accountsState.accounts = []
            })
        }
    }
#endif
