import os

import gi

import stillCenter.constants as constants
from stillCenter.i18n import _

gi.require_version("Gtk", "4.0")
gi.require_version("Adw", "1")
from gi.repository import Gtk, Adw


@Gtk.Template(filename=os.path.join(constants.UI_DIR, "LoadingPage.ui"))
class LoadingPage(Adw.NavigationPage):
    __gtype_name__ = "LoadingPage"
    stillCenter = None
    spinner: Adw.Spinner = Gtk.Template.Child()
    status_title: Gtk.Label = Gtk.Template.Child()
    status_description: Gtk.Label = Gtk.Template.Child()

    def __init__(self, stillCenter):
        super().__init__()
        self.stillCenter = stillCenter
        self.set_status(_("Loading stillCenter..."), _("Preparing the app window."))

    def push(self):
        self.stillCenter.main_view.push(self)

    def pop(self):
        self.stillCenter.main_view.pop()

    def set_status(self, title: str, description: str = ""):
        self.status_title.set_label(title)
        self.status_description.set_label(description)
        self.status_description.set_visible(bool(description))
