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

import Foundation

@objcMembers open class HeadersH1LandingPageHeader: HeaderView {
    //--------------------------------------------------
    // MARK: - Outlets
    //--------------------------------------------------
    public let headline = Label(fontStyle: .Title2XLarge)
    public let headline2 = Label(fontStyle: .Title2XLarge)
    public let subHeadline = Label(fontStyle: .BoldBodySmall)
    public let body = Label(fontStyle: .RegularBodySmall)
    public let link = Link()
    public let buttons = TwoButtonView()
    public var stack: Stack<StackModel>!
    
    //--------------------------------------------------
    // MARK: - Constants
    //--------------------------------------------------
    
    let spacingBetweenHeadlineHeadline2: CGFloat = 16.0
    let spacingBetweenHeadline2subHeadline: CGFloat = 32.0
    let spacingBetweenSubHeadlineBodyLink: CGFloat = 8.0
    let spacingBetweenLinkButtons: CGFloat = 128.0
    
    //-------------------------------------------------------
    // MARK: - View Lifecycle
    //-------------------------------------------------------
    open override func setupView() {
        super.setupView()
        stack = Stack<StackModel>.createStack(with: [(view: headline, model: StackItemModel()),
                                                     (view: headline2, model: StackItemModel(spacing: spacingBetweenHeadlineHeadline2)),
                                                     (view: subHeadline, model: StackItemModel(spacing: spacingBetweenHeadline2subHeadline)),
                                                     (view: body, model: StackItemModel(spacing: spacingBetweenSubHeadlineBodyLink)),
                                                     (view: link, model: StackItemModel(spacing: spacingBetweenSubHeadlineBodyLink, horizontalAlignment: .leading)),
                                                     (view: buttons, model: StackItemModel(spacing: spacingBetweenLinkButtons))])
        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? HeadersH1LandingPageHeaderModel else { return }
        headline.set(with: model.headline, delegateObject, additionalData)
        headline2.set(with: model.headline2, delegateObject, additionalData)
        subHeadline.set(with: model.subHeadline, delegateObject, additionalData)
        body.set(with: model.body, delegateObject, additionalData)
        link.set(with: model.link, delegateObject, additionalData)
        buttons.set(with: model.buttons, delegateObject, additionalData)
    }
    
    open override class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { 121 }
    
    open override func reset() {
        super.reset()
        headline.setFontStyle(.Title2XLarge)
        headline2.setFontStyle(.Title2XLarge)
        subHeadline.setFontStyle(.BoldBodySmall)
        body.setFontStyle(.RegularBodySmall)
    }
}
