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

$empresa = $pdo->query("SELECT * FROM empresa LIMIT 1")->fetch();
$e = $empresa ?: ['nome'=>'','nome_fantasia'=>'','cnpj'=>'','telefone'=>'','email'=>'','endereco'=>'','cep'=>'','numero'=>'','bairro'=>'','cidade'=>'','estado'=>'','logo'=>''];
$id = $empresa ? intval($empresa['id']) : 0;
$titulo = $id > 0 ? 'Editar Dados da Empresa' : 'Cadastrar Empresa';
?>

<div class="page-header">
    <div><h2><?= $titulo ?></h2><div class="subtitle">Informacoes cadastrais da escola</div></div>
    <div><a href="empresa.php" class="btn btn-secondary">Voltar</a></div>
</div>

<form method="POST" action="empresa_salvar.php" enctype="multipart/form-data">
<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 Principais</h3>
    <div style="display:grid;grid-template-columns:repeat(auto-fit,minmax(220px,1fr));gap:15px;">
        <div class="form-group"><label>Razao Social *</label><input name="nome" value="<?= sanitize($e['nome']) ?>" required></div>
        <div class="form-group"><label>Nome Fantasia</label><input name="nome_fantasia" value="<?= sanitize($e['nome_fantasia']) ?>"></div>
        <div class="form-group"><label>CNPJ</label><input name="cnpj" value="<?= sanitize($e['cnpj']) ?>"></div>
        <div class="form-group"><label>Telefone</label><input name="telefone" value="<?= sanitize($e['telefone']) ?>"></div>
        <div class="form-group"><label>Email</label><input type="email" name="email" value="<?= sanitize($e['email']) ?>"></div>
    </div>
</div>

<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;">Endereco</h3>
    <div style="display:grid;grid-template-columns:repeat(auto-fit,minmax(220px,1fr));gap:15px;">
        <div class="form-group" style="grid-column:span 2;"><label>Endereco</label><input name="endereco" value="<?= sanitize($e['endereco']) ?>"></div>
        <div class="form-group"><label>CEP</label><input name="cep" value="<?= sanitize($e['cep']) ?>"></div>
        <div class="form-group"><label>Numero</label><input name="numero" value="<?= sanitize($e['numero']) ?>"></div>
        <div class="form-group"><label>Bairro</label><input name="bairro" value="<?= sanitize($e['bairro']) ?>"></div>
        <div class="form-group"><label>Cidade</label><input name="cidade" value="<?= sanitize($e['cidade']) ?>"></div>
        <div class="form-group"><label>Estado</label><input name="estado" value="<?= sanitize($e['estado']) ?>"></div>
    </div>
</div>

<div style="display:flex;gap:10px;justify-content:flex-end;margin-bottom:30px;">
    <a href="empresa.php" class="btn btn-secondary">Cancelar</a>
    <button type="submit" class="btn btn-novo">Salvar Empresa</button>
</div>
</form>

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