<?php
require_once __DIR__.'/includes/config.php';
require_login();

$db=db();
$type=current_owner_type();
$id=current_owner_id();

if($type === 'admin'){
    header('Location: avisos_painel.php');
    exit;
}

$rows=[];
$st=$db->prepare('SELECT * FROM panel_notices WHERE is_active=1 AND target_type=:t AND target_id=:id ORDER BY id DESC');
$st->bindValue(':t',$type,SQLITE3_TEXT);
$st->bindValue(':id',$id,SQLITE3_INTEGER);
$res=$st->execute();
while($r=$res->fetchArray(SQLITE3_ASSOC)) $rows[]=$r;

include __DIR__.'/includes/header.php';
?>
<div class="card">
    <h3>📨 Meus Avisos</h3>
    <p class="muted">Mensagens enviadas pelo administrador para sua conta.</p>
    <?php if(!$rows): ?>
        <p class="muted">Nenhum aviso no momento.</p>
    <?php endif; ?>
    <?php foreach($rows as $r): ?>
        <div class="card" style="background:#0b111a;border-color:rgba(255,138,0,.32);margin:14px 0">
            <h3 style="margin-bottom:8px">📢 <?=h($r['title'] ?: 'Aviso do Admin')?></h3>
            <div class="muted">Enviado em: <?=h($r['created_at'])?></div>
            <p style="white-space:pre-wrap;font-size:16px;line-height:1.55"><?=h($r['message'])?></p>
        </div>
    <?php endforeach; ?>
</div>
<?php include __DIR__.'/includes/footer.php'; ?>
