//
//  YHPersonInfoIdentificationCardView.swift
//  galaxy
//
//  Created by davidhuangA on 2024/1/30.
//  Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//

import UIKit

class YHPersonInfoIdentificationCardView: UIView {
    
    var dataModel : YHPersonInfoCellModel2? {
        didSet {
            updateUI()
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private lazy var titleLable : UILabel = {
        let lable = UILabel()
        lable.textColor = UIColor(hex: 0x222222)
        lable.font = UIFont.PFSC_M(ofSize: 14)
        return lable
    }()
    
    
    private lazy var frontImagV : UIImageView = {
        let lable = UIImageView()
        lable.image = UIImage(named: "person_info_id_front")
        lable.contentMode = .scaleAspectFit
        lable.layer.cornerRadius = 6
        lable.clipsToBounds = true
        return lable
    }()
    
    
    private lazy var backImagV : UIImageView = {
        let lable = UIImageView()
        lable.image = UIImage(named: "person_info_id_back")
        lable.contentMode = .scaleAspectFit
        lable.layer.cornerRadius = 6
        lable.clipsToBounds = true
        return lable
    }()
    
    
    private lazy var subtitleFrontLable : UILabel = {
        let lable = UILabel()
        lable.textColor = UIColor(hex: 0x888F98)
        lable.font = UIFont.PFSC_R(ofSize: 14)
        lable.text = "身份证头像面"
        lable.textAlignment = .center
        return lable
    }()
    
    
    private lazy var subtitleBackLable : UILabel = {
        let lable = UILabel()
        lable.textColor = UIColor(hex: 0x888F98)
        lable.font = UIFont.PFSC_R(ofSize: 14)
        lable.text = "身份证国徽面"
        lable.textAlignment = .center
        return lable
    }()
    
    
    lazy var bottomLine : UIView = {
        let lable = UIView()
        lable.backgroundColor = UIColor(hex: 0xF0F0F0)
        return lable
    }()
}


extension YHPersonInfoIdentificationCardView {
    func setupUI() {
        addSubview(titleLable)
        titleLable.snp.makeConstraints { make in
            make.top.equalTo(18)
            make.left.equalTo(18)
            make.right.equalTo(-18)
            make.height.equalTo(17)
        }
        
        
        addSubview(subtitleFrontLable)
        subtitleFrontLable.snp.makeConstraints { make in
            make.top.equalTo(titleLable.snp.bottom).offset(20)
            make.height.equalTo(17)
            make.left.equalTo(16)
            make.right.equalTo(self.snp.centerX).offset(-4)
        }
        
        addSubview(frontImagV)
        frontImagV.snp.makeConstraints { make in
            make.top.equalTo(subtitleFrontLable.snp.bottom).offset(13)
            make.height.equalTo(95)
            make.left.equalTo(subtitleFrontLable.snp.left)
            make.right.equalTo(subtitleFrontLable.snp.right)
        }
        
        
        
        addSubview(subtitleBackLable)
        subtitleBackLable.snp.makeConstraints { make in
            make.top.equalTo(titleLable.snp.bottom).offset(20)
            make.height.equalTo(17)
            make.right.equalTo(-18)
            make.left.equalTo(self.snp.centerX).offset(4)
        }
        
        
        addSubview(backImagV)
        backImagV.snp.makeConstraints { make in
            make.top.equalTo(subtitleBackLable.snp.bottom).offset(13)
            make.height.equalTo(95)
            make.left.equalTo(subtitleBackLable.snp.left)
            make.right.equalTo(subtitleBackLable.snp.right)
        }
        
        
        
        addSubview(bottomLine)
        bottomLine.snp.makeConstraints { make in
            make.top.equalTo(backImagV.snp.bottom).offset(15)
            make.height.equalTo(0.5)
            make.left.right.equalToSuperview()
            
            make.bottom.equalToSuperview()
        }
    }
}


extension YHPersonInfoIdentificationCardView {
    func updateUI() {
        guard let dataModel = dataModel else { return  }
        titleLable.text = dataModel.cellTitle
        subtitleFrontLable.text = dataModel.idType == 1 ? "身份证头像面" : "港澳通行证正面"
        subtitleBackLable.text = dataModel.idType == 1 ? "身份证国徽面" : "港澳通行证反面"
    }
}


