//
//  TSSetingVC.swift
//  AIEmoji
//
//  Created by 100Years on 2025/1/16.
//

import Combine
import SwiftUI


class ListEventPublisher {
    /// 设置
    let settingPublisher = PassthroughSubject<SettingType, Never>()
    /// 进入订阅详情页
    let enterPurchasePublisher = PassthroughSubject<Bool, Never>()
}

class TSSetingVC: TSBaseVC {
    
    var viewModel: TSSetingViewModel = TSSetingViewModel()
    var publisher: ListEventPublisher = .init()
    
    
    lazy var hostVc: UIHostingController<TSSettingListView> = {
        let vc = UIHostingController(rootView: TSSettingListView(viewModel: viewModel, publisher: publisher))
        vc.view.backgroundColor = .clear
        return vc
    }()
    
    override func createView() {
        addNormalNavBarView()
        setPageTitle("Setting")
        contentView.addSubview(hostVc.view)
        hostVc.view.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
    }
    
    override func dealThings() {
        
        publisher.enterPurchasePublisher.receive(on: DispatchQueue.main).sink { [weak self] _ in
            guard let self = self else { return }
            viewModel.pushVipPurchase(parent: self)
        }.store(in: &cancellable)
        

        publisher.settingPublisher.receive(on: DispatchQueue.main).sink{ [weak self] type in
            guard let self = self else {
                return
            }
            
            switch type {
            case .howToUse:
                viewModel.pushTutorials(parent: self)
            case .shareus:
                viewModel.shareApp(parent: self)
            case .agreement:
                viewModel.showAgreement(parent: self)
            case .privacy:
                viewModel.showPrivacy(parent: self)
            case .about:
                break
            case .rateus:
                viewModel.rateAction()
            }
            
        }.store(in: &cancellable)
    }
    
}
