//
//  Tooltip.swift
//  MVMCoreUI
//
//  Created by Matt Bruce on 12/14/23.
//  Copyright © 2023 Verizon Wireless. All rights reserved.
//

import Foundation
import VDS

open class Tooltip: VDS.Tooltip, VDSMoleculeViewProtocol{
    //--------------------------------------------------
    // MARK: - Properties
    //--------------------------------------------------
    public var viewModel: MVMCoreUI.TooltipModel!
    public var delegateObject: MVMCoreUIDelegateObject?
    public var additionalData: [AnyHashable: Any]?
        
    //--------------------------------------------------
    // MARK: - Initializers
    //--------------------------------------------------
    public convenience required init() {
        self.init(frame: .zero)
    }
    
    //--------------------------------------------------
    // MARK: - Public
    //--------------------------------------------------
    public func viewModelDidUpdate() {
        surface = viewModel.surface
        fillColor = viewModel.fillColor
        size = viewModel.size
        closeButtonText = viewModel.closeButtonText
        title = viewModel.title
        content = viewModel.content
        
        if let moleculeModel = viewModel.molecule {
            if contentView != nil {
                (contentView as? MoleculeViewProtocol)?.set(with: moleculeModel, delegateObject, additionalData)
            } else if let molecule = ModelRegistry.createMolecule(moleculeModel, delegateObject: delegateObject, additionalData: additionalData) {
                contentView = molecule
            }
        }
    }

    //--------------------------------------------------
    // MARK: - MVMCoreViewProtocol
    //--------------------------------------------------
    open func updateView(_ size: CGFloat) {}

    //--------------------------------------------------
    // MARK: - MoleculeViewProtocol
    //--------------------------------------------------
    //since this is a class func, we can't reference it directly
    public static func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {
        VDS.Icon.Size.medium.dimensions.height
    }
}

extension Tooltip: MVMCoreUIViewConstrainingProtocol {

    public func needsToBeConstrained() -> Bool { true }
    
    public func horizontalAlignment() -> UIStackView.Alignment { .leading }
}
