//
//  QSLAppInfoController.swift
//  QuickSearchLocation
//
//  Created by Destiny on 2024/12/9.
//

import UIKit
import YYText

class QSLAppInfoController: QSLBaseController {
    
//    let photoClassifier = PhotoClassifier()
    
    lazy var appIcon: UIImageView = {
        
        let imageView = UIImageView()
        imageView.image = UIImage(named: "mine_about_logo")
        return imageView
    }()
    
    lazy var appTitle: UILabel = {
      
        let label = UILabel()
        label.text("手机关爱定位")
        label.font(15)
        label.textColor = QSLColor.Color_202020
        return label
    }()
    
    lazy var versionLabel: UILabel = {
        
        let label = UILabel()
        label.text("当前版本：\(QSLApi.appVersionName)")
        label.font(13)
        label.textColor = .hexStringColor(hexString: "#A7A7A7")
        return label
    }()
    
    lazy var serviceLabel: YYLabel = {
       
        let label = YYLabel()
        
        let attr = NSMutableAttributedString()
        
        let blankAttr = NSMutableAttributedString(string: " ")
        blankAttr.font(12)
        
        let privacyHL = YYTextHighlight()
        var privacyStr = "《隐私权政策》"
        
        let privacyText = NSMutableAttributedString(string: privacyStr)
        
        privacyText.font(12)
        privacyText.color(.hexStringColor(hexString: "#2F79FF"))
        privacyText.yy_setTextHighlight(privacyHL, range: NSRange(location: 0, length: privacyStr.count))
        privacyHL.tapAction = { [weak self] containerView, text, range, rect in
            self?.privacyAction()
        }
        attr.append(privacyText)
        
        attr.append(blankAttr)
        
        let andAttr = NSMutableAttributedString(string: "和")
        andAttr.font(12)
        andAttr.color(.hexStringColor(hexString: "#A7A7A7"))
        attr.append(andAttr)
        
        attr.append(blankAttr)
        
        let serviceHL = YYTextHighlight()
        var serviceStr = "《用户协议》"

        let serviceText = NSMutableAttributedString(string: serviceStr)
        serviceText.font(12)
        serviceText.color(.hexStringColor(hexString: "#2F79FF"))
        serviceText.yy_setTextHighlight(serviceHL, range: NSRange(location: 0, length: serviceStr.count))
        serviceHL.tapAction = { [weak self] containerView, text, range, rect in
            self?.serviceAction()
        }
        
        attr.append(serviceText)

        label.attributedText = attr
        
        return label
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        initView()

//        let loadingVC = LoadingViewController()
//        present(loadingVC, animated: true)
//        photoClassifier.classifyPhotos { result in
//            // 处理截图
//            print("找到 \(result.screenshots.count) 张截图")
//            
//            // 处理地点分组
//            for (location, assets) in result.locations {
//                print("\(location): \(assets.count) 张照片")
//            }
//            
//            // 处理人物分组
//            for (person, assets) in result.people {
//                print("\(person): \(assets.count) 张照片")
//            }
//        }
    }
    
    override func viewWillAppear(_ animated:Bool) {
//        super.viewWillAppear(animated)
        self.navigationController?.setNavigationBarHidden(false, animated: animated)
    }
    
    @objc func privacyAction() {
        
        let vc = QSLWebViewController()
        vc.webUrl = QSLConfig.AppPrivacyAgreementLink
        vc.title = "隐私政策"
        self.navigationController?.pushViewController(vc, animated: true)
    }
    
    @objc func serviceAction() {
        
        let vc = QSLWebViewController()
        vc.webUrl = QSLConfig.AppServiceAgreementLink
        vc.title = "服务协议"
        self.navigationController?.pushViewController(vc, animated: true)
    }
}

extension QSLAppInfoController {
    
    func initView() {
        
        self.view.backgroundColor = .white
        
        self.view.addSubview(appIcon)
        appIcon.snp.makeConstraints { make in
            make.size.equalTo(CGSize(width: 72.rpx, height: 72.rpx))
            make.centerX.equalToSuperview()
            make.top.equalTo(73.rpx)
        }
        
        self.view.addSubview(appTitle)
        appTitle.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(appIcon.snp.bottom).offset(12.rpx)
        }
        
        self.view.addSubview(versionLabel)
        versionLabel.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(appTitle.snp.bottom).offset(2.rpx)
        }
        
        self.view.addSubview(serviceLabel)
        serviceLabel.snp.makeConstraints { make in
            make.bottom.equalTo(-30.rpx)
            make.centerX.equalToSuperview()
        }
    }
}
