//
//  MoleculeHeaderView.swift
//  MVMCoreUI
//
//  Created by Scott Pfeil on 2/12/19.
//  Copyright © 2019 Verizon Wireless. All rights reserved.
//

import UIKit


public class MoleculeHeaderView: MoleculeContainer {
    //--------------------------------------------------
    // MARK: - Properties
    //--------------------------------------------------
    
    var line = Line()
    
    var headerModel: MoleculeHeaderModel? {
        get { model as? MoleculeHeaderModel }
    }
    
    //--------------------------------------------------
    // MARK: - MVMCoreViewProtocol
    //--------------------------------------------------
    
    open override func updateView(_ size: CGFloat) {
        super.updateView(size)
        line.updateView(size)
    }
    
    public override func setupView() {
        super.setupView()
        line.setStyle(.heavy)
        addSubview(line)
        NSLayoutConstraint.pinViewBottom(toSuperview: line, useMargins: false, constant: 0).isActive = true
        NSLayoutConstraint.pinViewLeft(toSuperview: line, useMargins: true, constant: 0).isActive = true
        NSLayoutConstraint.pinViewRight(toSuperview: line, useMargins: true, constant: 0).isActive = true
    }
    
    open override func reset() {
        super.reset()
        line.setStyle(.heavy)
    }
    
    open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
        super.set(with: model, delegateObject, additionalData)
        
        guard let headerModel = headerModel else { return }
        
        if let lineModel = headerModel.line {
            line.set(with: lineModel, delegateObject, additionalData)
        }
    }
}
