//
//  WA_historyLive.swift
//  wallpaper_project
//
//  Created by 忆海16 on 2024/3/27.
//

import UIKit
import JXSegmentedView
class WA_historyLive: WA_RootVC {
    
    @IBOutlet weak var dataView: UIView!
    
    @IBOutlet weak var collectionView: UICollectionView!
    var model = [WA_3DModel]()
    override func viewDidLoad() {
        super.viewDidLoad()

        setCollectionView()
    }
    func setCollectionView(){
        collectionView.delegate = self
        collectionView.dataSource = self
        
        // 设置 collection view 的布局
               let layout = CustomCollectionViewFlowLayout()
               collectionView.collectionViewLayout = layout
            layout.scrollDirection = .vertical
        
        collectionView.register(UINib(nibName: "WA_WallpaperCollectionCell", bundle: nil), forCellWithReuseIdentifier: "WA_WallpaperCollectionCell")
        
    }
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        navigationController?.navigationBar.isHidden = true
        self.model = liveManager.shared.history
        if self.model.count  == 0{
            self.dataView.isHidden = false
        }else{
            self.dataView.isHidden = true
        }
    }



}
extension WA_historyLive:JXSegmentedListContainerViewListDelegate{
    func listView() -> UIView {
        return view
    }
}
extension WA_historyLive:UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout{
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        
    
        return self.model.count
    }
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "WA_WallpaperCollectionCell", for: indexPath)as!WA_WallpaperCollectionCell
        cell.model = self.model[indexPath.row]

        return cell
    }
    
    
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        let vc = WA_LiveVideoVC()
        vc.model = self.model[indexPath.row]
        navigationController?.pushViewController(vc, animated: true)
        
    }
}
