//
//  AppDelegate.swift
//  PaymentModal Example
//
//  Created by Yuki Tokuhiro on 9/14/20.
//  Copyright © 2020 stripe-ios. All rights reserved.
//

import StripePaymentSheet
import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?

    func application(
        _: UIApplication,
        didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {
        // Override point for customization after application launch.
        #if targetEnvironment(simulator)
            if ProcessInfo.processInfo.environment["UITesting"] != nil {
                // Disable hardware keyboards in CI:
                let setHardwareLayout = NSSelectorFromString("setHardwareLayout:")
                UITextInputMode.activeInputModes
                    .filter { $0.responds(to: setHardwareLayout) }
                    .forEach { $0.perform(setHardwareLayout, with: nil) }

                // Delete cookies before running UI tests
                PaymentSheet.resetCustomer()
                PlaygroundController.resetCustomer()

                // Speed up animations for quicker CI times
                UIApplication.shared.windows.first(where: { $0.isKeyWindow })?.layer.speed = 100
            }
        #endif

        return true
    }

    // MARK: UISceneSession Lifecycle

    func application(
        _: UIApplication,
        configurationForConnecting connectingSceneSession: UISceneSession,
        options _: UIScene.ConnectionOptions
    ) -> UISceneConfiguration {
        // Called when a new scene session is being created.
        // Use this method to select a configuration to create the new scene with.
        return UISceneConfiguration(
            name: "Default Configuration", sessionRole: connectingSceneSession.role
        )
    }

    func application(
        _: UIApplication, didDiscardSceneSessions _: Set<UISceneSession>
    ) {
        // Called when the user discards a scene session.
        // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
        // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
    }
}
