<?php
$f = "/var/www/html/mikrotik/views/dashboard.php";
$c = file_get_contents($f);

// 1. Corrige bug do titulo (\'ltima -> última)
$c = str_replace("Tr\xc3\xa1fego &mdash; \\'ltima 1h", "Tr\xc3\xa1fego &mdash; \xc3\xbaltima 1h", $c);
echo "TITULO OK\n";

// 2. Borda mais forte no card
$c = str_replace(
    'background:#fff;border:1px solid <?= $stBorder ?>;border-radius:16px;overflow:hidden;box-shadow:0 1px 6px rgba(0,0,0,.06)',
    'background:#fff;border:2px solid <?= $stBorder ?>;border-radius:16px;overflow:hidden;box-shadow:0 2px 10px rgba(0,0,0,.10)',
    $c
);
$c = str_replace(
    "onmouseover=\"this.style.boxShadow='0 4px 16px rgba(0,0,0,.1)'\" onmouseout=\"this.style.boxShadow='0 1px 6px rgba(0,0,0,.06)'\"",
    "onmouseover=\"this.style.boxShadow='0 6px 20px rgba(0,0,0,.15)'\" onmouseout=\"this.style.boxShadow='0 2px 10px rgba(0,0,0,.10)'\"",
    $c
);
echo "BORDA OK\n";

// 3. Labels dos textos mais escuros (↓ Entrada / ↑ Saída)
$c = str_replace(
    '<div style="font-size:0.7rem;color:#94a3b8;font-weight:700;text-transform:uppercase;letter-spacing:.05em;">' . "\xe2\x86\x93" . ' Entrada</div>',
    '<div style="font-size:0.7rem;color:#475569;font-weight:700;text-transform:uppercase;letter-spacing:.05em;">' . "\xe2\x86\x93" . ' Entrada</div>',
    $c
);
$c = str_replace(
    '<div style="font-size:0.7rem;color:#94a3b8;font-weight:700;text-transform:uppercase;letter-spacing:.05em;">' . "\xe2\x86\x91" . ' Sa' . "\xc3\xad" . 'da</div>',
    '<div style="font-size:0.7rem;color:#475569;font-weight:700;text-transform:uppercase;letter-spacing:.05em;">' . "\xe2\x86\x91" . ' Sa' . "\xc3\xad" . 'da</div>',
    $c
);
$c = str_replace(
    '<div style="font-size:0.7rem;color:#94a3b8;font-weight:700;text-transform:uppercase;letter-spacing:.05em;">Alerta</div>',
    '<div style="font-size:0.7rem;color:#475569;font-weight:700;text-transform:uppercase;letter-spacing:.05em;">Alerta</div>',
    $c
);
echo "LABELS OK\n";

// 4. Valores de entrada/saida maiores
$c = str_replace(
    '<div style="font-size:1.05rem;font-weight:800;color:#22c55e;"><?= format_bps($inBps) ?></div>',
    '<div style="font-size:1.2rem;font-weight:900;color:#16a34a;"><?= format_bps($inBps) ?></div>',
    $c
);
$c = str_replace(
    '<div style="font-size:1.05rem;font-weight:800;color:#ef4444;"><?= format_bps($outBps) ?></div>',
    '<div style="font-size:1.2rem;font-weight:900;color:#dc2626;"><?= format_bps($outBps) ?></div>',
    $c
);
echo "VALORES OK\n";

// 5. Corrige formatBps para mostrar unidades completas
$old5 = "function formatBps(v) {
    if (!v || v <= 0) return '0';
    if (v >= 1e9)  return (v/1e9).toFixed(1)  + ' G';
    if (v >= 1e6)  return (v/1e6).toFixed(1)  + ' M';
    if (v >= 1e3)  return (v/1e3).toFixed(0)  + ' K';
    return v + ' b';
}";

$new5 = "function formatBps(v) {
    if (!v || v <= 0) return '0 bps';
    if (v >= 1e9)  return (v/1e9).toFixed(2) + ' Gbps';
    if (v >= 1e6)  return (v/1e6).toFixed(2) + ' Mbps';
    if (v >= 1e3)  return (v/1e3).toFixed(1) + ' Kbps';
    return v + ' bps';
}";

if (strpos($c, $old5) !== false) {
    $c = str_replace($old5, $new5, $c);
    echo "FORMATBPS OK\n";
} else {
    echo "WARN: formatBps nao encontrado\n";
}

// 6. Linhas mais grossas e fill mais opaco no grafico
$c = str_replace(
    "borderWidth: 2, pointRadius: 0, fill: true, backgroundColor: 'rgba(34,197,94,0.08)', tension: 0.3 }",
    "borderWidth: 2.5, pointRadius: 0, fill: true, backgroundColor: 'rgba(34,197,94,0.18)', tension: 0.3 }",
    $c
);
$c = str_replace(
    "borderWidth: 2, pointRadius: 0, fill: true, backgroundColor: 'rgba(239,68,68,0.06)',  tension: 0.3 }",
    "borderWidth: 2.5, pointRadius: 0, fill: true, backgroundColor: 'rgba(239,68,68,0.14)',  tension: 0.3 }",
    $c
);
echo "CHART LINES OK\n";

// 7. Grid do eixo Y mais visivel
$c = str_replace(
    "grid: { color: 'rgba(0,0,0,.04)' }",
    "grid: { color: 'rgba(0,0,0,.08)' }",
    $c
);
echo "GRID OK\n";

file_put_contents($f, $c);
echo "DONE\n";
