using Gtk 4.0;
using Adw 1;

Adw.StatusPage notice_no_results {
  icon-name: "system-search-symbolic";
  title: _("No Games Found");
  description: _("Try a different search.");
  vexpand: true;
  valign: center;
}

Adw.StatusPage hidden_notice_no_results {
  icon-name: "system-search-symbolic";
  title: _("No Games Found");
  description: _("Try a different search.");
  vexpand: true;
  valign: center;
}

Adw.StatusPage notice_empty {
  title: _("No Games");
  description: _("Use the + button to add games.");
  vexpand: true;
  valign: center;

  Button {
    label: _("Import");
    halign: center;
    action-name: "app.import";

    styles [
      "pill",
      "suggested-action",
    ]
  }
}

Adw.StatusPage hidden_notice_empty {
  icon-name: "view-conceal-symbolic";
  title: _("No Hidden Games");
  description: _("Games you hide will appear here.");
  vexpand: true;
  valign: center;
}

template $CartridgesWindow : Adw.ApplicationWindow {
  title: _("Cartridges");

  Adw.ToastOverlay toast_overlay {
    Stack stack {
      visible-child: library_view;
      transition-type: over_left;

      Overlay details_view {
        name: "details_view";

        [overlay]
        Box details_view_box {
          orientation: vertical;

          Adw.HeaderBar {
            [start]
            Button back_button {
              tooltip-text: _("Back");
              action-name: "win.go_back";
              icon-name: "go-previous-symbolic";
            }

            [title]
            Adw.WindowTitle details_view_header_bar_title {
              title: _("Game Details");
            }

            styles [
              "flat",
            ]
          }

          Adw.Bin {
            hexpand: true;
            vexpand: true;

            Box {
              halign: center;
              valign: center;
              margin-start: 24;
              margin-end: 24;
              margin-top: 24;
              margin-bottom: 24;

              Adw.Clamp {
                maximum-size: 200;

                Overlay {
                  [overlay]
                  Spinner details_view_spinner {
                    margin-start: 72;
                    margin-end: 72;
                  }

                  Picture details_view_cover {
                    halign: end;
                    valign: start;
                    width-request: 200;
                    height-request: 300;

                    styles [
                      "card",
                    ]
                  }
                }
              }

              Box {
                orientation: vertical;
                margin-start: 48;
                vexpand: true;
                valign: center;

                Label details_view_title {
                  label: _("Game Title");
                  hexpand: true;
                  halign: start;
                  max-width-chars: 24;
                  wrap: true;
                  wrap-mode: word_char;
                  natural-wrap-mode: word;

                  styles [
                    "title-1",
                  ]
                }

                Label details_view_developer {
                  margin-top: 6;
                  hexpand: true;
                  halign: start;
                  max-width-chars: 36;
                  wrap: true;
                  wrap-mode: word_char;
                  natural-wrap-mode: word;

                  styles [
                    "heading",
                  ]
                }

                Box {
                  orientation: horizontal;
                  margin-top: 16;
                  hexpand: true;
                  halign: start;

                  Label details_view_added {
                    wrap: true;
                    wrap-mode: word_char;
                    natural-wrap-mode: word;
                  }

                  Label details_view_last_played {
                    margin-start: 12;
                    wrap: true;
                    wrap-mode: word_char;
                    natural-wrap-mode: word;
                  }
                }

                Box {
                  hexpand: true;
                  vexpand: true;
                  valign: center;

                  Button details_view_play_button {
                    name: "details_view_play_button";
                    action-name: "app.launch_game";
                    label: _("Play");
                    halign: start;
                    margin-top: 24;

                    styles [
                      "opaque",
                      "pill",
                    ]
                  }

                  Box {
                    halign: start;
                    valign: center;
                    margin-top: 24;
                    margin-start: 9;

                    Button {
                      icon-name: "document-edit-symbolic";
                      action-name: "app.edit_game";
                      tooltip-text: _("Edit");

                      styles ["raised", "circular"]
                    }

                    Button details_view_hide_button {
                      action-name: "app.hide_game";

                      styles ["raised", "circular"]
                    }

                    Button {
                      icon-name: "user-trash-symbolic";
                      action-name: "app.remove_game";
                      tooltip-text: _("Remove");

                      styles ["raised", "circular"]
                    }

                    MenuButton {
                      icon-name: "system-search-symbolic";
                      menu-model: search;
                      tooltip-text: _("Search");

                      styles ["raised", "circular"]
                    }

                    styles [
                      "toolbar",
                    ]
                  }
                }
              }
            }
          }
        }

        Picture details_view_blurred_cover {
          keep-aspect-ratio: false;
        }
      }

      Box library_view {
        orientation: vertical;

        Adw.HeaderBar header_bar {
          [start]
          MenuButton {
            tooltip-text: _("Add Game");
            icon-name: "list-add-symbolic";
            menu-model: add_games;
          }

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

          [end]
          ToggleButton search_button {
            tooltip-text: _("Search");
            icon-name: "system-search-symbolic";
            action-name: "win.toggle_search";
          }
        }

        SearchBar search_bar {
          search-mode-enabled: bind-property search_button.active bidirectional;
          key-capture-widget: library_view;

          Adw.Clamp {
            maximum-size: 500;
            tightening-threshold: 500;

            SearchEntry search_entry {
              hexpand: true;
            }
          }
        }

        Adw.Bin library_bin {
          ScrolledWindow scrolledwindow {
            hexpand: true;
            vexpand: true;

            FlowBox library {
              homogeneous: true;
              halign: center;
              valign: start;
              column-spacing: 12;
              row-spacing: 12;
              margin-top: 16;
              margin-bottom: 16;
              margin-start: 16;
              margin-end: 16;
              selection-mode: none;
            }
          }
        }
      }

      Box hidden_library_view {
        orientation: vertical;

        Adw.HeaderBar hidden_header_bar {
          [start]
          Button hidden_back_button {
            tooltip-text: _("Back");
            action-name: "win.go_back";
            icon-name: "go-previous-symbolic";
          }

          [title]
          Adw.WindowTitle {
            title: _("Hidden Games");
          }

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

          [end]
          ToggleButton hidden_search_button {
            tooltip-text: _("Search");
            icon-name: "system-search-symbolic";
            action-name: "win.toggle_search";
          }
        }

        SearchBar hidden_search_bar {
          search-mode-enabled: bind-property hidden_search_button.active bidirectional;
          key-capture-widget: hidden_library_view;

          Adw.Clamp {
            maximum-size: 500;
            tightening-threshold: 500;

            SearchEntry hidden_search_entry {
              hexpand: true;
            }
          }
        }

        Adw.Bin hidden_library_bin {
          ScrolledWindow hidden_scrolledwindow {
            hexpand: true;
            vexpand: true;

            FlowBox hidden_library {
              homogeneous: true;
              halign: center;
              valign: start;
              column-spacing: 12;
              row-spacing: 12;
              margin-top: 16;
              margin-bottom: 16;
              margin-start: 16;
              margin-end: 16;
              selection-mode: none;
            }
          }
        }

        styles [
          "background",
        ]
      }
    }
  }
}

