//
//  TSChatViewController+View.swift
//  AIEmoji
//
//  Created by 100Years on 2025/2/17.
//

extension TSChatViewController {

    var creatFreeText: UILabel{
        let textLabel = UILabel.createLabel(
            text: "Remaining \(kPurchaseDefault.freeNum(type: .aichat)) free times",
            font: .font(size: 12),
            textColor: "#E83E3E".uiColor,
            textAlignment: .center,
            numberOfLines: 0
        )
        textLabel.isHidden = false
        return textLabel
    }
    
    
    var creatUpgradeVipBg: UIView{
        let upgradeVipBg = UIView()
        
        let imageView = UIImageView.createImageView(imageName: "vip_upgrade_bg",contentMode: .scaleToFill)
        upgradeVipBg.addSubview(imageView)
        imageView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        
        let label = UILabel.createLabel(
            text:"Free usage limit reached. Upgrade for unlimited chats.".localized,
            font: .font(size: 14,weight: .medium),
            textColor: "#111111".uiColor,
            numberOfLines: 0
        )
        upgradeVipBg.addSubview(label)
        label.snp.makeConstraints { make in
            make.leading.equalTo(16)
            make.top.equalTo(8)
            make.bottom.equalTo(-8)
            make.trailing.equalTo(-95)
        }
        
        let upgradeBtn = UIButton.createButton(
            title: "Upgrade".localized,
            backgroundColor: "#111111".uiColor,
            font:.font(size: 12,weight: .medium),
            titleColor:.white,
            corner: 14) { [weak self]  in
                guard let self = self else { return }
                TSPurchaseVC.show(target: self) { [weak self]  in
//                    guard let self = self else { return }
//                    updateVipView()
                }
            }
        upgradeVipBg.addSubview(upgradeBtn)
        upgradeBtn.snp.makeConstraints { make in
            make.trailing.equalTo(-12)
            make.centerY.equalToSuperview()
            make.width.equalTo(70)
            make.height.equalTo(28)
        }
        return upgradeVipBg
    }
    
}

extension TSChatViewController{
    
//    func updateVipView() {
//        inputBarTopView.subviews.forEach { $0.removeFromSuperview()}
//        
//        if viewModel.uiStyle == .chat ,
//           kPurchaseDefault.isVip == false
//        {
//            let freeNum = kPurchaseDefault.freeNum(type: .aichat)
//            if freeNum > 0 {
//                freeText.text = "Remaining \(freeNum) free times"
//                inputBarTopView.addSubview(freeText)
//                freeText.snp.makeConstraints { make in
//                    make.leading.equalTo(20)
//                    make.trailing.equalTo(-20)
//                    make.bottom.equalTo(-8)
//                    make.top.equalTo(8)
//                }
//            }else{
//                inputBarTopView.addSubview(upgradeVipBg)
//                upgradeVipBg.snp.makeConstraints { make in
//                    make.leading.equalTo(16)
//                    make.trailing.equalTo(-16)
//                    make.bottom.equalTo(-2)
//                    make.top.equalTo(14)
//                }
//            }
//        }
//    }

}
