//
//  NW_RankingVC.swift
//  wallpaper_BProject
//
//  Created by 忆海16 on 2024/8/28.
//

import UIKit
import FSPagerView

class NW_RankingVC: NW_RootVC {
    @IBOutlet weak var pagerView: FSPagerView!{
        didSet{
            self.pagerView.register(UINib(nibName: "NW_RankingFSpageCell", bundle: nil), forCellWithReuseIdentifier: "NW_RankingFSpageCell")
        }
    }
    
    
    var rankingArr = [NW_RankingModel]()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        setFSpageV()

    }
    
    //    MARK: - FSPagerView设置
    func setFSpageV(){
        self.pagerView.delegate = self
        self.pagerView.dataSource = self
        pagerView.transformer = FSPagerViewTransformer(type: .linear)
        pagerView.automaticSlidingInterval = 0
        pagerView.isInfinite = true
        pagerView.decelerationDistance = 2
        pagerView.itemSize = CGSize(width: 260, height:self.pagerView.bounds.height - 50)
        pagerView.interitemSpacing = 10

    }
    
    
    //    MARK: - 读取RankingJSon文件
//    func setNetwork(){
//        if let path = Bundle.main.path(forResource: "Ranking", ofType: "json") {
//            do {
//                let data = try Data(contentsOf: URL(fileURLWithPath: path))
//                
//                // 使用 JSONDecoder 进行解析
//                let decoder = JSONDecoder()
//                rankingArr = try decoder.decode([NW_RankingModel].self, from: data)
//                
//                
//            } catch {
//                print("Error reading JSON file:", error)
//            }
//        }
//    }

}

//    MARK: - FSPagerView代理
extension NW_RankingVC:FSPagerViewDelegate,FSPagerViewDataSource{
    public func numberOfItems(in pagerView: FSPagerView) -> Int {
        return 6
    }
    
    public func pagerView(_ pagerView: FSPagerView, cellForItemAt index: Int) -> FSPagerViewCell {
        let cell = pagerView.dequeueReusableCell(withReuseIdentifier: "NW_RankingFSpageCell", at: index) as! NW_RankingFSpageCell
        
        // 设置图片
        cell.wallpaperImageV?.image = UIImage(named: "zw")
        
        
        return cell
    }
    
    //    func pagerView(_ pagerView: FSPagerView, didSelectItemAt index: Int) {
    //        print("Tapped item at index: \(index)")
    //
    ////        var viewControllerToPresent: UIViewController?
    //
    //        // 根据索引跳转到不同的视图控制器
    //        switch index {
    //        case 0:
    //            if self.blocklive != nil{
    //                self.blocklive!()
    //            }
    //        case 1:
    //            if self.blockpopu != nil{
    //                self.blockpopu!()
    //            }
    //        case 2:
    //            if self.blocknew != nil{
    //                self.blocknew!()
    //            }
    //        default:
    //            break
    //        }
    //    }
    
}
