//
//  SpeakEleLearnReViewCtr.swift
//  SpeakEasyLearnEnglish
//
//  Created by edy on 2025/7/24.
//

import UIKit

class SpeakEleLearnReViewCtr: UIViewController {

    
    @IBOutlet weak var SpeakLearnSwitch: UISwitch!
    @IBOutlet weak var DatePickerView: UIDatePicker!
    @IBOutlet weak var StartReminder: UIButton!
    
    var isReminder : Bool = false {
        didSet {
            if isReminder == true {
                SpeakLearnSwitch.isOn = SpeakElePublicManager.share.PublicData.isReminder
            }else{
                SpeakLearnSwitch.isOn = false
            }
        }
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        StartReminder.alpha = 0
        StartReminder.transform = CGAffineTransformMakeTranslation(0, 10)
        SpeakPermission.checkNotificationPermission {[weak self] su in
            DispatchQueue.main.async {
                self?.isReminder = su
            }
        }
    }

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        UIView.animate(withDuration: 0.35) {
            self.StartReminder.alpha = 1
            self.StartReminder.transform = .identity
        }
    }
    
    func show() -> Void {
        self.modalPresentationStyle = .overFullScreen
        SpWindow.rootViewController?.present(self, animated: true)
    }
    
    @IBAction func SpeakRateSure(_ sender: Any) {
        let date = DatePickerView.date
        let string = date.toStr("hh:mm:aa") ?? ""
        SpeakElePublicManager.share.PublicData.MPractice = string
        NotificationCenter.default.post(name: NSNotification.Name.ProfilesettingUpdateUI, object: nil)
        self.dismiss(animated: true)
    }
    
    @IBAction func ReminderValueChange(_ sender: UISwitch) {
        if isReminder == false {
            if let url = URL(string: UIApplication.openSettingsURLString) {
                UIApplication.shared.open(url)
            }
        }
    }
}
