"""
主窗口
"""
from PyQt5.QtWidgets import (
    QMainWindow, QWidget, QVBoxLayout, QTabWidget, QStatusBar
)
from PyQt5.QtCore import Qt
from frontend.utils.api_client import APIClient
from frontend.widgets.student_management import StudentManagementWidget
from frontend.widgets.rollcall import RollCallWidget
from frontend.widgets.score_management import ScoreManagementWidget
from frontend.widgets.visualization import VisualizationWidget

class MainWindow(QMainWindow):
    """主窗口类"""
    
    def __init__(self):
        super().__init__()
        self.api_client = APIClient()
        self.init_ui()
    
    def init_ui(self):
        """初始化界面"""
        self.setWindowTitle("课堂随机点名系统")
        self.setGeometry(100, 100, 1200, 800)
        
        # 创建中央部件
        central_widget = QWidget()
        self.setCentralWidget(central_widget)
        
        # 创建布局
        layout = QVBoxLayout()
        central_widget.setLayout(layout)
        
        # 创建标签页
        self.tabs = QTabWidget()
        
        # 点名页面
        self.rollcall_widget = RollCallWidget(self.api_client)
        self.tabs.addTab(self.rollcall_widget, "点名")
        
        # 学生管理页面
        self.student_widget = StudentManagementWidget(self.api_client)
        self.tabs.addTab(self.student_widget, "学生管理")
        
        # 积分管理页面
        self.score_widget = ScoreManagementWidget(self.api_client)
        self.tabs.addTab(self.score_widget, "积分管理")
        
        # 可视化页面
        self.visualization_widget = VisualizationWidget(self.api_client)
        self.tabs.addTab(self.visualization_widget, "数据可视化")
        
        layout.addWidget(self.tabs)
        
        # 状态栏
        self.statusBar().showMessage("就绪")
        
        # 设置样式
        self.setStyleSheet("""
            QMainWindow {
                background-color: #f5f5f5;
            }
            QTabWidget::pane {
                border: 1px solid #ddd;
                background-color: white;
            }
            QTabBar::tab {
                background-color: #e0e0e0;
                padding: 8px 20px;
                margin-right: 2px;
            }
            QTabBar::tab:selected {
                background-color: white;
                border-bottom: 2px solid #4CAF50;
            }
        """)

