import customtkinter as ctk

class SettingsFrame(ctk.CTkFrame):
    def __init__(self, parent, get_themes_callback, set_theme_callback, heading_font=None, text_font=None):
        super().__init__(parent)
        self.get_themes = get_themes_callback
        self.set_theme = set_theme_callback
        self.heading_font = heading_font if heading_font else ctk.CTkFont(size=18, weight="bold")
        self.text_font = text_font if text_font else ctk.CTkFont(size=12)

        self.grid_columnconfigure(0, weight=1)
        self.grid_rowconfigure(1, weight=1)

        # Title
        title_label = ctk.CTkLabel(self, text="Configuración", font=self.heading_font)
        title_label.grid(row=0, column=0, padx=20, pady=(20, 10), sticky="nw")

        # Theme Selection
        theme_frame = ctk.CTkFrame(self)
        theme_frame.grid(row=1, column=0, padx=20, pady=10, sticky="new")

        theme_label = ctk.CTkLabel(theme_frame, text="Tema de la Aplicación:", font=self.text_font)
        theme_label.pack(side="left", padx=10, pady=10)

        available_themes = self.get_themes()
        self.theme_menu = ctk.CTkOptionMenu(theme_frame, values=available_themes, command=self.on_theme_select, font=self.text_font)
        self.theme_menu.pack(side="left", padx=10, pady=10)

    def on_theme_select(self, theme_name):
        self.set_theme(theme_name)
        # You might need to add a way to inform the user that a restart is needed
        # or implement a more dynamic theme switching mechanism.
        print(f"Tema seleccionado: {theme_name}")

