🏡 index : quine-global/bazaar.git

using Gtk 4.0;
using Adw 1;

template $BzInstallControls: Widget {
  hexpand: bind template.wide inverted;

  EventControllerFocus {
    enter => $on_focus_enter();
    leave => $on_focus_leave();
  }

  Stack stack {
    visible: bind $is_not_empty_page(stack.visible-child-name) as <bool>;
    visible-child-name: bind $get_visible_page(
      template.entry-group as <$BzEntryGroup>.installable,
      template.entry-group as <$BzEntryGroup>.removable,
      template.state as <$BzStateInfo>.available-updates,
      template.in-progress
      ) as <string>;
    transition-type: crossfade;
    hexpand: bind template.wide inverted;
    valign: center;

    StackPage {
      name: "install";

      child: Button install_button {
        styles [
          "pill",
          "suggested-action",
        ]

        hexpand: bind template.wide inverted;
        halign: bind $page_halign(template.wide) as <Align>;
        margin-start: 4;
        margin-end: 4;
        margin-top: 7;
        margin-bottom: 7;
        clicked => $on_install_clicked();

        child: Stack install_label_stack {
          transition-type: crossfade;
          transition-duration: 200;

          StackPage {
            name: "install";

            child: Label {
              label: C_("Install Controls", "Install");
            };
          }

          StackPage {
            name: "cancel";

            child: Label {
              label: C_("Install Controls", "Cancel");
            };
          }

          StackPage {
            name: "cancelling";

            child: Label {
              label: C_("Install Controls", "Cancelling");
            };
          }
        };
      };
    }

    StackPage {
      name: "open";

      child: Box {
        spacing: bind $choose(template.wide, 10, 8) as <int>;
        homogeneous: bind template.wide inverted;
        halign: bind $page_halign(template.wide) as <Align>;
        valign: center;
        margin-top: 3;
        margin-bottom: 3;

        Button {
          styles [
            "pill",
          ]

          visible: bind $is_not_blocked(
            template.state as <$BzStateInfo>.parental-blocked-ids,
            template.entry-group
            ) as <bool>;
          sensitive: bind template.entry-group as <$BzEntryGroup>.removable-and-available;
          hexpand: bind template.wide inverted;
          label: _("_Open");
          use-underline: true;
          clicked => $on_open_clicked();
        }

        Button {
          styles [
            "destructive-action",
            "circular",
          ]

          width-request: bind $choose(template.wide, 45, -1) as <int>;
          hexpand: bind template.wide inverted;
          tooltip-text: _("Uninstall Application");
          sensitive: bind template.entry-group as <$BzEntryGroup>.removable-and-available;
          clicked => $on_remove_clicked();

          child: Box {
            halign: center;
            hexpand: true;

            Label {
              visible: bind template.wide inverted;
              label: _("_Remove");
              use-underline: true;
            }

            Image {
              visible: bind template.wide;
              icon-name: "user-trash-symbolic";
            }
          };
        }
      };
    }

    StackPage {
      name: "update";

      child: Box {
        spacing: bind $choose(template.wide, 10, 8) as <int>;
        homogeneous: bind template.wide inverted;
        halign: bind $page_halign(template.wide) as <Align>;
        valign: center;
        margin-top: 3;
        margin-bottom: 3;

        Button {
          styles [
            "pill",
            "suggested-action",
          ]

          hexpand: bind template.wide inverted;
          label: _("Update");
          clicked => $on_update_clicked();
        }

        Button {
          styles [
            "destructive-action",
            "circular",
          ]

          width-request: bind $choose(template.wide, 45, -1) as <int>;
          hexpand: bind template.wide inverted;
          tooltip-text: _("Uninstall Application");
          sensitive: bind template.entry-group as <$BzEntryGroup>.removable-and-available;
          clicked => $on_remove_clicked();

          child: Box {
            halign: center;
            hexpand: true;

            Label {
              visible: bind template.wide inverted;
              label: _("Remove");
            }

            Image {
              visible: bind template.wide;
              icon-name: "user-trash-symbolic";
            }
          };
        }
      };
    }

    StackPage {
      name: "empty";

      child: Adw.Bin {};
    }
  }

  Adw.Bin pending_ring {
    styles [
      "install-button-indicator",
    ]

    can-target: false;
    opacity: 0;
  }

  Adw.Bin progress_ring {
    styles [
      "install-button-indicator",
    ]

    can-target: false;
    opacity: 0;
  }
}