using Gtk 4.0;
using Adw 1;

template $ExmExtensionRow: Adw.ExpanderRow {
  title-lines: 1;
  subtitle-lines: 1;

  [action]
  Gtk.Switch ext_toggle {
    valign: center;
    active: bind template.extension as <$ExmExtension>.enabled;
    sensitive: bind template.extension as <$ExmExtension>.can-change;
    state-set => $on_state_changed();
  }

  [action]
  Gtk.Button prefs_btn {
    styles [
      "flat"
    ]

    icon-name: "settings-symbolic";
    valign: center;
    halign: center;
    action-name: 'row.open-prefs';
    tooltip-text: _("Open extension preferences");
  }

  [action]
  Gtk.Image error_icon {
    styles [
      "error"
    ]

    icon-name: "dialog-error-symbolic";
    valign: center;
    halign: center;
    focusable: true;
    margin-start: 9;
    margin-end: 9;
    visible: false;
    tooltip-text: _("An error occurred while loading this extension");
  }

  [action]
  Gtk.Image out_of_date_icon {
    styles [
      "error"
    ]

    icon-name: "clock-alt-symbolic";
    valign: center;
    halign: center;
    focusable: true;
    margin-start: 9;
    margin-end: 9;
    visible: false;
    tooltip-text: _("This extension is incompatible with your current version of GNOME");
  }

  [action]
  Gtk.Image update_icon {
    styles [
      "update"
    ]

    icon-name: "software-update-available-symbolic";
    valign: center;
    halign: center;
    focusable: true;
    margin-start: 9;
    margin-end: 9;
    visible: false;
    tooltip-text: _("A newer version of this extension is available");
  }

  [action]
  Gtk.Image info_icon {
    styles [
      "warning"
    ]

    icon-name: "dialog-information-symbolic";
    valign: center;
    halign: center;
    focusable: true;
    margin-start: 9;
    margin-end: 9;
    visible: false;
    tooltip-text: _("This extension could be activated in session modes such as the login screen or the lock screen");
  }

  Gtk.ListBoxRow {
    activatable: false;

    Gtk.Grid {
      styles [
        "row-content"
      ]

      row-spacing: 15;
      column-spacing: 15;

      Gtk.Label description_title {
        styles [
          "dim-label"
        ]

        label: _("Description");
        xalign: 0;
        yalign: 0;

        layout {
          row: 0;
          column: 0;
        }
      }

      Gtk.Label description_label {
        styles [
          "multiline"
        ]

        xalign: 0;
        wrap-mode: word;
        wrap: true;
        selectable: true;

        layout {
          row: 0;
          column: 1;
        }

        accessibility {
          labelled-by: description_title;
        }
      }

      Gtk.Label version_title {
        styles [
          "dim-label"
        ]

        label: _("Version");
        xalign: 0;
        yalign: 0;

        layout {
          row: 1;
          column: 0;
        }
      }

      Gtk.Label version_label {
        xalign: 0;
        wrap-mode: word;
        wrap: true;
        selectable: true;

        layout {
          row: 1;
          column: 1;
        }

        accessibility {
          labelled-by: version_title;
        }
      }

      Gtk.Label error_label_tag {
        styles [
          "dim-label"
        ]

        label: _("Error");
        xalign: 0;
        yalign: 0;

        layout {
          row: 2;
          column: 0;
        }
      }

      Gtk.Label error_label {
        xalign: 0;
        wrap-mode: word_char;
        wrap: true;
        selectable: true;

        layout {
          row: 2;
          column: 1;
        }
      }
    }
  }

  Gtk.ListBoxRow {
    activatable: false;
    focusable: false;
    height-request: 46;

    Gtk.Box {
      halign: end;
      spacing: 6;
      margin-start: 4;
      margin-end: 4;

      Gtk.Button details_btn {
        styles [
          "flat"
        ]

        label: _("See Details");
        valign: center;
        action-name: 'win.show-detail';
      }

      Gtk.Button remove_btn {
        styles [
          "destructive-action"
        ]

        label: _("Remove…");
        valign: center;
        action-name: 'row.remove';
      }
    }
  }
}
