//
//  Badge.swift
//  MVMCoreUI
//
//  Created by Rebecca Antonelli on 4/6/23.
//  Copyright © 2023 Verizon Wireless. All rights reserved.
//

import Foundation
import MVMCore
import VDS
import Combine

open class Badge: VDS.Badge, VDSMoleculeViewProtocol {

    //--------------------------------------------------
    // MARK: - Public Properties
    //--------------------------------------------------
    public var viewModel: BadgeModel!
    
    public var delegateObject: MVMCoreUIDelegateObject?
    
    public var additionalData: [AnyHashable : Any]?
    
    //--------------------------------------------------
    // MARK: - Public Methods
    //--------------------------------------------------
    
    public func viewModelDidUpdate() {
        text = viewModel.text
        maxWidth = viewModel.maxWidth
        numberOfLines = viewModel.numberOfLines
        fillColor = viewModel.fillColor
        surface = viewModel.surface
    }
    
    public func updateView(_ size: CGFloat) {}
    
    //--------------------------------------------------
    // MARK: - Overrides
    //--------------------------------------------------
    open override func updateAccessibility() {
        super.updateAccessibility()
        
        if let viewModel {
            if let accessibilityText = viewModel.accessibilityText {
                self.accessibilityLabel = accessibilityText
            }
        }
    }
    
}

//to deal with how it's parent constrains this control
extension Badge: MVMCoreUIViewConstrainingProtocol {

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