//
//  ListTwoColumnCompareChanges.swift
//  MVMCoreUI
//
//  Created by Lekshmi S on 24/02/20.
//  Copyright © 2020 Verizon Wireless. All rights reserved.
//


@objcMembers open class ListTwoColumnCompareChanges: TableViewCell {
    //-------------------------------------------------------
    // MARK: - Outlets
    //-------------------------------------------------------
    
    let leftHeadlineBodyLink = ThreeHeadlineBodyLink()
    let rightHeadlineBodyLink = ThreeHeadlineBodyLink()
    
    //------------------------------------------------------
    // MARK: - Properties
    //------------------------------------------------------
    
    let containingStack: Stack<StackModel>
    
    //------------------------------------------------------
    // MARK: - Initializers
    //------------------------------------------------------
    
    public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        let stackHeadline1 = Stack<StackModel>.createStack(with: [(view: leftHeadlineBodyLink, model: StackItemModel(percent: 50, verticalAlignment: .leading)),
                                                                  (view: rightHeadlineBodyLink, model: StackItemModel(percent: 50, verticalAlignment: .leading))],
                                                           axis: .horizontal)
        
        containingStack = Stack<StackModel>.createStack(with: [stackHeadline1], spacing: Padding.Component.gutterForApplicationWidth)
        super.init(style: style, reuseIdentifier: reuseIdentifier)
    }
    
    public required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //-------------------------------------------------------
    // MARK: - Lifecycle
    //-------------------------------------------------------
    
    open override func setupView() {
        super.setupView()
        
        addMolecule(containingStack)
        
        for molecule in containingStack.stackItems {
            ((molecule as? StackItem)?.view as? Stack<StackModel>)?.restack()
        }
        containingStack.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? ListTwoColumnCompareChangesModel else { return }
        
        leftHeadlineBodyLink.headline1.set(with: model.leftHeadline1, delegateObject, additionalData)
        leftHeadlineBodyLink.headline2.set(with: model.leftHeadline2, delegateObject, additionalData)
        leftHeadlineBodyLink.headline3.set(with: model.leftHeadline3, delegateObject, additionalData)
        leftHeadlineBodyLink.body.set(with: model.leftBody, delegateObject, additionalData)
        leftHeadlineBodyLink.link.set(with: model.leftLink, delegateObject, additionalData)
        leftHeadlineBodyLink.updateAccessibilityLabel()
        
        rightHeadlineBodyLink.headline1.set(with: model.rightHeadline1, delegateObject, additionalData)
        rightHeadlineBodyLink.headline2.set(with: model.rightHeadline2, delegateObject, additionalData)
        rightHeadlineBodyLink.headline3.set(with: model.rightHeadline3, delegateObject, additionalData)
        rightHeadlineBodyLink.body.set(with: model.rightBody, delegateObject, additionalData)
        rightHeadlineBodyLink.link.set(with: model.rightLink, delegateObject, additionalData)
        rightHeadlineBodyLink.updateAccessibilityLabel()
    }
    
    open override func reset() {
        super.reset()
        leftHeadlineBodyLink.headline1.setFontStyle(.BoldBodySmall)
        leftHeadlineBodyLink.headline2.setFontStyle(.BoldBodySmall)
        leftHeadlineBodyLink.headline3.setFontStyle(.BoldBodySmall)
        leftHeadlineBodyLink.body.setFontStyle(.RegularBodySmall)
        rightHeadlineBodyLink.headline1.setFontStyle(.BoldBodySmall)
        rightHeadlineBodyLink.headline2.setFontStyle(.BoldBodySmall)
        rightHeadlineBodyLink.headline3.setFontStyle(.BoldBodySmall)
        rightHeadlineBodyLink.body.setFontStyle(.RegularBodySmall)
    }
    
    public override class func estimatedHeight(with molecule: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {
        return 121
    }
}
