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

import UIKit
import JXSegmentedView
class NW_MineVC: NW_RootVC {
    @IBOutlet weak var segmentedView: JXSegmentedView!
    var  segmentedDataSource = JXSegmentedTitleDataSource()
    var listContainerView: JXSegmentedListContainerView!
    override func viewDidLoad() {
        super.viewDidLoad()

        setSegamented()
    }

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.navigationController?.navigationBar.isHidden = true
      

    }
    
    func setSegamented(){
        segmentedView.delegate = self
        //配置数据源相关配置属性
        segmentedDataSource.titles = [ "Released","My Love"]
        segmentedDataSource.titleSelectedColor = .hexSting(color: "#3E3A37", alpha: 1)
        segmentedDataSource.titleNormalColor = .hexSting(color: "#3E3A37", alpha: 1)
        
        segmentedDataSource.titleSelectedFont = UIFont(name: "HoeflerText-Black", size: 18)
        segmentedDataSource.titleNormalFont = UIFont(name: "HoeflerText-Italic", size: 18)!
        segmentedDataSource.isTitleColorGradientEnabled = true
        self.segmentedDataSource.reloadData(selectedIndex: 0)
        //关联dataSource
        self.segmentedView.dataSource = segmentedDataSource
        
        
        let indicator = JXSegmentedIndicatorLineView()
        indicator.indicatorColor = .hexSting(color: "#4A3A27", alpha: 1)
        indicator.indicatorWidth = (UIScreen.main.bounds.width / 2) - 20
        
        self.segmentedView.indicators = [indicator]
        
        
        listContainerView =  JXSegmentedListContainerView(dataSource: self)
        self.view.addSubview(listContainerView)
        
        segmentedView.listContainer = listContainerView
    }
    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        listContainerView.snp.makeConstraints { make in
            make.top.equalTo(segmentedView.snp.bottom).offset(0)
            make.width.equalToSuperview()
            make.bottom.equalToSuperview()
        }
    }
    

}
extension NW_MineVC:JXSegmentedListContainerViewDataSource,JXSegmentedViewDelegate{
    
    //返回列表的数量
    func numberOfLists(in listContainerView: JXSegmentedListContainerView) -> Int {
        return 2
    }
    //返回遵从`JXSegmentedListContainerViewListDelegate`协议的实例
    func listContainerView(_ listContainerView: JXSegmentedListContainerView, initListAt index: Int) -> JXSegmentedListContainerViewListDelegate {
        
        if index == 0  {
            let vc = NW_JXOneVC()
            return vc
        }else{
            let vc = NW_JXOneVC()
            return vc
        }
    }
}
