//
//  AV_selectWeightVC.swift
//  anniversary_Project
//
//  Created by 忆海16 on 2024/7/9.
//

import UIKit

class AV_selectWeightVC: AV_RootVC {
    
    @IBOutlet weak var tableView: UITableView!
    
    var weightadd:Int?
   
    override func viewDidLoad() {
        super.viewDidLoad()
        
        setTableViewcell()
        requestTrackingAuthorization { idfa in
            if let idfa = idfa {
                print("IDFA: \(idfa)")
                StartManager.shared.idfaid = idfa
                print("Stored IDFA: \(StartManager.shared.idfaid ?? "N/A")")
            } else {
                print("IDFA is not available or tracking authorization denied.")
            }
        }
    }
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        
        self.navigationController?.navigationBar.isHidden = true
        
    }
    func setTableViewcell(){
        tableView.delegate = self
        tableView.dataSource = self
        tableView.register(UINib(nibName: "AV_selectWeightCell", bundle: nil), forCellReuseIdentifier: "AV_selectWeightCell")
        
    }
    
    
    @IBAction func backBtn(_ sender: UIButton) {
        navigationController?.popViewController(animated: true)
        
    }
    
    
    @IBAction func skip(_ sender: Any) {
        let defaults = UserDefaults.standard
        defaults.set(2000, forKey: "waterml")
        let appDelegate = UIApplication.shared.delegate
        appDelegate?.window??.rootViewController = AV_NAVVC(rootViewController: AV_WaterHomeVC())
   
    }
    
    
    @IBAction func nextGo(_ sender: Any) {

        let vc = AV_SportsVC()
        navigationController?.pushViewController(vc, animated: true)
//        let defaults = UserDefaults.standard
      

    }
    
}

    
extension AV_selectWeightVC:UITableViewDelegate,UITableViewDataSource{
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        
        return 1
        
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        
        let cell = tableView.dequeueReusableCell(withIdentifier: "AV_selectWeightCell", for: indexPath) as! AV_selectWeightCell
        cell.onAgeSelected = { age in
//            self?.age = age
            let defaults = UserDefaults.standard
            defaults.set(age, forKey: "age")
          
        }
        

        
        let currentRulerValue = cell.rulerV.rulerScrollView.currentRulerValue    
        self.weightadd = Int(currentRulerValue)

        return cell
        
    }
    
    
}
