//
//  KeyboardMenuView.swift
//  AiKeyboard
//
//  Created by Destiny on 2025/4/28.
//

import UIKit

protocol KeyboardMenuViewDelegate: NSObjectProtocol {
    
    func menuBackBtnClickAction()
}

class KeyboardMenuView: UIView {
    
    struct UX {
        static let btnWidth = (KeyboardConst.kb_kScreenW - 36.0) / 2.0
        static let btnHeight = 74.0
    }
    
    weak var delegate: KeyboardMenuViewDelegate?
    
    lazy var backBtn: UIButton = {
        
        let btn = UIButton()
        btn.setImage(UIImage(named: "keyboard_back_btn"), for: .normal)
        btn.layer.shadowOffset = CGSize(width: 0, height: 0)
        btn.layer.shadowColor = UIColor.hexStringColor(hexString: "#000000", alpha: 0.12).cgColor
        btn.layer.shadowRadius = 6.1
        btn.addTarget(self, action: #selector(backBtnClickAction), for: .touchUpInside)
        return btn
    }()
    
    lazy var diyCharacterBtn: UIButton = {
       
        let btn = UIButton(frame: CGRect(x: 0, y: 0, width: UX.btnWidth, height: UX.btnHeight))
        btn.backgroundColor = .white
        btn.layer.cornerRadius = 14
        btn.setTitle("定制人设", for: .normal)
        btn.setTitleColor(.hexStringColor(hexString: "#000000", alpha: 0.8), for: .normal)
        btn.titleLabel?.font = .systemFont(ofSize: 13, weight: .medium)
        btn.titleLabel?.textAlignment = .center
        btn.setImage(UIImage(named: "keyboard_menu_diy"), for: .normal)
        btn.setImageTitleLayout(.imgTop, spacing: 8)
        return btn
    }()
    
    lazy var marketBtn: UIButton = {
        
        let btn = UIButton(frame: CGRect(x: 0, y: 0, width: UX.btnWidth, height: UX.btnHeight))
        btn.backgroundColor = .white
        btn.layer.cornerRadius = 14
        btn.setTitle("人设市场", for: .normal)
        btn.setTitleColor(.hexStringColor(hexString: "#000000", alpha: 0.8), for: .normal)
        btn.titleLabel?.font = .systemFont(ofSize: 13, weight: .medium)
        btn.titleLabel?.textAlignment = .center
        btn.setImage(UIImage(named: "keyboard_menu_market"), for: .normal)
        btn.setImageTitleLayout(.imgTop, spacing: 8)
        return btn
    }()
    
    lazy var vipBtn: UIButton = {
        
        let btn = UIButton(frame: CGRect(x: 0, y: 0, width: UX.btnWidth, height: UX.btnHeight))
        btn.backgroundColor = .white
        btn.layer.cornerRadius = 14
        btn.setTitle("解锁会员", for: .normal)
        btn.setTitleColor(.hexStringColor(hexString: "#000000", alpha: 0.8), for: .normal)
        btn.titleLabel?.font = .systemFont(ofSize: 13, weight: .medium)
        btn.titleLabel?.textAlignment = .center
        btn.setImage(UIImage(named: "keyboard_menu_vip"), for: .normal)
        btn.setImageTitleLayout(.imgTop, spacing: 8)
        return btn
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        initUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

extension KeyboardMenuView {
    
    @objc func backBtnClickAction() {
        self.removeFromSuperview()
        delegate?.menuBackBtnClickAction()
    }
}

extension KeyboardMenuView {
    
    func initUI() {
        
        self.addSubview(backBtn)
        backBtn.snp.makeConstraints { make in
            make.size.equalTo(CGSize(width: 32, height: 32))
            make.left.equalTo(12)
            make.top.equalTo(16)
        }
        
        self.addSubview(diyCharacterBtn)
        diyCharacterBtn.snp.makeConstraints { make in
            make.size.equalTo(CGSize(width: UX.btnWidth, height: UX.btnHeight))
            make.top.equalTo(60)
            make.left.equalTo(12)
        }
        
        self.addSubview(marketBtn)
        marketBtn.snp.makeConstraints { make in
            make.size.equalTo(CGSize(width: UX.btnWidth, height: UX.btnHeight))
            make.top.equalTo(60)
            make.right.equalTo(-12)
        }
        
        self.addSubview(vipBtn)
        vipBtn.snp.makeConstraints { make in
            make.size.equalTo(CGSize(width: UX.btnWidth, height: UX.btnHeight))
            make.top.equalTo(diyCharacterBtn.snp.bottom).offset(12)
            make.left.equalTo(12)
        }
    }
}
