//
//  HeadersH2TinyButton.swift
//  MVMCoreUI
//
//  Created by Lekshmi S on 11/03/20.
//  Copyright © 2020 Verizon Wireless. All rights reserved.
//

import Foundation


@objcMembers open class HeadersH2TinyButton: HeaderView {
    //--------------------------------------------------
    // MARK: - Outlets
    //--------------------------------------------------
    
    public let headlineBody = HeadlineBody()
    public let button = PillButton()
    public lazy var stack: Stack<StackModel> = {
        return Stack<StackModel>.createStack(with: [(view: headlineBody, model: StackItemModel(horizontalAlignment: .fill)),
                                                    (view: button, model: StackItemModel(spacing: spacingBetwenHeadlineBodyAndButton, horizontalAlignment: .leading))],
                                             axis: .vertical)
      }()
    
    //------------------------------------------------------
    // MARK: - Constants
    //------------------------------------------------------
    
    let spacingBetwenHeadlineBodyAndButton: CGFloat = 16.0
    
    //-------------------------------------------------------
    // MARK: - Lifecycle
    //-------------------------------------------------------
    
    open override func setupView() {
        super.setupView()
        headlineBody.stylePageHeader()
        addMolecule(stack)
        stack.restack()
    }
    
    //----------------------------------------------------
    // MARK: - Molecule
    //----------------------------------------------------
    
    open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
        super.set(with: model, delegateObject, additionalData)
        
        guard let model = model as? HeadersH2TinyButtonModel else { return }
        
        headlineBody.set(with: model.headlineBody, delegateObject, additionalData)
        button.set(with: model.button, delegateObject, additionalData)
    }
    
    open override class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {
        return 121
    }
    
    open override func reset() {
        super.reset()
        headlineBody.stylePageHeader()
    }
}
