using Gtk 4.0;
using Adw 1;

template $SnapshotPage : Adw.BreakpointBin {
    width-request: 1;
	height-request: 1;

    Adw.Breakpoint bp1 {
		condition ("max-width: 600")

		setters {
			split_view.collapsed: true;
            split_view.show-content: false;
		}
	}

    Adw.NavigationPage {
        title: _("Snapshots");
        Adw.ToastOverlay toast_overlay {
            Stack status_stack {
                Adw.NavigationSplitView split_view {
                    sidebar-width-fraction: 0.5;
                    max-sidebar-width: 999999999;
                    sidebar:
                        Adw.NavigationPage sidebar_navpage {
                            title: _("Snapshots");
                            Adw.ToolbarView sidebar_tbv {
                                [top]
                                Adw.HeaderBar header_bar {
                                    [start]
                                    $SidebarButton {}
                                    [start]
                                    ToggleButton search_button {
                                        icon-name: "loupe-large-symbolic";
                                        tooltip-text: _("Search Packages");
                                    }
                                    [start]
                                    Button open_button {
                                        icon-name: "folder-open-symbolic";
                                        tooltip-text: _("Open Snapshots Folder");
                                    }
                                    [end]
                                    Button new_button {
                                        icon-name: "plus-large-symbolic";
                                        tooltip-text: _("New Snapshot");
                                    }
                                    [end]
                                    ToggleButton select_button {
                                        icon-name: "selection-mode-symbolic";
                                        tooltip-text: _("Select Packages");
                                    }
                                }
                                [top]
                                SearchBar search_bar {
                                    search-mode-enabled: bind search_button.active bidirectional;
                                    SearchEntry search_entry {
                                        hexpand: true;
                                        placeholder-text: _("Search Snapshots");
                                    }
                                }
                                Stack stack {
                                    Adw.StatusPage no_results {
                                        title: _("No Results Found");
                                        description: _("Try a different search");
                                        icon-name: "system-search-symbolic";
                                    }
                                    ScrolledWindow scrolled_window {
                                        Box {
                                            orientation: vertical;
                                            
                                            Box active_box {
                                                orientation: vertical;
                                                
                                                Label {
                                                    label: _("Active Snapshots");
                                                    halign: start;
                                                    styles ["heading"]
                                                    margin-top: 3;
                                                    margin-bottom: 6;
                                                    margin-start: 12;
                                                    margin-end: 12;
                                                    wrap: true;
                                                    wrap-mode: word_char;
                                                }
                                                Label {
                                                    label: _("Snapshots of installed apps");
                                                    halign: start;
                                                    styles ["dim-label"]
                                                    margin-start: 12;
                                                    margin-end: 12;
                                                    margin-bottom: 3;
                                                    wrap: true;
                                                    wrap-mode: word_char;
                                                }
                                                ListBox active_listbox {
                                                    styles ["navigation-sidebar"]
                                                    valign: start;
                                                }
                                            }
                                            Box leftover_box {
                                                orientation: vertical;
                                                
                                                Label {
                                                    label: _("Leftover Snapshots");
                                                    halign: start;
                                                    styles ["heading"]
                                                    margin-top: 3;
                                                    margin-bottom: 6;
                                                    margin-start: 12;
                                                    margin-end: 12;
                                                    wrap: true;
                                                    wrap-mode: word_char;
                                                }
                                                Label {
                                                    label: _("Snapshots of apps that are no longer installed");
                                                    halign: start;
                                                    styles ["dim-label"]
                                                    margin-start: 12;
                                                    margin-end: 12;
                                                    margin-bottom: 3;
                                                    wrap: true;
                                                    wrap-mode: word_char;
                                                }
                                                ListBox leftover_listbox {
                                                    styles ["navigation-sidebar"]
                                                    valign: start;
                                                }
                                            }
                                        }
                                    }
                                }
                                [bottom]
                                Revealer {
                                    reveal-child: bind select_button.active;
                                    transition-type: slide_up;
                                    [center]
                                    Box bottom_bar {
                                        styles ["toolbar"]
                                        hexpand: true;
                                        homogeneous: true;
                                        Button select_all_button {
                                            styles ["raised"]
                                            Adw.ButtonContent {
                                                icon-name: "selection-mode-symbolic";
                                                label: _("Select All");
                                                can-shrink: true;
                                            }
                                        }
                                        Button copy_button {
                                            sensitive: false;
                                            styles ["raised"]
                                            Adw.ButtonContent {
                                                icon-name: "edit-copy-symbolic";
                                                label: _("Copy");
                                                can-shrink: true;
                                            }
                                        }
                                        MenuButton more_button {
                                            sensitive: false;
                                            popover: more_popover;
                                            styles ["raised"]
                                            Adw.ButtonContent {
                                                icon-name: "view-more-symbolic";
                                                label: _("More");
                                                can-shrink: true;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    ;
                }
                Adw.ToolbarView no_snapshots {
                    [top]
                    Adw.HeaderBar {
                        [start]
                        $SidebarButton {}
                        [start]
                        Button status_open_button {
                            icon-name: "folder-open-symbolic";
                            tooltip-text: _("Open Snapshots Folder");
                        }
                    }
                    Adw.ToastOverlay no_snapshots_toast {
                        Adw.StatusPage {
                            title: _("No Snapshots");
                            description: _("Create a Snapshot to save the state of any Flatpak application");
                            icon-name: "snapshots-alt-symbolic";
                            Button status_new_button {
                                styles ["suggested-action", "pill"]
                                halign: center;
                                Adw.ButtonContent {
                                    icon-name: "plus-large-symbolic";
                                    label: _("New Snapshot");
                                }
                            }
                        }
                    }
                }
                Adw.ToolbarView loading_view {
                    [top]
                    Adw.HeaderBar {
                        [start]
                        $SidebarButton {}
                    }
                }
                Adw.ToolbarView snapshotting_view {
                    [top]
                    Adw.HeaderBar {
                        [start]
                        $SidebarButton {}
                    }
                }
            }
        }
    }
}

Popover more_popover {
    styles ["menu"]
    ListBox more_menu {
        Label new_snapshots {
            label: _("Snapshot Apps");
            halign: start;
        }
        Label install_from_snapshots {
            label: _("Install Apps");
            halign: start;
        }
        Label apply_snapshots {
            label: _("Apply Snapshots");
            halign: start;
        }
        Label trash_snapshots {
            label: _("Trash Snapshots");
            halign: start;
        }
    }
}
