<?php $render('header', ['loggedUser'=>$loggedUser, 'title'=>$titlePage]); ?>
<?=$render('sidebar', [
  'loggedUser'=>$loggedUser, 
  'pageActive'=>$pageActive,
  'permissions'=>$permissions
]);?>

<!-- Content System -->
<div class="content-wrapper">
  <div class="pages">
    <h3>CRM</h3>
    <div class="users">
      <div class="bar-top">
        <a href="<?=$base;?>/inititeration" class="btn btn-primary mr" style="width: 200px;">Iniciar Interação</a>
        <!-- Pesquisas -->

        <div class="right">
          <!-- End Busca por status -->
          <div class="right one">
            <form method="POST" action="<?=$base;?>/crm">
              <input type="hidden" id="isclear" name="filter[clear]">
              <!-- Busca por digitação -->
              <div class="right two">

                <!-- <div class="dates" style="display: flex; margin-right: 10px;">
                  <input type="text" name="filter[d_init]" id="dateInit" class="form-control" style="width: 120px!important;" placeholder="00/00/0000" value="<?= $arrayInfo['d_init']; ?>">

                  <input type="text" name="filter[d_end]" id="dateEnd" class="form-control" style="width: 120px!important; margin-left: 10px;" placeholder="00/00/0000" value="<?= $arrayInfo['d_end']; ?>">
                </div> -->

                <!-- Categoria de Produtos -->
                <select class="form-control" name="filter[status]">
                  <option <?= ($arrayInfo['status'] == '1')?'selected':''; ?> value="1">Ativa</option>
                  <option <?= ($arrayInfo['status'] == '2')?'selected':''; ?> value="2">Pausada</option>
                  <option <?= ($arrayInfo['status'] == '3')?'selected':''; ?> value="3">Ambos</option>                  
                </select>

                <!-- Categoria de Produtos -->
                <select class="form-control" name="filter[category]">
                  <option value="">Categoria</option>
                  <option <?= ($arrayInfo['category'] == '3')?'selected':''; ?> value="3">Ambos</option>
                  <option <?= ($arrayInfo['category'] == '1')?'selected':''; ?> value="1">Genética</option>
                  <option <?= ($arrayInfo['category'] == '2')?'selected':''; ?> value="2">Insumos</option>                  
                </select>

                <!-- Tipo de Interação -->
                <select class="form-control" name="filter[type_interaction]">
                  <option value="">Ambos</option>
                  <option <?= ($arrayInfo['type_interaction'] == '1')?'selected':''; ?> value="1">Cliente</option>
                  <option <?= ($arrayInfo['type_interaction'] == '2')?'selected':''; ?> value="2">Prospecção</option>
                </select>


                <!--Blue select-->
                <select class="form-control" name="filter[opt]" id="opt">
                  <option <?= ($arrayInfo['opt'] == 'client_name')?'selected':''; ?> value="client_name">Nome</option>
                </select>
                <input type="text" name="filter[tag]" value="<?= $arrayInfo['tag'] ?>" class="form-control" placeholder="Digite aqui..." id="busca">
              </div>

              <input type="text" name="filter[limit]" id="max_result" class="form-control" value="<?= $arrayInfo['limit']; ?>" style="display: none;">
              <!-- End Busca por digitação -->

              <button type="submit" class="proccess">PROCESSAR</button>
              <button id="interactions_list" class="proccess">LIMPAR</button>
            </form>
          </div>      
        </div>
      </div>

      <!-- Message -->
      <?php if(!empty($message)): ?>
        <div class="alert <?=$message['alertType'];?>" role="alert">
          <input type="hidden" name="ref" value="<?= $message['ref']; ?>">
          <?= $message['text']; ?>
          <button class="btn btn-primary" id="set-message-read">OK</button>
        </div>
      <?php endif; ?>
      <!-- /Message -->

      <table class="table table-hover">
        <tbody>
          <tr>
            <th scope="col">Item</th>
            <th scope="col">Próxima Interação</th>
            <th scope="col">Vendedor</th>
            <th scope="col">Cliente</th>
            <th scope="col">Ações</th>
          </tr>
          <?php foreach($result as $key => $item): ?>
            <tr class="<?= $item['color']; ?>">
              <td><?= ($key + 1); ?></td>
              <td><?= $item['last_message']['next_interation']; ?></td>
              <td><?= $item['last_message']['salesman_name']; ?></td>
              <td><?= $item['last_message']['client_name']; ?></td>
              <td><a href="<?=$base;?>/viewinteraction?cvt=<?= $item['id']; ?>" class="btn btn-info mbt">Visualizar</a></td>
            </tr>
          <?php endforeach; ?>
        </tbody>
      </table>

    </div>
    <script src="<?=$base;?>/assets/js/crm.js"></script>
  </div>  		
</div>
<!-- /.content-system -->

<?=$render('footer');?>