"""The configuration module for sphinx."""

import json
import os

metadata = json.load(os.popen("hatch project metadata"))
project = metadata["name"]
author = ",".join(author["name"] for author in metadata["authors"])
version = metadata["version"]
project_copyright = f"2018-%Y, {author}"

# -- General configuration ------------------------------------------------

extensions = [
    "myst_parser",
    "sphinx.ext.autodoc",
    "sphinx.ext.autosummary",
    "sphinx.ext.todo",
    "sphinx.ext.coverage",
    "sphinx.ext.mathjax",
    "sphinx.ext.intersphinx",
    "sphinx.ext.napoleon",
    "sphinx_book_theme",
    "nbsphinx",
    "sphinxcontrib.plantuml",
    "sphinx_autodoc_typehints",
    "sphinx_codeautolink",
    "sphinx_copybutton",
]

copybutton_prompt_text = (
    r">>> "
    r"|\.\.\. "
    r"|(?:\([^)\n]*\)\s*)?\$ "
    r"|In \[\d*\]: "
    r"| {2,5}\.\.\.: "
    r"| {5,8}: "
)
copybutton_prompt_is_regexp = True
copybutton_line_continuation_character = "\\"
plantuml_output_format = "svg_img"

add_module_names = False

# nbsphinx settings
nbsphinx_allow_errors = True

# Napoleon settings
napoleon_google_docstring = True
napoleon_numpy_docstring = True
napoleon_include_init_with_doc = True
napoleon_include_private_with_doc = False
napoleon_include_special_with_doc = True
napoleon_use_admonition_for_examples = True
napoleon_use_admonition_for_notes = True
napoleon_use_admonition_for_references = True
napoleon_use_ivar = False
napoleon_use_param = True
napoleon_use_rtype = True

# intersphinx setting
intersphinx_mapping = {"python": ("https://docs.python.org/3", None)}

# autodoc and autosummary settings
autosummary_generate = True
autodoc_member_order = "bysource"
autodoc_default_options = {
    "member-order": "bysource",
    "members": True,
    "show-inheritance": True,
}

typehints_defaults = "comma"

# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]

# The suffix(es) of source filenames.
source_suffix = {".rst": "restructuredtext", ".md": "markdown"}

# The master toctree document.
master_doc = "index"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = "en"

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
exclude_patterns = ["_build", "**.ipynb_checkpoints"]

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = "sphinx"

# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = True

# -- Options for HTML output ----------------------------------------------

# The theme to use for HTML and HTML Help pages.  See the documentation for
# a list of builtin themes.
#
html_theme = "sphinx_book_theme"

# Theme options are theme-specific and customize the look and feel of a theme
# further.  For a list of options available for each theme, see the
# documentation.
html_theme_options = {
    "max_navbar_depth": 1,
    "logo": {
        "image_dark": "icon-dark.svg",
        "text": project[len("galactic-") :],
    },
    "use_download_button": False,
    "use_fullscreen_button": False,
    "switcher": {
        "version_match": "latest",
        "json_url": "/docs/helpers/core/versions.json",
    },
    "icon_links": [
        {
            "name": "GitLab",
            "url": "https://gitlab.univ-lr.fr/galactic/public/src/helpers/galactic-helper-core/",
            "icon": "fa-brands fa-gitlab",
            "type": "fontawesome",
        },
    ],
}

# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
html_sidebars = {
    "**": [
        "navbar-logo.html",
        "version-switcher.html",
        "icon-links.html",
        "search-button-field.html",
        "sbt-sidebar-nav.html",
    ],
}
html_show_sourcelink = False
html_favicon = "thegalactic.ico"
html_logo = "icon-light.svg"
html_title = ""
