<?php
$clientesDao = new \Dao\Clientes();
$clientesDao->getClientePorId($conecta, base64_decode(filter_input(INPUT_GET, '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="clientes.php">Clientes</a></li>
            <li class="breadcrumb-item active"><?php echo ($clientesDao->id == 0 ? 'Adicionar Cliente' : 'Editar Cliente'); ?></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 ($clientesDao->id == 0 ? 'Adicionar Cliente' : 'Editar - ' . $clientesDao->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 $clientesDao->id; ?>">
                            <div class="form-group row">
                                <div class="col-md-2">
                                    <label class="form-label">Tipo</label>
                                    <select class="form-control" id="tipo" name="tipo" required>
                                        <option value="F" <?php echo ($clientesDao->tipo == 'F' ? 'selected' : ''); ?>>Física</option>
                                        <option value="J" <?php echo ($clientesDao->tipo == 'J' ? 'selected' : ''); ?>>Jurídica</option>
                                    </select>
                                </div><!--/.col-md-2 -->
                                <div class="col-md-3">
                                    <label class="form-label">CPF/CNPJ</label>
                                    <input type="text" name="cpf_cnpj" id="cpf_cnpj" placeholder="CPF/CNPJ" value="<?php echo $clientesDao->cpf; ?>" maxlength="18" class="form-control" required autofocus>
                                </div><!--/.col-md-3 -->
                                <div class="col-md-5">
                                    <label class="form-label">Nome</label>
                                    <input type="text" name="nome" id="nome" placeholder="Nome" value="<?php echo $clientesDao->nome; ?>" maxlength="50" class="form-control" required>
                                </div><!--/.col-md-5 -->
                                <div class="col-md-2">
                                    <label class="form-label">Situação</label>
                                    <select class="form-control" id="situacao" name="situacao">
                                        <option value="A" <?php echo ($clientesDao->situacao == 'A' ? 'selected' : ''); ?>>Ativo</option>
                                        <option value="B" <?php echo ($clientesDao->situacao == 'B' ? 'selected' : ''); ?>>Bloqueado</option>
                                    </select>
                                </div><!--/.col-md-2 -->
                            </div><!--/.form-group -->
                            <div class="form-group row">
                                <div class="col-md-2">
                                    <label class="form-label">RG</label>
                                    <input type="text" id="rg" name="rg" placeholder="RG" value="<?php echo $clientesDao->rg; ?>" class="form-control" maxlength="20">
                                </div><!--/.col-md-2 -->
                                <div class="col-md-2">
                                    <label class="form-label">Insc. Est.</label>
                                    <input type="text" id="ie" name="ie" placeholder="Insc. Est." value="<?php echo $clientesDao->ie; ?>" class="form-control" maxlength="20">
                                </div><!--/.col-md-2 -->
                                <div class="col-md-2">
                                    <label class="form-label">Sexo</label>
                                    <select class="form-control" id="sexo" name="sexo">
                                        <option value="M" <?php echo ($clientesDao->sexo == 'M' ? 'selected' : ''); ?>>Masculino</option>
                                        <option value="F" <?php echo ($clientesDao->sexo == 'F' ? 'selected' : ''); ?>>Feminino</option>
                                    </select>
                                </div><!--/.col-md-2 -->
                                <div class="col-md-4">
                                    <label class="form-label">E-mail</label>
                                    <input type="email" id="email" name="email" placeholder="E-mail" value="<?php echo $clientesDao->email; ?>" class="form-control" maxlength="60" required>
                                </div><!--/.col-md-4 -->
                                <div class="col-md-2">
                                    <label class="form-label">Est. Civil</label>
                                    <select class="form-control" id="estado_civil" name="estado_civil">
                                        <option value="Amasiado(a)" <?php echo ($clientesDao->est_civil == 'Amasiado(a)' ? 'selected' : ''); ?>>Amasiado(a)</option>
                                        <option value="Casado(a)" <?php echo ($clientesDao->est_civil == 'Casado(a)' ? 'selected' : ''); ?>>Casado(a)</option>
                                        <option value="Divorciado(a)" <?php echo ($clientesDao->est_civil == 'Divorciado(a)' ? 'selected' : ''); ?>>Divorciado(a)</option>
                                        <option value="Solteiro(a)" <?php echo ($clientesDao->est_civil == 'Solteiro(a)' ? 'selected' : ''); ?>>Solteiro(a)</option>
                                        <option value="Viuvo(a)" <?php echo ($clientesDao->est_civil == 'Viuvo(a)' ? 'selected' : ''); ?>>Viuvo(a)</option>
                                    </select>
                                </div><!--/.col-md-2 -->
                            </div><!--/.form-group -->
                            <div class="form-group row">
                                <div class="col-md-3">
                                    <label class="form-label">Data Nasc.</label>
                                    <div class="input-group" id="datePicker">
                                        <input type="text" name="data_nasc" id="data_nasc" class="form-control" value="<?php echo ($clientesDao->data_nasc == '' ? '' : date('d/m/Y', strtotime($clientesDao->data_nasc))); ?>" placeholder="Data Nascimento">
                                        <span class="input-group-addon btn-info">
                                            <i class="fa fa-calendar"></i>
                                        </span>
                                    </div><!--/.input-group -->
                                </div><!--/.col-md-3 -->
                                <div class="col-md-3">
                                    <label class="form-label">Telefone</label>
                                    <input type="tel" name="telefone" id="telefone" class="form-control" value="<?php echo $clientesDao->telefone; ?>" placeholder="Telefone" maxlength="20">
                                </div><!--/.col-md-3 -->
                                <div class="col-md-3">
                                    <label class="form-label">Celular</label>
                                    <input type="tel" name="celular" id="celular" class="form-control" value="<?php echo $clientesDao->celular; ?>" placeholder="Celular" maxlength="20">
                                </div><!--/.col-md-3 -->
                                <div class="col-md-3">
                                    <label class="form-label">Fax</label>
                                    <input type="tel" name="fax" id="fax" class="form-control" value="<?php echo $clientesDao->fax; ?>" placeholder="Fax" maxlength="20">
                                </div><!--/.col-md-3 -->
                            </div><!--/.form-group -->
                            <div class="form-group row">
                                <div class="col-md-4">
                                    <label class="form-label">Endereço</label>
                                    <input type="text" name="endereco" id="endereco" class="form-control" value="<?php echo $clientesDao->endereco; ?>" placeholder="Endereço" maxlength="60">
                                </div><!--/.col-md-4 -->
                                <div class="col-md-3">
                                    <label class="form-label">Bairro</label>
                                    <input type="text" name="bairro" id="bairro" class="form-control" value="<?php echo $clientesDao->bairro; ?>" placeholder="Bairro" maxlength="30">
                                </div><!--/.col-md-3 -->
                                <div class="col-md-2">
                                    <label class="form-label">Nº</label>
                                    <input type="number" name="numero" id="numero" class="form-control" value="<?php echo $clientesDao->num_end; ?>" placeholder="Nº" maxlength="7" min="0" max="9999999">
                                </div><!--/.col-md-2 -->
                                <div class="col-md-3">
                                    <label class="form-label">Cidade</label>
                                    <div class="input-group">
                                        <select name="cidade" id="cidade" class="form-control" data-name="cidades[]" required>
                                            <option value="0"></option>
                                            <?php
                                            $cidadesDao = new \Dao\Cidades();
                                            $lst_cidades = $cidadesDao->getLista($conecta, 'ORDER BY nome ASC');
                                            foreach ($lst_cidades as $cidade) {
                                                $selected = ($cidade->id == $clientesDao->fk_id_cidade ? 'selected' : '');
                                                echo '<option value="' . $cidade->id . '" ' . $selected . '>' . $cidade->nome . '</option>';
                                            }
                                            ?>
                                        </select>
                                        <span class="input-group-addon btn-info" data-toggle="modal" data-target="#modal_cidades">
                                            <i class="fa fa-plus"></i>
                                        </span>
                                    </div><!--/.input-group -->
                                </div><!--/.col-md-3 -->
                            </div><!--/.form-group -->
                            <div class="form-group row">
                                <div class="col-md-6">
                                    <label class="form-label">Complemento</label>
                                    <input type="text" name="complemento" id="complemento" class="form-control" value="<?php echo $clientesDao->complemento; ?>" placeholder="Complemento" maxlength="100">
                                </div><!--/.col-md-6 -->
                                <div class="col-md-3">
                                    <label class="form-label">Senha</label>
                                    <input type="password" name="senha" id="senha" class="form-control" value="<?php echo $clientesDao->senha; ?>" placeholder="Senha" maxlength="10">
                                </div><!--/.col-md-3 -->
                            </div><!--/.form-group -->
                            <div class="form-group row">
                                <div class="col-md-12 text-right">
                                    <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 -->