<?php 
    e($box_atendimento); 
    
    $tabelas = [
        (object)['id_titulo' => 'novos','titulo_section' => 'Novos','atendimentos' => $atendimentosAguardando??[]],
        (object)['id_titulo' => 'retornos','titulo_section' => 'Retornos','atendimentos' => $atendimentosProximoContato??[]],
        (object)['id_titulo' => 'finalizados','titulo_section' => 'Finalizados','atendimentos' => $atendimentosFinalizados??[]],
    ]
?>

<div class="animated fadeIn">
    <!--<div class="row mt-5">-->
        
    
    <div class="row">
        <div class="col-lg-12 my-5">
            <ul id="myTab" class="nav nav-tabs" role="tablist">
                <?php foreach($tabelas as $key=>$tabela){ ?>
                <li class="nav-item">
                    <a class="nav-link <?php e($key == 0?"active show":"") ?>" data-toggle="tab" href="#<?php e($tabela->id_titulo) ?>" role="tab" aria-controls="<?php e($tabela->titulo_section) ?>" aria-selected="<?php e($key == 0?"true":"false") ?>">
                        <?php e($tabela->titulo_section) ?>
                        <span class="badge badge-pill badge-danger"><?php e(count($tabela->atendimentos)) ?></span>
                    </a>
                </li>
                <?php } ?>
            </ul>
            
            <div class="tab-content">
                <?php foreach($tabelas as $key=>$tabela){ ?>
                <div class="tab-pane <?php e($key == 0?"active show":"") ?>" id="<?php e($tabela->id_titulo) ?>" role="tabpanel">
                    <?php if($tabela->id_titulo == 'novos'){ ?>
                    <div class="row">
                        <div class="col-md-12">
                            <div class="box-title-section">
                                <div class="form-inline">
                                    <div class="form-group">
                                        <label class="mr-1 text-value text-primary">Resultados da pesquisa</label>
                                    </div>
                                </div>
                                <hr>
                            </div>
                        </div>
                        <div class="col-sm-3">
                            <div class="card text-white bg-info">
                                <div class="card-body text-center">
                                    <div class="text-muted small text-uppercase font-weight-bold">Total</div>
                                    <div class="text-value-lg py-3"><?php e($total)?></div>
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-3">
                            <div class="card text-white bg-info">
                                <div class="card-body text-center">
                                    <div class="text-muted small text-uppercase font-weight-bold">Casa</div>
                                    <div class="text-value-lg py-3"><?php e($totalCasa)?></div>
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-3">
                            <div class="card text-white bg-info">
                                <div class="card-body text-center">
                                    <div class="text-muted small text-uppercase font-weight-bold">Apartamento</div>
                                    <div class="text-value-lg py-3"><?php e($totalApartamento)?></div>
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-3">
                            <div class="card text-white bg-info">
                                <div class="card-body text-center">
                                    <div class="text-muted small text-uppercase font-weight-bold">Não completaram</div>
                                    <div class="text-value-lg py-3"><?php e($totalIncompleto)?></div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <?php } ?>
                    
                    <button class="btn btn-primary mb-4" type="button" data-toggle="collapse" data-target="#collapseExample" aria-expanded="true" aria-controls="collapseExample">
                        Confira a quantidade em (%) das respostas
                    </button>

                    <div class="collapse show" id="collapseExample">
                      <div class="card card-body">


                        <?php foreach ($relatorio as $numero=>$questao): ?>
                            <p class="mb-2"><strong>O que você prefere?</strong></p>
                            <p class="mb-0"><small>
                                <strong><?= percent(((100/($questao->a+$questao->b))*$questao->a)) ?></strong> (<?= $questao->a ?>) - <?= $questao->respostas['a']['resposta'] ?> </small>
                            </p>
                            <p><small><strong><?= percent(((100/($questao->a+$questao->b))*$questao->b)) ?></strong> (<?= $questao->b ?>) - <?= $questao->respostas['b']['resposta'] ?> </small></p>
                        <?php endforeach; ?>


                        </div>
                    </div>
                    
                    <div class="table-container table-responsive">
                        <table class="display table table-striped table-bordered" style="width:100%">
                            <thead>
                                <tr>
                                    <th>Nome</th>
                                    <!--<th>E-mail</th>
                                    <th style="min-width: 85px;">Telefone</th>
                                    <th>Possui cadastro</th>-->
                                    <th class="sorting_asc_custom">Data captura</th>
                                    <th>Respostas</th>
                                    <th>Resultado</th>
                                    <?php if($tabela->id_titulo != 'novos'){ ?>
                                    <th style="min-width: 130px;">Último atendimento</th>
                                    <th style="min-width: 130px;">Proximo atendimento</th>
                                    <?php } ?>
                                    <th style="min-width: 70px;">Ação</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php foreach($tabela->atendimentos as $row) { $id = $row->id_captura; ?>
                                
                                <tr id="divImovel_<?php e($id) ?>" class="trData" data-atendimento='<?php e(json_encode($row->atendimento)) ?>'>
                                    
                                    <td><?php e($row->nome); ?></td>
                                    <!--<td><?php e($row->email); ?></td>
                                    <td><?php e($row->telefone); ?></td>
                                    <td class="text-center"><?php e($row->cadastro); ?></td>-->
                                    <?php 
                                        $nenv = '<span class="d-none">000000000</span>'.'<span class="badge badge-danger">Não enviado</span>'; 
                                        $denv = '<span class="d-none">'.$row->datetime_captura.'</span>'.(date("d/m/Y H:i:s", strtotime($row->datetime_captura)));
                                    ?>
                                    <td><?php e($row->datetime_captura == 0 ? $nenv:$denv); ?></td>
                                    <td><?php e($row->respostas); ?></td>
                                    <td><?php e($row->resultado); ?></td>
                                    
                                    <?php if($tabela->id_titulo != 'novos'){ ?>
                                        <td><p class="resumo-text m-0"><?php e(end($row->atendimento)->observacao??''); ?></p></td>
                                        <?php 
                                            $proximo_contato = end($row->atendimento)->proximo_contato??'';
                                            if($proximo_contato == 0 || $proximo_contato == '0000-00-00 00:00:00'){
                                                 $proximo_contato = '';
                                                 $alert = '<span class="d-none">z'.$proximo_contato.'</span>';
                                            }else{
                                                $alert = '<span class="d-none">a'.$proximo_contato.'</span>'.
                                                         '<span class="badge badge-danger">'.date("d/m/Y", strtotime($proximo_contato)).'</span>';
                                            }
                                            $normal = '<span class="d-none">b'.$proximo_contato.'</span>'.(date("d/m/Y", strtotime($proximo_contato)));
                                        ?>
                                        <td>
                                            <?php 
                                            $proximo_contato = end($row->atendimento)->proximo_contato??'';
                                            if($proximo_contato == 0 || $proximo_contato == '0000-00-00 00:00:00'){
                                                 $proximo_contato = '';
                                                 $alert = '<span class="d-none">z'.$proximo_contato.'</span>';
                                            }else{
                                                $alert = '<span class="d-none">a'.$proximo_contato.'</span>'.
                                                         '<span class="badge badge-danger">'.date("d/m/Y", strtotime($proximo_contato)).'</span>';
                                            }
                                            $normal = '<span class="d-none">b'.$proximo_contato.'</span>'.(date("d/m/Y", strtotime($proximo_contato)));
                                            
                                            e($proximo_contato <= date("Y-m-d H:i:s") ? $alert:$normal);
                                            ?>
                                        </td>
                                    <?php } ?>
                                    
                                    <td class="tdAction_<?php e($id) ?>" >
                                        <?php 
                                            foreach ($row->actions??[] as $action){
                                                e($action);
                                            } 
                                        ?>
                                        
                                        <button class="btn btn-sm btn-primary set_leed" data-id="<?php e($id); ?>" data-toggle="modal" data-target="#atendimentoRapidoModal" data-toggle="tooltip" data-original-title="Atendimento rápido">
                                            <i class="icon-plus"></i>
                                        </button>
                                        
                                        <button class="btn btn-sm btn-outline-success mr-1 addAtendimentoComdono set_leed" data-id="<?php e($id); ?>" data-toggle="tooltip" data-original-title="Atendimento completo">
                                            <i class="icon-check"></i>
                                        </button>
                                    </td>
                                </tr>
                                <?php } ?>
                            </tbody>
                        </table>
                    </div>
                </div>
                <?php } ?>
            </div>
        </div>
    </div>
</div>

<!-- ACTION USER     

<a href="<?php e(base_url()); ?>administrativo/usuarios/perfil/<?php e($captura->id_captura_cadastro??0)?>/<?php e($captura->id_captura_captura??0)?>" target="_blank" class="btn btn-sm btn-secondary mr-1" data-toggle="tooltip" data-original-title="Visualizar perfil">
        <i class="icon-user"></i> 
</a>-->
