using Gtk 4.0;
using Adw 1;

Adw.Window _root {
  default-width: 440;
  modal: true;
  resizable: false;
  
  content: Adw.ToolbarView {
    [top]
    Adw.HeaderBar _header {
      title-widget: Gtk.Label {};

      [start]
      Gtk.Button _btnBack {
        halign: start;
        valign: center;
        visible: false;
        child: Adw.ButtonContent {
          icon-name: "go-previous-symbolic";
          label: _("Back");
        };
      }
    }

    Gtk.WindowHandle {
      Gtk.Box {
        orientation: vertical;
        spacing: 24;
        
        Gtk.Label _titleLabel {
          label: _("Account Settings");

          styles ["title-2"]
        }

        Adw.ViewStack _viewStack {
          margin-start: 24;
          margin-end: 24;
          margin-bottom: 24;

          Adw.ViewStackPage {
            name: "main";
            child: Gtk.Box {
              orientation: vertical;
              spacing: 24;
              margin-top: 4;

              Adw.PreferencesGroup {
                Adw.EntryRow _nameRow {
                  title: _("Name");
                  activates-default: true;
                }

                Adw.ComboRow _accountTypeRow {
                  title: _("Account Type");
                  model: Gtk.StringList {
                    strings [_("Checking"), _("Savings"), _("Business")]
                  };
                }

                Adw.ActionRow {
                  title: _("Default Transaction Type");

                  [suffix]
                  Gtk.Box {
                    orientation: horizontal;
                    valign: center;

                    Gtk.ToggleButton _incomeButton {
                      label: _("Income");
                    }

                    Gtk.ToggleButton _expenseButton {
                      label: _("Expense");
                    }

                    styles ["linked"]
                  }
                }
                
                Adw.ComboRow _transactionRemindersRow {
                  title: _("Transaction Reminders Threshold");
                  model: Gtk.StringList {
                    strings [_("Never"), _("One Day Before"), _("One Week Before"), _("One Month Before"), _("Two Months Before")]
                  };
                }
              }

              Adw.PreferencesGroup {
                Adw.ActionRow _customCurrencyRow {
                  title: _("Currency");
                  subtitle: _("Manage the currency used by the account.");

                  [prefix]
                  Gtk.Image {
                    icon-name: "money-symbolic";
                  }

                  [suffix]
                  Gtk.Image _imgCustomCurrency {
                    icon-name: "go-next-symbolic";
                    valign: center;
                  }

                  activatable-widget: _imgCustomCurrency;
                }

                Adw.ActionRow _managePasswordRow {
                  title: _("Change Password");
                  subtitle: _("Set a new password or remove one.");

                  [prefix]
                  Gtk.Image {
                    icon-name: "dialog-password-symbolic";
                  }

                  [suffix]
                  Gtk.Image _imgManagePassword {
                    icon-name: "go-next-symbolic";
                    valign: center;
                  }

                  activatable-widget: _imgManagePassword;
                }
              }

              Gtk.Button _applyButton {
                halign: center;
                valign: center;
                margin-top: 24;
                label: _("Apply");

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

          Adw.ViewStackPage {
            name: "currency";
            child: Gtk.Box {
              visible: false;
              orientation: vertical;
              spacing: 24;

              Gtk.Label _reportedCurrencyLabel {
                use-markup: true;
                justify: center;
              }

              Adw.PreferencesGroup {
                Adw.SwitchRow _useCustomCurrencyRow {
                  title: _("Use Custom Currency");
                }
              }

              Adw.PreferencesGroup {
                sensitive: bind _useCustomCurrencyRow.active;

                Adw.EntryRow _customSymbolRow {
                  title: _("Currency Symbol");
                }

                Adw.EntryRow _customCodeRow {
                  title: _("Currency Code");
                }
                
                Adw.ComboRow _customAmountStyleRow {
                  title: _("Amount Display Style");
                  model: Gtk.StringList {
                    strings ["$100", "100$", "$ 100", "100 $"]
                  };
                }

                Adw.ComboRow _customDecimalSeparatorRow {
                  title: _("Decimal Separator");
                  model: Gtk.StringList {
                    strings [" . ", " , ", _("Other")]
                  };

                  [suffix]
                  Gtk.Entry _customDecimalSeparatorText {
                    visible: false;
                    valign: center;
                    halign: end;
                    max-length: 2;
                    max-width-chars: 4;
                  }
                }

                Adw.ComboRow _customGroupSeparatorRow {
                  title: _("Group Separator");
                  model: Gtk.StringList {
                    strings [" . ", " , ", " ' ", _("None"), _("Other")]
                  };

                  [suffix]
                  Gtk.Entry _customGroupSeparatorText {
                    visible: false;
                    valign: center;
                    halign: end;
                    max-length: 2;
                    max-width-chars: 4;
                  }
                }

                Adw.ComboRow _customDecimalDigitsRow {
                  title: _("Decimal Digits");
                  model: Gtk.StringList {
                    strings [_("Two"), _("Three"), _("Four"), _("Five"), _("Six"), _("Unlimited")]
                  };
                }
              }
            };
          }

          Adw.ViewStackPage {
            name: "password";
            child: Gtk.Box {
              visible: false;
              orientation: vertical;
              spacing: 24;

              Adw.PreferencesGroup {
                Adw.PasswordEntryRow _newPasswordRow {
                  title: _("New Password");
                }

                Adw.PasswordEntryRow _newPasswordConfirmRow {
                  title: _("Confirm Password");
                }
                
                Adw.ActionRow {
                  title: _("Password Strength");
                  
                  [suffix]
                  Gtk.LevelBar _passwordStrengthBar {
                    hexpand: true;
                    valign: center;
                    
                    styles ["strength"]
                  }
                }

                Adw.ActionRow {
                  subtitle: _("If the password is lost, there is no way to restore the file!");

                  [suffix]
                  Gtk.Button _removePasswordButton {
                    label: _("Remove");
                    valign: center;

                    styles ["destructive-action"]
                  }

                  styles ["warning"]
                }
              }

              Gtk.Label _lblPasswordStatus {
                hexpand: true;

                styles ["error"]
              }
            };
          }
        }
      }
    }
  };
  
  Gtk.ShortcutController {
    Gtk.Shortcut {
      trigger: "Escape";
      action: "action(window.close)";
    }
  }

  default-widget: _applyButton;
}