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

import Foundation
import MVMCore
import VDS

/**
 This class expects its height and width to be equal.
 */
open class Tilet: VDS.Tilet, VDSMoleculeViewProtocol {
    //--------------------------------------------------
    // MARK: - Properties
    //--------------------------------------------------
    public var viewModel: TiletModel!
    public var delegateObject: MVMCoreUIDelegateObject?
    public var additionalData: [AnyHashable: Any]?
    
    //--------------------------------------------------
    // MARK: - Initializers
    //--------------------------------------------------
    public convenience required init() {
        self.init(frame: .zero)
    }
        
    open func updateView(_ size: CGFloat) {}
    
    open override func updateView() {
        super.updateView()
        //we want to overwrite the VDS color that is set in the ToggleBase
        //for surface since the Atomic controls doesn't look at
        //surface today for its views. We just want to show whatever
        //the current parent's background color.
        backgroundColor = .clear
    }
    
    public func viewModelDidUpdate() {
        surface = viewModel.surface
        titleModel = viewModel.title
        subTitleModel = viewModel.subTitle
        badgeModel = viewModel.badge
        descriptiveIconModel = viewModel.descriptiveIcon
        directionalIconModel = viewModel.directionalIcon
        width = viewModel.width
        textWidth = viewModel.textWidth
        textPercentage = viewModel.textPercentage
    }
            
    //Return the same height as the internal ToggleBase.toggleContainerSize.height
    //since this is a class func, we can't reference it directly
    public static func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {
        nil
    }
    
}

// MARK: - MVMCoreUIViewConstrainingProtocol
extension Tilet: MVMCoreUIViewConstrainingProtocol {
    
    public func needsToBeConstrained() -> Bool { true }
    
    public func horizontalAlignment() -> UIStackView.Alignment { .trailing }
}

