//
//  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",backgroundColor: .black,font: UIFont.font(size: 16,weight: .regular),titleColor:.themeColor,corner: 24)
        {[weak self] in
            guard let self = self else { return }
            clickBlock()
        }
        
        btn.layer.borderWidth = 1
        btn.layer.borderColor = UIColor.themeColor.cgColor
        btn.frame = CGRectMake(0, 0, 200, 48)
        return btn
    }()
    
    lazy var shadowView: UIView = {
        let shadowView = UIView()
        shadowView.frame = creatBtn.frame
        shadowView.layer.shadowColor = UIColor.themeColor.cgColor
        shadowView.layer.shadowOffset = CGSize(width: 0, height: 4)
        shadowView.layer.shadowOpacity = 0.5
        shadowView.layer.shadowRadius = 5
        return shadowView
    }()

    override func creatUI() {
        
        contentView.addSubview(shadowView)
        shadowView.snp.makeConstraints { make in
            make.center.equalToSuperview()
            make.leading.equalTo(16)
            make.trailing.equalTo(-16)
            make.height.equalTo(creatBtn.height)
        }

        shadowView.addSubview(creatBtn)
        creatBtn.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
    }

    func setBtnEnabled(isEnabled:Bool) {
        creatBtn.isEnabled = isEnabled
        if isEnabled {
            shadowView.layer.shadowColor = UIColor.themeColor.cgColor
            creatBtn.layer.borderColor = UIColor.themeColor.withAlphaComponent(1.0).cgColor
            creatBtn.setTitleColor(UIColor.themeColor.withAlphaComponent(1.0), for: .normal)
        }else{
            shadowView.layer.shadowColor = UIColor.clear.cgColor
            creatBtn.layer.borderColor = UIColor.themeColor.withAlphaComponent(0.4).cgColor
            creatBtn.setTitleColor(UIColor.themeColor.withAlphaComponent(0.6), for: .normal)
        }
    }
}
