//
//  StateLabel.swift
//  MVMCoreUI
//
//  Created by Matt Bruce on 12/10/21.
//  Copyright © 2021 Verizon Wireless. All rights reserved.
//

import Foundation

/// Subclass of label that helps with different states
public class FormLabel: Label {
    //properties used in setting label
    private var delegateObject: MVMCoreUIDelegateObject?
    private var additionalData: [AnyHashable: Any]?
    
    //models that drive the label UI
    private var formModel: FormLabelModel!
  
    //public properties
    public override var isEnabled: Bool {
        didSet{
            self.formModel.enabled = isEnabled
            self.set(with: isRequired ? formModel.model : formModel.requiredModel, delegateObject, additionalData)
        }
    }
    
    public var isRequired: Bool = true {
        didSet{
            self.set(with: isRequired ? formModel.model : formModel.requiredModel, delegateObject, additionalData)
        }
    }

    public override func reset(){
        super.reset()
        self.isEnabled = true
    }
    
    /// Used in setting up the Label for use
    /// - Parameters:
    ///   - text: If there is no Model, there should be a TEXT only version of the label that will be applied to the default font / color styles
    ///   - model: Model takes priority over a text value. The model has its own text value that will be looked at to draw the screen, this model is used for both enabled/disabled models
    ///   - delegateObject: passed in from the creator
    ///   - additionalData: passed in from the creator
    public func setup(model: FormLabelModel, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?){
        self.additionalData = additionalData
        self.delegateObject = delegateObject
        self.formModel = model
        
        //default to enabled state
        self.reset()
    }
    
    /// Text change that will update both enabledModel and disabledModel text values
    /// - Parameter text: text you want to see
    public func set(text: String?){
        self.formModel.set(text: text ?? "")
    }
}
