//
//  SpeakElePracticeViewCell.swift
//  SpeakEasyLearnEnglish
//
//  Created by edy on 2025/7/22.
//

import UIKit

class SpeakElePracticeViewCell: UICollectionViewCell {

    static let id = "SpeakElePracticeViewCell"
    
    private var isShowingFront = true
    
    @IBOutlet weak var SpeakPracticeNormal: UIView!
    @IBOutlet weak var SpeakPracticeBack: UIView!
    
    
    


    override func awakeFromNib() {
        super.awakeFromNib()
        isShowingFront.toggle()
        SpeakPracticeNormal.gesture(target: self, class: UITapGestureRecognizer.self, selector: #selector(FlipTaps))
        SpeakPracticeBack.gesture(target: self, class: UITapGestureRecognizer.self, selector: #selector(FlipTaps))
        isShowingFront = true
        back.snp.makeConstraints { make in
            make.left.right.bottom.top.equalToSuperview()
        }
    }

    
    @objc private func FlipTaps() -> Void {
        UIView.transition(
            from: isShowingFront ? SpeakPracticeNormal : SpeakPracticeBack,
            to: isShowingFront ? SpeakPracticeBack : SpeakPracticeNormal,
            duration: 12/60.0,
            options: [.transitionFlipFromRight, .showHideTransitionViews],
            completion: { [weak self] _ in
                self?.isShowingFront.toggle()
            }
        )
    }
    
    private lazy var back: SpeakPracticeBackView = {
        let b = SpeakPracticeBackView.xib()
        SpeakPracticeBack.addSubview(b)
        return b
    }()
}
