"""
Home app that provides an overview of all available apps.
"""

import gradio as gr
from apps.base_app import BaseApp


class HomeApp(BaseApp):
    """Welcome page with overview of all available apps."""

    def create_interface(self) -> gr.Blocks:
        """Create the home interface with app overview."""
        with gr.Blocks() as interface:
            gr.Markdown(f"# Welcome to {self.settings.project_title}")
            gr.Markdown("""
            This application provides multiple tools organized in tabs.
            Select a tab above to get started with any of the available apps.
            """)

            gr.Markdown("## 📱 Available Apps")

            # Get all app configurations and sort by order
            app_configs = []
            for app_key, app_config in self.settings.apps.items():
                if app_config.enabled and app_key != "home":
                    app_configs.append((app_key, app_config))

            # Sort by order
            app_configs.sort(key=lambda x: x[1].order)

            # Create a card for each app
            for app_key, app_config in app_configs:
                with gr.Accordion(
                    f"{app_config.icon} {app_config.title}",
                    open=False
                ):
                    gr.Markdown(f"**Description:** {app_config.description}")
                    gr.Markdown(f"**Module:** `apps/{app_key}.py`")
                    gr.Markdown(f"**Order:** {app_config.order}")

            gr.Markdown("---")
            gr.Markdown("## 🚀 Quick Start")
            gr.Markdown("""
            1. **Navigate** to any app tab above
            2. **Explore** the features available in each app
            3. **Customize** app settings in `config.yaml`
            4. **Add your own apps** by creating new files in the `apps/` directory
            """)

            gr.Markdown("## ⚙️ Configuration")
            gr.Markdown(f"""
            - **Apps Directory:** `{self.settings.apps_directory}/`
            - **Theme:** {self.settings.theme}
            - **Debug Mode:** {self.settings.debug}
            - **Server:** {self.settings.server_name}:{self.settings.server_port}
            """)

            gr.Markdown("## 📖 Documentation")
            gr.Markdown("""
            - See `README.md` for quick start guide
            - See `.copilot/README.md` for AI agents and tools
            - See `.copilot/QUICKREF.md` for quick reference
            - See `.copilot/context/` for detailed documentation
            - Check `config.yaml` for app configurations
            """)

        return interface


# Export the app class
app = HomeApp
