namespace QuickSetup {

    public struct PageContext {
        public QuickSetupWindow window;
        public Adw.NavigationView navigation_view;
        public QsConfig config;
    }

    public abstract class QsPage : Adw.NavigationPage {
        private Gtk.Box v_box;
        protected Adw.HeaderBar header_bar;
        private Gtk.Box content_area;
        protected PageContext context;
        public abstract string page_id { get; }
        public abstract bool can_go_back_to { get; }
        public virtual bool needs_network { get { return false; } }

        protected QsPage(PageContext context, string title) {
            Object();

            this.context = context;
            this.v_box = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);

            // Header bar
            this.header_bar = new Adw.HeaderBar();
            this.header_bar.show_start_title_buttons = false;
            this.header_bar.show_end_title_buttons = false;
            this.header_bar.add_css_class("flat");

            // Content area
            this.content_area = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
            this.content_area.vexpand = true;
            this.content_area.valign = Gtk.Align.FILL;
            this.content_area.hexpand = true;
            this.content_area.halign = Gtk.Align.FILL;

            // Add all the areas to the page
            this.v_box.append(header_bar);
            this.v_box.append(content_area);

            // Set the v_box as the child of the NavigationPage
            this.set_child(this.v_box);
            this.set_title(tr(title));
        }

        public new void set_title(string title) {
            base.set_title(title);
            this.header_bar.set_title_widget(new Adw.WindowTitle(title, ""));
            // this.header_bar.title = title;
        }

        public void add_content(Gtk.Widget content) {
            this.content_area.append(content);
        }

        public void set_back_button(bool visible) {
            this.header_bar.show_back_button = visible;
        }

        protected Gtk.Button create_page_button(string label, bool suggested = false) {
            var button = new Gtk.Button.with_label(tr(label));
            button.add_css_class("pill");
            if (suggested) {
                button.add_css_class("suggested-action");
            }
            return button;
        }

        protected Gtk.Box create_button_bar() {
            var button_bar = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 12);
            button_bar.halign = Gtk.Align.CENTER;
            button_bar.homogeneous = true;
            button_bar.margin_top = 24;
            return button_bar;
        }

        protected Gtk.Box create_trailing_button_bar() {
            var button_bar = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 12);
            button_bar.halign = Gtk.Align.END;
            button_bar.margin_top = 24;
            return button_bar;
        }
    }

    public QsPage? get_page_from_id(string id, PageContext context) {
        switch (id) {
            case "welcome": 
                return new WelcomePage(context);
            case "drivers-pre-wifi":
                return new DriversPreWifiPage(context);
            case "network":
                return new NetworkPage(context);
            case "drivers-post-wifi":
                return new DriversPostWifiPage(context);
            case "drivers-reboot":
                return new DriverRebootPromptPage(context);
            case "installing-apps":
                return new InstallingAppsPage(context);
            case "webbrowser":
                return new WebBrowserPage(context);
            case "apps":
                return new AppsPage(context);
            case "sam-demo":
                return new SamDemoPage(context);
            case "explore":
                return new ExplorePage(context);
            case "donate":
                return new DonatePage(context);
            default:
                //  error("Page not found: %s", id);
                break;
        }
        return null;
    }

}
