<?php


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


include "includes/header.php";
?>

<style>
/* === DESIGN FUTURISTA MODERNO === */
:root {
    --primary: #00D4FF;
    --primary-dark: #0099CC;
    --secondary: #FF6B9D;
    --accent: #00FF88;
    --surface: #0A0F1C;
    --surface-light: #1A1F2C;
    --surface-lighter: #2A2F3C;
    --text-primary: #FFFFFF;
    --text-secondary: #B0B7C3;
    --text-muted: #6B7280;
    --border: rgba(255,255,255,0.1);
    --glow: 0 0 20px rgba(0, 212, 255, 0.3);
    --glow-accent: 0 0 20px rgba(0, 255, 136, 0.3);
}

.main-content {
    background: transparent !important;
    padding: 20px;
}

.card {
    background: var(--surface-light) !important;
    border: 1px solid var(--border) !important;
    border-radius: 20px !important;
    box-shadow: 0 8px 40px rgba(0,0,0,0.4) !important;
    color: var(--text-primary) !important;
    overflow: hidden;
    position: relative;
}

.card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--primary), var(--accent), var(--secondary));
    animation: borderGlow 3s ease-in-out infinite;
}

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

.card-header {
    background: linear-gradient(135deg, var(--surface-light), var(--surface-lighter)) !important;
    border-bottom: 1px solid var(--border) !important;
    color: var(--text-primary) !important;
    font-weight: 700 !important;
    padding: 20px !important;
}

.card-body {
    background: transparent !important;
    color: var(--text-primary) !important;
    padding: 30px !important;
}

/* Títulos futuristas */
.h1, .h3 {
    color: var(--text-primary) !important;
    font-weight: 700;
}

.text-primary2 {
    color: var(--primary) !important;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-size: 1.3rem !important;
}

/* Preview da imagem */
.preview-image {
    border-radius: 16px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.3);
    border: 3px solid var(--border);
    transition: all 0.3s ease;
    max-width: 100%;
    height: auto;
    margin: 20px 0;
}

.preview-image:hover {
    transform: scale(1.02);
    border-color: var(--primary);
    box-shadow: var(--glow);
}

/* Radio buttons futuristas */
.radio-container {
    display: flex;
    gap: 30px;
    margin: 25px 0;
    flex-wrap: wrap;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 15px 20px;
    background: var(--surface-lighter);
    border: 2px solid var(--border);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 600;
    color: var(--text-primary);
}

.radio-label:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
}

.radio-label input[type="radio"] {
    width: 20px;
    height: 20px;
    accent-color: var(--primary);
}

/* Formulários futuristas */
.form-container {
    background: var(--surface-lighter);
    border-radius: 16px;
    padding: 25px;
    margin: 20px 0;
    border: 1px solid var(--border);
    transition: all 0.3s ease;
}

.form-container:hover {
    border-color: var(--primary);
    box-shadow: var(--glow);
}

.custom-button {
    background: var(--surface-light) !important;
    border: 1px solid var(--border) !important;
    color: var(--text-primary) !important;
    border-radius: 12px !important;
    padding: 14px 18px !important;
    font-size: 1rem;
    transition: all 0.3s ease;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    width: 100%;
    margin-bottom: 15px;
}

.custom-button:focus {
    border-color: var(--primary) !important;
    box-shadow: 0 0 0 0.3rem rgba(0, 212, 255, 0.25) !important;
    background: var(--surface-light) !important;
    color: var(--text-primary) !important;
    transform: translateY(-2px);
    outline: none;
}

/* Botões futuristas */
.btn-success {
    background: linear-gradient(135deg, var(--accent), #00cc7a) !important;
    border: none !important;
    border-radius: 12px !important;
    box-shadow: var(--glow-accent) !important;
    padding: 14px 30px !important;
    font-weight: 600 !important;
    transition: all 0.3s ease !important;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-size: 1rem;
    width: 100%;
    margin-top: 10px;
}

.btn-success:hover {
    transform: translateY(-3px) !important;
    box-shadow: 0 8px 25px rgba(0, 255, 136, 0.5) !important;
}

/* Labels */
label {
    color: var(--text-primary) !important;
    font-weight: 600;
    margin-bottom: 10px;
    display: block;
    font-size: 1rem;
}

/* Status atual */
.current-status {
    background: linear-gradient(135deg, var(--surface-light), var(--surface-lighter));
    border: 2px solid var(--primary);
    border-radius: 12px;
    padding: 20px;
    margin: 20px 0;
    text-align: center;
    box-shadow: var(--glow);
}

.current-status h4 {
    color: var(--text-primary);
    margin-bottom: 10px;
    font-weight: 600;
}

.current-status .status-value {
    color: var(--accent);
    font-weight: 700;
    font-size: 1.1rem;
}

/* Efeito de partículas */
@keyframes moveParticles {
    from { transform: translateY(0); opacity: 0.7; }
    to { transform: translateY(-1000px); opacity: 0; }
}

.particle {
    position: fixed;
    bottom: 0;
    width: 2px;
    height: 2px;
    background: var(--primary);
    opacity: 0.5;
    animation: moveParticles linear infinite;
    z-index: -1;
}

.particle:nth-child(odd) { background: var(--accent); }

/* Esconder formulários */
#url-form {
    display: none;
}

