namespace QuickSetup {
    public class InstallingAppsPage : QsPage {
        private const string INSTALLED_SAM_IMAGE = "/usr/share/quick-setup/images/samdemo.png";
        private const string DEV_SAM_IMAGE = "data/images/samdemo.png";

        public override string page_id { get { return "installing-apps"; } }
        public override bool can_go_back_to { get { return false; } } // Probably shouldn't go back while installing
        public override bool needs_network { get { return true; } }

        public InstallingAppsPage(PageContext context) {
            base(context, "Installing Apps");

            // Content container
            var content_box = new Gtk.Box(Gtk.Orientation.VERTICAL, 24);
            content_box.vexpand = true;
            content_box.hexpand = true;
            content_box.valign = Gtk.Align.CENTER;
            content_box.halign = Gtk.Align.CENTER;

            // Load SAM demo image
            string image_path = INSTALLED_SAM_IMAGE;
            if (!FileUtils.test(INSTALLED_SAM_IMAGE, FileTest.EXISTS)) {
                image_path = DEV_SAM_IMAGE;
            }
            
            if (FileUtils.test(image_path, FileTest.EXISTS)) {
                var image = new Gtk.Picture.for_filename(image_path);
                image.set_size_request(550, 350);
                image.content_fit = Gtk.ContentFit.CONTAIN;
                image.halign = Gtk.Align.CENTER;
                content_box.append(image);
            }

            // Title and description
            string update_title = context.window.nvidia_driver_queued
                ? tr("We are installing system updates and NVIDIA drivers in the background.")
                : tr("We are installing a system update in the background.");
            var title_label = new Gtk.Label(update_title);
            title_label.add_css_class("title-1");
            title_label.halign = Gtk.Align.CENTER;
            content_box.append(title_label);

            var desc_label = new Gtk.Label(tr("Update and app installation progress can be viewed in the panel."));
            desc_label.add_css_class("dim-label");
            desc_label.halign = Gtk.Align.CENTER;
            content_box.append(desc_label);

            this.add_content(content_box);

            // Button bar
            var button_bar = this.create_trailing_button_bar();
            var next_button = this.create_page_button("Continue", true);
            next_button.clicked.connect(() => {
                this.queue_system_update_only();
                context.window.push_next_page();
            });
            button_bar.append(next_button);
            content_box.append(button_bar);
        }

        private void queue_system_update_only() {
            var monitor = GLib.NetworkMonitor.get_default();
            if (monitor.get_connectivity() == GLib.NetworkConnectivity.FULL) {
                queue_system_update();
            }
        }
    }
}
