//
//  SpeakEleFLoginViewCtr.swift
//  SpeakEasyLearnEnglish
//
//  Created by edy on 2025/7/17.
//

import UIKit

class SpeakEleFLoginViewCtr: SpeakEleBaseViewCtr {

    // MARK: - ib
    @IBOutlet var LoginBtns: [UIButton]!
    
    private let viewModel = SpeakEleLoginViewModel()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        SpeakElePublicManager.share.PublicData.state = .login
        self.navigationController?.interactivePopGestureRecognizer?.isEnabled = false
        
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        titleView.isHidden = true
        self.view.layoutIfNeeded()
        LoginBtns.forEach { btn in
            btn.setBackgroundImage(UIColor.white.generate(btn.size,20), for: .normal)
            btn.setBackgroundImage(UIColor.init(hex: 0x191919).generate(btn.size,20), for: .highlighted)
            btn.clipsToBounds = false
        }
    }

    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        self.view.layoutIfNeeded()
        LoginBtns.forEach { btn in
            btn.shadow(cornerRadius: 20,shadowColor: .init(hex: 0x000000),offset: CGSize(width: 0, height: 2) ,opacity: 0.06,radius: 20)
        }
    }
    
    @IBAction func LoginBtnTaps(_ sender: UIButton) {
        if sender == LoginBtns[0] {
            viewModel.AppleLogin { response in
                switch response {
                case .success(let token):
                    
                    break
                case .failure(let error):
                    
                    break
                }
            }
        }else if sender == LoginBtns[1] {
            
        }else{
            let vc = SpeakEleLoginViewCtr()
            vc.state = .register
            self.navigationController?.pushViewController(vc, animated: true)
        }
    }
    
    @IBAction func EmailLoginTaps(_ sender: UIButton) {
        let vc = SpeakEleLoginViewCtr()
        self.navigationController?.pushViewController(vc, animated: true)
    }
}
