#!/usr/bin/env python3
# ----------------------------------------------------------------------
# Copyright (C) 2025 Tristan Hoellinger
# Distributed under the GNU General Public License v3.0 (GPLv3).
# See the LICENSE file in the root directory for details.
# SPDX-License-Identifier: GPL-3.0-or-later
# ----------------------------------------------------------------------

__author__ = "Tristan Hoellinger"
__version__ = "0.1.0"
__date__ = "2025"
__license__ = "GPLv3"

"""Plotting parameters and custom colormaps for the WIP-P3M package."""


# Global font sizes
GLOBAL_FS = 18
GLOBAL_FS_LARGE = 20
GLOBAL_FS_XLARGE = 22
GLOBAL_FS_SMALL = 16
GLOBAL_FS_TINY = 14
COLOUR_LIST = ["C{}".format(i) for i in range(10)]


def reset_plotting():
    import matplotlib as mpl

    mpl.rcParams.update(mpl.rcParamsDefault)


def setup_plotting():
    """
    Configure Matplotlib plotting settings for consistent appearance.
    """
    import matplotlib.pyplot as plt
    import importlib.resources

    with importlib.resources.open_text("wip3m", "preamble.tex") as f:
        preamble = f.read()

    # Dictionary with rcParams settings
    rcparams = {
        "font.family": "serif",
        "font.size": GLOBAL_FS,  # Base font size
        "axes.titlesize": GLOBAL_FS_XLARGE,
        "axes.labelsize": GLOBAL_FS_LARGE,
        "axes.linewidth": 1.0,
        "xtick.labelsize": GLOBAL_FS_SMALL,
        "ytick.labelsize": GLOBAL_FS_SMALL,
        "xtick.major.width": 1.2,
        "ytick.major.width": 1.2,
        "xtick.minor.width": 1.0,
        "ytick.minor.width": 1.0,
        "xtick.direction": "in",
        "ytick.direction": "in",
        "xtick.major.pad": 5,
        "xtick.minor.pad": 5,
        "ytick.major.pad": 5,
        "ytick.minor.pad": 5,
        "legend.fontsize": GLOBAL_FS_SMALL,
        "legend.title_fontsize": GLOBAL_FS_LARGE,
        "figure.titlesize": GLOBAL_FS_XLARGE,
        "figure.dpi": 300,
        "grid.color": "gray",
        "grid.linestyle": "dotted",
        "grid.linewidth": 0.6,
        "lines.linewidth": 2,
        "lines.markersize": 8,
        "text.usetex": True,
        "text.latex.preamble": preamble,
    }

    # Update rcParams
    plt.rcParams.update(rcparams)
