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

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

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

RICH_LINK_MARKUP = link_markup('https://pypi.org/project/rich/', 'rich')
MOBILE_WARNING = f"This page was generated by {RICH_LINK_MARKUP}. It is not optimized for mobile."


# TODO: another thing that changes based on mobile is id_only for link texts
@dataclass
class MobileConfig:
    abbreviations_width: ClassVar[int | None] = None
    num_color_key_cols: ClassVar[int] = 6
    other_files_preview_chars: ClassVar[int] = 300
    show_emailer_tables: bool = False
    width: ClassVar[int] = 45

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

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


class SiteConfig(MobileConfig):
    abbreviations_width: ClassVar[int | None] = 62
    num_color_key_cols: ClassVar[int] = 6
    other_files_preview_chars: ClassVar[int] = 900
    show_emailer_tables: bool = True
    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)
        )