menu primary_menu {
  section {
    submenu {
      label: _("Sort");

      item {
        label: _("A-Z");
        action: "win.sort_by";
        target: "a-z";
      }

      item {
        label: _("Z-A");
        action: "win.sort_by";
        target: "z-a";
      }

      item {
        label: _("Newest");
        action: "win.sort_by";
        target: "newest";
      }

      item {
        label: _("Oldest");
        action: "win.sort_by";
        target: "oldest";
      }

      item {
        label: _("Last Played");
        action: "win.sort_by";
        target: "last_played";
      }
    }

    item {
      label: _("Show Hidden");
      action: "win.show_hidden";
      hidden-when: "action-disabled";
    }
  }

  section {
    item {
      label: _("Preferences");
      action: "app.preferences";
    }

    item {
      label: _("Keyboard Shortcuts");
      action: "win.show-help-overlay";
    }

    item {
      label: _("About Cartridges");
      action: "app.about";
    }
  }
}

menu add_games {
  section {
    item {
      label: _("Add Game");
      action: "app.add_game";
    }
  }

  section {
    item {
      label: _("Import");
      action: "app.import";
    }
  }
}

menu search {
  section {
    label: "Search on…";

    item {
      label: "IGDB";
      action: "app.igdb_search";
    }

    item {
      label: "SteamGridDB";
      action: "app.sgdb_search";
    }

    item {
      label: "ProtonDB";
      action: "app.protondb_search";
    }

    item {
      label: "Lutris";
      action: "app.lutris_search";
    }

    item {
      label: "HowLongToBeat";
      action: "app.hltb_search";
    }
  }
}
