//
//  HeadlineBodyLinkToggle.swift
//  MVMCoreUI
//
//  Created by Priya on 5/6/19.
//  Copyright © 2019 Verizon Wireless. All rights reserved.
//

import UIKit

@objcMembers public class HeadlineBodyLinkToggle: View {
    let headlineBodyLink = HeadlineBodyLink(frame: .zero)
    let toggle = Toggle()

    // MARK: - MVMCoreViewProtocol
    open override func updateView(_ size: CGFloat) {
        super.updateView(size)
        headlineBodyLink.updateView(size)
        toggle.updateView(size)
    }
    
    public override func setupView() {
        super.setupView()
        guard toggle.superview == nil else {
            return
        }
        headlineBodyLink.headlineBody.styleListItem()
        addSubview(headlineBodyLink)
        addSubview(toggle)
        NSLayoutConstraint.pinViews(leftView: headlineBodyLink, rightView: toggle, alignTop: false)
    }
    
    // MARK: - MVMCoreUIMoleculeViewProtoco
    public override func reset() {
        super.reset()
        headlineBodyLink.reset()
        toggle.reset()
    }
    
    // MARK:- MoleculeViewProtocol
    open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
        super.set(with: model, delegateObject, additionalData)
        guard let model = model as? HeadlineBodyLinkToggleModel else { return }
        headlineBodyLink.set(with: model.headlineBodyLink, delegateObject, additionalData)
        toggle.set(with: model.toggle, delegateObject, additionalData)
    }
       
    public override class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject:  MVMCoreUIDelegateObject?) -> CGFloat? {
        guard let model = model as? HeadlineBodyLinkToggleModel else { return nil }
        return HeadlineBodyLink.estimatedHeight(with: model.headlineBodyLink, delegateObject)
    }
}


