//
//  YHCertificateInfoCell.swift
//  galaxy
//
//  Created by edy on 2024/3/13.
//  Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//

import UIKit
import AttributedString

enum YHCertificateUploadStatus : Int {
    case unknown = 0
    case preUpload = 1
    case review = 2
    case rejected = 3
    case finish = 4
}

class YHCertificateInfoCell: UITableViewCell {

    
    static let cellReuseIdentifier = "YHCertificateNameCell"
    
    var status : YHCertificateUploadStatus = .unknown
    var whiteView: UIView!
    var nameTextView: UITextView!
    var infoLabel: UILabel!
    var statusBtn: UIButton!
    
    private lazy var templateLabel : UILabel = {
        let customLabel = UILabel(frame: CGRect(x: 0, y: 0, width: 48, height: 16))
        customLabel.text = "资料模版"
        customLabel.font = .PFSC_M(ofSize: 10)
        customLabel.backgroundColor = .brandMainColor8
        customLabel.textColor = .brandMainColor
        customLabel.layer.cornerRadius = 3
        customLabel.clipsToBounds = true
        customLabel.textAlignment = .center
        return customLabel
    }()
    

    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupUI()
    }
    
    func update() {
        
        var titleColor: UIColor = .labelTextColor2
        switch status  {
        case .preUpload:
            titleColor = .brandMainColor
        case .rejected:
            titleColor = .failColor
        case .review, .finish:
            titleColor = .labelTextColor2
        case .unknown:
            titleColor = .labelTextColor2
        }
    }
    
    func setupUI() {
        
        self.selectionStyle = .none
        contentView.backgroundColor = UIColor(hexString:"#F8F8F8")
        
        whiteView = UIView()
        whiteView.layer.cornerRadius = 6.0
        whiteView.clipsToBounds = true
        whiteView.backgroundColor = .white
        contentView.addSubview(whiteView)
        
        nameTextView = UITextView()
        nameTextView.textColor = UIColor.mainTextColor
        nameTextView.font = UIFont.PFSC_M(ofSize: 16)
        nameTextView.isScrollEnabled = false
        nameTextView.isEditable = false
        nameTextView.isSelectable = false
        whiteView.addSubview(nameTextView)
        
        nameTextView.attributed.text = """
        \("我是资料名称", .foreground(UIColor.mainTextColor), .font(UIFont.PFSC_M(ofSize: 16)))  \(.view(templateLabel, .original(.center)))
        """
        
        infoLabel = UILabel()
        infoLabel.textColor = UIColor.labelTextColor2
        infoLabel.textAlignment = .left
        infoLabel.font = UIFont.PFSC_R(ofSize:11)
        infoLabel.text = "类型：证件资料   所属人：张康"
        whiteView.addSubview(infoLabel)
        
        statusBtn = UIButton()
        statusBtn.titleLabel?.font = UIFont.PFSC_R(ofSize:14)
        
        let iconWidth = 16.0
        let titleWidth = 42.0
        statusBtn.titleEdgeInsets = UIEdgeInsets(top: 0, left: -iconWidth, bottom: 0, right: iconWidth)
        statusBtn.imageEdgeInsets = UIEdgeInsets(top: 0, left: titleWidth, bottom: 0, right: -titleWidth)
        statusBtn.setImage(UIImage(named:"my_cer_arrow_right"), for:.normal)
        statusBtn.setTitle("待上传", for:.normal)
        statusBtn.setTitleColor(.blue, for:.normal)
        whiteView.addSubview(statusBtn)
        
        whiteView.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(20)
            make.right.equalToSuperview().offset(-20)
            make.top.bottom.equalToSuperview()
        }
        
        nameTextView.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(10)
            make.top.equalToSuperview().offset(4)
            make.right.equalTo(statusBtn.snp.left)
        }
        
        infoLabel.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(16)
            make.right.equalTo(nameTextView)
            make.top.equalTo(nameTextView.snp.bottom)
            make.bottom.equalToSuperview().offset(-12)
            make.height.equalTo(20)
        }
        
        statusBtn.snp.makeConstraints { make in
            make.height.equalTo(60)
            make.width.equalTo(92)
            make.centerY.equalToSuperview()
            make.right.equalToSuperview()
        }
    }

}
