from typing import Dict
from typing import Any
import toml
import base64


def get_config_download_link(config: Dict[Any, Any], filename: str, linkname: str) -> str:
    """Creates a link to download the config as a toml file. Removes keys that should not be customized.

    Parameters
    ----------
    config : Dict
        Config file to export as toml.
    filename : str
        Name of the exported file.
    linkname : str
        Text displayed in the streamlit app.

    Returns
    -------
    str
        Download link.
    """
    config_template = config.copy()
    if "datasets" in config_template.keys():
        del config_template["datasets"]
    toml_string = toml.dumps(config)
    b64 = base64.b64encode(toml_string.encode()).decode()
    href = f'<a href="data:file/toml;base64,{b64}" download="{filename}">{linkname}</a>'
    return href