# -*- coding: utf-8 -*-
"""
MCS Dock: Mission Control System panel.
Contains all MCS controls, commands, and telemetry widgets.
"""
import tkinter as tk
from tkinter import ttk
from pymsc.gui.docking import DockFrame
from pymsc.gui.pages.control_page import ControlPage
from pymsc.gui.pages.mission_page import MissionPage


class MCSDock(DockFrame):
    """
    MCS (Mission Control System) dockable panel.
    Contains tabs for different MCS functions:
    - Control: Radar modes, functions, parameters
    - Mission: Navigation data, cursor, attitude
    """
    
    def __init__(self, parent: tk.Widget, bus_module, **kwargs):
        """
        Args:
            parent: Parent widget
            bus_module: Bus1553Module instance for message access
            **kwargs: Additional DockFrame options
        """
        self.bus_module = bus_module
        
        super().__init__(
            parent, 
            title="MCS - Mission Control System",
            closable=False,  # MCS is always visible
            **kwargs
        )
    
    def populate_content(self):
        """Create the MCS tab structure and pages."""
        # Create notebook for MCS tabs
        self.notebook = ttk.Notebook(self.content_frame)
        self.notebook.pack(fill=tk.BOTH, expand=True)
        
        # Dictionary to store page instances
        self.pages = {}
        
        # Create Control page
        control_frame = ttk.Frame(self.notebook)
        self.notebook.add(control_frame, text="Control")
        self.pages['control'] = ControlPage(control_frame, self.bus_module)
        self.pages['control'].pack(fill=tk.BOTH, expand=True)
        
        # Create Mission page
        mission_frame = ttk.Frame(self.notebook)
        self.notebook.add(mission_frame, text="Mission")
        self.pages['mission'] = MissionPage(mission_frame, self.bus_module)
        self.pages['mission'].pack(fill=tk.BOTH, expand=True)
    
    def start_refresh(self):
        """Start the refresh loop for all pages."""
        for page in self.pages.values():
            if hasattr(page, 'start_refresh'):
                page.start_refresh()
    
    def stop_refresh(self):
        """Stop the refresh loop for all pages."""
        for page in self.pages.values():
            if hasattr(page, 'stop_refresh'):
                page.stop_refresh()
