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

using Gtk 4.0;
using Adw 1;

template $BzSearchPage: Adw.Bin {
  child: Adw.BreakpointBin {
    width-request: 360;
    height-request: 100;

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

      setters {
        grid_view.min-columns: 2;
        grid_view.max-columns: 2;
        clamp_scrollable.maximum-size: 700;
      }
    }

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

      setters {
        empty_box.margin-start: 10;
        empty_box.margin-end: 10;
        empty_box.margin-top: 5;
        search_box_clamp.margin-start: 12;
        search_box_clamp.margin-end: 12;
        grid_view.min-columns: 1;
        grid_view.max-columns: 1;
        clamp_scrollable.maximum-size: 400;
      }
    }

    child: Box {
      orientation: vertical;

      Adw.Clamp search_box_clamp {
        margin-start: 12;
        margin-end: 12;
        margin-top: 10;
        margin-bottom: 10;
        maximum-size: 375;

        child: $BzSearchBar search_bar {
          placeholder: _("Search Apps, Games, Software");
          search-activated => $search_activate(template);
          search-changed => $search_changed(template);

          end-widget: MenuButton filter_button {
            visible: bind $is_valid_string(search_bar.text) as <bool>;
            icon-name: "sliders-horizontal-symbolic";
            tooltip-text: _("Search Filters");
            valign: center;

            popover: $BzSearchFilterPopover filter_popover {
              notify::has-active-filters => $has_active_filters_cb();
            };

            styles [
              "flat",
              "circular",
              "searchbar-button",
            ]

            accessibility {
              label: _("Filters");
            }
          };
        };
      }

      Adw.Clamp {
        margin-start: 12;
        margin-end: 12;
        maximum-size: 375;

        child: Box {
          margin-start: 12;
          margin-end: 12;
          margin-top: 6;
          margin-bottom: 6;

          styles [
            "bz-debug",
          ]

          orientation: vertical;
          spacing: 5;
          visible: bind template.state as <$BzStateInfo>.debug_mode;

          Box {
            orientation: horizontal;
            spacing: 10;

            Label {
              label: "Interpreted Query:";
            }
            Label {
              styles [
                "caption-heading",
              ]
              label: bind template.current-query as <$BzFinishedSearchQuery>.interpreted-query;
            }
          }

          Box {
            orientation: horizontal;
            spacing: 10;

            Label {
              label: "# of Results:";
            }
            Label {
              styles [
                "caption-heading",
              ]
              label: bind $format_uint(template.current-query as <$BzFinishedSearchQuery>.n-results as <uint>) as <string>;
            }
          }

          Box {
            orientation: horizontal;
            spacing: 10;

            Label {
              label: "Seconds Elapsed:";
            }
            Label {
              styles [
                "caption-heading",
              ]
              label: bind $format_double(template.current-query as <$BzFinishedSearchQuery>.elapsed as <double>) as <string>;
            }
          }
        };
      }

      Stack search_stack {
        transition-type: crossfade;
        transition-duration: 150;

        StackPage {
          name: "empty";

          child: Box {
            orientation: vertical;
            vexpand: true;

            ScrolledWindow {
              hscrollbar-policy: never;
              vexpand: true;
              visible: bind $invert_boolean($is_empty(template.state as <$BzStateInfo>.flathub as <$BzFlathubState>.categories) as <bool>) as <bool>;

              child: Adw.Clamp {
                maximum-size: 1000;
                tightening-threshold: 900;

                child: Box empty_box {
                  margin-start: 30;
                  margin-end: 30;
                  margin-top: 16;
                  margin-bottom: 50;
                  orientation: vertical;

                  $BzSearchPillList {
                    margin-bottom: 25;
                    activated => $pill_list_cb(template);
                  }

                  Label {
                    label: _("Browse Categories");
                    halign: start;
                    margin-bottom: 12;
                    margin-start: 4;
                    wrap: true;
                    wrap-mode: word_char;

                    styles [
                      "heading",
                    ]
                  }

                  $BzDynamicListView {
                    styles [
                      "flathub-page-section",
                    ]

                    hexpand: true;
                    max-children-per-line: 4;
                    scroll: false;
                    noscroll-kind: flow-box;
                    child-type: "BzCategoryTile";
                    child-prop: "category";
                    model: FilterListModel visible_categories {
                      filter: CustomFilter categories_filter {};
                      model: bind template.state as <$BzStateInfo>.flathub as <$BzFlathubState>.categories;
                    };
                    bind-widget => $bind_category_tile_cb(template);
                    unbind-widget => $unbind_category_tile_cb(template);
                  }

                  Adw.StatusPage {
                    visible: bind $is_empty(template.state as <$BzStateInfo>.flathub as <$BzFlathubState>.categories) as <bool>;
                    hexpand: true;
                    vexpand: true;
                    icon-name: "system-search-symbolic";
                    title: _("Categories Unavailable");
                    description: _("Search for apps using the search bar above.");
                  }
                };
              };
            }
          };
        }

        StackPage {
          name: "results";

          child: Box content_box {
            orientation: horizontal;
            visible: bind $invert_boolean($is_null(grid_view.model as <SingleSelection>.selected-item) as <bool>) as <bool>;

            ScrolledWindow entry_grid_scroll {
              hexpand: true;
              vexpand: true;
              hscrollbar-policy: never;

              child: Adw.ClampScrollable clamp_scrollable {
                maximum-size: 1000;
                tightening-threshold: 900;

                child: GridView grid_view {
                  styles [
                    "search-grid",
                  ]

                  min-columns: 3;
                  max-columns: 3;

                  factory: BuilderListItemFactory {
                    template ListItem {

                      child: Box {
                        orientation: vertical;
                        spacing: 5;

                        $BzRichAppTile {
                          group: bind template.item as <$BzSearchResult>.group as <$BzEntryGroup>;
                          focusable: false;
                        }

                        Box {
                          styles [
                            "bz-debug",
                          ]

                          visible: bind template.item as <$BzSearchResult>.state as <$BzStateInfo>.debug_mode;
                          orientation: vertical;
                          spacing: 2;

                          Box {
                            orientation: horizontal;
                            spacing: 10;

                            Label {
                              label: "Result Score:";
                            }
                            Label {
                              styles [
                                "caption-heading",
                              ]
                              label: bind $format_double(template.item as <$BzSearchResult>.score as <double>) as <string>;
                            }
                          }

                          Separator {
                            margin-bottom: 5;
                          }
                          Box {
                            orientation: horizontal;
                            spacing: 10;

                            Label {
                              styles [
                                "bz-monospace",
                              ]
                              hexpand: true;
                              xalign: 0.0;
                              label: bind template.item as <$BzSearchResult>.group as <$BzEntryGroup>.id;
                              selectable: true;
                              wrap: true;
                              wrap-mode: char;
                            }
                            Button {
                              icon-name: "edit-copy-symbolic";
                              clicked => $copy_id_cb(template);
                            }
                          }
                          Box {
                            orientation: horizontal;
                            spacing: 10;

                            Button {
                              hexpand: true;
                              halign: end;
                              label: "Inspect UI Entry";
                              clicked => $debug_id_inspect_cb(template);
                            }
                          }
                        }
                      };
                    }
                  };
                };
              };
            }
          };
        }

        StackPage {
          name: "no-results";

          child: Adw.StatusPage {
            vexpand: true;
            icon-name: "edit-find-symbolic";
            title: _("No Applications Found");
            description: bind $no_results_found_subtitle(search_bar.text) as <string>;
          };
        }
      }
    };
  };
}