//
//  AppDelegate + UIAppearance.swift
//  SleepDoctor
//
//  Created by DAVIDiOS1 on 2020/12/24.
//  Copyright © 2020 sumian. All rights reserved.
//

import UIKit

// MARK: - 设置导航栏样式
extension AppDelegate{
    func customAppearance() {
        setNavigationBarAppearanceWhenContainedInInstancesOf(containers: [YHNavigationController.self])
        setNavigationBarAppearanceWhenContainedInInstancesOf(containers: [YHBaseViewController.self])
    }
    
    func setNavigationBarAppearanceWhenContainedInInstancesOf(containers: [UIAppearanceContainer.Type]){
        let navigationBarAppearance = UINavigationBar.appearance(whenContainedInInstancesOf: containers)
        
        navigationBarAppearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor : UIColor.commonColor100,NSAttributedString.Key.font:UIFont.PFSCM(ofSize: 16)]
        navigationBarAppearance.barTintColor = UIColor.yellow
        navigationBarAppearance.tintColor = UIColor.commonColor100
        navigationBarAppearance.backIndicatorImage = UIImage(named: "back_icon")
        navigationBarAppearance.backIndicatorTransitionMaskImage = UIImage(named: "back_icon")
        navigationBarAppearance.setBackgroundImage(UIImage.from(color: UIColor.clear),for: .default)
        navigationBarAppearance.isOpaque = true
        navigationBarAppearance.shadowImage = nil
        
        //隐藏返回文字
        if #available(iOS 13, *) {
            UIBarButtonItem.appearance().setBackButtonTitlePositionAdjustment(UIOffset( horizontal: -UIDevice.kScreenW, vertical: 0), for: .default)
        }
        
        let barItemAppearance = UIBarButtonItem.appearance(whenContainedInInstancesOf: containers)
        
        barItemAppearance.setTitleTextAttributes([NSAttributedString.Key.foregroundColor : UIColor.clear,NSAttributedString.Key.font:UIFont.systemFont(ofSize: 14)], for: UIControl.State.normal)
        
        barItemAppearance.setTitleTextAttributes([NSAttributedString.Key.foregroundColor : UIColor.clear,NSAttributedString.Key.font:UIFont.systemFont(ofSize: 14)], for: UIControl.State.highlighted)
    }
}



// MARK: - Pay 支付
extension AppDelegate {
    
    func payCallback(url: URL) {
//        //支付宝支付
//        if url.host == "safepay" {
//            AlipaySDK.defaultService().processOrder(withPaymentResult: url, standbyCallback: { resultDic in
//                let status = resultDic?["resultStatus"] as? String ?? ""
//                var success: Bool = false
//                if status == "9000" {
//                    success = true
//                    print("支付宝: 支付成功")
//                } else {
//                    success = false
//                    print("支付宝: 支付失败")
//                }
//                NotificationCenter.default.post(name: BsConstant.BsNotification.payResultNotification, object: success)
//            })
//        }
    }
    
}