/* Responsividade */
@media (max-width: 768px) {
    .main-content {
        padding: 10px !important;
    }
    
    .card-body {
        padding: 20px !important;
    }
    
    .radio-container {
        flex-direction: column;
        gap: 15px;
    }
    
    .radio-label {
        padding: 12px 15px;
    }
    
    .preview-image {
        max-width: 100%;
        height: auto;
    }
    
    .btn-success {
        padding: 12px 20px !important;
        font-size: 0.9rem !important;
    }
}
</style>

<script>
document.addEventListener("DOMContentLoaded", function() {
    // Partículas animadas
    const numParticles = 20;
    const particlesContainer = document.createElement('div');
    particlesContainer.style.position = 'fixed';
    particlesContainer.style.top = '0';
    particlesContainer.style.left = '0';
    particlesContainer.style.width = '100%';
    particlesContainer.style.height = '100%';
    particlesContainer.style.pointerEvents = 'none';
    particlesContainer.style.zIndex = '-1';
    
    for (let i = 0; i < numParticles; i++) {
        const particle = document.createElement('div');
        particle.classList.add('particle');
        particle.style.left = Math.random() * 100 + 'vw';
        particle.style.animationDuration = (2 + Math.random() * 8) + 's';
        particle.style.animationDelay = Math.random() * 10 + 's';
        particle.style.width = particle.style.height = (1 + Math.random() * 3) + 'px';
        particlesContainer.appendChild(particle);
    }
    
    document.body.appendChild(particlesContainer);

    // Controle dos radios
    const uploadRadio = document.getElementById('upload-radio');
    const urlRadio = document.getElementById('url-radio');
    const uploadForm = document.getElementById('upload-form');
    const urlForm = document.getElementById('url-form');

    uploadRadio.addEventListener('change', () => {
        uploadForm.style.display = 'block';
        urlForm.style.display = 'none';
    });

    urlRadio.addEventListener('change', () => {
        uploadForm.style.display = 'none';
        urlForm.style.display = 'block';
    });
});
</script>

