//
//  SpeakEleIAPViewCtr.swift
//  SpeakEasyLearnEnglish
//
//  Created by edy on 2025/7/11.
//

import UIKit

class SpeakEleIAPViewCtr: SpeakEleBaseViewCtr {

    enum iapstate {
        case guide
        case plan
        case other
    }
    
    // MARK: - ib
    @IBOutlet weak var SpeakEasyV: UIView!
    
    @IBOutlet weak var SpeakPayDescritionL: UILabel!
    @IBOutlet weak var SpeakPayContentV: UIView!
    @IBOutlet weak var SpeakPayTitleL: UILabel!
    @IBOutlet weak var SpeakSwitch: UISwitch!
    
    
    @IBOutlet weak var SpeakTL1: UILabel!
    @IBOutlet weak var SpeakFreeTL1: UILabel!
    @IBOutlet weak var SpeakRTL1: UILabel!
    
    @IBOutlet weak var SpeakTL2: UILabel!
    @IBOutlet weak var SpeakRTL2: UILabel!
    
    
    @IBOutlet weak var SpeakPayBut: SpeakEleButton!
    @IBOutlet weak var SpeakBotDescription: UILabel!
    
    var state:iapstate = .other
    
    var isFree:Bool = true {
        didSet {
            SpeakSwitch.isOn = isFree
        }
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        SpeakSwitch.addTarget(self, action: #selector(valueChange(_:)), for: .touchUpInside)
        isFree = true
        
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.navigationController?.AnimationState = .none
        titleView.isHidden = true
    }

    override func setup() {
        let privacy = "Privacy".attributed().underline(.single).paragraphStyle(.center,lineSpacing: 4).build()
        let terms = "Terms".attributed().underline(.single).paragraphStyle(.center,lineSpacing: 4).build()
        let att = "Cancel Anytime & ".combined(with: [privacy,"｜",terms])
        self.SpeakBotDescription.attributedText = att
        self.SpeakBotDescription.AddTextTap(["Privacy","Terms"])
        self.SpeakBotDescription.callblack = { [weak self] text in
            guard let text:String = text as? String else { return }
            if text == privacy.string {
                
            } else {
                
            }
        }
    }
    
    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        SpeakEasyV.shadow(cornerRadius: 16,shadowColor: .init(hex: 0x000000,alpha: 1),opacity: 0.06,radius: 16)
        SpeakPayContentV.shadow(cornerRadius: 8,shadowColor: .init(hex: 0x000000,alpha: 1),opacity: 0.06,radius: 8)
    }
    
    @IBAction func SpeakCloseTaps(_ sender: Any) {
        if state == .guide {
            let QAndA = SpeakEleQAViewCtr()
            self.navigationController?.pushViewController(QAndA, animated: true)
        }else if state == .plan {
            let login = SpeakEleFLoginViewCtr()
            self.navigationController?.pushViewController(login, animated: true)
        }else{
            self.navigationController?.popViewController(animated: true)
        }
    }
    
    @objc private func valueChange(_ switch:UISwitch) -> Void {
        isFree = SpeakSwitch.isOn
    }
    
    @IBAction func SpeakPayTaps(_ sender: Any) {
        
    }
    
    @IBAction func SpeakRestoreTaps(_ sender: Any) {
        
    }
}
