<?php

//<----------------------------------------------------------->
//<-------------------COPIA AI BRUXÃO------------------------->
//<-------------CONTATO: https://t.me/eonbry------------------>
//<-------------DEVELOPER: EMANUEL NASCIMENTO----------------->
//<----------------------------------------------------------->


include ('includes/header.php');

$jsonData = file_get_contents('./api/theme.json');
$dataArray = json_decode($jsonData, true);

function getPanalData($dataArray) {
    if (isset($dataArray[0]["PanalData"])) {
        return $dataArray[0]["PanalData"];
    } else {
        return null;
    }
}

$panalData = getPanalData($dataArray);

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $selectedOption = $_POST['options'];
    
    $jsonData = file_get_contents('./api/theme.json');
    $data = json_decode($jsonData, true);
    $data[0]["PanalData"] = $selectedOption;
    
    $jsonData = json_encode($data, JSON_PRETTY_PRINT);
    file_put_contents('./api/theme.json', $jsonData);
    
    echo "<script>window.location.href='UI_Setting.php';</script>";
    exit();
}
?>

<style>
/* TEMA AZUL ESCURO CINZENTO COM GLASS */
:root {
    --azul-escuro: #0f172a;
    --azul-medio: #1e293b;
    --azul-claro: #334155;
    --azul-brilho: #3b82f6;
    --cinza-escuro: #1e293b;
    --cinza-medio: #334155;
    --cinza-claro: #cbd5e1;
    --branco: #f8fafc;
    --verde: #10b981;
    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(148, 163, 184, 0.1);
    --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

body {
    background: linear-gradient(135deg, var(--azul-escuro) 0%, var(--cinza-escuro) 100%);
    min-height: 100vh;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    padding: 20px;
}

.container-main {
    max-width: 1000px;
    margin: 30px auto;
    padding: 20px;
}

/* CARD GLASS */
.card-glass {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 0;
    box-shadow: var(--glass-shadow);
    overflow: hidden;
    border-top: 1px solid rgba(255,255,255,0.1);
}

.card-header-glass {
    background: linear-gradient(135deg, rgba(30, 41, 59, 0.9), rgba(51, 65, 85, 0.9));
    padding: 25px 30px;
    border-bottom: 1px solid var(--glass-border);
    text-align: center;
    position: relative;
    overflow: hidden;
}

.card-header-glass::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--azul-brilho), transparent);
}

.card-header-glass h2 {
    color: var(--branco);
    margin: 0;
    font-size: 26px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    text-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.card-header-glass h2 i {
    color: var(--azul-brilho);
    font-size: 28px;
    filter: drop-shadow(0 0 8px rgba(59, 130, 246, 0.4));
}

.card-body-glass {
    padding: 35px;
}

/* STATUS ATUAL */
.current-status {
    background: rgba(15, 23, 42, 0.4);
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 16px;
    padding: 25px;
    margin-bottom: 35px;
    text-align: center;
    backdrop-filter: blur(10px);
    position: relative;
    overflow: hidden;
}

.current-status::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(59, 130, 246, 0.3), transparent);
}

.status-label {
    color: var(--cinza-claro);
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
    opacity: 0.8;
}

.status-value {
    color: var(--azul-brilho);
    font-size: 24px;
    font-weight: 700;
    margin-top: 8px;
    text-shadow: 0 0 10px rgba(59, 130, 246, 0.3);
}

.status-badge {
    background: linear-gradient(135deg, var(--verde), #0ea271);
    color: white;
    padding: 6px 15px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    margin-left: 12px;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.2);
    border: 1px solid rgba(255,255,255,0.1);
}

/* SELECT GLASS */
.select-glass {
    width: 100%;
    max-width: 450px;
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 12px;
    padding: 15px 20px;
    color: var(--branco);
    font-size: 16px;
    font-weight: 500;
    transition: all 0.3s;
    backdrop-filter: blur(10px);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' fill='%233b82f6' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 20px center;
    background-size: 16px;
    padding-right: 50px;
}

