//
//  YHPreviewInfoQuestionAndAnswerView.swift
//  galaxy
//
//  Created by davidhuangA on 2024/2/24.
//  Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//

import UIKit

class YHPreviewInfoQuestionAndAnswerItemView: UIView {
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
   
    //title
    private lazy var nameLable : UILabel = {
        let lable0 = UILabel(text: "--")
        lable0.textColor = UIColor.labelTextColor2
        lable0.font = UIFont.PFSC_R(ofSize: 14)
        lable0.numberOfLines = 0
        lable0.lineBreakMode = .byCharWrapping
        return lable0
    }()
    
    
    //subtitleLable
    private lazy var subtitleLable : UILabel = {
        let lable0 = UILabel(text: "--")
        lable0.textColor = UIColor.mainTextColor
        lable0.font = UIFont.PFSC_R(ofSize: 14)
        lable0.numberOfLines = 0
        lable0.lineBreakMode = .byWordWrapping
//        lable0.textAlignment = .right
        return lable0
    }()
    
    
    //remarkLable
    private lazy var remarkLable : UILabel = {
        let lable0 = UILabel(text: "--")
        lable0.textColor = UIColor.labelTextColor2
        lable0.font = UIFont.PFSC_R(ofSize: 14)
        lable0.numberOfLines = 0
        lable0.lineBreakMode = .byWordWrapping
        lable0.text = "--"
        return lable0
    }()
    
    private lazy var remarkHoldView : UIView =  {
        let view = UIView()
        view.backgroundColor = .contentBkgColor
        view.layer.cornerRadius = kCornerRadius6
        view.clipsToBounds = true
        view.isHidden = true
        return view
    }()
    
    
//    private lazy var remarkTextField : UITextView = {
//        let lable0 = UITextView(frame: .zero)
//        lable0.contentInset = UIEdgeInsets(top: 20, left: 12, bottom: 12, right: 12)
//        lable0.textColor = UIColor.labelTextColor2
//        lable0.font = UIFont.PFSC_R(ofSize: 14)
//        lable0.backgroundColor = .contentBkgColor
//        lable0.layer.cornerRadius = kCornerRadius6
//        lable0.clipsToBounds = true
//        lable0.isEditable = false
//        lable0.isSelectable = false
//        lable0.isScrollEnabled = false
//        lable0.text = "我是测试数据哈"
//        lable0.isHidden = true
//        return lable0
//    }()
    
    private func setupUI() {
        addSubview(nameLable)
        nameLable.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(18)
            make.left.equalToSuperview()
            make.right.equalToSuperview()
            make.height.equalTo(20)
        }
        
        addSubview(subtitleLable)
//        subtitleLable.snp.makeConstraints { make in
//            make.top.equalTo(nameLable.snp.bottom).offset(8)
//            make.right.equalToSuperview()
//            make.left.equalToSuperview()
//            
//            make.bottom.equalToSuperview()
//        }
        
    }
    
    var dataModel : YHPreviewQuestionAndAnswerModel? {
        didSet {
            updateUI()
        }
    }
}

extension YHPreviewInfoQuestionAndAnswerItemView {
    func updateUI() {
        guard let model = dataModel else { return }
        
        
        removeSubviews()
        setupUI()
        
        nameLable.text = model.question
        subtitleLable.text = model.answer
        
        if let remark = model.remark {
            
            subtitleLable.snp.makeConstraints { make in
                make.top.equalTo(nameLable.snp.bottom).offset(8)
                make.right.equalToSuperview()
                make.left.equalToSuperview()
            }
            
            
            addSubview(remarkHoldView)
            remarkHoldView.snp.makeConstraints { make in
                make.top.equalTo(subtitleLable.snp.bottom).offset(8)
                make.right.equalToSuperview()
                make.left.equalToSuperview()
            }
            remarkHoldView.addSubview(remarkLable)
            remarkLable.snp.makeConstraints { make in
                make.top.left.equalTo(12)
                make.bottom.right.equalTo(-12)
            }
            
            remarkLable.text = remark
            remarkHoldView.isHidden = false
            remarkHoldView.snp.makeConstraints { make in
                make.top.equalTo(subtitleLable.snp.bottom).offset(8)
                make.right.equalToSuperview()
                make.left.equalToSuperview()
                make.bottom.equalToSuperview()
            }
        } else {
            
            subtitleLable.snp.makeConstraints { make in
                make.top.equalTo(nameLable.snp.bottom).offset(8)
                make.right.equalToSuperview()
                make.left.equalToSuperview()
                make.bottom.equalToSuperview()
            }
        }
    }
}
