<?php

require_once __DIR__ . '/../../includes/header.php';

$id = intval($_GET['id'] ?? 0);

$evento = [

    'nome' => '',
    'descricao' => '',
    'data_evento' => '',
    'hora_evento' => '',
    'local_evento' => '',
    'valor_convite' => '10.00',
    'status' => 'ATIVO'

];

if ($id > 0) {

    $stmt = $pdo->prepare("
        SELECT *
        FROM eventos
        WHERE id = :id
    ");

    $stmt->execute([
        'id' => $id
    ]);

    $evento = $stmt->fetch(PDO::FETCH_ASSOC);

}

$titulo = $id > 0
    ? 'Editar Evento'
    : 'Novo Evento';

?>

<div class="page-header">

    <div>

        <h2><?= $titulo ?></h2>

        <div class="subtitle">

            Cadastro de eventos da escola

        </div>

    </div>

    <div>

        <a
            href="eventos.php"
            class="btn btn-secondary">

            Voltar

        </a>

    </div>

</div>

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

<input
type="hidden"
name="id"
value="<?= $id ?>">

<div
class="card-premium"
style="
padding:25px;
margin-bottom:20px;
">

<h3
style="
color:var(--accent);
margin-bottom:15px;
border-bottom:1px solid var(--border);
padding-bottom:10px;
">

Dados do Evento

</h3>

<div
style="
display:grid;
grid-template-columns:
repeat(auto-fit,minmax(250px,1fr));
gap:15px;
">

<div class="form-group">

<label>Nome do Evento *</label>

<input
type="text"
name="nome"
required
value="<?= sanitize($evento['nome']) ?>">

</div>

<div class="form-group">

<label>Data *</label>

<input
type="date"
name="data_evento"
required
value="<?= $evento['data_evento'] ?>">

</div>

<div class="form-group">

<label>Horário *</label>

<input
type="time"
name="hora_evento"
required
value="<?= substr($evento['hora_evento'],0,5) ?>">

</div>

<div class="form-group">

<label>Local *</label>

<input
type="text"
name="local_evento"
required
value="<?= sanitize($evento['local_evento']) ?>">

</div>

<div class="form-group">

<label>Valor do Convite</label>

<input
type="number"
step="0.01"
name="valor_convite"
value="<?= $evento['valor_convite'] ?>">

</div>

<div class="form-group">

<label>Status</label>

<select name="status">

<option
value="ATIVO"
<?= $evento['status']=='ATIVO'
? 'selected'
: '' ?>>

ATIVO

</option>

<option
value="ENCERRADO"
<?= $evento['status']=='ENCERRADO'
? 'selected'
: '' ?>>

ENCERRADO

</option>

</select>

</div>

<div
class="form-group"
style="grid-column:1/-1;">

<label>Descrição</label>

<textarea
name="descricao"
rows="5"><?= sanitize($evento['descricao']) ?></textarea>

</div>

</div>

</div>

<div
style="
display:flex;
justify-content:flex-end;
gap:10px;
margin-bottom:30px;
">

<a
href="eventos.php"
class="btn btn-secondary">

Cancelar

</a>

<button
type="submit"
class="btn btn-novo">

Salvar Evento

</button>

</div>

</form>

<?php require_once __DIR__ . '/../../includes/footer.php'; ?>