"""
Size Manager:
    used to check size boundaries of the whole window and
    specific tabs
"""

from poezio.windows import base_wins
from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from poezio.core.core import Core

THRESHOLD_WIDTH_DEGRADE = 45
THRESHOLD_HEIGHT_DEGRADE = 10

FULL_WIDTH_DEGRADE = 66
FULL_HEIGHT_DEGRADE = 10


class SizeManager:
    """Class handling  the size reduction of the poezio UI."""

    def __init__(self, core: 'Core') -> None:
        self._core = core

    @property
    def tab_degrade_x(self) -> bool:
        """Returns True if we need to reduce the horizontal size used by the tab."""
        if base_wins.TAB_WIN is None:
            raise ValueError()
        _, x = base_wins.TAB_WIN.getmaxyx()
        return x < THRESHOLD_WIDTH_DEGRADE

    @property
    def tab_degrade_y(self) -> bool:
        """Returns True if we need to reduce the vertical size used by the tab."""
        if base_wins.TAB_WIN is None:
            raise ValueError()
        y, x = base_wins.TAB_WIN.getmaxyx()
        return y < THRESHOLD_HEIGHT_DEGRADE

    @property
    def core_degrade_x(self) -> bool:
        """Returns True if we need to reduce the horizontal size used by poezio."""
        if self._core.stdscr is None:
            return False
        _, x = self._core.stdscr.getmaxyx()
        return x < FULL_WIDTH_DEGRADE

    @property
    def core_degrade_y(self) -> bool:
        """Returns True if we need to reduce the vertical size used by the poezio."""
        if self._core.stdscr is None:
            return False
        y, _ = self._core.stdscr.getmaxyx()
        return y < FULL_HEIGHT_DEGRADE
