<div class="animated fadeIn">
    <div class="row">
        <!-- .col-->
        <div class="col-md-12">
            
            
            <div id="accordion">
                <!-- /.row-->
                <div class="row">
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-header"><a href="#" data-toggle="collapse" data-target="#collapseOportunidades" aria-expanded="true" class=""><i class="icon-home"></i> Oportunidades</a>
                                <div class="card-header-actions">
                                    <a class="card-header-action btn-minimize" href="#" data-toggle="collapse" data-target="#collapseOportunidades" aria-expanded="true" class="">
                                        <i class="icon-arrow-up"></i>
                                    </a>
                                </div>
                            </div>
                            <div class="collapse show" id="collapseOportunidades" data-parent="#accordion">
                                <div class="card-body">
                                    <div class="table-container table-responsive">
                                        <table class="display table table-striped table-bordered" style="width:100%">
                                            <thead>
                                                <tr>
                                                    <th>Bairro</th>
                                                    <th>Tipo</th>
                                                    <th>Titulo</th>
                                                    <th>Valor</th>
                                                    <th>Origem</th>
                                                    <th>Status</th>
                                                    <th>Ação</th>
                                                </tr>
                                            </thead>
                                            
                                            <tbody>
                                                <?php foreach ($olxs as $key => $imv){ ?>
                                                    <tr id="olx_<?php e($imv->id); ?>">
                                                        
                                                        <td><?php e($imv->bairro); ?></td>
                                                        <td><?php e($imv->tipo_imovel); ?></td>
                                                        <td><?php e($imv->titulo); ?></td>
                                                        <td><?php e($imv->val_public_total); ?></td>
                                                        <td>OLX</td>
                                                        <td>
                                                            <?php if($imv->status == ''){ ?>
                                                                <a class="badge"><span class="d-none">zzz</span>Aguardando</a>
                                                            <?php }else if($imv->status == 'Negado'){ ?>
                                                                <a class="badge badge-danger"><?php e($imv->status);?></a>
                                                            <?php }else if($imv->status == 'Aguardando'){ ?>
                                                                <a class="badge badge-warning"><?php e($imv->status);?></a>
                                                            <?php }else{ ?>
                                                                <a class="badge badge-success"><?php e($imv->status);?></a>
                                                            <?php } ?>
                                                        </td>
                                                        
                                                        <td>
                                                            <ul class="list-inline m-0">
                                                                <li class="list-inline-item" data-toggle="tooltip" data-placement="top" title="" data-original-title="Visualizar imóvel">
                                                                    <a class="btn btn-primary mb-1" target="_blank" href="<?php e($imv->url); ?>" ><i class="icon-eye"></i></a>
                                                                </li>
                                                                <?php if(!empty($imv->atendimento)){ ?>
                                                                <a href="<?php e(base_url().'administrativo/atendimento/atendimento_geral/olx/'.$imv->atendimento[0]->id_atendimento); ?>" class="actAtendimento btn btn-success mb-1" data-id="<?php e($imv->atendimento[0]->id_atendimento); ?>" data-toggle="tooltip" data-original-title="Visualizar atendimento">
                                                                    <i class="icon-check"></i>
                                                                </a>
                                                                <?php }else{ ?>
                                                                <a href="javascript:;" class="_addAtendimentoGeral btn btn-primary mb-1 set_leed" data-id="<?php e($imv->id); ?>" data-origem="olx" type="button" data-toggle="modal" data-target="#primaryModal">
                                                                    <i class="icon-plus"></i>
                                                                </a>
                                                                <?php } ?>
                                                                            
                                                                 <?php if($imv->status == ''){ ?>
                                                                 
                                                                    <li class="list-inline-item" data-toggle="tooltip" data-placement="top" title="" data-original-title="Gerar atendimento">
                                                                        <button class="btn btn-success mb-1 set_leed" data-id="<?php e($imv->id); ?>" data-origem="olx" type="button" data-toggle="modal" data-target="#successModal">
                                                                            <i class="icon-like"></i>
                                                                        </button>
                                                                    </li>
                                                                    <li class="list-inline-item" data-toggle="tooltip" data-placement="top" title="" data-original-title="Dispensar">
                                                                        <button class="btn btn-danger mb-1 set_leed" data-id="<?php e($imv->id); ?>" data-origem="olx" type="button" data-toggle="modal" data-target="#dangerModal">
                                                                            <i class="icon-dislike"></i>
                                                                        </button>
                                                                    </li>
                                                                    
                                                                    <?php } else if($imv->status == 'Negado'){ ?>
                                                                     <li class="list-inline-item" data-toggle="tooltip" data-placement="top" title="" data-original-title="<?php e($imv->motivo);?>">
                                                                        <button class="btn btn-secondary mb-1">
                                                                            <i class="icon-info"></i>
                                                                        </button>
                                                                    </li> 
                                                                 
                                                                    <?php }else{?>
                                                                    <li class="list-inline-item" data-toggle="tooltip" data-placement="top" title="" data-original-title="Visualizar Cartões">
                                                                        <a class="btn btn-primary mb-1"  href="<?php e(base_url('administrativo/operacao/quadro/1')); ?>" >Cartões</a>
                                                                    </li>
                                                                     <?php } ?>
                                                                </td> 
                                                            </ul>
                                                        </a>
                                                    </tr>
                                                <?php } ?>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                
                <div class="row">
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-header"><a href="#" data-toggle="collapse" data-target="#collapseAguardando" aria-expanded="true" class=""><i class="icon-home"></i> Aguardando Retorno</a>
                                <div class="card-header-actions">
                                    <a class="card-header-action btn-minimize" href="#" data-toggle="collapse" data-target="#collapseAguardando" aria-expanded="true" class="">
                                        <i class="icon-arrow-up"></i>
                                    </a>
                                </div>
                            </div>
                            <div class="collapse show" id="collapseAguardando" data-parent="#accordion">
                                <div class="card-body">
                                    <div class="table-container table-responsive">
                                        <table class="display table table-striped table-bordered" style="width:100%">
                                            <thead>
                                                <tr>
                                                    <th>Bairro</th>
                                                    <th>Tipo</th>
                                                    <th>Titulo</th>
                                                    <th>Valor</th>
                                                    <th>Origem</th>
                                                    <th>Status</th>
                                                    <th style="min-width: 130px;">Último atendimento</th>
                                                    <th style="min-width: 130px;">Proximo atendimento</th>
                                                    <th>Ação</th>
                                                </tr>
                                            </thead>
                                            
                                            <tbody>
                                                <?php foreach ($olxsAguradando as $key => $imv){ ?>
                                                    <tr id="olx_<?php e($imv->id); ?>">
                                                        
                                                        <td><?php e($imv->bairro); ?></td>
                                                        <td><?php e($imv->tipo_imovel); ?></td>
                                                        <td><?php e($imv->titulo); ?></td>
                                                        <td><?php e($imv->val_public_total); ?></td>
                                                        <td>OLX</td>
                                                        <td>
                                                            <?php if($imv->status == ''){ ?>
                                                                <a class="badge"><span class="d-none">zzz</span>Aguardando</a>
                                                            <?php }else if($imv->status == 'Negado'){ ?>
                                                                <a class="badge badge-danger"><?php e($imv->status);?></a>
                                                            <?php }else if($imv->status == 'Aguardando'){ ?>
                                                                <a class="badge badge-warning"><?php e($imv->status);?></a>
                                                            <?php }else{ ?>
                                                                <a class="badge badge-success"><?php e($imv->status);?></a>
                                                            <?php } ?>
                                                        </td>
                                                        <td><p class="resumo-text m-0"><?php e(end($imv->atendimento)->observacao??''); ?></p></td>
                                                        <td>
                                                            <?php 
                                                            $proximo_contato = end($imv->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>
                                                        <td>
                                                            <ul class="list-inline m-0">
                                                                <li class="list-inline-item" data-toggle="tooltip" data-placement="top" title="" data-original-title="Visualizar imóvel">
                                                                    <a class="btn btn-primary mb-1" target="_blank" href="<?php e($imv->url); ?>" ><i class="icon-eye"></i></a>
                                                                </li>
                                                                
                                                                <a href="<?php e(base_url().'administrativo/atendimento/atendimento_geral/olx/'.$imv->atendimento[0]->id_atendimento); ?>" class="actAtendimento btn btn-success mb-1" data-id="<?php e($imv->atendimento[0]->id_atendimento); ?>" data-toggle="tooltip" data-original-title="Visualizar atendimento">
                                                                    <i class="icon-check"></i>
                                                                </a>
                                                                            
                                                                 <?php if($imv->status == 'Iniciado'){ ?>
                                                                     
                                                                     <li class="list-inline-item" data-toggle="tooltip" data-placement="top" title="" data-original-title="Visualizar Cartões">
                                                                        <a class="btn btn-primary mb-1"  href="<?php e(base_url('administrativo/operacao/quadro/1')); ?>" >Cartões</a>
                                                                    </li>
                                                                 
                                                                 
                                                                 
                                                                 
                                                                    
                                                                    
                                                                    <?php } else if($imv->status == 'Negado'){ ?>
                                                                     <li class="list-inline-item" data-toggle="tooltip" data-placement="top" title="" data-original-title="<?php e($imv->motivo);?>">
                                                                        <button class="btn btn-secondary mb-1">
                                                                            <i class="icon-info"></i>
                                                                        </button>
                                                                    </li> 
                                                                 
                                                                    <?php }else{?>
                                                                        <li class="list-inline-item" data-toggle="tooltip" data-placement="top" title="" data-original-title="Gerar atendimento">
                                                                            <button class="btn btn-success mb-1 set_leed" data-id="<?php e($imv->id); ?>" data-origem="olx" type="button" data-toggle="modal" data-target="#successModal">
                                                                                <i class="icon-like"></i>
                                                                            </button>
                                                                        </li>
                                                                        <li class="list-inline-item" data-toggle="tooltip" data-placement="top" title="" data-original-title="Dispensar">
                                                                            <button class="btn btn-danger mb-1 set_leed" data-id="<?php e($imv->id); ?>" data-origem="olx" type="button" data-toggle="modal" data-target="#dangerModal">
                                                                                <i class="icon-dislike"></i>
                                                                            </button>
                                                                        </li>
                                                                     <?php } ?>
                                                                </td> 
                                                            </ul>
                                                        </a>
                                                    </tr>
                                                <?php } ?>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                
                
                <div class="row">
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-header"><a href="#" data-toggle="collapse" data-target="#collapseFinalizados" aria-expanded="true" class=""><i class="icon-home"></i> Finalizados</a>
                                <div class="card-header-actions">
                                    <a class="card-header-action btn-minimize" href="#" data-toggle="collapse" data-target="#collapseFinalizados" aria-expanded="true" class="">
                                        <i class="icon-arrow-up"></i>
                                    </a>
                                </div>
                            </div>
                            <div class="collapse show" id="collapseFinalizados" data-parent="#accordion">
                                <div class="card-body">
                                    <div class="table-container table-responsive">
                                        <table class="display table table-striped table-bordered" style="width:100%">
                                            <thead>
                                                <tr>
                                                    <th>Bairro</th>
                                                    <th>Tipo</th>
                                                    <th>Titulo</th>
                                                    <th>Valor</th>
                                                    <th>Origem</th>
                                                    <th>Status</th>
                                                    <th style="min-width: 130px;">Último atendimento</th>
                                                    <th style="min-width: 130px;">Proximo atendimento</th>
                                                    <th>Ação</th>
                                                </tr>
                                            </thead>
                                            
                                            <tbody>
                                                <?php foreach ($olxsFinalizado as $key => $imv){ ?>
                                                    <tr id="olx_<?php e($imv->id); ?>">
                                                        
                                                        <td><?php e($imv->bairro); ?></td>
                                                        <td><?php e($imv->tipo_imovel); ?></td>
                                                        <td><?php e($imv->titulo); ?></td>
                                                        <td><?php e($imv->val_public_total); ?></td>
                                                        <td>OLX</td>
                                                        <td>
                                                            <?php if($imv->status == ''){ ?>
                                                                <a class="badge"><span class="d-none">zzz</span>Aguardando</a>
                                                            <?php }else if($imv->status == 'Negado'){ ?>
                                                                <a class="badge badge-danger"><?php e($imv->status);?></a>
                                                            <?php }else if($imv->status == 'Aguardando'){ ?>
                                                                <a class="badge badge-warning"><?php e($imv->status);?></a>
                                                            <?php }else{ ?>
                                                                <a class="badge badge-success"><?php e($imv->status);?></a>
                                                            <?php } ?>
                                                        </td>
                                                        <td><p class="resumo-text m-0"><?php e(end($imv->atendimento)->observacao??''); ?></p></td>
                                                        <td>
                                                            <?php 
                                                            $proximo_contato = end($imv->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>
                                                        <td>
                                                            <ul class="list-inline m-0">
                                                                <li class="list-inline-item" data-toggle="tooltip" data-placement="top" title="" data-original-title="Visualizar imóvel">
                                                                    <a class="btn btn-primary mb-1" target="_blank" href="<?php e($imv->url); ?>" ><i class="icon-eye"></i></a>
                                                                </li>
                                                                
                                                                <a href="<?php e(base_url().'administrativo/atendimento/atendimento_geral/olx/'.$imv->atendimento[0]->id_atendimento); ?>" class="actAtendimento btn btn-success mb-1" data-id="<?php e($imv->atendimento[0]->id_atendimento); ?>" data-toggle="tooltip" data-original-title="Visualizar atendimento">
                                                                    <i class="icon-check"></i>
                                                                </a>
                                                                            
                                                                 <?php if($imv->status == 'Iniciado'){ ?>
                                                                     
                                                                     <li class="list-inline-item" data-toggle="tooltip" data-placement="top" title="" data-original-title="Visualizar Cartões">
                                                                        <a class="btn btn-primary mb-1"  href="<?php e(base_url('administrativo/operacao/quadro/1')); ?>" >Cartões</a>
                                                                    </li>
                                                                 
                                                                 
                                                                 
                                                                 
                                                                    
                                                                    
                                                                    <?php } else if($imv->status == 'Negado'){ ?>
                                                                     <li class="list-inline-item" data-toggle="tooltip" data-placement="top" title="" data-original-title="<?php e($imv->motivo);?>">
                                                                        <button class="btn btn-secondary mb-1">
                                                                            <i class="icon-info"></i>
                                                                        </button>
                                                                    </li> 
                                                                 
                                                                    <?php }else{?>
                                                                        <li class="list-inline-item" data-toggle="tooltip" data-placement="top" title="" data-original-title="Gerar atendimento">
                                                                            <button class="btn btn-success mb-1 set_leed" data-id="<?php e($imv->id); ?>" data-origem="olx" type="button" data-toggle="modal" data-target="#successModal">
                                                                                <i class="icon-like"></i>
                                                                            </button>
                                                                        </li>
                                                                        <li class="list-inline-item" data-toggle="tooltip" data-placement="top" title="" data-original-title="Dispensar">
                                                                            <button class="btn btn-danger mb-1 set_leed" data-id="<?php e($imv->id); ?>" data-origem="olx" type="button" data-toggle="modal" data-target="#dangerModal">
                                                                                <i class="icon-dislike"></i>
                                                                            </button>
                                                                        </li>
                                                                     <?php } ?>
                                                                </td> 
                                                            </ul>
                                                        </a>
                                                    </tr>
                                                <?php } ?>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                
                <!-- .row
                <div class="row">
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-header"><a href="#" data-toggle="collapse" data-target="#collapsePrecadastros" aria-expanded="false" class="collapsed"><i class="icon-wallet"></i> Pre-cadastros</a>
                                <div class="card-header-actions">
                                    <a class="card-header-action btn-minimize" href="#" data-toggle="collapse" data-target="#collapsePrecadastros" aria-expanded="false" class="collapsed">
                                        <i class="icon-arrow-up"></i>
                                    </a>
                                </div>
                            </div>
                            <div class="collapse" id="collapsePrecadastros" data-parent="#accordion">
                                <div class="card-body">
                                    <div class="table-container table-responsive">
                                        <table class="display table table-striped table-bordered" style="width:100%">
                                            <thead>
                                                <tr>
                                                    <th>Imóvel</th>
                                                    <th>Valor imóvel</th>
                                                    <th>Valor entrada</th>
                                                    <th>Parcelas</th>
                                                    <th>Ação</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <tr>
                                                    <td class="text-center">
                                                        <div class="avatar">
                                                        <img class="img-avatar" src="https://s3.us-west-2.amazonaws.com/dev.comdono/anunciante/2/perfil/bg-avaliacao-rs.jpg" alt="admin@bootstrapmaster.com">
                                                        <span class="avatar-status badge-success"></span>
                                                        </div>
                                                    </td>
                                                    <td>R$ 448.999,00</td>
                                                    <td>R$ 112.899,90</td>
                                                    <td>180</td>
                                                    <td><a href="<?php e(base_url('administrativo/financiamentos/bancos/52')); ?>" target="_blank"><i class="icon-credit-card font-2xl"></i></a>
                                                </tr>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- /.row-->
                <!-- .row
                <div class="row">
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-header"><a href="#" data-toggle="collapse" data-target="#collapseCapturas" aria-expanded="false" class="collapsed"><i class="icon-wallet"></i> Capturas</a>
                                <div class="card-header-actions">
                                    <a class="card-header-action btn-minimize" href="#" data-toggle="collapse" data-target="#collapseCapturas" aria-expanded="false" class="collapsed">
                                        <i class="icon-arrow-up"></i>
                                    </a>
                                </div>
                            </div>
                            <div class="collapse" id="collapseCapturas" data-parent="#accordion">
                                <div class="card-body">
                                    <div class="table-container table-responsive">
                                        <table class="display table table-striped table-bordered" style="width:100%">
                                            <thead>
                                                <tr>
                                                    <th>Imóvel</th>
                                                    <th>Valor imóvel</th>
                                                    <th>Valor entrada</th>
                                                    <th>Parcelas</th>
                                                    <th>Ação</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <tr>
                                                    <td class="text-center">
                                                        <div class="avatar">
                                                        <img class="img-avatar" src="https://s3.us-west-2.amazonaws.com/dev.comdono/anunciante/2/perfil/bg-avaliacao-rs.jpg" alt="admin@bootstrapmaster.com">
                                                        <span class="avatar-status badge-success"></span>
                                                        </div>
                                                    </td>
                                                    <td>R$ 448.999,00</td>
                                                    <td>R$ 112.899,90</td>
                                                    <td>180</td>
                                                    <td><a href="<?php e(base_url('administrativo/financiamentos/bancos/52')); ?>" target="_blank"><i class="icon-credit-card font-2xl"></i></a>
                                                </tr>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- /.row-->
            </div>
        </div>
    </div>
</div>
 
<div class="modal fade" id="primaryModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
    <div class="modal-dialog modal-primary" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title">Atendimento</h4>
                <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>
            </div>
            <div class="modal-body">
                <p><strong>O cliente já foi contactado?</strong> Descreva o seu atendimento abaixo.</p>
                <form id="formAtenderAnuncio" action="" method="post">
                    <div class="form-group">
                       <label for="observacao">Observação</label>
                       <textarea name="observacao"  class="form-control" required="required"></textarea>
                    </div>
                </form>
                <div class="erroFormAtenderAnuncio"></div>
            </div>
            <div class="modal-footer">
                <button class="btn btn-primary btnAtenderAnuncio" type="button"><i class="fa fa-check"></i> Adicionar</button>
                <button class="btn btn-secondary" type="button" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="successModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
    <div class="modal-dialog modal-success" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title">Atendimento</h4>
                <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>
            </div>
            <div class="modal-body">
                <p>O cliente já foi contactado e tem interesse em anunciar Comdono?</p>
                <form id="formAceitarAnuncio" action="" method="post">
                    <div class="form-group">
                       <label for="observacao">Observação</label>
                       <textarea name="observacao"  class="form-control" required="required"></textarea>
                    </div>
                </form>
                <div class="erroAceitarAnuncio"></div>
            </div>
            <div class="modal-footer">
                <a href="javascript:;" class="btn btn-success _ini_olx btnAceitarAnuncio">Iniciar atendimento</a>
                <button class="btn btn-secondary" type="button" data-dismiss="modal">Fechar</button>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="dangerModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
    <div class="modal-dialog modal-danger" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title">Atendimento</h4>
                <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>
            </div>
            <div class="modal-body">
                <p><strong>Você realmente deseja negar esse anúnicio?</strong> Informe o motivo abaixo.</p>
                <form id="formNegarAnuncio" action="" method="post">
                    <div class="form-group">
                       <label for="observacao">Observação</label>
                       <textarea name="observacao"  class="form-control" required="required"></textarea>
                    </div>
                </form>
                <div class="erroFormNegarAnuncio"></div>
            </div>
            <div class="modal-footer">
                <button class="btn btn-danger btnNegarAnuncio" type="button">Negar anúncio</button>
                <button class="btn btn-secondary" type="button" data-dismiss="modal">Fechar</button>
            </div>
        </div>
    </div>
</div>