<?php

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


session_start();
if (!isset($_SESSION['user'])) { header("Location: adm/login.php"); exit; }

$wppPath = __DIR__ . "/config/whatsapp.json";

if (!file_exists($wppPath)) {
    file_put_contents($wppPath, json_encode([
        "modelo" => "📱 *Baixe agora:* {TITULO}\n\n🔗 Link de Download:\n{URL_APK}\n\n🚀 Boa instalação!"
    ], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
}

$wpp = json_decode(file_get_contents($wppPath), true);
$msg = isset($_GET['ok']) ? "Salvo com sucesso!" : "";
?>

<?php include 'includes/header.php'; ?>

<style>
.page-box{
    background:#111827cc;
    padding:30px;
    border-radius:16px;
    max-width:900px;
    margin-left:260px;
    margin-top:20px;
    box-shadow:0 0 25px rgba(0,0,0,.40);
    border:1px solid rgba(255,255,255,0.25);
    backdrop-filter:blur(12px);
}
.section-title{
    color:#fff;
    font-size:18px;
    margin:20px 0 10px;
    border-left:4px solid #3b82f6;
    padding-left:10px;
}
.label{
    color:#cbd5e1;
    margin-bottom:6px;
    display:block;
    font-size:15px;
}
.input-text{
    width:97%;
    padding:12px;
    border-radius:10px;
    border:none;
    margin-bottom:18px;
    background:#1f2937;
    color:white;
}
.btn{
    width:100%;
    padding:14px;
    border:none;
    background:#2563eb;
    color:white;
    border-radius:10px;
    cursor:pointer;
    font-size:16px;
    margin-top:10px;
}
.msg-success{
    background:#065f46;
    color:#ecfdf5;
    padding:12px;
    border-radius:10px;
    margin-bottom:20px;
    text-align:center;
    font-weight:bold;
}
</style>

<div class="page-box">

<h2 style="color:white; margin-bottom:20px;">📲 Editar Mensagem do WhatsApp</h2>

<?php if ($msg): ?>
<div class="msg-success" id="msgBox"><?= $msg ?></div>
<?php endif; ?>

<form method="POST" action="save_whatsapp.php">

    <div class="section-title">Modelo da Mensagem</div>

    <label class="label">Use os placeholders abaixo:</label>
    <div style="color:#9ca3af; font-size:14px; margin-bottom:10px;">
        <strong>{TITULO}</strong> = título do app <br>
        <strong>{URL_APK}</strong> = link direto do APK
    </div>

    <textarea class="input-text" name="modelo" rows="8"><?= $wpp['modelo'] ?></textarea>

    <button class="btn">Salvar Mensagem</button>

</form>

</div>

<script>
setTimeout(()=>{
    let msg=document.getElementById("msgBox");
    if(msg){
        msg.style.opacity="0";
        msg.style.transition=".4s";
        setTimeout(()=>msg.remove(),400);
    }
},1500);
</script>
