//
//  WA_NewHomeBannerCell.swift
//  wallpaper_project
//
//  Created by 忆海16 on 2024/3/28.
//

import UIKit
import FSPagerView
class WA_NewHomeBannerCell: UITableViewCell {
    @IBOutlet weak var pageControl: UIPageControl!
    
    @IBOutlet weak var pagerView: FSPagerView!{
        didSet{
            self.pagerView.register(FSPagerViewCell.self, forCellWithReuseIdentifier: "FW_HomePagerCell")
        }
    }
    
    var blocklive:(()->())?
    var blocknew:(()->())?
    var blockpopu:(()->())?
    
    override func awakeFromNib() {
        super.awakeFromNib()
        setFSpageV()
    }
    
    func setFSpageV(){
        self.pagerView.delegate = self
        self.pagerView.dataSource = self
        pagerView.transformer = FSPagerViewTransformer(type: .depth)
        pagerView.automaticSlidingInterval = 2.0
        pagerView.isInfinite = true
        pagerView.decelerationDistance = 2
        pagerView.itemSize = CGSize(width: UIScreen.main.bounds.size.width - 20, height: 99)
        pagerView.interitemSpacing = 10
        
        pageControl.numberOfPages = 3 // 设置总页数
        pageControl.currentPage = 0
        pageControl.currentPageIndicatorTintColor = UIColor.white // 设置当前页的颜色
        pageControl.pageIndicatorTintColor = UIColor.clear
        
    }
    
}
extension WA_NewHomeBannerCell:FSPagerViewDelegate,FSPagerViewDataSource{
    public func numberOfItems(in pagerView: FSPagerView) -> Int {
        return 3
    }
    
    public func pagerView(_ pagerView: FSPagerView, cellForItemAt index: Int) -> FSPagerViewCell {
        let cell = pagerView.dequeueReusableCell(withReuseIdentifier: "FW_HomePagerCell", at: index)
        
        // 设置图片
        cell.imageView?.image = UIImage(named: "banner_\(index)")
        
        
        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
        }
    }
    
}
