//
//  YHWholeScreenTipsView.swift
//  galaxy
//
//  Created by davidhuangA on 2024/3/8.
//  Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//

import UIKit

enum YHWholeScreenTipsViewType : Int {
    case unKnow //默认情况
    case residenceInfo //居住信息
    case degreeType //学位类型
    case company //用人单位介绍
}



class YHWholeScreenTipsView: UIView {
    
    lazy var blackMaskView: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor(hex: 0x000000, alpha: 0.1)
        let tap = UITapGestureRecognizer(target: self, action: #selector(dismiss))
        view.addGestureRecognizer(tap)
        return view
    }()
    
    lazy var whiteContentView: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor(hex: 0x222222, alpha: 0.9)
        view.layer.cornerRadius = kCornerRadius6
        view.clipsToBounds = true
        return view
    }()
    
    lazy var contentLable : UILabel = {
        let lable = UILabel()
        lable.text = "依日期顺序列出你自出生后曾居住12个月或更长时间的所有国家或地区，包括你的现居国家或地区"
        lable.font = UIFont.PFSC_R(ofSize: 14)
        lable.textColor = .white
        lable.numberOfLines = 0
        return lable
    }()
    
    
    init(type: YHWholeScreenTipsViewType, targetView : UIView) {
        super.init(frame: UIScreen.main.bounds)
        contentLable.text = getTitleBy(type: type)
        self.createUI(targetView : targetView)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func getTitleBy(type : YHWholeScreenTipsViewType)-> String {
        switch type {
        case .residenceInfo:
            return "依日期顺序列出你自出生后曾居住12个月或更长时间的所有国家或地区，包括你的现居国家或地区"
        case .degreeType:
            return "该内容在学位证上，通常是授予后面，如授予“理学”学士学位，则填理学"
        case .company:
            return "可先填写用人单位名称，选择指定的用人单位后，系统将为您自动填写单位介绍"
        default:
            return "--"
        }
    }
    
    func show() {
        UIApplication.shared.yhKeyWindow()?.addSubview(self)
    }
    
    static func show(type:YHWholeScreenTipsViewType, targetView : UIView) {
        let view = YHWholeScreenTipsView(type: type,targetView : targetView)
        view.show()
    }
    
    @objc func dismiss() {
        self.removeFromSuperview()
    }
    
    func createUI(targetView : UIView) {
        addSubview(blackMaskView)
        addSubview(whiteContentView)
        whiteContentView.addSubview(contentLable)
        
        blackMaskView.snp.makeConstraints { make in
            make.edges.equalTo(0)
        }
        let rrrrr = targetView.convert(targetView.bounds, to: UIApplication.shared.yhKeyWindow())
        let left = rrrrr.origin.x
        let top = rrrrr.origin.y + targetView.height + 5
        
        whiteContentView.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(left)
            make.top.equalToSuperview().offset(top)
            make.width.equalTo(214)
        }
        
        contentLable.snp.makeConstraints { make in
            make.top.left.equalTo(12)
            make.right.bottom.equalTo(-12)
        }
    }
}

