//
//  MP_GuideViewController.swift
//  relax.offline.mp3.music
//
//  Created by Mr.Zhou on 2024/7/3.
//

import UIKit

class MP_GuideViewController: UIViewController {
    @IBOutlet var startBtns: [UIButton]!
    @IBOutlet weak var nextBtn: UIButton!
    var disMissBlock:(() -> Void)?
    var storeBlock:(() -> Void)?
    var feedBackBlock:(() -> Void)?
    override func viewDidLoad() {
        super.viewDidLoad()
        
    }
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        disMissBlock?()
    }
    //选择星级，根据用户选择星级不同，next呈现不同文本以及效果
    @IBAction func startClick(_ sender: UIButton) {
        let tag = sender.tag
        //调整星星按钮的显示状态
        startBtns.forEach { btn in
            btn.isSelected = (btn.tag <= tag)
        }
        //调整next的显示状态
        nextBtn.isSelected = tag > 3
    }
    //不选择，取消
    @IBAction func notNowClick(_ sender: UIButton) {
        MP_AnalyticsManager.shared.guide_clickAction("Cancel")
        dismiss(animated: true)
    }
    @IBAction func nextClick(_ sender: UIButton) {
        //用户执行评论
        UserDefaults.standard.setValue(true, forKey: "isGuide")
        dismiss(animated: true) {
            [weak self] in
            //根据当前按钮状态确定事件详情
            if sender.isSelected {
                MP_AnalyticsManager.shared.guide_clickAction("Jump Store")
                //跳转商店页面
                if let block = self?.storeBlock {
                    block()
                }
            }else {
                MP_AnalyticsManager.shared.guide_clickAction("Feed Back")
                //前往反馈页面
                if let block = self?.feedBackBlock {
                    block()
                }
            }
        }
    }
}
