//
//  TSChatMsgToolView.swift
//  AIEmoji
//
//  Created by 100Years on 2025/2/23.
//


//30
class TSChatMsgToolView: TSChatMsgBaseView {
    var viewHeight = TSLayoutSizeCalculator.cellMessageToolViewH
    //是否显示失败
    var isShowRefresh:Bool = false {
        didSet{
            updateRefreshBtn()
        }
    }
    //是否只显示失败
    var isOnlyShowRefresh:Bool = false {
        didSet{
            updateNotRefreshBtn()
        }
    }
    
    lazy var copyBtn: UIButton = {
        let copyBtn = UIButton.createButton(image: UIImage(named: "aichat_copy")) { [weak self]  in
            guard let self = self else { return }
            didTapCustomViewBlock?(.copyMsg)
        }
        return copyBtn
    }()
    
    
    
    lazy var refreshBtn: UIButton = {
        let refreshBtn = UIButton.createButton(image: UIImage(named: "refresh_gary")) { [weak self]  in
            guard let self = self else { return }
            didTapCustomViewBlock?(.refreshMsg)
        }
        return refreshBtn
    }()
    
    
    lazy var stackView: TSCustomStackView = {
        let stackView = TSCustomStackView(axis: .horizontal,spacing: 16)
        return stackView
    }()
    
    override func creatUI() {
        
        self.clipsToBounds = true
        
        contentView.addSubview(stackView)
        stackView.snp.makeConstraints { make in
            make.leading.equalTo(12)
            make.trailing.equalTo(-12)
            make.top.equalTo(0)
            make.height.equalTo(20)
        }
        
        //        stackView.addSubviewToStack(copyBtn)
        //        copyBtn.snp.makeConstraints { make in
        //            make.width.equalTo(20)
        //        }
        
    }
    
    func updateRefreshBtn() {
        if isShowRefresh {
            stackView.insertViewToStack(refreshBtn, at: 0)
            refreshBtn.snp.makeConstraints { make in
                make.width.equalTo(20)
            }
        }else{
            stackView.removeViewToStack(refreshBtn)
        }
    }
    
    
    func updateNotRefreshBtn(){
        if isOnlyShowRefresh {
            stackView.removeViewToStack(copyBtn)
        }else{
            if copyBtn.superview == nil {
                stackView.addSubviewToStack(copyBtn)
                copyBtn.snp.makeConstraints { make in
                    make.width.equalTo(20)
                }
            }
        }
    }
}
