//
//  TSBottomAlertVC.swift
//  AIEmoji
//
//  Created by 100Years on 2025/1/17.
//

class TSBottomAlertVC: TSBaseVC {
    
    
    
    lazy var topBgView: UIView = {
        let topBgView = UIView(frame: CGRectMake(0, 0, k_ScreenWidth, k_ScreenHeight-400))
        topBgView.backgroundColor = .black.withAlphaComponent(0.5)
        topBgView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(dismissKeyboard)))
        return topBgView
    }()
    
    lazy var bottomView: UIView = {
        let bottomView = UIView(frame: CGRectMake(0, k_ScreenHeight-448, k_ScreenWidth, 448))
        bottomView.backgroundColor = "#222222".uiColor
        bottomView.cornersRound(radius: 20, corner: [.topLeft,.topRight])
        return bottomView
    }()
    

    lazy var xBtn: UIButton = {
        let xBtn = UIButton.createButton(image: UIImage(named: "x")) { [weak self]  in
            guard let self = self else { return }
            clickXBtn()
        }
        return xBtn
    }()
    
    lazy var submitBtn: UIButton = {
        let tryAgainBtn = kCreateNormalSubmitBtn(title: "Try Again".localized) { [weak self]  in
            guard let self = self else { return }
            clickSubmitBtn()
        }
        return tryAgainBtn
    }()
    
    
    lazy var cancelBtn: UIButton = {
        let tryAgainBtn = kCreateNormalCancelBtn(title: "Copy".localized) { [weak self]  in
            guard let self = self else { return }
            clickCancelBtn()
        }
        return tryAgainBtn
    }()
    
    lazy var confirmBtn: UIButton = {
        let tryAgainBtn = kCreateNormalConfirmBtn(title: "Save".localized) { [weak self]  in
            guard let self = self else { return }
            clickConfirmBtn()
        }
        return tryAgainBtn
    }()
    
    //点击空白,关闭页面
    var isClickTheBlankClosePage = true
    
    override func createView() {
        view.backgroundColor = .clear
        setNavBarViewHidden(true)

        contentView.addSubview(topBgView)
        contentView.addSubview(bottomView)
    
        bottomView.addSubview(xBtn)
        xBtn.snp.makeConstraints { make in
            make.top.equalTo(8)
            make.trailing.equalTo(-8)
            make.width.equalTo(24)
            make.height.equalTo(24)
        }
        
        //重试
        bottomView.addSubview(submitBtn)
        submitBtn.snp.makeConstraints { make in
            make.bottom.equalTo(-34)
            make.centerX.equalToSuperview()
            make.width.equalTo(329)
            make.height.equalTo(60)
        }
        
        
        //中心点
        let centerView = UIView()
        bottomView.addSubview(centerView)
        centerView.snp.makeConstraints { make in
            make.center.equalToSuperview()
        }
        bottomView.addSubview(cancelBtn)
        cancelBtn.snp.makeConstraints { make in
            make.bottom.equalTo(-34)
            make.trailing.equalTo(centerView.snp.leading).offset(-8)
            make.width.equalTo(163)
            make.height.equalTo(60)
        }
        
        bottomView.addSubview(confirmBtn)
        confirmBtn.snp.makeConstraints { make in
            make.bottom.equalTo(-34)
            make.leading.equalTo(centerView.snp.trailing).offset(8)
            make.width.equalTo(163)
            make.height.equalTo(60)
        }
    }
    
    func closePage() {
        self.dismiss(animated: true, completion: nil)
    }

    
    @objc func clickSubmitBtn(){
        
    }
    
    @objc func clickCancelBtn(){
        
    }
    
    @objc func clickConfirmBtn(){
        
    }
    
    @objc func clickXBtn(){
        closePage()
    }
    
    @objc private func dismissKeyboard() {
        if isClickTheBlankClosePage {
            closePage()
        }
    }
}
