import sys
import base64
import json
from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout, QLabel, QLineEdit, QPushButton, QMessageBox, QSizePolicy
from PyQt5.QtGui import QFont, QIcon
from PyQt5.QtCore import Qt
from qt_material import apply_stylesheet
import arabic_reshaper
from bidi.algorithm import get_display
import ctypes
import requests
from MainDashbord import MainDashboard
from MainActivation import MainActivation
from MainDashbord import LoadingScreen
from PyQt5.QtCore import  QTimer
import os

def changeWindow(window):
    main_window = MainDashboard()
    main_window.start_loading(window)

if __name__ == "__main__":
    app = QApplication(sys.argv)

    # اعمال تم متریال دیزاین
    apply_stylesheet(app, theme='dark_blue.xml')
    if os.path.exists("login.json") and os.path.getsize("login.json") > 0:
        with open("login.json", "r", encoding='utf-8') as file:
            content = file.read()
            if content:
                data = json.loads(content)
            else:
                data = {}
    else:
        data = {}


    login_status = data.get("login")
    if login_status == "True":
        window = LoadingScreen()
        window.show()

        # استفاده از lambda برای پاس دادن متد به QTimer.singleShot
        QTimer.singleShot(2000, lambda: changeWindow(window))  # Close after 2 seconds


    else:
        window = MainActivation()
        window.show()



    sys.exit(app.exec_())
