import ComponentLibrary
import ComposableArchitecture
import FeatureOnboardingModels
import Foundation
import Localization
import SwiftUI

public struct OnboardingNotificationsQuestionScreen: View {
    @Bindable var store: StoreOf<OnboardingNotificationsQuestion>

    public init(store: StoreOf<OnboardingNotificationsQuestion>) {
        self.store = store
    }

    public var body: some View {
        ZStack {
            Color.clear

            VStack(spacing: .zero) {
                ZStack {
                    Color.clear
                    VStack {
                        HStack {
                            Text(L10n.FeatureOnboarding.dontMissOut)
                                .typographyV1(.headline2)
                            Text("👀")
                                .font(.system(size: 32))
                        }

                        var attributedString: AttributedString {
                            let boldAttributes = TypographyV1.attributedContainer(
                                .body3.size { _ in 16.0 }.neueMontrealMedium(),
                                .SemanticV1.textPrimary
                            )

                            let regularAttributes = TypographyV1.attributedContainer(
                                .body3.size { _ in 16.0 }.neueMontrealRegular(),
                                .SemanticV1.textPrimary
                            )

                            let strA = AttributedString(L10n.FeatureOnboarding.allowNotificationsTo + " ", attributes: regularAttributes)
                            let strB = AttributedString(L10n.FeatureOnboarding.getNotifiedWhenCopy + " ", attributes: boldAttributes)
                            let strC = AttributedString(L10n.FeatureOnboarding.stayUpdatedOnCopy, attributes: regularAttributes)

                            var attibutedString = AttributedString()
                            attibutedString.append(strA)
                            attibutedString.append(strB)
                            attibutedString.append(strC)
                            return attibutedString
                        }

                        Text(attributedString)
                            .frame(width: 320)
                            .kerning(1.0)
                            .multilineTextAlignment(.center)
                            .padding(.bottom, 16.0)

                        Image.Assets.onboardingNotificationIcon
                            .resizable()
                            .aspectRatio(contentMode: .fit)
                            .frame(width: 128.0, height: 128.0)
                    }
                }

                PrimaryButtonV1(
                    title: L10n.FeatureOnboarding.turnOnNotifications,
                    isLoading: false,
                    colorCombination: .dark,
                    preferredSize: .large,
                    action: {
                        store.send(.tappedShowNotification)
                    }
                )
                .padding(.bottom, 8.0)

                PrimaryButtonV1(
                    title: L10n.FeatureOnboarding.notNow,
                    isLoading: false,
                    colorCombination: .secondary,
                    preferredSize: .large,
                    action: {
                        store.send(.tappedSkip)
                    }
                )
                .padding(.bottom, 8.0)
            }
            .padding(.horizontal, 16.0)
        }
        .onAppear {
            store.send(.onAppear)
        }
        .navigationBarBackButtonHidden()
    }
}
