<?php
$file = 'admin.php';
$content = file_get_contents($file);

$oldUi = '<div style="display: flex; gap: 15px; align-items: center; margin-bottom: 10px;">
                                    <div style="flex: 0 0 180px; font-size: 11px; color: #88c0d0; font-weight: bold;">FACTION DOMINANTE :</div>
                                    <div class="form-group" style="flex: 1; margin-bottom: 0;">
                                        <label style="font-size: 10px;">En Orbite</label>
                                        <select name="orbital_dominance" id="rule_orb_dom">
                                            <option value="">-</option>
                                            <option value="ANY">N\'importe laquelle</option>
                                            <option value="NONE">Aucune (Vide)</option>
                                            <?php foreach($factions_list as $f): if($f[\'name\'] !== \'Aucune\'): ?>
                                                <option value="<?php echo $f[\'id\']; ?>"><?php echo htmlspecialchars($f[\'name\']); ?></option>
                                            <?php endif; endforeach; ?>
                                        </select>
                                    </div>
                                    <div class="form-group" style="flex: 1; margin-bottom: 0;">
                                        <label style="font-size: 10px;">Au Sol</label>
                                        <select name="terrestrial_dominance" id="rule_terr_dom">
                                            <option value="">-</option>
                                            <option value="ANY">N\'importe laquelle</option>
                                            <option value="NONE">Aucune (Vide)</option>
                                            <?php foreach($factions_list as $f): if($f[\'name\'] !== \'Aucune\'): ?>
                                                <option value="<?php echo $f[\'id\']; ?>"><?php echo htmlspecialchars($f[\'name\']); ?></option>
                                            <?php endif; endforeach; ?>
                                        </select>
                                    </div>
                                </div>';

$newUi = '<div style="display: flex; gap: 15px; align-items: flex-start; margin-bottom: 10px;">
                                    <div style="flex: 0 0 180px; font-size: 11px; color: #88c0d0; font-weight: bold; padding-top: 5px;">FILTRE DOMINANCE :</div>
                                    
                                    <!-- Orbite -->
                                    <div class="form-group" style="flex: 1; margin-bottom: 0;">
                                        <label style="font-size: 10px;">En Orbite</label>
                                        <div class="ms-container" id="ms_orb">
                                            <div class="ms-display" onclick="toggleMS(\'ms_orb_list\')">Toutes / Peu importe</div>
                                            <div class="ms-dropdown" id="ms_orb_list">
                                                <label class="ms-item"><input type="checkbox" value="none" onchange="updateMSLabel(\'ms_orb\')"> Aucune (Vide)</label>
                                                <?php foreach($factions_list as $f): if($f[\'name\'] !== \'Aucune\'): ?>
                                                    <label class="ms-item"><input type="checkbox" value="<?php echo $f[\'id\']; ?>" name="orbital_dominance[]" onchange="updateMSLabel(\'ms_orb\')"> <?php echo htmlspecialchars($f[\'name\']); ?></label>
                                                <?php endif; endforeach; ?>
                                            </div>
                                        </div>
                                    </div>

                                    <!-- Sol -->
                                    <div class="form-group" style="flex: 1; margin-bottom: 0;">
                                        <label style="font-size: 10px;">Au Sol</label>
                                        <div class="ms-container" id="ms_terr">
                                            <div class="ms-display" onclick="toggleMS(\'ms_terr_list\')">Toutes / Peu importe</div>
                                            <div class="ms-dropdown" id="ms_terr_list">
                                                <label class="ms-item"><input type="checkbox" value="none" onchange="updateMSLabel(\'ms_terr\')"> Aucune (Vide)</label>
                                                <?php foreach($factions_list as $f): if($f[\'name\'] !== \'Aucune\'): ?>
                                                    <label class="ms-item"><input type="checkbox" value="<?php echo $f[\'id\']; ?>" name="terrestrial_dominance[]" onchange="updateMSLabel(\'ms_terr\')"> <?php echo htmlspecialchars($f[\'name\']); ?></label>
                                                <?php endif; endforeach; ?>
                                            </div>
                                        </div>
                                    </div>
                                </div>';

$content = str_replace($oldUi, $newUi, $content);

file_put_contents($file, $content);
echo "UI patched";
?>
