//
//  CLContainerVC.swift
//  Visual_Novel_iOS
//
//  Created by mh on 2025/10/15.
//

import Foundation

// tabbar的四个rootvc都用共同的header 做一个包容的vc
final class CLContainerVC: UIViewController {
    private let header = HeaderView()          // 头像栏
    var nav  = CLNavigationController() // 真正堆栈
    
    init(rootvc: UIViewController) {
        super.init(nibName: nil, bundle: nil)
        nav = CLNavigationController(rootViewController: rootvc)
        addChild(nav)
        //            nav.setViewControllers([rootViewController], animated: false)
    }
    required init?(coder: NSCoder) { fatalError() }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .systemBackground
        [header, nav.view].forEach { v in
//            v.translatesAutoresizingMaskIntoConstraints = false
            view.addSubview(v)
        }
        
        header.snp.makeConstraints { make in
            make.left.right.top.equalToSuperview()
            make.height.equalTo(88)
        }
        
        nav.view.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.top.equalTo(header.snp.bottom)
            make.bottom.equalToSuperview()
        }
    }
}

final class HeaderView: UIView {
    
    lazy var avatar: UIImageView = {
        let imageview = UIImageView()
        imageview.backgroundColor = .blue
        return imageview
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = .red
        setup()
    }
    
    required init?(coder: NSCoder) { fatalError() }
    
    func render(_ model: AnyObject) {
//        avatar.image = model.avatar
    }
    
    private func setup() {
        /* 圆角、阴影、布局代码略 */
        addSubview(avatar)
        avatar.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.left.equalToSuperview().offset(30)
            make.width.height.equalTo(44)
        }
    }
}

