#!/usr/bin/env python3
"""
Adwaita Lite - First Run Wizard
Simple setup wizard for normal users - NO command line needed!
"""

import os
import sys

def run_gtk():
    try:
        import gi
        gi.require_version('Gtk', '3.0')
        from gi.repository import Gtk, Gdk
    except:
        print("ERROR: GTK3 not available")
        sys.exit(1)

    class LiteWizard(Gtk.Window):
        def __init__(self):
            super().__init__(title="Welcome to Adwaita Lite!")
            self.set_default_size(650, 550)
            self.set_position(Gtk.WindowPosition.CENTER)
            self.set_resizable(False)
            
            # Main box
            box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0)
            self.add(box)
            
            # Header with green accent
            header = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=5)
            header.set_property("margin", 25)
            header.set_size_request(-1, 100)
            
            title = Gtk.Label()
            title.set_markup("<span size='24000' weight='bold' color='#4e9a06'>Adwaita Lite</span>")
            header.pack_start(title, False, False, 0)
            
            subtitle = Gtk.Label()
            subtitle.set_markup("<span size='14000' color='#777'>Optimized for older computers</span>")
            header.pack_start(subtitle, False, False, 0)
            
            box.pack_start(header, False, False, 0)
            
            # Content area with scroll
            scrolled = Gtk.ScrolledWindow()
            scrolled.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
            scrolled.set_size_request(600, 300)
            
            content = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=15)
            content.set_property("margin", 25)
            
            # What works section
            content.pack_start(self._make_section("✅ Your Computer Still Does Everything!", [
                "🌐 Web browsing (Firefox)",
                "🎬 Watch videos (Video player)",
                "📝 Write documents", 
                "🎵 Play music",
                "📁 Manage files",
                "💌 Email & video calls (in browser)"
            ]), False, False, 0)
            
            # What was optimized
            content.pack_start(self._make_section("🚀 What's Faster Now?", [
                "• Less memory used at startup",
                "• Faster boot time",
                "• Smoother scrolling",
                "• Better battery life on laptops"
            ]), False, False, 0)
            
            # Need help section
            content.pack_start(self._make_section("❓ What If I Need Something That Stopped Working?", [
                "Click the buttons below to re-enable:",
            ]), False, False, 0)
            
            # Buttons row 1
            btn_row1 = Gtk.Box(spacing=10)
            btn_row1.set_homogeneous(True)
            
            btn_print = Gtk.Button(label="🖨️ Printing")
            btn_print.connect("clicked", self.enable_printing)
            btn_row1.pack_start(btn_print, True, True, 0)
            
            btn_bt = Gtk.Button(label="📶 Bluetooth")
            btn_bt.connect("clicked", self.enable_bluetooth)
            btn_row1.pack_start(btn_bt, True, True, 0)
            
            btn_scan = Gtk.Button(label="📷 Scanner")
            btn_scan.connect("clicked", self.enable_scanner)
            btn_row1.pack_start(btn_scan, True, True, 0)
            
            content.pack_start(btn_row1, False, False, 5)
            
            # Buttons row 2 - more options
            btn_row2 = Gtk.Box(spacing=10)
            btn_row2.set_homogeneous(True)
            
            btn_modem = Gtk.Button(label="📱 Mobile Data/Modem")
            btn_modem.connect("clicked", self.enable_modem)
            btn_row2.pack_start(btn_modem, True, True, 0)
            
            content.pack_start(btn_row2, False, False, 5)
            
            # Tips section
            content.pack_start(self._make_section("💡 Tips To Keep It Fast", [
                "• Use Firefox (not Chrome/Edge) - it's lighter",
                "• Close apps when you're done with them",
                "• Don't open too many browser tabs at once",
                "• Restart your computer once a week"
            ]), False, False, 0)
            
            # Recommended apps - browsers first
            content.pack_start(self._make_section("🌐 Faster Web Browser", [
                "Install a lighter browser for better performance:",
            ]), False, False, 0)
            
            btn_browser = Gtk.Box(spacing=10)
            btn_browser.set_homogeneous(True)
            
            btn_palemoon = Gtk.Button(label="🌙 Pale Moon (Firefox-based)")
            btn_palemoon.connect("clicked", self.install, "palemoon")
            btn_browser.pack_start(btn_palemoon, True, True, 0)
            
            btn_row3 = Gtk.Box(spacing=10)
            btn_row3.set_homogeneous(True)
            
            btn_thunar = Gtk.Button(label="📁 Thunar (File Manager)")
            btn_thunar.connect("clicked", self.install, "thunar")
            btn_row3.pack_start(btn_thunar, True, True, 0)
            
            btn_mousepad = Gtk.Button(label="📝 Mousepad (Text Editor)")
            btn_mousepad.connect("clicked", self.install, "mousepad")
            btn_row3.pack_start(btn_mousepad, True, True, 0)
            
            btn_qpdfview = Gtk.Button(label="📄 Qpdfview (PDF Viewer)")
            btn_qpdfview.connect("clicked", self.install, "qpdfview")
            btn_row3.pack_start(btn_qpdfview, True, True, 0)
            
            content.pack_start(btn_row3, False, False, 5)
            
            scrolled.add(content)
            box.pack_start(scrolled, True, True, 0)
            
            # Footer with close button
            footer = Gtk.Box(spacing=10)
            footer.set_property("margin", 15)
            
            footer.pack_start(Gtk.Label(), True, True, 0)
            
            close_btn = Gtk.Button(label="Get Started! ▶️")
            close_btn.connect("clicked", lambda x: self.destroy())
            close_btn.set_size_request(150, 40)
            close_btn.get_child().set_markup("<span weight='bold'>Get Started!</span>")
            footer.pack_start(close_btn, False, False, 0)
            
            footer.pack_start(Gtk.Label(), True, True, 0)
            
            box.pack_start(footer, False, False, 0)
            
        def _make_section(self, title, items):
            frame = Gtk.Frame()
            frame.set_shadow_type(Gtk.Shadow.NONE)
            frame.get_style_context().add_class("linked")
            
            vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=5)
            vbox.set_property("margin", 10)
            
            label = Gtk.Label()
            label.set_markup(f"<span weight='bold' size='11000'>{title}</span>")
            vbox.pack_start(label, False, False, 0)
            
            for item in items:
                item_label = Gtk.Label()
                item_label.set_text(item)
                item_label.set_alignment(0, 0.5)
                vbox.pack_start(item_label, False, False, 0)
            
            frame.add(vbox)
            return frame
        
        def enable_printing(self, widget):
            dlg = Gtk.MessageDialog(self, 0, Gtk.MessageType.INFO,
                Gtk.ButtonsType.OK, "To enable printing:\n\n"
                "1. Click 'Menu' → 'Software'\n"
                "2. Search for 'cups'\n"
                "3. Click 'Install'\n\n"
                "Or open Terminal and type:\n"
                "sudo pacman -S cups")
            dlg.run()
            dlg.destroy()
            
        def enable_bluetooth(self, widget):
            dlg = Gtk.MessageDialog(self, 0, Gtk.MessageType.INFO,
                Gtk.ButtonsType.OK, "To enable Bluetooth:\n\n"
                "1. Click 'Menu' → 'Software'\n"
                "2. Search for 'blueman'\n"
                "3. Click 'Install'\n\n"
                "Or open Terminal and type:\n"
                "sudo pacman -S blueman")
            dlg.run()
            dlg.destroy()
            
        def enable_scanner(self, widget):
            dlg = Gtk.MessageDialog(self, 0, Gtk.MessageType.INFO,
                Gtk.ButtonsType.OK, "To enable scanner:\n\n"
                "1. Click 'Menu' → 'Software'\n"
                "2. Search for 'sane'\n"
                "3. Click 'Install'")
            dlg.run()
            dlg.destroy()
            
        def enable_modem(self, widget):
            dlg = Gtk.MessageDialog(self, 0, Gtk.MessageType.INFO,
                Gtk.ButtonsType.OK, "To enable mobile data/modem:\n\n"
                "1. Click 'Menu' → 'Software'\n"
                "2. Search for 'ModemManager'\n"
                "3. Click 'Install'\n\n"
                "Or open Terminal and type:\n"
                "sudo pacman -S ModemManager")
            dlg.run()
            dlg.destroy()
            
        def install(self, widget, package):
            dlg = Gtk.MessageDialog(self, 0, Gtk.MessageType.INFO,
                Gtk.ButtonsType.OK, f"To install {package}:\n\n"
                "1. Click 'Menu' → 'Software'\n"
                f"2. Search for '{package}'\n"
                "3. Click 'Install'\n\n"
                f"Or: sudo pacman -S {package}")
            dlg.run()
            dlg.destroy()

    win = LiteWizard()
    win.connect("destroy", Gtk.main_quit)
    win.show_all()
    Gtk.main()

if __name__ == "__main__":
    run_gtk()
