//
//  SelectAgeVM.swift
//  WOKA
//
//  Created by Bilal on 26/04/2024.
//

import UIKit

class SelectAgeVM{
    
    weak var vc : SelectAgeVC!
    
    func initData(){
        vc.underAgeView.roundCorner(radius: 25)
        vc.aboveAgeView.roundCorner(radius: 25)
        
        // Add tap gesture recognizer to the view
        let tapGesture = UITapGestureRecognizer(target: self, action: #selector(kid))
        vc.underAgeView.addGestureRecognizer(tapGesture)
        
        // Add tap gesture recognizer to the view
        let tapGesture2 = UITapGestureRecognizer(target: self, action: #selector(adult))
        vc.aboveAgeView.addGestureRecognizer(tapGesture2)
        
        vc.privacyLabel.text = "We Value Your Privacy".localized(loc: AuthFunc.shareInstance.languageSelected.rawValue)
        vc.magicNoLabel.text = "16 IS THE MAGIC NUMBER".localized(loc: AuthFunc.shareInstance.languageSelected.rawValue)
        vc.yearsLabel.text = "YEARS".localized(loc: AuthFunc.shareInstance.languageSelected.rawValue)
        vc.iAmAboveLabel.text = "I AM".localized(loc: AuthFunc.shareInstance.languageSelected.rawValue)
        vc.iAmUnderLabel.text = "I AM".localized(loc: AuthFunc.shareInstance.languageSelected.rawValue)
        vc.underLabel.text = "UNDER".localized(loc: AuthFunc.shareInstance.languageSelected.rawValue)
        vc.aboveLabel.text = "ABOVE".localized(loc: AuthFunc.shareInstance.languageSelected.rawValue)
        vc.numberText.text = "16".localized(loc: AuthFunc.shareInstance.languageSelected.rawValue)
        vc.underTextLabel.text = "We will need your parent’s email so they can verify and agree to create an account.".localized(loc: AuthFunc.shareInstance.languageSelected.rawValue)
        vc.aboveTextLabel.text = "Above 16 users will be registered as a guardian with additional content.".localized(loc: AuthFunc.shareInstance.languageSelected.rawValue)
        
        self.vc.wokaLogoTopSpacing.constant = CheckPhoneHomeBtnOrNotch.shareInstance.topConstriant()
    }
    
    @objc func kid() {
        PersistentStorage.shared.addOthersCount()
        // Apply click effect animation
        UIView.animate(withDuration: 0.1, animations: {
            self.vc.underAgeView.transform = CGAffineTransform(scaleX: 0.9, y: 0.9)
        }) { _ in
            UIView.animate(withDuration: 0.1) {
                self.vc.underAgeView.transform = .identity
            }
        }
        AuthFunc.shareInstance.userType = .kid
        pushToEmail()
    }
    
    @objc func adult() {
        PersistentStorage.shared.addOthersCount()
        // Apply click effect animation
        UIView.animate(withDuration: 0.1, animations: {
            self.vc.aboveAgeView.transform = CGAffineTransform(scaleX: 0.9, y: 0.9)
        }) { _ in
            UIView.animate(withDuration: 0.1) {
                self.vc.aboveAgeView.transform = .identity
            }
        }
        AuthFunc.shareInstance.userType = .adult
        pushToEmail()
    }
    
    private func pushToEmail(){
        let sb = UIStoryboard(name: K.StoryBoard.authenticationSB, bundle: nil)
        let vc = sb.instantiateViewController(withIdentifier: K.StoryBoardID.Authentication.emailVC) as! EmailVC
        self.vc.navigationController?.pushViewController(vc, animated: true)
    }
}


extension String {

    var localized: String {
        return NSLocalizedString(self, tableName: nil, bundle: Bundle.main, value: "", comment: "")
    }


    func localizedWithComment(comment:String) -> String {
        return NSLocalizedString(self, tableName: nil, bundle: Bundle.main, value: "", comment: comment)
    }
}
