//
//  SpeakEleQATextCell.swift
//  SpeakEasyLearnEnglish
//
//  Created by edy on 2025/7/15.
//

import UIKit

class SpeakEleQATextCell: SpeakEleQABaseViewCell {
    
    static let id = "SpeakEleQATextCell"
    
    override var data:SpeakEleQAModel? {
        didSet {
            bgView.type = data?.role ?? .speakAI
            
            var title = data?.speakMsg.replacingOccurrences(of: "$$$N", with: SpeakElePublicManager.share.PublicData.userName)
            title = title?.replacingOccurrences(of: "$$$L", with: SpeakElePublicManager.share.PublicData.MLanguage)
            title = title?.whitespacesAndNew()
            titleL.text = title
            
            titleL.textAlignment = (data?.role == .speakAI ? .left : .center)
            titleL.sizeToFit()
            let role = (data?.role == .speakAI ? true : false)
            contentV.snp.remakeConstraints { make in
                if role {
                    make.left.equalToSuperview().inset(marginLR)
                    make.top.equalToSuperview().inset(5)
                }else{
                    make.right.equalToSuperview().inset(marginLR)
                    make.top.equalToSuperview().inset(5)
                }
                make.width.equalTo(titleL.snp.width).offset(32)
                make.bottom.equalToSuperview().inset(16)
            }
        }
    }
    
    override func reload() {
        setNeedsLayout()
        layoutIfNeeded()
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
    }
}
