# Configuration file for the Sphinx documentation builder.
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

import sys
from pathlib import Path

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = "ARIS-lite"
copyright = "2024-2025, Jan Haacker"
author = "Jan Haacker"
# version = (
#     subprun(
#         'git tag --sort=taggerdate | grep -e "^v" | head -1',
#         shell=True,
#         check=True,
#         capture_output=True,
#     )
#     .stdout.decode()
#     .strip()
# )
# # print(version)
# git_hash = (
#     subprun(f"git rev-list -n 1 {version}", shell=True, check=True, capture_output=True)  # noqa: E501
#     .stdout.decode()
#     .strip()
# )
# # print(git_hash)

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = [
    "sphinx.ext.autodoc",
    "sphinx.ext.githubpages",
    "sphinx.ext.viewcode",
    "myst_parser",
    "sphinx_immaterial",
    "sphinxcontrib.bibtex",
    # "sphinx.ext.linkcode",
    # 'sphinx.ext.napoleon',
]
bibtex_bibfiles = ["refs.bib"]

templates_path = ["_templates"]
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]


# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = "sphinx_immaterial"
html_static_path = ["_static"]
html_theme_options = {
    "repo_url": "https://github.com/boku-met/aris_lite",
    "palette": [
        {
            "media": "(prefers-color-scheme)",
            "scheme": "slate",
            "primary": "orange",
            "accent": "teal",
            "toggle": {
                "icon": "material/weather-sunny",
                "name": "Switch to light mode",
            },
        },
        {
            "media": "(prefers-color-scheme: light)",
            "scheme": "default",
            "primary": "orange",
            "accent": "teal",
            "toggle": {
                "icon": "material/weather-night",
                "name": "Switch to dark mode",
            },
        },
        {
            "media": "(prefers-color-scheme: dark)",
            "scheme": "slate",
            "primary": "orange",
            "accent": "teal",
            "toggle": {
                "icon": "material/weather-sunny",
                "name": "Switch to light mode",
            },
        },
    ],
    "icon": {
        "logo": "material/sprout",
        "repo": "fontawesome/brands/github",
    },
}

# sys.path.insert(0, str(Path("..").resolve()))
sys.path.insert(0, str(Path("..", "aris_lite").resolve()))
# print(list(Path("..", "aris_lite").resolve().glob("*")))


# def get_func_line_number(module, func_name) -> int:
#     with open(str(Path("..", module + ".py").resolve())) as f:
#         for num, line in enumerate(f, 1):
#             if f"def {func_name}" in line:
#                 return num


# def linkcode_resolve(domain, info):
#     # ! apparent issue with current project structure!
#     if domain != "py":
#         return None
#     if not info["module"]:
#         return None
#     filename = "/".join(info["module"].split(".")[1:])
#     if "fullname" in info:
#         anchor = "#L%d" % get_func_line_number(filename, info["fullname"])
#     else:
#         anchor = ""
#     return "https://github.com/j-haacker/aris_lite/blob/%s/%s.py%s" % (
#         git_hash,
#         filename,
#         anchor,
#     )
