"""
Mobile vs. non-mobile.
"""
from dataclasses import dataclass
from datetime import datetime
from typing import ClassVar

from rich.padding import PaddingDimensions
from rich.text import Text

from epstein_files.util.constant.strings import SUBHEADER_STYLE, TIMESTAMP_STYLE
from epstein_files.util.helpers.link_helper import link_markup
from epstein_files.util.helpers.string_helper import capitalize_first, iso_timestamp, starred_header

ALL_OTHER_FILES_MULTIPLIER = 1.5  # applied when --all-other-files is in use
DEFAULT_WIDTH = 150

RICH_LINK_MARKUP = link_markup('https://pypi.org/project/rich/', 'rich')
MOBILE_WARNING = f"This page was generated by {RICH_LINK_MARKUP}. It is very poorly optimized for mobile and may take a while to render on a phone." \
                  "\nIf your browser won't render part of the page try reloading."
NOT_ALL_FILES_MSG = 'Not All Epstein Files Are Here!'


# TODO: another thing that changes based on mobile is id_only for link texts
@dataclass
class MobileConfig:
    """
    show_with_indent (int): Indent for `show_with_name` files
    """
    abbreviations_width: ClassVar[int | None] = None
    attachment_indent: ClassVar[int] = 6
    character_bio_padding: ClassVar[tuple[int, int, int, int]] = (0, 0, 1, 2)
    email_info_in_subtitle: ClassVar[bool] = False
    info_indent: ClassVar[int] = 1
    max_alt_links: ClassVar[int | None] = 1
    not_all_files_warning: ClassVar[str] = starred_header(NOT_ALL_FILES_MSG, num_spaces=1, num_stars=1)
    num_color_key_cols: ClassVar[int] = 2
    other_files_preview_chars: ClassVar[int] = 300
    other_files_table_indent: ClassVar[int] = 0
    section_header_padding: ClassVar[PaddingDimensions] = (2, 1, 1, 1)
    show_with_indent: ClassVar[int] = 0
    show_emailer_tables: ClassVar[bool] = False
    site_glossary_horizontal_padding: ClassVar[int] = 2
    social_link_separator: ClassVar[str] = ' '
    subtitle_width: ClassVar[int | None] = None
    suppressed_file_indent: ClassVar[int] = 0
    width: ClassVar[int] = 52

    @classmethod
    def format_text_msg_time(cls, dt: datetime) -> str:
        return dt.strftime(r"%-d/%-m/%-y %-H:%M")

    @classmethod
    def info_padding(cls) -> tuple[int, int, int, int]:
        return (0, 0, 0, cls.info_indent)

    @classmethod
    def email_subheader(cls, email_type: str, author: Text, recipients: Text, timestamp: datetime | Text) -> Text:
        prefix = f"{capitalize_first(email_type)} from " if email_type != 'email' else ''
        txt = Text(prefix, SUBHEADER_STYLE).append(author)
        timestamp = timestamp if isinstance(timestamp, Text) else Text(' at ').append(str(timestamp), TIMESTAMP_STYLE)
        txt.append(' to ').append(recipients).append(timestamp)
        return txt

    @classmethod
    def suppressed_file_padding(cls) -> tuple[int, int, int, int]:
        return (0, 0, 0, cls.suppressed_file_indent)


class SiteConfig(MobileConfig):
    abbreviations_width: ClassVar[int | None] = 62
    attachment_indent: ClassVar[int] = 12
    character_bio_padding: ClassVar[tuple[int, int, int, int]] = (0, 1, 0, 0)
    email_info_in_subtitle: ClassVar[bool] = True
    info_indent: ClassVar[int] = 1
    max_alt_links: ClassVar[int | None] = None
    not_all_files_warning: ClassVar[str] = starred_header(NOT_ALL_FILES_MSG, num_spaces=6, num_stars=14)
    num_color_key_cols: ClassVar[int] = 6
    other_files_preview_chars: ClassVar[int] = 900
    other_files_table_indent: ClassVar[int] = 2
    section_header_padding: ClassVar[PaddingDimensions] = (2, 25, 1, 25)
    show_emailer_tables: ClassVar[bool] = True
    show_with_indent: ClassVar[int] = 30
    site_glossary_horizontal_padding: ClassVar[int] = 5
    social_link_separator: ClassVar[str] = '  /  '
    subtitle_width: ClassVar[int | None] = 110
    suppressed_file_indent: ClassVar[int] = 0
    width: ClassVar[int] = DEFAULT_WIDTH

    @classmethod
    def format_text_msg_time(cls, dt: datetime) -> str:
        return iso_timestamp(dt)

    @classmethod
    def email_subheader(cls, email_type: str, author: Text, recipients: Text, timestamp: datetime) -> Text:
        return super().email_subheader(
            f"OCR text of {email_type}",
            author,
            recipients,
            Text(f" probably sent at ").append(str(timestamp), style=TIMESTAMP_STYLE)
        )
