//
//  WP_HomeVC.swift
//  WallpaperHD_Live
//
//  Created by 忆海16 on 2024/7/22.
//

import UIKit
import JXSegmentedView

import SnapKit
class WP_HomeVC: WP_RootVC {

    
    @IBOutlet weak var openlabel: UILabel!
    
    
    @IBOutlet weak var segmentedView: JXSegmentedView!
    var  segmentedDataSource = JXSegmentedTitleDataSource()
    var listContainerView: JXSegmentedListContainerView!
    override func viewDidLoad() {
        super.viewDidLoad()

        setSegmentedViewUI()
    }

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.navigationController?.navigationBar.isHidden = true
        let userDefaults = UserDefaults.standard
        if userDefaults.bool(forKey: "islock"){
            self.openlabel.text = "open"
        }else{
            self.openlabel.text = "closed"
        }
    }
    func setSegmentedViewUI(){
        segmentedView.delegate = self
        //配置数据源相关配置属性
        segmentedDataSource.titles = [ "Flowers","Popular","Christmas","Newest"]
        segmentedDataSource.titleSelectedColor = UIColor.black
        segmentedDataSource.titleNormalColor = UIColor.gray
        segmentedDataSource.titleSelectedFont = .boldSystemFont(ofSize: 20)
        segmentedDataSource.titleNormalFont = .systemFont(ofSize: 18)
        segmentedDataSource.isTitleColorGradientEnabled = true
        self.segmentedDataSource.reloadData(selectedIndex: 0)
        //关联dataSource
        self.segmentedView.dataSource = segmentedDataSource
        
        
        let indicator = JXSegmentedIndicatorLineView()
        indicator.indicatorColor = UIColor.black
        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()
        }
    }
    
    @IBAction func lockBtn(_ sender: Any) {
        
        let vc = WP_LockVC()
        vc.modalPresentationStyle = .fullScreen
        vc.type = 1
        self.present(vc, animated: true)
        
    }
    
    @IBAction func album(_ sender: Any) {
        
        let vc = WP_PhotoAlbumVC()
        navigationController?.pushViewController(vc, animated: true)
        
    }
    
}
extension WP_HomeVC:JXSegmentedListContainerViewDataSource,JXSegmentedViewDelegate {
    //返回列表的数量
    func numberOfLists(in listContainerView: JXSegmentedListContainerView) -> Int {
        return 4
    }
    
    //返回遵从`JXSegmentedListContainerViewListDelegate`协议的实例
    func listContainerView(_ listContainerView: JXSegmentedListContainerView, initListAt index: Int) -> JXSegmentedListContainerViewListDelegate {
        
        if index == 0  {
            let vc = WP_FlowersVC()
            return vc
        }else if index == 1{
            let vc = WP_PopularVC()
            return vc
        }else if index == 2{
            let vc = WP_Christmas()
            return vc
        }else{
            let vc = WP_NewestVC()
            return vc
        }
    }
    
}
