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

import UIKit

class YHContractCell: UITableViewCell {
    static let cellReuseIdentifier = "YHContractCell"
    
    var dataModel : YHContactItemModel? {
        didSet {
            updateUI()
        }
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    lazy var contractNameLable = {
        let lable = UILabel()
        lable.textColor = UIColor(red: 0.133, green: 0.133, blue: 0.133, alpha: 1)
        lable.font = kFont(name: "PingFangSC-Medium", size: 17)
        lable.text = "香港优秀人才计划-张先生"
        return lable
    }()
    
    lazy var contractIdLable = {
        let lable = UILabel()
        lable.font = kFont(name: "PingFangSC-Medium", size: 17)
        lable.text = "订单号：10936"
        lable.textColor = UIColor(red: 0.533, green: 0.561, blue: 0.596, alpha: 1)
        lable.font = kFont(name: "PingFangSC-Regular", size: 12)
        return lable
    }()
    
    
    
    
    
    
}

extension YHContractCell {
    func updateUI() {
        contractNameLable.text = dataModel?.productName ?? "-"
        contractIdLable.text = dataModel?.orderSn ?? "-"
    }
    
    func setupUI() {
        let holdView = UIView()
        holdView.backgroundColor = .white
        holdView.layer.cornerRadius = 12
        holdView.clipsToBounds = true
        
        backgroundColor = .clear
        contentView.backgroundColor = .clear
        
        contentView.addSubview(holdView)
        holdView.snp.makeConstraints { make in
            make.top.bottom.equalToSuperview()
            make.left.equalTo(16)
            make.right.equalTo(-16)
        }
        
        
        let nextImgV = UIImageView()
        nextImgV.image = UIImage(named: "service_center_right_next_icon")
        nextImgV.contentMode = .scaleAspectFill
        holdView.addSubview(nextImgV)
        nextImgV.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.right.equalTo(-16)
            make.width.height.equalTo(16)
        }
        
        
        holdView.addSubview(contractNameLable)
        contractNameLable.snp.makeConstraints { make in
            make.top.equalTo(16)
            make.left.equalTo(21)
            make.right.equalTo(nextImgV.snp.left).offset(-10)
            make.height.equalTo(24)
        }
        
        
        holdView.addSubview(contractIdLable)
        contractIdLable.snp.makeConstraints { make in
            make.top.equalTo(contractNameLable.snp.bottom).offset(4)
            make.left.equalTo(contractNameLable)
            make.right.equalTo(contractNameLable)
            make.height.equalTo(20)
            make.bottom.equalToSuperview().offset(-16)
        }
    }
    
}
