//
//  TSCreatBtnView.swift
//  AIRingtone
//
//  Created by 100Years on 2025/3/6.
//

class TSCreatBtnView: TSBaseView {

    var viewH:CGFloat = 64
    
    var clickBlock:()->Void

    init(clickBlock: @escaping () -> Void) {
        self.clickBlock = clickBlock
        super.init(frame: .zero)
    }
    
    @MainActor required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //###################################### Button ######################################
    lazy var creatBtn:UIButton  = {
        
        let btn = UIButton.createButton(title:"Create Now",font: UIFont.font(size: 16,weight: .regular),titleColor:.white,corner: 24)
        {[weak self] in
            guard let self = self else { return }
            clickBlock()
        }
        btn.frame = CGRectMake(0, 0, k_ScreenWidth - 32, 48)
        btn.contentEdgeInsets = UIEdgeInsets(top: 0, left: 8, bottom: 0, right: 0)
        btn.imageEdgeInsets = UIEdgeInsets(top: 0, left: -8, bottom: 0, right: 0)
        btn.addGradientBg(colors: ["#E961F6".uiColor.cgColor,"#7E57F4".uiColor.cgColor])
        return btn
    }()
     
    override func creatUI() {
        contentView.addSubview(creatBtn)
        creatBtn.snp.makeConstraints { make in
            make.center.equalToSuperview()
            make.leading.equalTo(16)
            make.trailing.equalTo(-16)
            make.height.equalTo(creatBtn.height)
        }
        setVip(vip:true)
    }

    func setBtnEnabled(isEnabled:Bool) {
        creatBtn.isEnabled = isEnabled
        creatBtn.alpha = isEnabled ? 1.0 : 0.6
    }
    
    func setVip(vip:Bool) {
        if vip {
            creatBtn.setImage(UIImage(named: "vip_icon_white"), for: .normal)
        }else{
            creatBtn.setImage(nil, for: .normal)
        }
    }
}
