from __future__ import annotations

from dataclasses import dataclass

from openpyxl.styles import Alignment, Border, Font, PatternFill, Side


@dataclass(frozen=True)
class ThemeFonts:
    title: Font
    section: Font
    body: Font
    small: Font
    kpi_label: Font
    kpi_value: Font


@dataclass(frozen=True)
class ThemeFills:
    header: PatternFill
    zebra: PatternFill
    card_bg: PatternFill
    section_bg: PatternFill
    title_bg: PatternFill
    muted_bg: PatternFill


@dataclass(frozen=True)
class ThemeBorders:
    thin: Border


@dataclass(frozen=True)
class ThemeAlignments:
    left: Alignment
    center: Alignment
    right: Alignment
    wrap_left: Alignment
    wrap_center: Alignment


@dataclass(frozen=True)
class ThemeNumberFormats:
    integer: str
    percent: str
    datetime: str


@dataclass(frozen=True)
class ThemeSpacing:
    section_gap: int = 2
    block_gap: int = 1
    card_gap: int = 1


@dataclass(frozen=True)
class Theme:
    fonts: ThemeFonts
    fills: ThemeFills
    borders: ThemeBorders
    alignments: ThemeAlignments
    number_formats: ThemeNumberFormats
    spacing: ThemeSpacing
    accent_color: str


def LightTheme() -> Theme:
    subtle_line = Side(style="thin", color="D7DCE2")

    fonts = ThemeFonts(
        title=Font(name="Calibri", size=16, bold=True, color="1F2A37"),
        section=Font(name="Calibri", size=11, bold=True, color="1F2A37"),
        body=Font(name="Calibri", size=10, color="2F3A45"),
        small=Font(name="Calibri", size=9, color="5B6570"),
        kpi_label=Font(name="Calibri", size=10, bold=True, color="2F3A45"),
        kpi_value=Font(name="Calibri", size=18, bold=True, color="1B4D8A"),
    )

    fills = ThemeFills(
        header=PatternFill(fill_type="solid", fgColor="ECF1F6"),
        zebra=PatternFill(fill_type="solid", fgColor="F8FAFC"),
        card_bg=PatternFill(fill_type="solid", fgColor="F3F7FB"),
        section_bg=PatternFill(fill_type="solid", fgColor="E8EEF5"),
        title_bg=PatternFill(fill_type="solid", fgColor="E2EAF3"),
        muted_bg=PatternFill(fill_type="solid", fgColor="F6F8FA"),
    )

    borders = ThemeBorders(thin=Border(left=subtle_line, right=subtle_line, top=subtle_line, bottom=subtle_line))

    alignments = ThemeAlignments(
        left=Alignment(horizontal="left", vertical="center"),
        center=Alignment(horizontal="center", vertical="center"),
        right=Alignment(horizontal="right", vertical="center"),
        wrap_left=Alignment(horizontal="left", vertical="top", wrap_text=True),
        wrap_center=Alignment(horizontal="center", vertical="center", wrap_text=True),
    )

    number_formats = ThemeNumberFormats(
        integer="#,##0",
        percent="0.00%",
        datetime="yyyy-mm-dd hh:mm:ss",
    )

    spacing = ThemeSpacing(section_gap=2, block_gap=1, card_gap=1)

    return Theme(
        fonts=fonts,
        fills=fills,
        borders=borders,
        alignments=alignments,
        number_formats=number_formats,
        spacing=spacing,
        accent_color="1B4D8A",
    )
