<?php
$id = filter_input(INPUT_GET, 'id');
if ($id !== null) {
    $cadastroDao = new \Dao\Cadastro();
    $cadastroDao->getCadastroPorId($conecta, base64_decode($id));
}
?>

<div class="breadcrumb-holder">
    <div class="container-fluid">
        <ul class="breadcrumb">
            <li class="breadcrumb-item"><a href="./">Home</a></li>
            <li class="breadcrumb-item"><a href="cadastro.php">Cadastro</a></li>
            <li class="breadcrumb-item active"><?php echo ($cadastroDao->id == 0 ? 'Adicionar Cadastro' : 'Editar Cadastro'); ?></li>
        </ul><!--/.breadcrumb -->
    </div><!---/.container-fluid -->
</div><!--/.breadcrumb-holder -->
<section class="dashboard-counts section-padding">
    <div class="container-fluid">
        <div class="row">
            <div class="col-lg-12">
                <div class="card">
                    <div class="card-header d-flex align-items-center">
                        <h2 class="h5 display"><?php echo ($cadastroDao->id == 0 ? 'Adicionar Cadastro' : 'Editar - ' . $cadastroDao->nome); ?></h2>
                    </div><!--/.card-header -->
                    <div class="card-body">
                        <form class="form-horizontal" method="post" action="?p=salvar" enctype="multipart/form-data">
                            <input type="hidden" name="id" id="id" value="<?php echo $cadastroDao->id; ?>">
                            <div class="form-group row">
                                <label class="col-sm-2 form-label">Nome</label>
                                <div class="col-sm-7">
                                    <input type="text" name="nome" id="nome" placeholder="Nome" value="<?php echo $cadastroDao->nome; ?>" maxlength="120" class="form-control" required autofocus>
                                </div><!--/.col-sm-7 -->
                            </div><!--/.form-group -->
                            <div class="form-group row">
                                <label class="col-sm-2 form-label">Telefone</label>
                                <div class="col-sm-7">
                                    <input type="text" name="telefone" id="telefone" placeholder="Telefone" value="<?php echo $cadastroDao->telefone; ?>" class="form-control" required>
                                </div><!--/.col-sm-7 -->
                            </div><!--/.form-group -->
                            <div class="form-group row">
                                <label class="col-sm-2 form-label">RG</label>
                                <div class="col-sm-7">
                                    <input type="text" name="rg" id="rg" placeholder="RG" value="<?php echo $cadastroDao->rg; ?>" class="form-control">
                                </div><!--/.col-sm-7 -->
                            </div><!--/.form-group -->
                            <div class="form-group row">
                                <label class="col-sm-2 form-label">CPF</label>
                                <div class="col-sm-7">
                                    <input type="text" name="cpf" id="cpf" placeholder="CPF" value="<?php echo $cadastroDao->cpf; ?>" class="form-control">
                                </div><!--/.col-sm-7 -->
                            </div><!--/.form-group -->
                            <div class="form-group row">
                                <label class="col-sm-2 form-label">Email</label>
                                <div class="col-sm-7">
                                    <input type="email" name="email" id="email" placeholder="Email" value="<?php echo $cadastroDao->email; ?>" class="form-control">
                                </div><!--/.col-sm-7 -->
                            </div><!--/.form-group -->
                            <div class="form-group row">
                                <label class="col-sm-2 form-label">Endereço</label>
                                <div class="col-sm-7">
                                    <input type="text" name="endereco" id="endereco" placeholder="Endereço" value="<?php echo $cadastroDao->endereco; ?>" class="form-control">
                                </div><!--/.col-sm-7 -->
                            </div><!--/.form-group -->
                            <div class="form-group row">
                                <label class="col-sm-2 form-label">Cidade</label>
                                <div class="col-sm-7">
                                    <input type="text" name="cidade" id="cidade" placeholder="Cidade" value="<?php echo $cadastroDao->cidade; ?>" class="form-control">
                                </div><!--/.col-sm-7 -->
                            </div><!--/.form-group -->
                            <div class="form-group row">
                                <label class="col-sm-2 form-label">Estado</label>
                                <div class="col-sm-7">
                                    <input type="text" name="estado" id="estado" placeholder="Estado" value="<?php echo $cadastroDao->estado; ?>" class="form-control">
                                </div><!--/.col-sm-7 -->
                            </div><!--/.form-group -->
							<div class="form-group row">
                                <label class="col-sm-2 form-label">Data de Nascimento</label>
                                <div class="col-sm-7">
                                    <input type="date" name="data_nascimento" id="data_nascimento" placeholder="Data de Nascimento" value="<?php echo $cadastroDao->data_nascimento; ?>" class="form-control">
                                </div><!--/.col-sm-7 -->
                            </div><!--/.form-group -->
                            <div class="form-group row">
                                <label class="col-sm-2 form-label">Dependentes</label>
                                <div class="col-sm-7">
                                    <input type="number" name="dependentes" id="dependentes" placeholder="Número de Dependentes" value="<?php echo $cadastroDao->dependentes; ?>" class="form-control">
                                </div><!--/.col-sm-7 -->
                            </div><!--/.form-group -->
                            <!-- Adicione outros campos conforme necessário -->
                            <div class="form-group row">
                                <label class="col-sm-2 form-label"></label>
                                <div class="col-sm-12">
                                    <button class="btn btn-sm btn-primary">
                                        <i class="fa fa-database"></i> Salvar
                                    </button>
                                </div>
                            </div><!--/.form-group -->
                        </form>
                    </div><!--/.card-body -->
                </div><!--/.card -->
            </div><!--/.col-lg-12 -->
        </div><!--/.row -->
    </div><!--/.container-fluid -->
</section><!--/.dashboard-counts -->