<main role="main" class="col-12 pt-4 px-4 main-content">
    <div class="container-fluid">
        <h1 class="h3 mb-4 text-gray-800">
            <i class="fas fa-palette me-2"></i>Alterar Logotipo
        </h1>
        
        <div class="row">
            <div class="col-lg-10 mx-auto">
                <div class="card border-left-primary shadow h-100 card shadow mb-4">
                    <div class="card-header py-3">
                        <h6 class="m-0 font-weight-bold text-primary2">
                            <i class="fas fa-cogs me-2"></i>Escolher Logo
                        </h6>
                    </div>
                    <div class="card-body">
                        <?php
                        $jsonFilex = './a/rtx/logo_filenames.json';
                        $jsonDatax = file_get_contents($jsonFilex);
                        $imageDatax = json_decode($jsonDatax, true);
                        
                        $filenamex = $imageDatax[0]['ImageName'];
                        $uploadmethord = $imageDatax[0]['Upload_type'];
                        
                        if ($uploadmethord == "by_file") {
                            $string = $filenamex;
                            $firstLetterRemoved = substr($string, 1);
                            $imageFilex = "$firstLetterRemoved";
                            $methord = "Upload Method";
                        } elseif ($uploadmethord == "by_url") {
                            $imageFilex = "$filenamex";
                            $methord = "URL Method";
                        } else {
                            $imageFilex = "https://c4.wallpaperflare.com/wallpaper/159/71/731/errors-minimalism-typography-red-wallpaper-preview.jpg";
                            $methord = "";
                        }
                        ?>

                        <!-- Status Atual -->
                        <div class="current-status">
                            <h4><i class="fas fa-info-circle me-2" style="color: #31ff03;"></i>Método Atual</h4>
                            <div class="status-value">
                                <?php echo $methord ? $methord : "Nenhum método configurado"; ?>
                            </div>
                        </div>

                        <!-- Preview da Imagem -->
                        <div style="text-align: center;">
                            <h5><i class="fas fa-eye me-2" style="color: #31ff03;"></i>Preview do Logotipo Atual</h5>
                            <img class="preview-image" src="<?php echo $imageFilex; ?>" alt="Uploaded Image" style="max-width: 600px; max-height: 300px;">
                        </div>

                        <!-- Seleção de Método -->
                        <div class="radio-container">
                            <label class="radio-label">
                                <input type="radio" name="upload-type" id="upload-radio" checked>
                                <i class="fas fa-upload" style="color: red;"></i> 
                                Upload de Arquivo
                            </label>
                            <label class="radio-label">
                                <input type="radio" name="upload-type" id="url-radio">
                                <i class="fas fa-link" style="color: red;"></i>
                                URL Externa
                            </label>
                        </div>
                        <p style="color:#31ff03;">ESCOLHA AQUI O SEU LOGOTIPO PARA UPLOAD</p>

                        <!-- Formulários -->
                        <div class="form-container" id="upload-form">
                            <form method="post" enctype="multipart/form-data">
                                <label for="image">
                                    <i class="fas fa-file-image me-2"></i>Selecione uma imagem para carregar:
                                </label>
                                <input class="custom-button" type="file" name="image" id="image" accept="image/jpeg, image/png, image/gif">
                                <button class="btn btn-success" type="submit" name="upload">
                                    <i class="fas fa-cloud-upload-alt me-2"></i>Upload
                                </button>
                            </form>
                        </div>

                        <div class="form-container" id="url-form">
                            <form method="post">
                                <label for="image-url">
                                    <i class="fas fa-globe me-2"></i>URL da Imagem
                                </label>
                                <input class="custom-button" type="text" name="image-url" id="image-url" placeholder="https://example.com/image.jpg">
                                <button class="btn btn-success" type="submit" name="url-submit">
                                    <i class="fas fa-check-circle me-2"></i>Enviar URL
                                </button>
                            </form>
                        </div>

                        <?php
                        // Lógica de upload (mantida original)
                        if (isset($_POST['upload'])) {
                            $selectedFiles = ['logo.png', 'index.php', 'iimg.json', 'filenames.json', 'binding_dark.webp', 'bg.jpg', 'api.php', 'favicon.ico', 'logo_ne.png', '.htaccess'];
                            $folderPath = './rtx/logo/ADM/';
                            
                            $files = scandir($folderPath);
                            foreach ($files as $file) {
                                if ($file !== '.' && $file !== '..' && !in_array($file, $selectedFiles)) {
                                    $filePath = $folderPath . $file;
                                    unlink($filePath);
                                }
                            }
                            
                            if (isset($_FILES['image'])) {
                                $file = $_FILES['image'];
                                $fileType = $file['type'];
                                $fileTemp = $file['tmp_name'];
                        
                                $allowedTypes = ['image/jpeg', 'image/png', 'image/gif'];
                                if (in_array($fileType, $allowedTypes)) {
                                    $uploadPath = './rtx/logo/ADM/';
                                    $fileName = uniqid() . '.' . pathinfo($file['name'], PATHINFO_EXTENSION);
                                    $destination = $uploadPath . $fileName;
                        
                                    if (move_uploaded_file($fileTemp, $destination)) {
                                        echo "<script>window.location.href='mRTXBGlogo.php';</script>";
                                        
                                        $jsonFilePath = './a/rtx/logo_filenames.json';
                                        $jsonData = json_encode([["ImageName" => "../rtx/logo/ADM/" . $fileName, 'Upload_type' => 'by_file']]);
                                        file_put_contents($jsonFilePath, $jsonData);
                                    }
                                }
                            }
                        }

                        if (isset($_POST['url-submit'])) {
                            $imageUrl = $_POST['image-url'];
                            if (filter_var($imageUrl, FILTER_VALIDATE_URL)) {
                                $jsonFilePath = './a/rtx/logo_filenames.json';
                                $newImageData = [
                                    'ImageName' => $imageUrl,
                                    'Upload_type' => 'by_url'
                                ];
                                $jsonData = file_get_contents($jsonFilePath);
                                $imageData = json_decode($jsonData, true);
                                $imageData[0] = $newImageData;
                                $jsonData = json_encode($imageData);
                                if (file_put_contents($jsonFilePath, $jsonData)) {
                                    echo "<script>window.location.href='mRTXBGlogo.php';</script>";
                                }
                            }
                        }
                        ?>
                    </div>
                </div>
            </div>
        </div>
    </div>
</main>

<?php
include "includes/footer.php";
?>
</body>
</html>