import ComponentLibrary
import ComposableArchitecture
import FeatureOnboardingModels
import Localization
import SwiftUI

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

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

    var body: some View {
        VStack(spacing: 32) {
            Image.Assets.madlibsOnboardingNotificationIcon
                .resizable()
                .aspectRatio(contentMode: .fit)
                .frame(width: 128.0, height: 128.0)

            VStack(spacing: 16) {
                Text(L10n.FeatureOnboarding.madlibsDontMissOut)
                    .typographyV1(.headline2.editorialNewRegular())
                    .foregroundStyle(Color.SemanticV1.alwaysLighterBeige)
                    .multilineTextAlignment(.center)
                    .lineLimit(2)
                    .minimumScaleFactor(0.8)

                Text(createAttributedSubtitle())
                    .frame(width: 320)
                    .kerning(1.0)
                    .multilineTextAlignment(.center)
            }
        }
    }

    private func createAttributedSubtitle() -> AttributedString {
        let regularAttributes = TypographyV1.attributedContainer(
            .body3.size { _ in 16.0 }.neueMontrealRegular(),
            .SemanticV1.alwaysLighterBeige
        )

        let boldAttributes = TypographyV1.attributedContainer(
            .body3.size { _ in 16.0 }.ppNeueMontrealBook(),
            .SemanticV1.alwaysLighterBeige
        )

        let partA = AttributedString(L10n.FeatureOnboarding.madlibsNotificationsAllowTo + " ", attributes: regularAttributes)
        let partB = AttributedString(L10n.FeatureOnboarding.madlibsNotificationsGetNotified + " ", attributes: boldAttributes)
        let partC = AttributedString(L10n.FeatureOnboarding.madlibsNotificationsAndStayUpdated, attributes: regularAttributes)

        var attributedString = AttributedString()
        attributedString.append(partA)
        attributedString.append(partB)
        attributedString.append(partC)

        return attributedString
    }
}
