using Gtk 4.0;
using Adw 1;

template $ExmWindow: Adw.ApplicationWindow {
  width-request: 360;
  height-request: 294;
  title: _("Extension Manager");

  Adw.Breakpoint {
    condition ("max-width: 400sp")

    setters {
      header_bar.title-widget: null;
      switcher_bar.reveal: true;
    }
  }

  Adw.ToastOverlay toast_overlay {
    child: Adw.NavigationView navigation_view {
      Adw.NavigationPage main_view {
        can-pop: false;
        title: bind template.title;
        tag: "main";

        Adw.ToolbarView {
          [top]
          Adw.HeaderBar header_bar {
            show-back-button: false;

            title-widget: Adw.ViewSwitcher title {
              policy: wide;
              stack: view_stack;
            };

            [start]
            Gtk.ToggleButton search_button {
              icon-name: "edit-find-symbolic";
              tooltip-text: _("Search Installed Extensions");
              receives-default: true;
            }

            [end]
            Gtk.MenuButton {
              icon-name: "open-menu-symbolic";
              menu-model: primary_menu;
              primary: true;
              tooltip-text: _("Main Menu");
            }
          }

          [top]
          Gtk.SearchBar search_bar {
            key-capture-widget: template;
            search-mode-enabled: bind search_button.active bidirectional;
            notify::search-mode-enabled => $on_visible_installed_stack_changed();

            child: Gtk.SearchEntry {
              placeholder-text: _("Search for installed extensions");
              max-width-chars: 35;
            };
          }

          content: Gtk.Box {
            orientation: vertical;

            Adw.ViewStack view_stack {
              vexpand: true;
              hexpand: true;
              notify::visible-child => $on_visible_page_changed();

              Adw.ViewStackPage installed_stack {
                name: "installed";
                title: C_("Navigation", "_Installed");
                icon-name: "puzzle-piece-symbolic";
                use-underline: true;

                child: $ExmInstalledPage installed_page {};
              }

              Adw.ViewStackPage {
                name: "browse";
                title: C_("Navigation", "_Browse");
                icon-name: "globe-symbolic";
                use-underline: true;

                child: $ExmBrowsePage browse_page {};
              }
            }

            Adw.ViewSwitcherBar switcher_bar {
              stack: view_stack;
            }
          };
        }
      }

      $ExmDetailView detail_view {}

      $ExmScreenshotView screenshot_view {
        title: bind detail_view.title;
      }
    };
  }
}

menu primary_menu {
  section {
    // Translators: the character preceded by "_" should not be the same
    // as others in the same menu
    item (_("Sort _Enabled First"), "app.sort-enabled-first")
    item (_("_Show Unsupported"), "app.show-unsupported")
  }

  section {
    item (_("_Upgrade Assistant"), "win.show-upgrade-assistant")
    item (_("_Keyboard Shortcuts"), "win.show-help-overlay")
    item (_("_About Extension Manager"), "app.about")
  }
}

Adw.AlertDialog remove_dialog {
  heading: _("Uninstall Extension?");
  body: _("The extension's features and functionality will no longer be accessible. Are you sure you want to uninstall?");
  default-response: "no";
  close-response: "no";

  responses [
    no: _("_No"),
    yes: _("_Yes") destructive
  ]
}

Adw.AlertDialog unsupported_dialog {
  heading: _("Unsupported Extension");
  body: _("This extension does not support your GNOME Shell version. It may cause errors if installed.");
  default-response: "back";
  close-response: "back";
  prefer-wide-layout: true;

  responses [
    install: _("_Install Anyway") destructive,
    back: _("_Go Back") suggested
  ]
}
