import math


def create_text_widget(text_data: dict, title: str) -> dict:
    """Creates a new text widget with the specified data

    :param text_data: the metric data to put in the widget
    :type text_data: dict
    :param title: the title of the widget
    :type title: str
    :returns: the dictionary representing the widget
    :rtype: dict
    """
    if not title or not text_data or not isinstance(text_data, dict):
        print("failed to create a text widget. Missing parameters")
        return {}

    text_widget_string = '## ' + title + '\n Name | Value \n ----|----- \n'
    for metric_name, metric_text in text_data.items():
        text_widget_string += metric_name + ' | ' + metric_text + '\n'

    # Keep height of text widget closer to height of content (makes height more responsive)
    height = 2 + (math.ceil(len(text_data) / 3) * 2 if math.floor(len(text_data) / 3) >= 1 else 2)
    return {
        'type': 'text',
        'height': height,
        'properties': {
            'markdown': text_widget_string
        }
    }