//
//  TSGeneralRintoneVC+Event.swift
//  AIRingtone
//
//  Created by 100Years on 2025/3/6.
//

extension TSGeneralRintoneVC {
    
    var resultIcon:UIImage?{
        return UIImage(named: "ai_rintone_icon")
    }

}
extension TSGeneralRintoneVC {
    func upDateView(state:TSProgressState,model:TSActionInfoModel?){
        switch state {
            case .failed(let errorStr):
                showError(text: errorStr)
            case .success:
                if let model = model {
                    showSuccess(model: model)
                }else{
                    showError(text: nil)
                }
            case .progressString(let string):
                showProgress(text: string)
            default:
                showLoading()
        }
    }
    
    func showProgress(text:String) {
        generateInView.isHidden = false
        generateInView.showLoading(text: text)
        generateInView.isRotating = true
        
        bottomView.isHidden = true
        
        isClickTheBlankClosePage = false
    }
    
    func showLoading(){
        generateInView.isHidden = false
        generateInView.showLoading(text: "Generating...".localized)
        generateInView.isRotating = true
        
        bottomView.isHidden = true
        
        isClickTheBlankClosePage = false
    }
    
    func showError(text:String?){
        let msg = "Failed to Generate, please try later".localized
        generateInView.isHidden = true
        generateInView.isRotating = false
    
        bottomView.isHidden = false
   
        againBtn.isHidden = false//重试
        failView.isHidden = false
//        failLabel.text = msg
        saveBtn.isHidden = true
        successTopView.isHidden = true
        
        ringView.isHidden = true
        regenerateBtn.isHidden = true
        
        isClickTheBlankClosePage = true
    }
    
    func showSuccess(model:TSActionInfoModel){
        generateInView.isHidden = true
        generateInView.isRotating = false
        
        bottomView.isHidden = false
        
        againBtn.isHidden = true//重试
        failView.isHidden = true
        saveBtn.isHidden = false
        successTopView.isHidden = false

        infoModel = model
        isClickTheBlankClosePage = true
        
        ringView.isHidden = false
        regenerateBtn.isHidden = false
        
        kPurchaseToolShared.useOnceForFree(type: .ringtones)
        
        if let model = infoModel {
            complete(model)
            setRingViewData(model: model)
        }
    }
}
