<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>PC Monitor - Admin</title>
    <link rel="stylesheet" href="{{ url_for('static', filename='css/admin.css') }}">
    <!-- SortableJS pour le drag & drop -->
    <script src="https://cdn.jsdelivr.net/npm/sortablejs@1.15.0/Sortable.min.js"></script>
</head>
<body>
    <div class="container">
        <header>
            <h1>âš™ï¸ Configuration PC Monitor</h1>
            <div class="header-actions">
                <a href="/dashboard" class="btn btn-secondary">ðŸ“Š Dashboard</a>
                <button id="save-btn" class="btn btn-primary">ðŸ’¾ Sauvegarder</button>
            </div>
        </header>

        <div class="content">
            <!-- Navigation des sections -->
            <nav class="sections-nav">
                <button class="section-tab active" data-section="plugin">ðŸ”Œ Source</button>
                <button class="section-tab" data-section="sensors">ðŸ“¡ Capteurs</button>
                <button class="section-tab" data-section="order">â†•ï¸ Ordre</button>
                <button class="section-tab" data-section="tabs">ðŸ“‘ Onglets</button>
                <button class="section-tab" data-section="media">🎵 Média</button>
                <button class="section-tab" data-section="apps">ðŸš€ Applications</button>
                <button class="section-tab" data-section="theme">ðŸŽ¨ ThÃ¨me</button>
            </nav>

            <!-- Section Plugin -->
            <section id="section-plugin" class="config-section active">
                <h2>Source de monitoring</h2>
                <p class="help-text">Choisissez le logiciel de monitoring Ã  utiliser</p>
                
                <div class="plugin-selector" id="plugin-selector">
                    <!-- GÃ©nÃ©rÃ© dynamiquement -->
                </div>
                
                <div class="plugin-config" id="plugin-config">
                    <h3>âš™ï¸ Configuration de la connexion</h3>
                    
                    <div class="config-group">
                        <label>ðŸŒ HÃ´te</label>
                        <input type="text" id="plugin-host" value="127.0.0.1" placeholder="127.0.0.1">
                    </div>
                    
                    <div class="config-group">
                        <label>ðŸ”¢ Port</label>
                        <input type="number" id="plugin-port" value="8085" placeholder="8085">
                    </div>
                    
                    <div class="plugin-actions">
                        <button id="test-connection-btn" class="btn btn-secondary">ðŸ” Tester la connexion</button>
                        <span id="connection-status"></span>
                    </div>
                </div>
                
                <div class="plugin-info" id="plugin-info">
                    <!-- Info sur le plugin sÃ©lectionnÃ© -->
                </div>
            </section>

            <!-- Section Capteurs -->
            <section id="section-sensors" class="config-section">
                <h2>SÃ©lection des capteurs</h2>
                <p class="help-text">Cochez les capteurs que vous souhaitez afficher sur le dashboard</p>
                
                <div class="sensors-container">
                    <div id="sensors-loading">Chargement des capteurs...</div>
                    <div id="sensors-list" style="display: none;"></div>
                </div>
            </section>

            <!-- Section Ordre des capteurs -->
            <section id="section-order" class="config-section">
                <h2>Ordre des capteurs</h2>
                <p class="help-text">Glissez-dÃ©posez les capteurs pour changer leur ordre d'affichage</p>
                
                <div id="order-tabs-container">
                    <!-- GÃ©nÃ©rÃ© dynamiquement -->
                </div>
            </section>

            <!-- Section Onglets -->
            <section id="section-tabs" class="config-section">
                <h2>Gestion des onglets</h2>
                <p class="help-text">CrÃ©ez et organisez vos onglets personnalisÃ©s</p>
                
                <div class="tabs-manager">
                    <div class="tabs-list" id="tabs-list"></div>
                    
                    <button id="add-tab-btn" class="btn btn-primary">âž• Ajouter un onglet</button>
                </div>
            </section>

            <!-- Section Applications -->

            <!-- Section Média (Plexamp) -->
            <section id="section-media" class="config-section">
                <h2>🎵 Lecteur Média</h2>
                <p class="help-text">Configurez Plexamp pour afficher le lecteur sur le dashboard</p>
                
                <div class="plugin-card">
                    <div class="plugin-header">
                        <label class="plugin-toggle">
                            <input type="checkbox" id="plexamp-enabled">
                            <span class="toggle-slider"></span>
                        </label>
                        <div class="plugin-title">
                            <h3>Plexamp</h3>
                            <p>Lecteur Plex (via serveur Plex)</p>
                        </div>
                    </div>
                    
                    <div class="plugin-config" id="plexamp-config">
                        <div class="config-group">
                            <label>🖥️ Serveur Plex (IP)</label>
                            <input type="text" id="plexamp-host" value="192.168.1.235" placeholder="192.168.1.235">
                        </div>
                        
                        <div class="config-group">
                            <label>🔢 Port</label>
                            <input type="number" id="plexamp-port" value="32400" placeholder="32400">
                        </div>
                        
                        <div class="config-group">
                            <label>🔑 Token Plex</label>
                            <input type="password" id="plexamp-token" placeholder="Votre token Plex">
                            <small>Trouvez-le dans Plexamp → Paramètres → Dépannage → Copier le token</small>
                        </div>
                        
                        <div class="plugin-actions">
                            <button id="plexamp-test-btn" class="btn btn-secondary">🔍 Tester</button>
                            <button id="plexamp-save-btn" class="btn btn-primary">💾 Sauvegarder</button>
                            <span id="plexamp-status"></span>
                        </div>
                    </div>
                </div>
            </section>

            <section id="section-apps" class="config-section">
                <h2>Applications lancables</h2>
                <p class="help-text">Configurez les applications que vous voulez lancer depuis le dashboard</p>
                
                <div class="config-group" style="margin-bottom: 20px;">
                    <label>ðŸ“‘ Afficher les applications dans l'onglet :</label>
                    <select id="apps-tab-select">
                        <option value="">-- Section sÃ©parÃ©e (en bas) --</option>
                        <!-- Options gÃ©nÃ©rÃ©es dynamiquement -->
                    </select>
                </div>
                
                <div class="apps-list" id="apps-list"></div>
                
                <button id="add-app-btn" class="btn btn-primary">âž• Ajouter une application</button>
            </section>

            <!-- Section ThÃ¨me -->
            <section id="section-theme" class="config-section">
                <h2>Apparence</h2>
                <p class="help-text">Personnalisez le thÃ¨me de l'interface</p>
                
                <div class="theme-selector">
                    <label>
                        <input type="radio" name="theme" value="dark" checked>
                        <div class="theme-option">
                            <div class="theme-preview theme-dark"></div>
                            <span>Sombre</span>
                        </div>
                    </label>
                    
                    <label>
                        <input type="radio" name="theme" value="light">
                        <div class="theme-option">
                            <div class="theme-preview theme-light"></div>
                            <span>Clair</span>
                        </div>
                    </label>
                    
                    <label>
                        <input type="radio" name="theme" value="blue">
                        <div class="theme-option">
                            <div class="theme-preview theme-blue"></div>
                            <span>Bleu</span>
                        </div>
                    </label>
                </div>
            </section>
        </div>
    </div>

    <!-- Modal de configuration capteur -->
    <div id="sensor-config-modal" class="modal" style="display: none;">
        <div class="modal-content">
            <div class="modal-header">
                <h3>âš™ï¸ Configuration du capteur</h3>
                <button class="modal-close">&times;</button>
            </div>
            <div class="modal-body">
                <div class="config-group">
                    <label>ðŸ“ Taille de la carte</label>
                    <select id="config-card-size">
                        <option value="tiny">Minuscule (Â½ colonne) - Mobile</option>
                        <option value="xs">TrÃ¨s petit (1 colonne) - Mobile</option>
                        <option value="small">Petit (1.5 colonnes)</option>
                        <option value="medium" selected>Moyen (2 colonnes)</option>
                        <option value="large">Grand (3 colonnes)</option>
                        <option value="xl">TrÃ¨s grand (4 colonnes)</option>
                    </select>
                    
                    <label style="margin-top: 10px;">ðŸ”¤ Police de caractÃ¨res</label>
                    <select id="config-font-family">
                        <option value="system" selected>System (par dÃ©faut)</option>
                        <option value="roboto">Roboto</option>
                        <option value="opensans">Open Sans</option>
                        <option value="lato">Lato</option>
                        <option value="montserrat">Montserrat</option>
                        <option value="poppins">Poppins</option>
                        <option value="inter">Inter</option>
                        <option value="mono">Monospace (technique)</option>
                        <option value="digital">Digital (LCD)</option>
                    </select>
                    
                    <label style="margin-top: 10px;">
                        <input type="checkbox" id="config-font-bold" checked>
                        Texte en gras (bold)
                    </label>
                    
                    <label style="margin-top: 10px;">ðŸ“± Taille de police</label>
                    <select id="config-font-size">
                        <option value="tiny">Minuscule (8px nom, 14px valeur) - Ultra compact</option>
                        <option value="xs">TrÃ¨s petit (9px nom, 16px valeur) - Compact</option>
                        <option value="small" selected>Petit (10px nom, 18px valeur) - Par dÃ©faut</option>
                        <option value="medium">Moyen (11px nom, 20px valeur) - Confortable</option>
                        <option value="large">Grand (12px nom, 22px valeur) - Large</option>
                    </select>
                    
                    <label style="margin-top: 10px;">
                        <input type="checkbox" id="config-hide-value-mobile">
                        Masquer la valeur sur mobile (plus d'espace pour le graphique)
                    </label>
                    
                    <label style="margin-top: 10px;">
                        <input type="checkbox" id="config-show-type-badge" checked>
                        Afficher le badge de type (temperature, frequency, etc.)
                    </label>
                </div>

                <div class="config-group" id="gauge-options-group" style="display: none;">
                    <h4>ðŸŽ¯ Options de la jauge</h4>
                    
                    <label>
                        <input type="checkbox" id="config-gauge-show-value" checked>
                        Afficher la valeur au centre
                    </label>

                    <label>Taille de la jauge</label>
                    <select id="config-gauge-size">
                        <option value="tiny">Minuscule (60px) - Mobile</option>
                        <option value="xs">TrÃ¨s petit (90px) - Mobile</option>
                        <option value="small">Petit (120px)</option>
                        <option value="medium" selected>Moyen (180px)</option>
                        <option value="large">Grand (240px)</option>
                    </select>

                    <label>Style de la jauge</label>
                    <select id="config-gauge-style">
                        <option value="arc" selected>Arc (3/4 cercle)</option>
                        <option value="semicircle">Demi-cercle</option>
                        <option value="circle">Cercle complet</option>
                    </select>
                </div>

                <div class="config-group" id="chart-options-group" style="display: none;">
                    <h4>ðŸ“ˆ Options du graphique</h4>
                    
                    <label>Hauteur du graphique</label>
                    <select id="config-chart-height">
                        <option value="tiny">Minuscule (50px) - Mobile</option>
                        <option value="xs">TrÃ¨s petit (70px) - Mobile</option>
                        <option value="small">Petit (90px)</option>
                        <option value="medium" selected>Moyen (120px)</option>
                        <option value="large">Grand (180px)</option>
                    </select>
                </div>
            </div>
            <div class="modal-footer">
                <button class="btn btn-secondary modal-cancel">Annuler</button>
                <button class="btn btn-primary modal-save">Appliquer</button>
            </div>
        </div>
    </div>

    <div id="notification" class="notification"></div>

    <script src="{{ url_for('static', filename='js/admin.js') }}"></script>
</body>
</html>
