# -*- coding: utf-8 -*-
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
# -- Path setup --------------------------------------------------------------
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import sys

# import sphinx_bootstrap_theme

sys.path.insert(0, os.path.abspath("../.."))


def skip(app, what, name, obj, would_skip, options):
    if name == "__init__":
        return False
    return would_skip


def setup(app):
    # app.add_css_file("my-styles.css")  # also can be a full URL
    app.connect("autodoc-skip-member", skip)


import iechelle

# -- Project information -----------------------------------------------------

project = "iechelle"
copyright = "2025 - CEA (Dinil Bose Palakkatharappil "
author = "Dinil Bose Palakkatharappil"
version = iechelle.__version__
release = iechelle.__version__
title = iechelle.__title__
project_url = "https://gitlab.com/dinilbose/iechelle"


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

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
    "sphinx.ext.autodoc",
    "sphinx.ext.autosummary",
    "sphinx.ext.ifconfig",
    "sphinx.ext.napoleon",
    "sphinx.ext.coverage",
    "sphinx.ext.intersphinx",
    "sphinx.ext.viewcode",
    "sphinxcontrib.plantuml",
    "sphinxcontrib.mermaid",
    "sphinx.ext.graphviz",
]

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

source_suffix = ".rst"

# The master toctree document.
master_doc = "index"

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

# 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 = False

# Enable figure numbering
numfig = True


html_theme = "alabaster"
# html_logo = "_static/logo.png"
html_static_path = ["_static"]
templates_path = ["_templates"]
html_css_files = ["my-styles.css"]

# Output file base name for HTML help builder.
htmlhelp_basename = "iechelledoc"

# -- Options for LaTeX output ------------------------------------------

latex_elements = {
    # Paper size: 'letterpaper' or 'a4paper'
    "papersize": "a4paper",
    # Font size: '10pt', '11pt', or '12pt'
    "pointsize": "10pt",
    # Additional preamble customization
    "preamble": r"""
        % Numbering levels for sections
        \setcounter{secnumdepth}{3}  % Enable numbering for subsubsections
        \setcounter{tocdepth}{2}     % Include up to subsubsections in TOC

        % Packages for math and symbols
        \usepackage{amsmath, amsfonts, amssymb, amsthm}

        % Figure alignment and graphicx support
        \usepackage{graphicx}

        % Adjustments for TOC, figures, and tables
        \usepackage[notlot,nottoc,notlof]{}

        % Fancy headers
        \usepackage{fancyhdr}
        \pagestyle{fancy}
        \fancyhf{}  % Clear all header and footer fields
        \fancyhead[L]{\small \nouppercase{\leftmark}}
        \fancyhead[R]{\small \thepage}
        \renewcommand{\headrulewidth}{0.4pt}
        \renewcommand{\footrulewidth}{0.4pt}

        % Reduce spacing for itemize
        \usepackage{enumitem}
        \setlist{nosep}

        % Custom quotes for chapters
        \usepackage{epigraph}
        \setlength{\epigraphwidth}{0.8\columnwidth}

        % Hyperlink customization
        \usepackage{hyperref}
        \hypersetup{
            colorlinks=true,
            linkcolor=blue,
            filecolor=magenta,
            urlcolor=cyan,
        }

        % Footer customization
        \fancyfoot[C]{\thepage}
    """,
    # Maketitle customization
    "maketitle": r"""
        \pagenumbering{Roman}  % Start Roman numbering for pre-content pages
        \begin{titlepage}
            \centering

            \vspace*{2cm}
            {\Huge \bfseries """
    + title
    + r""" \\}

            \vspace{1cm}
            \includegraphics[scale=0.3]{logo.png}

            \vspace{2cm}
            {\Large \textbf{"""
    + author
    + r""" \\}}
            \vspace{1cm}

            \small Created: June 2025 \\
            Last updated: \today

            \vfill
            \small \textit{More information available at: } \href{"""
    + project_url
    + r"""}{"""
    + project_url
    + r"""}
        \end{titlepage}

        \clearpage
        \pagenumbering{roman}
        \sphinxtableofcontents
        \listoffigures
        \listoftables
        \clearpage
        \pagenumbering{arabic}
    """,
    # Page margins and spacing
    "sphinxsetup": "hmargin={0.7in,0.7in}, vmargin={1in,1in}",
    # Table of contents customization
    "tableofcontents": "",
}

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass
# [howto, manual, or own class]).
latex_documents = [
    (
        master_doc,
        "iechelle.tex",
        title.replace("_", r"\_") + " Documentation",
        author,
        "manual",
    ),
]

# -- Options for manual page output ------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [(master_doc, "iechelle", title + " Documentation", [author], 1)]

# -- Options for Texinfo output ----------------------------------------

# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
#  dir menu entry, description, category)
texinfo_documents = [
    (
        master_doc,
        "iechelle",
        title + " Documentation",
        author,
        "iechelle",
        "My Great Project description.",
        "Miscellaneous",
    ),
]

html_theme_options = {
    "logo": "logo.png",
    "description": "Interactive Echelle Diagram analysis and peakbagging tool.",
    "github_button": False,
    "sidebar_width": "220px",
    "page_width": "1200px",
}

html_sidebars = {
    "**": [
        "about.html",
        "navigation.html",
        "relations.html",
        "searchbox.html",
    ]
}

# -- Options for Epub output ----------------------------------------------

# Bibliographic Dublin Core info.
epub_title = project
epub_author = author
epub_publisher = author
epub_copyright = copyright

# The unique identifier of the text. This can be a ISBN number
# or the project homepage.
#
# epub_identifier = ''

# A unique identification for the text.
#
# epub_uid = ''

# A list of files that should not be packed into the epub file.
epub_exclude_files = ["search.html"]
