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

import UIKit
import BRPickerView

class AV_pagesAllVC: AV_RootVC {
    
    @IBOutlet weak var genderV: UIView!
    
    @IBOutlet weak var genderLabel: UILabel!
    
    
    @IBOutlet weak var ageView: UIView!
    
    @IBOutlet weak var ageLabel: UILabel!
    
    
    @IBOutlet weak var exerciseView: UIView!
    
    
    @IBOutlet weak var exerciseLabel: UILabel!
    
    @IBOutlet weak var tempView: UIView!
    
    
    @IBOutlet weak var tempLabel: UILabel!
    let defaults = UserDefaults.standard
    override func viewDidLoad() {
        super.viewDidLoad()
        
        genderV.layer.cornerRadius = 28
        ageView.layer.cornerRadius = 28
        exerciseView.layer.cornerRadius = 28
        tempView.layer.cornerRadius = 28
//        let defaults = UserDefaults.standard
        genderLabel.text = defaults.string(forKey: "people")
        let age = "\(defaults.integer(forKey: "age"))"
        let weight = "\(defaults.integer(forKey: "weight"))"
        ageLabel.text = "\(age),\(weight)kg"
        exerciseLabel.text = defaults.string(forKey: "sports")
        tempLabel.text = defaults.string(forKey: "temperature")
    }
    
    
    @IBAction func genderBtn(_ sender: Any) {
        let stringPickerView = BRStringPickerView()
         stringPickerView.pickerMode = .componentSingle
         stringPickerView.title = "Gender"
         stringPickerView.dataSourceArr = ["Man", "Woman", "Pregnancy", "Pregnancy"]
         stringPickerView.selectIndex = 2
        stringPickerView.resultModelBlock = { [self] resultModel in
//             print("选择的值：\(resultModel!.value ?? "")")
             defaults.set(resultModel!.value , forKey: "people")
            self.genderLabel.text = resultModel!.value
         }
         
         stringPickerView.show()
    }
    
    
    @IBAction func agebtn(_ sender: Any) {
        let stringPickerView = BRStringPickerView()
           stringPickerView.pickerMode = .componentMulti
           stringPickerView.title = "Age and weight"
           
           // 创建两个 0 到 100 的数字数组，并将其转换为字符串数组
           let numberArray1 = (0...100).map { "\($0)" }
           let numberArray2 = (0...300).map { "\($0)" }
           stringPickerView.dataSourceArr = [numberArray1, numberArray2]
           
           // 默认选择的索引
           stringPickerView.selectIndexs = [20, 50]
           
           stringPickerView.resultModelArrayBlock = { [weak self] resultModelArray in
               guard let self = self else { return }
               
               if let resultModelArray = resultModelArray, resultModelArray.count == 2 {
                   let value1 = resultModelArray[0].value
                   let value2 = resultModelArray[1].value
                   let combinedValue = "\(value1 ?? ""),\(value2 ?? "")kg"
                   self.defaults.set(value1, forKey: "age")
                   self.defaults.set(value2, forKey: "weight")
                   
                   self.ageLabel.text = combinedValue
               }
           }
           
           stringPickerView.show()
       
    }
    
    
    
    @IBAction func exerciseBtn(_ sender: Any) {
        let stringPickerView = BRStringPickerView()
         stringPickerView.pickerMode = .componentSingle
         stringPickerView.title = "Amount of exercise"
         stringPickerView.dataSourceArr = ["Exercise regularly", "Occasional exercise", "Almost no exercise"]
         stringPickerView.selectIndex = 2
        stringPickerView.resultModelBlock = { [self] resultModel in
//             print("选择的值：\(resultModel!.value ?? "")")
             defaults.set(resultModel!.value , forKey: "sports")
            self.exerciseLabel.text = resultModel!.value
         }
         
         stringPickerView.show()
    }
    
    
    @IBAction func temperBtn(_ sender: Any) {
        let stringPickerView = BRStringPickerView()
         stringPickerView.pickerMode = .componentSingle
         stringPickerView.title = "Current temperature"
         stringPickerView.dataSourceArr = ["Heat", "Warm and warm exercise", "Comfortable","Clod"]
         stringPickerView.selectIndex = 2
        stringPickerView.resultModelBlock = { [self] resultModel in
//             print("选择的值：\(resultModel!.value ?? "")")
             defaults.set(resultModel!.value , forKey: "temperature")
            self.tempLabel.text = resultModel!.value
         }
         
         stringPickerView.show()
    }
    
    
    @IBAction func back(_ sender: Any) {
        navigationController?.popViewController(animated: true)
    }
    
}