.select-glass:focus {
    outline: none;
    border-color: var(--azul-brilho);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
    background: rgba(15, 23, 42, 0.7);
    transform: translateY(-2px);
}

.select-glass option {
    background: var(--azul-medio);
    color: var(--branco);
    padding: 12px;
    font-size: 14px;
}

/* BOTÃO GLASS */
.btn-glass {
    background: linear-gradient(135deg, var(--azul-brilho), #2563eb);
    color: white;
    border: none;
    border-radius: 12px;
    padding: 16px 35px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    display: inline-flex;
    align-items: center;
    gap: 12px;
    margin-top: 25px;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,0.1);
    box-shadow: 0 8px 20px rgba(59, 130, 246, 0.3);
    position: relative;
    overflow: hidden;
}

.btn-glass::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    transition: 0.5s;
}

.btn-glass:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 25px rgba(59, 130, 246, 0.4);
}

.btn-glass:hover::before {
    left: 100%;
}

.btn-glass:active {
    transform: translateY(-1px);
}

/* FORM */
.form-glass {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

/* GRID DE IMAGENS */
.image-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 25px;
    margin-top: 45px;
}

@media (max-width: 900px) {
    .image-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 600px) {
    .image-grid {
        grid-template-columns: 1fr;
    }
}

.image-card {
    background: rgba(15, 23, 42, 0.4);
    border: 2px solid rgba(148, 163, 184, 0.15);
    border-radius: 16px;
    padding: 25px 20px;
    text-align: center;
    transition: all 0.3s;
    backdrop-filter: blur(10px);
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.image-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(59, 130, 246, 0.2), transparent);
}

.image-card:hover {
    transform: translateY(-8px);
    border-color: var(--azul-brilho);
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.3);
    background: rgba(15, 23, 42, 0.6);
}

.image-card.active {
    border-color: var(--azul-brilho);
    background: rgba(15, 23, 42, 0.7);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2), 0 10px 25px rgba(0,0,0,0.3);
}

.image-card.active::after {
    content: '✓';
    position: absolute;
    top: 15px;
    right: 15px;
    background: var(--verde);
    color: white;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    box-shadow: 0 4px 10px rgba(16, 185, 129, 0.3);
}

.image-title {
    color: var(--branco);
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 18px;
    text-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.image-preview {
    width: 100%;
    height: 160px;
    object-fit: contain;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.2);
    padding: 10px;
    border: 1px solid rgba(148, 163, 184, 0.2);
    transition: all 0.3s;
}

.image-card:hover .image-preview {
    border-color: var(--azul-brilho);
    transform: scale(1.03);
}

/* ANIMAÇÕES */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.card-glass {
    animation: fadeInUp 0.5s ease-out;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.7;
    }
}

.status-badge {
    animation: pulse 2s infinite;
}
</style>

