🏡 index : quine-global-labs/bazaar.git

using Gtk 4.0;
using Adw 1;

template $BzLibraryPage: Adw.Bin {
  child: Box {
    orientation: vertical;

    Adw.Clamp search_box_clamp {
      margin-start: 12;
      margin-end: 12;
      margin-top: 10;
      margin-bottom: 10;
      maximum-size: 375;
      visible: bind template.has-apps;

      child: $BzSearchBar search_bar {
        placeholder: _("Search installed apps");
        search-activated => $search_text_activate(template);
        search-changed => $search_text_changed(template);
      };
    }

    Adw.ViewStack stack {
      enable-transitions: true;
      transition-duration: 400;

      Adw.ViewStackPage {
        name: "empty";

        child: Adw.StatusPage {
          icon-name: "library-symbolic";
          title: _("No Apps Found");
          description: "";
        };
      }

      Adw.ViewStackPage {
        name: "no-results";

        child: Adw.StatusPage {
          icon-name: "library-symbolic";
          description: bind $no_results_found_subtitle(search_bar.text) as <string>;

          child: Button {
            styles [
              "pill",
            ]
            halign: center;
            label: _("Search Store Instead");

            clicked => $global_search_cb(template);
          };
        };
      }

      Adw.ViewStackPage {
        name: "content";

        child: ScrolledWindow scroll{
          hscrollbar-policy: never;

          child: Adw.Clamp {
            vexpand: true;
            maximum-size: 650;

            child: Box margin_box {
              orientation: vertical;
              margin-start: 9;
              margin-end: 9;
              margin-bottom: 30;

              Box non_search_content {
                orientation: vertical;
                visible: bind $is_empty_string(search_bar.text) as <bool>;

                Revealer {
                  reveal-child: bind $invert_boolean($is_empty(template.state as <$BzStateInfo>.available-updates) as <bool>) as <bool>;
                  transition-type: slide_down;

                  child: Box {
                    orientation: vertical;
                    spacing: 8;
                    margin-top: 15;

                    Label {
                      label: _("Pending Updates");
                      xalign: 0;
                      margin-start: 12;
                      margin-top: 15;

                      styles [
                        "heading",
                        "h4",
                      ]
                    }

                    $BzUpdatesCard {
                      state: bind template.state;
                      update => $updates_card_update_cb(template);
                    }
                  };
                }

                Revealer {
                  reveal-child: bind $invert_boolean($is_zero(template.state as <$BzStateInfo>.transaction-manager as <$BzTransactionManager>.install-trackers as <FilterListModel>.n-items) as <bool>) as <bool>;
                  transition-type: slide_down;

                  child: Box {
                    margin-top: 15;
                    orientation: vertical;

                    Label install_label {
                      label: _("Downloads");
                      xalign: 0;
                      margin-start: 12;

                      styles [
                        "heading",
                        "h4",
                      ]
                    }

                    ListView install_list_view {
                      styles [
                        "navigation-sidebar",
                        "installed-list-view",
                      ]

                      model: NoSelection {
                        model: bind template.state as <$BzStateInfo>.transaction-manager as <$BzTransactionManager>.install-trackers;
                      };

                      factory: BuilderListItemFactory {
                        template ListItem {
                          activatable: false;

                          child: $BzTransactionTile {
                            tracker: bind template.item;
                            activated => $tile_activated_cb();
                          };
                        }
                      };
                    }
                  };
                }

                Revealer {
                  reveal-child: bind $invert_boolean($is_zero(template.state as <$BzStateInfo>.transaction-manager as <$BzTransactionManager>.removal-trackers as <FilterListModel>.n-items) as <bool>) as <bool>;
                  transition-type: slide_down;

                  child: Box {
                    margin-top: 15;
                    orientation: vertical;

                    Label removal_label {
                      label: _("Recently Uninstalled");
                      xalign: 0;
                      margin-start: 12;

                      styles [
                        "heading",
                        "h4",
                      ]
                    }

                    ListView removal_list_view {
                      styles [
                        "navigation-sidebar",
                        "installed-list-view",
                      ]

                      model: NoSelection {
                        model: bind template.state as <$BzStateInfo>.transaction-manager as <$BzTransactionManager>.removal-trackers;
                      };

                      factory: BuilderListItemFactory {
                        template ListItem {
                          activatable: false;

                          child: $BzTransactionTile {
                            tracker: bind template.item;
                            activated => $tile_activated_cb();
                          };
                        }
                      };
                    }
                  };
                }

                Revealer {
                  reveal-child: bind template.state as <$BzStateInfo>.transaction-manager as <$BzTransactionManager>.has-transactions;
                  margin-bottom: 15;
                  transition-type: slide_down;

                  child: ListBox {
                    margin-bottom: 16;
                    margin-top: 4;
                    margin-start: 4;
                    margin-end: 4;
                    selection-mode: none;

                    styles [
                      "boxed-list",
                    ]

                    Adw.ButtonRow {
                      title: _("Clear Finished Tasks");
                      activated => $clear_tasks_cb(template);

                      styles [
                        "error",
                      ]
                    }
                  };
                }
                Box {
                  margin-start: 12;
                  margin-end: 4;
                  Label {
                    label: bind $format_install_count(filter_model.n-items) as <string>;
                    xalign: 0;
                    visible: bind template.has-apps;
                    hexpand: true;
                    margin-top: 4;

                    styles [
                      "heading",
                      "h4",
                    ]
                  }
                  MenuButton {
                    icon-name: "sliders-horizontal-symbolic";
                    popover: sort_popover;
                    tooltip-text: _("Sort Options");
                    styles ["flat"]
                  }
                }
              }

              ListView list_view {
                styles [
                  "navigation-sidebar",
                  "installed-list-view",
                  "installed-section"
                ]

                visible: bind template.has-apps;

                model: NoSelection {
                  model: FilterListModel filter_model {
                    filter: CustomFilter filter {};

                    model: SortListModel sort_model {
                      sorter: CustomSorter sorter {};
                      model: bind template.model;
                    };

                    notify::n-items => $n_filtered_items_changed(template);
                  };
                };

                factory: BuilderListItemFactory {
                  template ListItem {
                    activatable: false;
                    selectable: false;
                    focusable: false;

                    child: $BzInstalledTile {
                      group: bind template.item as <$BzEntryGroup>;
                      activated => $tile_activated_cb();
                    };
                  }
                };
              }
            };
          };
        };
      }
    }
  };
}

Popover sort_popover {
  child: Box {
    orientation: vertical;
    spacing: 6;
    margin-top: 8;
    margin-bottom: 8;
    margin-start: 8;
    margin-end: 16;

    Label {
      label: _("Sort By");
      wrap: true;
      wrap-mode: word_char;
      xalign: 0;
      margin-start: 28;

      styles [
        "heading",
        "h4",
        "dimmed"
      ]
    }

    CheckButton sort_name {
      label: _("Name");
      active: true;
      toggled => $sort_changed_cb(template);
    }

    CheckButton sort_size {
      label: _("Size");
      group: sort_name;
      toggled => $sort_changed_cb(template);
    }
  };
}