import os
import sys
import tkinter as tk

# Cuando se ejecuta como .exe (PyInstaller onefile), __file__ apunta a la
# carpeta temporal de extracción. sys.executable apunta al .exe real.
if getattr(sys, 'frozen', False):
    BASE_DIR = os.path.dirname(sys.executable)
else:
    BASE_DIR = os.path.dirname(os.path.abspath(__file__))

if BASE_DIR not in sys.path:
    sys.path.insert(0, BASE_DIR)

from core.config import ConfigManager
from ui.app import PocketSyncApp

CONFIG_FILE = os.path.join(BASE_DIR, "config.json")


def main() -> None:
    cm = ConfigManager(CONFIG_FILE)
    cm.load()

    root = tk.Tk()
    ico = os.path.join(BASE_DIR, "assets", "pocketsync.ico")
    if os.path.isfile(ico):
        root.iconbitmap(ico)
    PocketSyncApp(root, cm)
    root.mainloop()


if __name__ == "__main__":
    main()
