# -*- coding: utf-8 -*-
"""Main tab views."""

from util.runtime import *
from util.utils import node_host_only, _server_id_sort_key
from models.config import Config, apply_terminal_launch_config
from controllers.workers import (
    CommandRunner,
    GroupedNodeStatusCheckWorker,
    NodeStatusCheckWorker,
    StopServerWorker,
)
from views.common import (
    NoWheelComboBox,
    NoWheelDateTimeEdit,
    NoWheelSpinBox,
    ServerIdTableItem,
    apply_button_style,
    make_line_icon,
    set_button_icon,
)
from views.console import OutputConsole
from views.dialogs import (
    ClearDatabaseDialog,
    KvConfigEditDialog,
    RemoteConnectDialog,
    ServerSelectDialog,
    ViewAccountsDialog,
)

from views.tabs.server_manage_actions import ServerManageActionsMixin
from views.tabs.server_manage_local import ServerManageLocalMixin
from views.tabs.server_manage_remote import ServerManageRemoteMixin
from views.tabs.server_manage_ui import ServerManageUiMixin


class ServerManageTab(
    ServerManageUiMixin,
    ServerManageLocalMixin,
    ServerManageRemoteMixin,
    ServerManageActionsMixin,
    QWidget,
):
    """Server management tab."""

    LOCAL_COLUMN_RATIOS = (0.24, 0.14, 0.11, 0.13, 0.38)

    def __init__(self, config: Config, console: OutputConsole):
        super().__init__()
        self.config = config
        self.console = console
        self._local_status_worker = None
        self._remote_status_worker = None
        self._scheduled_status_worker = None
        self._local_stop_worker = None
        self._pending_status_checks = {}
        self._status_check_timer = QTimer(self)
        self._status_check_timer.setSingleShot(True)
        self._status_check_timer.timeout.connect(self._flush_scheduled_status_checks)
        self.init_ui()
