//
//  YHUserInfoHeaderView.swift
//  galaxy
//
//  Created by edy on 2024/2/6.
//  Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//

import UIKit

class YHUserInfoHeaderView: UIView {

    static let bgRatio = 312.0/375.0 // 背景图高宽比
    static let height = (KScreenWidth*bgRatio + 24)
    
    var settingBlock:(()->Void)?
    var evaluateBlock:(()->Void)?

    
    private lazy var avarImgView:UIImageView = {
        let img = UIImageView(image: UIImage(named: "mine_head_default"))
        return img
    }()
    
    private lazy var bgImgView:UIImageView = {
        let imgView = UIImageView(image: UIImage(named: "mine_header_bg"))
        imgView.isHidden = true
        return imgView
    }()
    
    private lazy var userNameLabel:UILabel = {
        let label = UILabel()
        label.textColor = UIColor(hexString:"##242424")
        label.textAlignment = NSTextAlignment.left
        label.font = UIFont.PFSC_B(ofSize: 21)
        return label
    }()
    
    private lazy var infoLabel:UILabel = {
        let label = UILabel()
        label.textColor = UIColor(hexString:"#949DB5")
        label.textAlignment = NSTextAlignment.left
        label.font = UIFont.PFSC_R(ofSize: 13)
        return label
    }()
    
    private lazy var evaluateView:UIView = {
        let view = UIView()
        return view
    }()
    
    private lazy var evaluateLabel:UILabel = {
        let label = UILabel()
        label.textColor = UIColor(hexString:"#242424")
        label.textAlignment = NSTextAlignment.left
        label.font = UIFont.PFSC_M(ofSize: 17)
        return label
    }()
    
    private lazy var evaluateBtn: UIButton = {
        let btn = UIButton()
        btn.setTitle("免费测评", for: .normal)
        btn.titleLabel?.font = UIFont.PFSC_M(ofSize: 12)
        btn.setTitleColor(.white, for: .normal)
        btn.backgroundColor = UIColor(hexString:"#242424")
        btn.layer.cornerRadius = 6.0
        btn.clipsToBounds = true
        btn.addTarget(self, action: #selector(didClickEvaluateBtn(btn:)), for: .touchUpInside)
        return btn
    }()
    
    private lazy var evaluateBgImgView:UIImageView = {
        // radio:750:623
        let img = UIImageView(image: UIImage(named: "mine_evaluate_bg"))
        return img
    }()
    
    private lazy var settingBtn: UIButton = {
        let btn = UIButton()
        btn.setImage(UIImage(named: "mine_btn_setting"), for: .normal)
        btn.addTarget(self, action: #selector(didClickSettingBtn(btn:)), for: .touchUpInside)
        return btn
    }()
    
    private lazy var settingView:UIView = {
        let view = UIView()
        return view
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        createUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    static func createView() -> YHUserInfoHeaderView {
       let view = YHUserInfoHeaderView(frame: CGRect(x: 0, y: 0, width: KScreenWidth, height: Self.height))
       return view
    }
    
    private func createUI() {
            
        self.addSubview(bgImgView)
        self.addSubview(settingView)
        settingView.addSubview(settingBtn)
        
        self.addSubview(avarImgView)
        self.addSubview(userNameLabel)
        self.addSubview(infoLabel)
        
        self.addSubview(evaluateView)
        evaluateView.addSubview(evaluateBgImgView)
        evaluateView.addSubview(evaluateLabel)
        evaluateView.addSubview(evaluateBtn)
        
        userNameLabel.text = "登录/注册".local
        infoLabel.text = "点赞 0  收藏 0 最近浏览 0".local
        evaluateLabel.text = "香港身份20秒极速测评".local
        
        bgImgView.snp.makeConstraints { make in
            make.left.right.top.equalToSuperview()
            make.height.equalTo(bgImgView.snp.width).multipliedBy(Self.bgRatio)
        }
        
        settingView.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.top.equalToSuperview().offset(k_Height_statusBar())
            make.height.equalTo(44.0)
        }
        
        settingBtn.snp.makeConstraints { make in
            make.size.equalTo(CGSize(width: 21, height: 21))
            make.right.equalToSuperview().offset(-21)
            make.centerY.equalToSuperview()
        }
        
        avarImgView.snp.makeConstraints { make in
            make.size.equalTo(CGSize(width: 72, height: 72))
            make.top.equalTo(settingBtn.snp.bottom).offset(12)
            make.left.equalToSuperview().offset(30)
        }
        
        userNameLabel.snp.makeConstraints { make in
            make.left.equalTo(avarImgView)
            make.top.equalTo(avarImgView.snp.bottom).offset(16)
            make.right.equalToSuperview().offset(-30)
            make.height.equalTo(30.0)
        }
        
        infoLabel.snp.makeConstraints { make in
            make.left.equalTo(avarImgView)
            make.right.equalToSuperview().offset(-30)
            make.height.equalTo(18.0)
            make.top.equalTo(userNameLabel.snp.bottom).offset(6)
        }
        
        evaluateView.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(18)
            make.right.equalToSuperview().offset(-18)
            make.height.equalTo(evaluateView.snp.width).multipliedBy(98.0/357.0)
            make.top.equalTo(infoLabel.snp.bottom).offset(9.0)
        }
        
        evaluateBgImgView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        
        evaluateLabel.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(20+13)
            make.centerY.equalToSuperview()
            make.height.equalTo(24.0)
        }
        
        evaluateBtn.snp.makeConstraints { make in
            make.right.equalToSuperview().offset(-20)
            make.centerY.equalToSuperview()
            make.size.equalTo(CGSize(width: 72, height: 30))
        }
    }
    
    @objc func didClickEvaluateBtn(btn: UIButton) {
        
        if let evaluateBlock = evaluateBlock {
            evaluateBlock()
        }
    }
    
    @objc func didClickSettingBtn(btn: UIButton) {
        
        if let settingBlock = settingBlock {
            settingBlock()
        }
    }

}
