from bs4 import BeautifulSoup


def title_card_factory(title: str, sub_title: str, image_link: str = ""):
    """
    For creating title card HTML.

    Args:
        title (str): Title on the title card.
        sub_title (str): The subtitle below the title card.
        image_link (str, optional): The image on the title card. Defaults to "".

    Returns:
        _type_: the Beautifulsoup title card tag.
    """
    soup = BeautifulSoup()
    title_tag = soup.new_tag("h1", **{"class": "center"})
    title_tag.string = title
    tiny_tag = soup.new_tag("h2", **{"class": "center"})
    tiny_tag.string = sub_title

    card_tag = soup.new_tag("div")

    if image_link:
        image_tag = soup.new_tag("img", **{"class": "center_img", "src": image_link, "style": "max-height: 400px;"})
        card_tag.append(image_tag)
    card_tag.append(title_tag)
    card_tag.append(tiny_tag)
    return card_tag