//
//  ImageBarButtonItem.swift
//  MVMCoreUI
//
//  Created by Scott Pfeil on 5/27/20.
//  Copyright © 2020 Verizon Wireless. All rights reserved.
//


@objcMembers open class ImageBarButtonItem: BarButtonItem {
    //--------------------------------------------------
    // MARK: - Initializers
    //--------------------------------------------------
    
    public static func create(with image: UIImage?) -> Self {
        let actionObject = ActionDelegate()
        let button = self.init(image: image, style: .plain, target: actionObject, action: #selector(actionObject.callActionBlock))
        button.actionDelegate = actionObject
        return button
    }
    
    /// Creates the item with the passed in action.
    public static func create(with image: UIImage?, model: MoleculeModelProtocol & NavigationButtonModelProtocol, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) -> Self {
        let button = create(with: image)
        button.set(with: model, delegateObject: delegateObject, additionalData: additionalData)
        return button
    }
    
    /// Creates the item with the passed in action.
    public static func create(with image: UIImage?, action: @escaping BarButtonAction) -> Self {
        let button = create(with: image)
        button.actionDelegate?.buttonAction = action
        return button
    }
}
