//
//  YHSaveAndSubmitView.swift
//  galaxy
//
//  Created by edy on 2024/1/31.
//  Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//

import UIKit

class YHSaveAndSubmitView: UIView {

    static let submitBtnHeight = 48.0
    static let gap = 8.0
    static let height = submitBtnHeight+gap*2
    
    var saveBlock:(()->Void)?
    var submitBlock:(()->Void)?

    lazy var submitBtn:UIButton = {
        let btn = UIButton()
        btn.setTitle("提交".local, for: .normal)
        btn.titleLabel?.font = UIFont.PFSC_R(ofSize: 14)
        btn.setTitleColor(.white, for: .normal)
        btn.backgroundColor = UIColor(hexString:"#4388FF")
        btn.layer.cornerRadius = 8.0
        btn.addTarget(self, action: #selector(didClickSubmitBtn), for: .touchUpInside)
        return btn
    }()
    
    lazy var saveBtn:UIButton = {
        let btn = UIButton()
        btn.setTitle("保存", for: .normal)
        btn.titleLabel?.font = UIFont.PFSC_R(ofSize: 14)
        btn.setTitleColor(UIColor(hexString:"#222222"), for: .normal)
        btn.backgroundColor = UIColor(hexString:"#F8F9FB")
        btn.layer.cornerRadius = 8.0
        btn.addTarget(self, action: #selector(didClickSaveBtn), for: .touchUpInside)
        return btn
    }()
    
    lazy var bottomView:UIView = {
        let view = UIView()
        view.backgroundColor = .white
        view.addSubview(submitBtn)
        view.addSubview(saveBtn)
        return view
    }()
    
    static func createView() -> YHSaveAndSubmitView {
        
        let view = YHSaveAndSubmitView(frame: CGRect(x: 0, y: 0, width: KScreenWidth, height: Self.height))
        return view
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.createUI()
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }
    
    func createUI() {
        
        self.backgroundColor = .white
        
        self.addSubview(saveBtn)
        self.addSubview(submitBtn)
        
        saveBtn.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(16)
            make.size.equalTo(CGSize(width: 86.0, height: Self.submitBtnHeight))
            make.top.equalTo(Self.gap)
        }
        
        submitBtn.snp.makeConstraints { make in
            make.left.equalTo(saveBtn.snp.right).offset(10)
            make.right.equalToSuperview().offset(-16)
            make.height.equalTo(Self.submitBtnHeight)
            make.centerY.equalTo(saveBtn)
        }
    }
    
    @objc func didClickSubmitBtn() {
        if let submitBlock = submitBlock {
            submitBlock()
        }
    }
    
    @objc func didClickSaveBtn() {
        if let saveBlock = saveBlock {
            saveBlock()
        }
    }
}
