import dearpygui.dearpygui as dpg
from src.ui.main_window import create_main_window
from src.core.database.database import Database
from src.utils.logger import get_logger

logger = get_logger("main")

def main():
    db = Database()
    dpg.create_context()
    dpg.configure_app(init_file="dpg.ini")
    
    # Увеличен размер шрифта с 16 до 24
    
    big_let_start = 0x00C0  # Capital "A" in cyrillic alphabet
    big_let_end = 0x00DF  # Capital "Я" in cyrillic alphabet
    small_let_end = 0x00FF  # small "я" in cyrillic alphabet
    remap_big_let = 0x0410  # Starting number for remapped cyrillic alphabet
    alph_len = big_let_end - big_let_start + 1  # adds the shift from big letters to small
    alph_shift = remap_big_let - big_let_start  # adds the shift from remapped to non-remapped
    with dpg.font_registry():
        with dpg.font("fonts/Exo2.ttf", 24) as default_font:
            dpg.add_font_range_hint(dpg.mvFontRangeHint_Default)
            dpg.add_font_range_hint(dpg.mvFontRangeHint_Cyrillic)
            biglet = remap_big_let  # Starting number for remapped cyrillic alphabet
            for i1 in range(big_let_start, big_let_end + 1):  # Cycle through big letters in cyrillic alphabet
                dpg.add_char_remap(i1, biglet)  # Remap the big cyrillic letter
                dpg.add_char_remap(i1 + alph_len, biglet + alph_len)  # Remap the small cyrillic letter
                biglet += 1  # choose next letter
            dpg.bind_font(default_font)
    
    create_main_window(db)
    dpg.bind_font(default_font)
    
    # Увеличены минимальные размеры окна
    dpg.create_viewport(
        title="Security Scanner", 
        min_width=1600,
        min_height=900,
    )
    dpg.setup_dearpygui()
    dpg.show_viewport()
    
    # Растягиваем главное окно на весь viewport
    dpg.set_primary_window("main_window", True)
    
    dpg.start_dearpygui()
    dpg.destroy_context()
    logger.info("Application closed")

if __name__ == "__main__":
    main()