using Gtk 4.0;
using Adw 1;

menu actionsMenu {
  item(_("Transfer Money"), "account.transferMoney")
  
  section {
    item(_("Import from File"), "account.importFromFile")

    submenu {
      label: _("Export to File");
      
      submenu {
        label: _("CSV");
        
        item(_("Export All Information"), "account.exportToCSVAll")
        item(_("Export Current View"), "account.exportToCSVCurrent")
      }

      submenu {
        label: _("PDF");

        item(_("Export All Information"), "account.exportToPDFAll")
        item(_("Export Current View"), "account.exportToPDFCurrent")
      }
    }
  }
  
  section {
    item(_("Account Settings"), "account.accountSettings")
  }
}

Adw.BreakpointBin _root {
  width-request: 360;
  height-request: 420;

  Adw.Breakpoint {
    condition ("max-width: 660sp")

    setters {
      _splitView.collapsed: true;
    }
  }

  child: Adw.OverlaySplitView _splitView {
    min-sidebar-width: 320;
    max-sidebar-width: 360;

    sidebar: Gtk.ScrolledWindow _paneScroll {
      hscrollbar-policy: never;
    
      Gtk.Box {
        orientation: vertical;
        spacing: 10;
        hexpand: false;
        vexpand: true;
        margin-start: 10;
        margin-end: 10;
        margin-top: 10;
        margin-bottom: 10;
        
        Gtk.SearchEntry _searchDescriptionEntry {
          placeholder-text: _("Search by description");
        }
        
        Adw.PreferencesGroup {
          title: _("Today's Overview");
          header-suffix: Gtk.Box {
            orientation: horizontal;
            
            Gtk.Button _remindersButton {
              icon-name: "bell-outline-symbolic";
              tooltip-text: _("Reminders");
              
              styles ["flat"]
            }            
            
            Gtk.MenuButton {
              menu-model: actionsMenu;
            
              Adw.ButtonContent {
                icon-name: "document-properties-symbolic";
                label: _("Actions");
              }
            
              styles ["flat"]
            }
            
            Gtk.Button _resetOverviewFilterButton {
              icon-name: "edit-select-all-symbolic";
              tooltip-text: _("Select All Overview Filters");
              
              styles ["flat"]
            }
          };
          
          Adw.ActionRow {
            title: _("Total");
            
            [suffix]
            Gtk.Label _totalLabel {
              valign: center;
              
              styles ["denaro-total"]
            }
          }
          
          Adw.ActionRow {
            title: _("Income");
            activatable-widget: _incomeCheck;
            
            [prefix]
            Gtk.CheckButton _incomeCheck {
              active: true;
              valign: center;
              
              styles ["selection-mode"]
            }
            
            [suffix]
            Gtk.Label _incomeLabel {
              valign: center;
              visible: bind _incomeCheck.active;
              
              styles ["denaro-income"]
            }
          }
          
          Adw.ActionRow {
            title: _("Expense");
            activatable-widget: _expenseCheck;
            
            [prefix]
            Gtk.CheckButton _expenseCheck {
              active: true;
              valign: center;
              
              styles ["selection-mode"]
            }
            
            [suffix]
            Gtk.Label _expenseLabel {
              valign: center;
              visible: bind _expenseCheck.active;
              
              styles ["denaro-expense"]
            }
          }
        }
        
        Adw.PreferencesGroup {
          title: _("Groups");
          header-suffix: Gtk.Box {
            Gtk.Button {
              tooltip-text: _("New Group (Ctrl+G)");
              action-name: "account.newGroup";
              
              Adw.ButtonContent {
                icon-name: "list-add-symbolic";
                label: C_("Group", "New");
              }
            
              styles ["flat"]
            }

            Gtk.Button _toggleGroupsButton {
              tooltip-text: _("Toggle Groups Visibility");
              icon-name: "view-conceal-symbolic";

              styles ["flat"]
            }

            Gtk.Button _resetGroupsFilterButton {
              icon-name: "edit-select-all-symbolic";
              tooltip-text: _("Select All Groups Filters");

              styles ["flat"]
            }

            Gtk.Button _unselectAllGroupsFilterButton {
              icon-name: "edit-select-none-symbolic";
              tooltip-text: _("Unselect Groups Filters");
            
              styles ["flat"]
            }
          };
          
          Gtk.ListBox _groupsList {
            selection-mode: none;

            styles ["boxed-list"]
          }
        }

        Adw.PreferencesGroup {
          title: _("Tags");
          header-suffix: Gtk.Box {
            Gtk.Button _toggleTagsButton {
              tooltip-text: _("Toggle Tags Visibility");
              icon-name: "view-conceal-symbolic";

              styles ["flat"]
            }
          
            Gtk.Button _resetTagsFilterButton {
              icon-name: "edit-select-all-symbolic";
              tooltip-text: _("Select All Tags Filters");

              styles ["flat"]
            }

            Gtk.Button _unselectAllTagsFilterButton {
              icon-name: "edit-select-none-symbolic";
              tooltip-text: _("Unselect Tags Filters");

              styles ["flat"]
            }
          };

          Adw.Bin _tagsBin {
            Gtk.FlowBox _tagsFlowBox {
              valign: start;
              margin-top: 6;
              margin-start: 6;
              margin-end: 6;
              margin-bottom: 6;
              column-spacing: 2;
              row-spacing: 2;
              selection-mode: none;
            }

            styles ["card"]
          }
        }

        Adw.PreferencesGroup {
          title: _("Calendar");
          header-suffix: Gtk.Box {
            orientation: horizontal;

            Gtk.Button _selectMonthButton {
              tooltip-text: _("Select Current Month");
              icon-name: "month-symbolic";
              styles ["flat"]
            }
            
            Gtk.Button _resetCalendarFilterButton {
              tooltip-text: _("Reset To Today");
              Adw.ButtonContent {
                icon-name: "today-symbolic";
                label: _("Today");
              }
            
              styles ["flat"]
            }
          };
           
          
          Gtk.Calendar _calendar {
            name: "calendarAccount";
            focusable: false;
            
            styles ["card"]
          }
        }
        
        Adw.PreferencesGroup {
          Adw.ExpanderRow _rangeExpander {
            title: _("Select Range");
            enable-expansion: false;
            show-enable-switch: true;
            
            Adw.ActionRow {
              title: C_("DateRange", "Start");
              
              [suffix]
              Gtk.Box {
                orientation: horizontal;
                spacing: 6;
                
                Gtk.DropDown _startYearDropDown {
                  valign: center;
                  show-arrow: false;
                }
                
                Gtk.DropDown _startMonthDropDown {
                  valign: center;
                  show-arrow: false;
                }
                
                Gtk.DropDown _startDayDropDown {
                  valign: center;
                  show-arrow: false;
                }
              }
            }
            
            Adw.ActionRow {
              title: C_("DateRange", "End");
              
              [suffix]
              Gtk.Box {
                orientation: horizontal;
                spacing: 6;
                
                Gtk.DropDown _endYearDropDown {
                  valign: center;
                  show-arrow: false;
                }
                
                Gtk.DropDown _endMonthDropDown {
                  valign: center;
                  show-arrow: false;
                }
                
                Gtk.DropDown _endDayDropDown {
                  valign: center;
                  show-arrow: false;
                }
              }
            }
          }
        }
      }
    };
    
    content: Gtk.Overlay {
      vexpand: true;
      
      child: Adw.ViewStack _viewStack {
        Adw.ViewStackPage {
          name: "spinner";
          child: Gtk.Spinner {
            hexpand: true;
            vexpand: true;
            halign: center;
            valign: center;
            spinning: true;
            width-request: 40;
            height-request: 40;
          };
        }
      
        Adw.ViewStackPage {
          name: "no-transactions";
          child: Adw.StatusPage _noTransactionsStatusPage {
            icon-name: "money-none-symbolic";
            hexpand: true;
            vexpand: true;
          };
        }
        
        Adw.ViewStackPage {
          name: "transactions";
          child: Gtk.Box {
            orientation: vertical;
            hexpand: true;
            vexpand: true;
            
            Adw.PreferencesGroup _visualizeGroup {
              title: _("Visualize");
              margin-top: 4;
              margin-start: 10;
              margin-end: 10;
              header-suffix: Gtk.Box {
                orientation: horizontal;
                
                Gtk.Button _graphBackButton {
                  valign: center;
                  icon-name: "go-previous-symbolic";
                  tooltip-text: _("Back");
                  
                  styles ["flat"]
                }
                
                Gtk.Button _graphNextButton {
                  valign: center;
                  icon-name: "go-next-symbolic";
                  tooltip-text: _("Next");
                  
                  styles ["flat"]
                }
              };
              
              Gtk.Box {
                orientation: vertical;
                spacing: 6;
                
                Adw.Carousel _carousel {
                  Gtk.DrawingArea _incomeExpenseOverTimeImage {
                    height-request: 300;
                    hexpand: true;
                  }
                  
                  Gtk.DrawingArea _incomeExpensePieImage {
                    height-request: 200;
                    hexpand: true;
                  }
                  
                  Gtk.DrawingArea _incomeExpensePerGroupImage {
                    height-request: 300;
                    hexpand: true;
                  }

                  Gtk.DrawingArea _incomeExpensePerGroupPieImage {
                    height-request: 300;
                    hexpand: true;
                  }
                  
                  styles ["card"]
                }
                
                Adw.CarouselIndicatorDots {
                  halign: center;
                  carousel: _carousel;
                }
              }
            }
            
            Gtk.Separator _visualizeSeparator {
              orientation: horizontal;
              margin-top: 10;
            }
            
            Gtk.Box {
              orientation: vertical;
              
              Adw.PreferencesGroup _transactionsGroup {
                margin-top: 8;
                margin-start: 10;
                margin-end: 10;
                header-suffix: Gtk.Box {
                  orientation: horizontal;
                  spacing: 6;

                  Gtk.DropDown _sortTransactionByDropDown {}

                  Gtk.Box _transactionsHeaderBox {
                    orientation: horizontal;
                    valign: center;

                    Gtk.ToggleButton _sortFirstToLastButton {
                      icon-name: "view-sort-descending-symbolic";
                      tooltip-text: _("Sort From First To Last");
                      active: bind _sortLastToFirstButton.active inverted bidirectional;
                    }

                    Gtk.ToggleButton _sortLastToFirstButton {
                      icon-name: "view-sort-ascending-symbolic";
                      tooltip-text: _("Sort From Last To First");
                    }

                    styles ["linked"]
                  }
                };
              }

              Gtk.ScrolledWindow _transactionsScroll {
                width-request: 300;
                min-content-height: 142;
                vexpand: true;

                Gtk.FlowBox _transactionsFlowBox {
                  margin-start: 10;
                  margin-end: 10;
                  margin-bottom: 62;
                  homogeneous: true;
                  column-spacing: 10;
                  row-spacing: 10;
                  halign: fill;
                  valign: start;
                  selection-mode: none;
                }
              }
            }
          };
        }
      };
      
      [overlay]
      Gtk.Button {
        tooltip-text: _("New Transaction (Ctrl+Shift+N)");
        action-name: "account.newTransaction";
        halign: center;
        valign: end;
        margin-bottom: 10;
        
        Adw.ButtonContent {
          icon-name: "list-add-symbolic";
          label: C_("Transaction", "New");
        }
        
        styles ["pill", "suggested-action"] 
      }
    };
  };
}