<div class="container-main">
    <div class="card-glass">
        <div class="card-header-glass">
            <h2><i class="fas fa-wrench"></i> Configurar Interface</h2>
        </div>
        
        <div class="card-body-glass">
            <div class="current-status">
                <div class="status-label">Interface Atual</div>
                <div class="status-value">
                    <?php 
                    if ($panalData) {
                        echo htmlspecialchars($panalData);
                        echo '<span class="status-badge">Ativo</span>';
                    } else {
                        echo 'Nenhuma interface selecionada';
                    }
                    ?>
                </div>
            </div>
            
            <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" class="form-glass" id="interfaceForm">
                <select name="options" id="options" class="select-glass" required onchange="highlightSelected()">
                    <option value="" disabled <?php echo !$panalData ? 'selected' : ''; ?>>Selecione uma interface</option>
                    <option value="Widget_1" <?php echo $panalData == 'Widget_1' ? 'selected' : ''; ?>>Widget_1 Canal</option>
                    <option value="Widget_2" <?php echo $panalData == 'Widget_2' ? 'selected' : ''; ?>>Widget_2 Ads</option>
                    <option value="Widget_3" <?php echo $panalData == 'Widget_3' ? 'selected' : ''; ?>>Widget_3 Esports</option>
                </select>
                
                <button type="submit" class="btn-glass">
                    <i class="fas fa-save"></i>
                    Salvar Configuração
                </button>
            </form>
            
            <div class="image-grid">
                <div class="image-card" onclick="selectWidget('Widget_1')" id="widget1">
                    <div class="image-title">Widget_1 Canal</div>
                    <img src="./img/1.png" class="image-preview" alt="Widget_1 Canal" 
                         onerror="this.onerror=null; this.src='data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjUwIiBoZWlnaHQ9IjE2MCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cmVjdCB3aWR0aD0iMjUwIiBoZWlnaHQ9IjE2MCIgZmlsbD0iIzBGMTcyQSIvPjx0ZXh0IHg9IjEyNSIgeT0iODAiIGZvbnQtZmFtaWx5PSJBcmlhbCIgZm9udC1zaXplPSIxNCIgZmlsbD0iI0NCZDVlMSIgdGV4dC1hbmNob3I9Im1pZGRsZSI+Q2FuYWwgV2lkZ2V0IDE8L3RleHQ+PC9zdmc+'">
                </div>
                
                <div class="image-card" onclick="selectWidget('Widget_2')" id="widget2">
                    <div class="image-title">Widget_2 Ads</div>
                    <img src="./img/2.png" class="image-preview" alt="Widget_2 Ads"
                         onerror="this.onerror=null; this.src='data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjUwIiBoZWlnaHQ9IjE2MCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cmVjdCB3aWR0aD0iMjUwIiBoZWlnaHQ9IjE2MCIgZmlsbD0iIzBGMTcyQSIvPjx0ZXh0IHg9IjEyNSIgeT0iODAiIGZvbnQtZmFtaWx5PSJBcmlhbCIgZm9udC1zaXplPSIxNCIgZmlsbD0iI0NCZDVlMSIgdGV4dC1hbmNob3I9Im1pZGRsZSI+QWRzIFdpZGdldCAyPC90ZXh0Pjwvc3ZnPg=='">
                </div>
                
                <div class="image-card" onclick="selectWidget('Widget_3')" id="widget3">
                    <div class="image-title">Widget_3 Esports</div>
                    <img src="./img/3.png" class="image-preview" alt="Widget_3 Esports"
                         onerror="this.onerror=null; this.src='data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjUwIiBoZWlnaHQ9IjE2MCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cmVjdCB3aWR0aD0iMjUwIiBoZWlnaHQ9IjE2MCIgZmlsbD0iIzBGMTcyQSIvPjx0ZXh0IHg9IjEyNSIgeT0iODAiIGZvbnQtZmFtaWx5PSJBcmlhbCIgZm9udC1zaXplPSIxNCIgZmlsbD0iI0NCZDVlMSIgdGV4dC1hbmNob3I9Im1pZGRsZSI+RXNwb3J0cyBXaWRnZXQgMzwvdGV4dD48L3N2Zz4='">
                </div>
                
                
            </div>
        </div>
    </div>
</div>

<script>
// FUNÇÕES SIMPLES E FUNCIONAIS
function selectWidget(value) {
    // Seleciona no dropdown
    document.getElementById('options').value = value;
    
    // Remove classe active de todos
    document.querySelectorAll('.image-card').forEach(card => {
        card.classList.remove('active');
    });
    
    // Adiciona classe active no selecionado
    if(value === 'Widget_1') document.getElementById('widget1').classList.add('active');
    if(value === 'Widget_2') document.getElementById('widget2').classList.add('active');
    if(value === 'Widget_3') document.getElementById('widget3').classList.add('active');
}

function highlightSelected() {
    const select = document.getElementById('options');
    selectWidget(select.value);
}

// Inicializar highlight com valor atual
document.addEventListener('DOMContentLoaded', function() {
    const select = document.getElementById('options');
    if(select.value) {
        highlightSelected();
    }
    
    // Botão loading
    document.getElementById('interfaceForm').addEventListener('submit', function(e) {
        const btn = this.querySelector('button[type="submit"]');
        btn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Salvando...';
        btn.disabled = true;
    });
});
</script>

<?php include ('includes/footer.php'); ?>
</body>
</html>