from PySide6.QtWidgets import QApplication, QMainWindow
from PySide6.QtGui import QIcon
from app.controllers.main_controller import MainController
from app.core.theme import theme_manager
import app.core.config as config
import sys
from app.core.database import init_db

class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setWindowTitle(config.APP_HEADER)
        self.setMinimumSize(400, 650)
        
        self.controller = MainController()
        self.setCentralWidget(self.controller)
        
        theme_manager.theme_changed.connect(self.apply_theme)
        self.apply_theme(theme_manager.get_theme())

    def apply_theme(self, theme):
        if theme == "dark":
            self.setStyleSheet("background-color: #2e2e2e;")
        else:
            self.setStyleSheet("background-color: #f0f0f0;")

def main():
    init_db()
    app = QApplication(sys.argv)
    app.setWindowIcon(QIcon("app/icons/logo3.png"))
    
    window = MainWindow()
    window.show()
    
    sys.exit(app.exec())

if __name__ == "__main__":
    main()
