using Gtk 4.0;
using Adw 1;

template $ProviderPreferences : Adw.NavigationPage {
  title: _("Provider Preferences");

  Adw.ToolbarView {

    [top]
    Adw.HeaderBar {
      title-widget: Adw.WindowTitle title {
        title: _("Provider Preferences");
      };
    }

    Adw.PreferencesPage page {

      Adw.PreferencesGroup instance_group {

        Adw.EntryRow instance_entry {
          title: _("Instance URL");
          tooltip-text: _("Enter an Instance URL for the Provider.");
          show-apply-button: true;

          apply => $_on_instance_apply();
          notify::text => $_on_instance_changed();

          Stack instance_stack {
            StackPage {
              name: "reset";
              child:  Button instance_reset {
                tooltip-text: _("Reset to Default");
                icon-name: "view-refresh-symbolic";
                valign: center;

                clicked => $_on_reset_instance();

                styles ["flat"]
              };
            }

            StackPage {
              name: "spinner";
              child: Adw.Spinner {
                valign: center;
              };
            }
          }
        }

        Adw.PasswordEntryRow api_key_entry {
          title: _("API Key");
          tooltip-text: _("Enter an API Key for the Provider.");
          show-apply-button: true;

          apply => $_on_api_key_apply();

          Stack api_key_stack {
            StackPage {
              name: "reset";
              child:  Button api_key_reset {
                tooltip-text: _("Reset to Default");
                icon-name: "view-refresh-symbolic";
                valign: center;

                clicked => $_on_reset_api_key();

                styles ["flat"]
              };
            }

            StackPage {
              name: "spinner";
              child: Adw.Spinner {
                valign: center;
              };
            }
          }
        }
      }

      Adw.PreferencesGroup api_usage_group {
        title: _("Character Usage");
        visible: false;

        Box {
          orientation: vertical;
          spacing: 3;

          LevelBar api_usage {

          }

          Label api_usage_label {

          }
        }

      }
    }
  }
}