using Gtk 4.0;
using Adw 1;

Adw.Window _root {
  default-width: 450;
  resizable: false;
  modal: true;

  content: Adw.ToolbarView {
    [top]
    Adw.HeaderBar {
      title-widget: Gtk.Label {};

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

      [start]
      Gtk.Button _copyButton {
        child: Adw.ButtonContent {
          icon-name: "edit-copy-symbolic";
          label: _("Make a Copy");
        };
      }
    }

    Gtk.WindowHandle {
      Adw.ViewStack _stack {
        Adw.ViewStackPage {
          name: "main";

          child: Gtk.Box {
            orientation: vertical;
            spacing: 18;

            Gtk.Label _titleLabel {
              styles ["title-2"]
            }

            Gtk.ScrolledWindow _scrolledWindow {
              propagate-natural-width: true;
              propagate-natural-height: true;
              hscrollbar-policy: never;

              Gtk.Overlay _overlay {
                Gtk.Box {
                  orientation: vertical;
                  spacing: 24;
                  margin-top: 6;
                  margin-start: 24;
                  margin-end: 24;
                  margin-bottom: 6;

                  Adw.PreferencesGroup {
                    Adw.EntryRow _descriptionRow {
                      title: _("Description");
                      input-hints: spellcheck;
                      activates-default: true;
                    }
                  }

                  Gtk.Box {
                    spacing: 12;

                    Adw.Bin {
                      Adw.EntryRow _amountRow {
                        title: _("Amount");
                        input-purpose: number;
                        activates-default: true;
                        hexpand: true;

                        [suffix]
                        Gtk.Label _currencyLabel {
                          styles ["dim-label"]
                        }

                        styles ["transaction-amount"]
                      }

                      styles ["card"]
                    }

                    Gtk.Box {
                      orientation: vertical;
                      halign: center;

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

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

                      styles ["linked"]
                    }
                  }

                  Adw.PreferencesGroup {
                    Adw.ActionRow {
                      title: _("Date");
                      activatable-widget: _dateCalendarButton;

                      [suffix]
                      Gtk.Box {
                        spacing: 4;

                        Gtk.MenuButton _dateCalendarButton {
                          valign: center;
                          direction: none;
                          popover: Gtk.Popover {
                            Gtk.Calendar _dateCalendar {
                              name: "calendarTransactions";
                            }
                          };

                          styles ["calendar-button"]
                        }

                        Gtk.Label _dateDashLabel {
                          label: " — ";
                        }

                        Gtk.MenuButton _repeatEndDateCalendarButton {
                          valign: center;
                          direction: none;
                          tooltip-text: _("Repeat End Date");
                          popover: Gtk.Popover {
                            Gtk.Box {
                              orientation: vertical;
                              spacing: 6;

                              Gtk.Button _repeatEndDateClearButton {
                                halign: center;

                                child: Adw.ButtonContent {
                                  icon-name: "larger-brush-symbolic";
                                  label: _("Clear End Date");
                                };
                              }

                              Gtk.Calendar _repeatEndDateCalendar {
                                name: "calendarTransactions";
                              }
                            }
                          };

                          styles ["calendar-button"]
                        }
                      }
                    }

                    Adw.ComboRow _repeatIntervalRow {
                      title: _("Repeat Interval");
                      model: Gtk.StringList {
                        strings [_("Never"), _("Daily"), _("Weekly"), _("Biweekly"), _("Monthly"), _("Quarterly"), _("Yearly"), _("Biyearly")]
                      };
                    }
                  }

                  Adw.PreferencesGroup {
                    hexpand: true;

                    Adw.ComboRow _groupRow {
                      title: _("Group");
                      title-lines: 1;
                    }

                    Adw.ActionRow {
                      title: _("Color");

                      [suffix]
                      Gtk.ColorDialogButton _colorButton {
                        valign: center;
                        margin-start: 4;
                        margin-end: 4;
                      }

                      [suffix]
                      Gtk.DropDown _colorDropDown {
                        valign: center;
                        model: Gtk.StringList {
                          strings [_("Use group color"), _("Use unique color")]
                        };

                        styles ["color-dropdown"]
                      }
                    }

                    Adw.ActionRow {
                      title: _("Tags");

                      [suffix]
                      Gtk.MenuButton _tagsButton {
                        valign: center;
                        direction: none;
                        popover: Gtk.Popover {
                          Gtk.Box {
                            orientation: vertical;
                            spacing: 6;

                            Gtk.ScrolledWindow _tagsScrolledWindow {
                              hscrollbar-policy: never;
                              height-request: 124;
                              width-request: 300;

                              Gtk.FlowBox _tagsFlowBox {
                                valign: start;
                                margin-top: 4;
                                margin-start: 4;
                                margin-end: 4;
                                column-spacing: 2;
                                row-spacing: 2;
                                selection-mode: none;
                              }

                              styles ["card"]
                            }

                            Gtk.Box {
                              Gtk.Entry _addTagEntry {
                                hexpand: true;
                                placeholder-text: _("Enter a new tag name...");
                              }

                              Gtk.Button _addTagButton {
                                child: Adw.ButtonContent {
                                  label: _("Add Tag");
                                  icon-name: "list-add-symbolic";
                                };
                              }

                              styles ["linked"]
                            }
                          }
                        };
                      }
                    }
                  }

                  Adw.PreferencesGroup {
                    hexpand: true;

                    Adw.ActionRow _extrasRow {
                      title: _("Extras");
                      subtitle: _("Manage extra fields of the transaction.");

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

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

                      activatable-widget: _imgExtras;
                    }
                  }
                }
              }
            }

            Gtk.Box {
              orientation: horizontal;
              spacing: 24;
              halign: center;
              homogeneous: true;
              margin-start: 24;
              margin-top: 24;
              margin-end: 24;
              margin-bottom: 24;

              Gtk.Button _deleteButton {
                valign: center;
                label: _("Delete");

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

              Gtk.Button _applyButton {
                valign: center;

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

        Adw.ViewStackPage {
          name: "extras";

          child: Gtk.Box {
            orientation: vertical;
            spacing: 18;
            margin-start: 24;
            margin-end: 24;
            margin-bottom: 24;

            Gtk.Label {
              label: _("Extras");
              margin-bottom: 6;

              styles ["title-2"]
            }

            Adw.PreferencesGroup {
              Adw.ActionRow _receiptRow {
                title: _("Receipt");

                [suffix]
                Gtk.Box {
                  orientation: horizontal;
                  spacing: 6;

                  Gtk.Button _viewReceiptButton {
                    valign: center;
                    tooltip-text: _("View");

                    Adw.ButtonContent _viewReceiptButtonContent {
                      icon-name: "image-x-generic-symbolic";
                    }

                    styles ["flat"]
                  }

                  Gtk.Button _deleteReceiptButton {
                    valign: center;
                    tooltip-text: _("Delete");

                    Adw.ButtonContent {
                      icon-name: "user-trash-symbolic";
                    }

                    styles ["flat"]
                  }

                  Gtk.Button _uploadReceiptButton {
                    valign: center;
                    tooltip-text: _("Upload");

                    Adw.ButtonContent _uploadReceiptButtonContent {
                      icon-name: "denaro-upload-symbolic";
                    }

                    styles ["flat"]
                  }
                }
              }
            }

            Adw.PreferencesGroup {
              title: _("Notes");
              description: _("Enter notes here");

              Gtk.TextView _notesView {
                vexpand: true;
                top-margin: 12;
                left-margin: 12;
                right-margin: 12;
                bottom-margin: 12;

                styles ["card"]
              }
            }
          };
        }
      }
    }
  };

  default-widget: _applyButton;
}