//
//  RolesRootPageController.swift
//  Visual_Novel_iOS
//
//  Created by mh on 2025/10/14.
//

import UIKit
import Combine


class RolesRootPageController: CLTabRootController<RolesRootPageView> {
    
    private var cancellables = Set<AnyCancellable>()

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let baseImageView = UIImageView(image: R.image.base_bg())
        baseImageView.contentMode = .scaleAspectFill
        self.view.insertSubview(baseImageView, at: 0)
        baseImageView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        view.backgroundColor = .clear
        bgTopIv.isHidden = true
        
        setupViews()
        setupEvent()
    }
    
    private func setupViews() {
        navigationView.bgView.alpha = 0
        navigationView.setupBgViewToStatusBarHeight()
        navigationView.isUserInteractionEnabled = false
    }
    
    private func setupEvent() {
        self.container.jumpPublisher
            .receive(on: RunLoop.main)
            .sink { [weak self] target in
                self?.handleJump(target)
            }
            .store(in: &cancellables)
    }
    
    // 点击顶部 实现跳转
    private func handleJump(_ target: JumpTarget) {
        switch target {
        case .search:
            let vc = TestEntrancesController()
            navigationController?.pushViewController(vc, animated: true)
        case .check:
            let vc = TestEntrancesController()
            navigationController?.pushViewController(vc, animated: true)
        case .discord:
            let vc = TestEntrancesController()
            navigationController?.pushViewController(vc, animated: true)
        }
    }
}
