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

import UIKit
class YHPayMemberContentItems: UIView {
    //用来自动布局
    lazy var fakeView: UIView = {
        let view = UIView()
        return view
    }()
    
    
    lazy var lineView: UIView = {
        let view = UIView()
        view.backgroundColor = .separatorColor
        return view
    }()
    
    
    lazy var whiteContentView: UIView = {
        let view = UIView()
        view.backgroundColor = .clear
        return view
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}

private extension YHPayMemberContentItems {
    func setupUI() {
        backgroundColor = .contentBkgColor
        layer.cornerRadius = kCornerRadius3
        clipsToBounds = true
    }
}


extension YHPayMemberContentItems {
    func updateUI( type : Int) {
        whiteContentView.removeSubviews()
        removeSubviews()
        
        
        addSubview(whiteContentView)
        whiteContentView.snp.makeConstraints { make in
            make.top.bottom.equalToSuperview()
            make.right.equalToSuperview().offset(-14)
            make.left.equalToSuperview().offset(14)
        }
        
        let item = YHPayMemberContentItem()
        whiteContentView.addSubview(item)
        item.snp.makeConstraints { make in
            make.top.equalTo(kMargin)
            make.left.right.equalToSuperview()
        }
        item.updateUI(title: "档案号：",detail: "TQEN-03709888-23",showBtn: true)
        
        
        var lastView : UIView = item
        
        
        if type == 1 || type == 2 {
            do {
                let item = YHPayMemberContentItem()
                whiteContentView.addSubview(item)
                item.snp.makeConstraints { make in
                    make.top.equalTo(lastView.snp.bottom).offset(kMargin)
                    make.left.right.equalToSuperview()
                }
                item.updateUI(title: "可缴费时间段：",detail: "2023.10.1 - 2023.11.20",showBtn: false)
                lastView = item
            }
            
            
            do {
                let item = YHPayMemberContentItem()
                whiteContentView.addSubview(item)
                item.snp.makeConstraints { make in
                    make.top.equalTo(lastView.snp.bottom).offset(kMargin)
                    make.left.right.equalToSuperview()
                }
                item.updateUI(title: "缴费金额：",detail: "230港币（≈211.89人民币)",showBtn: false)
                lastView = item
            }
            
        } else if type == 3 {
            
            do {
                let item = YHPayMemberContentItem()
                whiteContentView.addSubview(item)
                item.snp.makeConstraints { make in
                    make.top.equalTo(lastView.snp.bottom).offset(kMargin)
                    make.left.right.equalToSuperview()
                }
                item.updateUI(title: "缴费金额：",detail: "230港币（≈211.89人民币)",showBtn: false)
                lastView = item
            }
            
            do {
                whiteContentView.addSubview(lineView)
                lineView.snp.makeConstraints { make in
                    make.top.equalTo(lastView.snp.bottom).offset(kMargin)
                    make.height.equalTo(1)
                    make.left.right.equalToSuperview()
                }
                lastView = lineView
            }
            
            do {
                let item = YHPayMemberContentItem()
                whiteContentView.addSubview(item)
                item.snp.makeConstraints { make in
                    make.top.equalTo(lastView.snp.bottom).offset(kMargin)
                    make.left.right.equalToSuperview()
                }
                item.updateUI(title: "缴费电子签证：",detail: "Visa QMEN-0021813-22.pdf",oneLine: false,showBtn: true)
                lastView = item
            }
        }
        
        
        
        whiteContentView.addSubview(fakeView)
        fakeView.snp.makeConstraints { make in
            make.top.equalTo(lastView.snp.bottom).offset(kMargin)
            make.height.equalTo(1)
            make.left.bottom.right.equalToSuperview()
        }
        
    }
}
