<?php
session_start();

require 'conexao.php';
require 'config.php';
require 'includes/inc_verifica_caixa.php';
require 'includes/limpar_session.php';

$pdo = Conexao::getInstance();

function formatarTempo($dataCadastro)
{
  if (empty($dataCadastro)) return '';
  $agora = new DateTime();
  $data  = new DateTime($dataCadastro);
  $diff  = $agora->diff($data);
  $minutos = ($diff->days * 24 * 60) + ($diff->h * 60) + $diff->i;
  if ($minutos < 60) {
    return $minutos . 'min';
  }
  $horas = floor($minutos / 60);
  if ($horas > 99) {
    return $horas . 'h';
  }
  $mins  = $minutos % 60;
  return $horas . 'h' . ($mins > 0 ? ' ' . $mins . 'min' : '');
}

function calcularMinutos($dataCadastro)
{
  if (empty($dataCadastro)) return 0;
  $agora = new DateTime();
  $data  = new DateTime($dataCadastro);
  $diff  = $agora->diff($data);
  return ($diff->days * 24 * 60) + ($diff->h * 60) + $diff->i;
}

$sql = "SELECT v.ven_001, v.ven_027, v.ven_026, COALESCE(v.cli_001, 0) as cli_001, c.cli_002 as nome_cliente ";
$sql .= "FROM venda v LEFT JOIN clientes c ON v.cli_001 = c.cli_001 ";
$sql .= "WHERE v.sit_001 IN (8,21) AND v.ven_024 = 'C' ORDER BY v.ven_026";
$stm = $pdo->prepare($sql);
$stm->execute();
$comandas = $stm->fetchAll(PDO::FETCH_OBJ);

$comandaData = [];
foreach ($comandas as $comanda) {
  $n_comanda = $comanda->ven_026;
  $link = 'pedido.php?tipo=C&comanda=' . $comanda->ven_026 . '&venda=' . $comanda->ven_001 . '&cliente=' . $comanda->ven_027 . '&id_cliente=' . $comanda->cli_001;

  $stm2 = $pdo->prepare("SELECT sit_001 FROM venda WHERE sit_001 = 21 AND ven_026 = :num");
  $stm2->execute([':num' => $comanda->ven_026]);
  $preFechada = $stm2->fetch(PDO::FETCH_OBJ);

  if (!empty($preFechada)) {
    $status = 'pre-fechada';
    $back   = 'btn-yellow';
    $link   = 'javascript:void(0)';
  } else {
    $status = 'aberta';
    $back   = '';
  }

  $stmTempo = $pdo->prepare("SELECT MAX(data_cadastro) as ultimo_pedido FROM vendaitem WHERE ven_001 = :venda AND sit_001 = 4");
  $stmTempo->execute([':venda' => $comanda->ven_001]);
  $rowTempo = $stmTempo->fetch(PDO::FETCH_OBJ);
  $tempo = formatarTempo($rowTempo->ultimo_pedido ?? '');

  $comandaData[] = [
    'numero'       => $comanda->ven_026,
    'nome'         => $comanda->ven_027,
    'mesa'         => preg_replace('/[^0-9]/', '', $comanda->ven_027),
    'observacao'   => $comanda->ven_027,
    'nome_cliente' => (!empty($comanda->cli_001) && $comanda->cli_001 > 0) ? $comanda->nome_cliente : '',
    'link'         => $link,
    'back'         => $back,
    'status'       => $status,
    'idVenda'      => $comanda->ven_001,
    'tempo'        => $tempo,
    'tempoMinutos' => calcularMinutos($rowTempo->ultimo_pedido ?? ''),
  ];
}
?>
<!DOCTYPE html>
<html>

<head>
  <title>Comanda Eletrônica</title>
  <?php require 'includes/inc_head.php'; ?>
  <style>
    .chip-filtro.ativo {
      background: #3f51b5 !important;
      color: #fff !important;
      border-color: #3f51b5 !important;
      box-shadow: 0 2px 8px rgba(63, 81, 181, 0.3) !important;
    }

    .chip-aberta.ativo {
      background: #3f51b5 !important;
      border-color: #3f51b5 !important;
    }

    .chip-pre-fechada.ativo {
      background: #d0a000 !important;
      border-color: #b08000 !important;
      color: #fff !important;
      box-shadow: 0 2px 8px rgba(208, 160, 0, 0.3) !important;
    }

    .secao-header {
      display: flex;
      align-items: center;
      gap: 8px;
      padding: 14px 16px 6px;
      font-weight: 700;
      font-size: 13px;
      text-transform: uppercase;
      letter-spacing: 0.5px;
    }

    .secao-header:not(:first-child) {
      margin-top: 6px;
      border-top: 1px solid #f0f0f0;
    }

    .secao-header .material-icons {
      font-size: 18px;
    }

    .secao-aberta {
      color: #e74c3c;
    }

    .secao-pre-fechada {
      color: #b08000;
    }

    .secao-count {
      background: rgba(0, 0, 0, 0.08);
      border-radius: 10px;
      padding: 1px 8px;
      font-size: 12px;
      margin-left: 2px;
    }

    .secao-vazia {
      grid-column: 1 / -1;
      padding: 4px 16px 12px;
      font-size: 13px;
      color: #bdbdbd;
      white-space: nowrap;
    }

    .filtros-wrapper {
      display: flex;
      gap: 8px;
      padding: 0 12px 10px;
      overflow-x: auto;
      -webkit-overflow-scrolling: touch;
      scrollbar-width: none;
    }

    .filtros-wrapper::-webkit-scrollbar {
      display: none;
    }

    #btn-toggle-view {
      color: rgba(255, 255, 255, 0.9) !important;
    }

    /* ── Dark Theme Overrides ── */
    [data-theme="dark"] #modal-filtro-tempo>div {
      background: var(--bg-card) !important;
    }

    [data-theme="dark"] #modal-filtro-tempo>div>div:first-child {
      background: linear-gradient(135deg, #1a237e, #283593) !important;
    }

    [data-theme="dark"] .secao-header:not(:first-child) {
      border-top-color: var(--border-color);
    }

    [data-theme="dark"] .secao-count {
      background: rgba(255, 255, 255, 0.1);
    }

    [data-theme="dark"] .secao-vazia {
      color: var(--text-label);
    }

    [data-theme="dark"] #btn-filtro-tempo {
      background: var(--bg-card) !important;
      border-color: var(--color-primary) !important;
      color: var(--color-primary) !important;
    }
  </style>
</head>

<body>
  <div class="mdl-layout mdl-js-layout mdl-layout--fixed-header">
    <header class="mdl-layout__header">
      <div class="mdl-layout__header-row login">
        <span class="mdl-layout-title">Comanda Eletrônica</span>
        <div class="mdl-layout-spacer"></div>
        <button id="btn-toggle-view" class="mdl-button mdl-js-button mdl-button--icon" title="Alternar visualização">
          <i class="material-icons" id="icon-toggle-view">view_module</i>
        </button>
      </div>
    </header>

    <?php include 'includes/inc_menu.php'; ?>

    <main class="mdl-layout__content">
      <div style="padding: 10px 0 20px 0;">

        <!-- Search + Tempo filter -->
        <div class="pesquisa-wrapper" style="display:flex; align-items:center; gap:8px;">
          <div style="flex:1; position:relative;">
            <i class="material-icons pesquisa-icon">search</i>
            <input type="text" id="pesquisa" class="pesquisa-input" placeholder="Buscar por comanda ou mesa...">
          </div>
          <button id="btn-filtro-tempo" type="button" style="display:flex; align-items:center; gap:4px; padding:8px 14px; border-radius:20px; border:2px solid #3f51b5; background:#fff; color:#3f51b5; font-size:13px; font-weight:700; cursor:pointer; white-space:nowrap; box-shadow:0 1px 4px rgba(0,0,0,.1); transition:all .2s;">
            <i class="material-icons" style="font-size:18px;">schedule</i>
            <span id="btn-filtro-tempo-label">Tempo</span>
          </button>
        </div>

        <!-- Filter chips -->
        <div id="filtros-container" class="filtros-wrapper">
          <button class="mdl-button mdl-js-button btn-categoria chip-filtro ativo" data-filtro="todos">Todas</button>
          <button class="mdl-button mdl-js-button btn-categoria chip-filtro chip-aberta" data-filtro="aberta">Abertas</button>
          <button class="mdl-button mdl-js-button btn-categoria chip-filtro chip-pre-fechada" data-filtro="pre-fechada">Pré-Fechadas</button>
        </div>

        <!-- List view -->
        <div id="view-lista" class="box-comandas-flex">
          <?php foreach ($comandaData as $c): ?>
            <a href="<?= $c['link'] ?>" data-venda="<?= $c['idVenda'] ?>" data-status="<?= $c['status'] ?>"
              data-numero="<?= $c['numero'] ?>" data-nome="<?= htmlspecialchars($c['nome']) ?>" data-mesa="<?= $c['mesa'] ?>" data-tempo-min="<?= $c['tempoMinutos'] ?>"
              class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored btn-comanda <?= $c['back'] ?>">
              <span class="texto-comanda"><?= $c['numero'] ?></span>
              <?php if (!empty($c['observacao'])): ?>
                <span class="texto-mesa"><?= htmlspecialchars($c['observacao']) ?></span>
              <?php endif; ?>
              <?php if (!empty($c['nome_cliente'])): ?>
                <span class="texto-cliente"><?= htmlspecialchars($c['nome_cliente']) ?></span>
              <?php endif; ?>
              <?php if (!empty($c['tempo'])): ?>
                <span class="texto-tempo"><i class="material-icons">schedule</i><?= $c['tempo'] ?></span>
              <?php endif; ?>
            </a>
          <?php endforeach; ?>
        </div>

        <!-- Sections view -->
        <div id="view-secoes" style="display:none">
          <div class="secao-header secao-aberta">
            <i class="material-icons">restaurant</i>
            <span>Abertas</span>
            <span class="secao-count" id="count-abertas">
              <?= count(array_filter($comandaData, function ($c) {
                return $c['status'] === 'aberta';
              })) ?>
            </span>
          </div>
          <div class="box-comandas-flex" id="secao-abertas">
            <?php $abertas = array_filter($comandaData, function ($c) {
              return $c['status'] === 'aberta';
            }); ?>
            <?php if (empty($abertas)): ?>
              <p class="secao-vazia">Nenhuma comanda aberta</p>
              <?php else: foreach ($abertas as $c): ?>
                <a href="<?= $c['link'] ?>" data-venda="<?= $c['idVenda'] ?>" data-status="<?= $c['status'] ?>"
                  data-numero="<?= $c['numero'] ?>" data-nome="<?= htmlspecialchars($c['nome']) ?>" data-mesa="<?= $c['mesa'] ?>" data-tempo-min="<?= $c['tempoMinutos'] ?>"
                  class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored btn-comanda">
                  <span class="texto-comanda"><?= $c['numero'] ?></span>
                  <?php if (!empty($c['observacao'])): ?>
                    <span class="texto-mesa"><?= htmlspecialchars($c['observacao']) ?></span>
                  <?php endif; ?>
                  <?php if (!empty($c['nome_cliente'])): ?>
                    <span class="texto-cliente"><?= htmlspecialchars($c['nome_cliente']) ?></span>
                  <?php endif; ?>
                  <?php if (!empty($c['tempo'])): ?>
                    <span class="texto-tempo"><i class="material-icons">schedule</i><?= $c['tempo'] ?></span>
                  <?php endif; ?>
                </a>
            <?php endforeach;
            endif; ?>
          </div>

          <div class="secao-header secao-pre-fechada">
            <i class="material-icons">schedule</i>
            <span>Pré-Fechadas</span>
            <span class="secao-count" id="count-pre-fechadas">
              <?= count(array_filter($comandaData, function ($c) {
                return $c['status'] === 'pre-fechada';
              })) ?>
            </span>
          </div>
          <div class="box-comandas-flex" id="secao-pre-fechadas">
            <?php $preFechadas = array_filter($comandaData, function ($c) {
              return $c['status'] === 'pre-fechada';
            }); ?>
            <?php if (empty($preFechadas)): ?>
              <p class="secao-vazia">Nenhuma comanda pré-fechada</p>
              <?php else: foreach ($preFechadas as $c): ?>
                <a href="<?= $c['link'] ?>" data-venda="<?= $c['idVenda'] ?>" data-status="<?= $c['status'] ?>"
                  data-numero="<?= $c['numero'] ?>" data-nome="<?= htmlspecialchars($c['nome']) ?>" data-mesa="<?= $c['mesa'] ?>" data-tempo-min="<?= $c['tempoMinutos'] ?>"
                  class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored btn-comanda btn-yellow">
                  <span class="texto-comanda"><?= $c['numero'] ?></span>
                  <?php if (!empty($c['observacao'])): ?>
                    <span class="texto-mesa"><?= htmlspecialchars($c['observacao']) ?></span>
                  <?php endif; ?>
                  <?php if (!empty($c['nome_cliente'])): ?>
                    <span class="texto-cliente"><?= htmlspecialchars($c['nome_cliente']) ?></span>
                  <?php endif; ?>
                  <?php if (!empty($c['tempo'])): ?>
                    <span class="texto-tempo"><i class="material-icons">schedule</i><?= $c['tempo'] ?></span>
                  <?php endif; ?>
                </a>
            <?php endforeach;
            endif; ?>
          </div>
        </div>

      </div>
    </main><br><br><br>
    <button class="btn-rodape-azul adicionar">
      <i class="material-icons">add_circle</i>
      Adicionar Comanda
    </button>
  </div>

  <!-- Modal Filtro Tempo -->
  <div id="modal-filtro-tempo" style="display:none; position:fixed; inset:0; z-index:9999; background:rgba(0,0,0,.4); backdrop-filter:blur(4px); -webkit-backdrop-filter:blur(4px); align-items:center; justify-content:center;">
    <div style="background:#fff; border-radius:16px; width:90%; max-width:360px; box-shadow:0 8px 32px rgba(0,0,0,.25); overflow:hidden;">
      <div style="background:linear-gradient(135deg,#3f51b5,#5c6bc0); padding:18px 20px; display:flex; align-items:center; justify-content:space-between;">
        <div>
          <div style="display:flex; align-items:center; gap:8px; color:#fff; font-size:17px; font-weight:700;"><i class="material-icons" style="font-size:22px;">schedule</i> Filtro por Tempo</div>
          <div style="color:rgba(255,255,255,.8); font-size:12px; margin-top:4px;">Sem novos pedidos há mais de...</div>
        </div>
        <button id="modal-tempo-close" type="button" style="background:rgba(255,255,255,.15); border:none; cursor:pointer; padding:6px; border-radius:50%;"><i class="material-icons" style="color:#fff; font-size:20px;">close</i></button>
      </div>
      <div style="padding:20px; display:grid; grid-template-columns:1fr 1fr; gap:10px;">
        <button class="tempo-opt" data-tempo="0" style="padding:14px 12px; border-radius:12px; border:2px solid #c5cae9; background:#e8eaf6; font-size:14px; font-weight:600; color:#3f51b5; cursor:pointer; transition:all .2s; display:flex; align-items:center; justify-content:center; gap:6px;"><i class="material-icons" style="font-size:18px;">visibility</i> Todos</button>
        <button class="tempo-opt" data-tempo="10" style="padding:14px 12px; border-radius:12px; border:2px solid #c5cae9; background:#f5f5ff; font-size:14px; font-weight:600; color:#3f51b5; cursor:pointer; transition:all .2s; display:flex; align-items:center; justify-content:center; gap:6px;"><i class="material-icons" style="font-size:18px;">timer</i> 10 min</button>
        <button class="tempo-opt" data-tempo="20" style="padding:14px 12px; border-radius:12px; border:2px solid #c5cae9; background:#f5f5ff; font-size:14px; font-weight:600; color:#3f51b5; cursor:pointer; transition:all .2s; display:flex; align-items:center; justify-content:center; gap:6px;"><i class="material-icons" style="font-size:18px;">timer</i> 20 min</button>
        <button class="tempo-opt" data-tempo="30" style="padding:14px 12px; border-radius:12px; border:2px solid #c5cae9; background:#f5f5ff; font-size:14px; font-weight:600; color:#3f51b5; cursor:pointer; transition:all .2s; display:flex; align-items:center; justify-content:center; gap:6px;"><i class="material-icons" style="font-size:18px;">timer</i> 30 min</button>
        <button class="tempo-opt" data-tempo="40" style="padding:14px 12px; border-radius:12px; border:2px solid #c5cae9; background:#f5f5ff; font-size:14px; font-weight:600; color:#3f51b5; cursor:pointer; transition:all .2s; display:flex; align-items:center; justify-content:center; gap:6px;"><i class="material-icons" style="font-size:18px;">timer</i> 40 min</button>
        <button class="tempo-opt" data-tempo="50" style="padding:14px 12px; border-radius:12px; border:2px solid #c5cae9; background:#f5f5ff; font-size:14px; font-weight:600; color:#3f51b5; cursor:pointer; transition:all .2s; display:flex; align-items:center; justify-content:center; gap:6px;"><i class="material-icons" style="font-size:18px;">timer</i> 50 min</button>
        <button class="tempo-opt" data-tempo="60" style="padding:14px 12px; border-radius:12px; border:2px solid #c5cae9; background:#f5f5ff; font-size:14px; font-weight:600; color:#3f51b5; cursor:pointer; transition:all .2s; grid-column:span 2; display:flex; align-items:center; justify-content:center; gap:6px;"><i class="material-icons" style="font-size:18px;">timer</i> 1 hora</button>
      </div>
    </div>
  </div>

  <?php include 'includes/inc_js.php'; ?>
  <?php include 'includes/inc_notifica_js.php'; ?>
  <script>
    if (localStorage.hasOwnProperty('carrinho')) {
      localStorage.removeItem('carrinho');
    }

    $(document).ready(function($) {

      // ── View toggle ──────────────────────────────────────────────
      var VIEW_KEY = 'comandas_view_mode';
      var currentView = localStorage.getItem(VIEW_KEY) || 'lista';

      function applyView(view) {
        if (view === 'secoes') {
          $('#view-lista').hide();
          $('#filtros-container').hide();
          $('#view-secoes').show();
          $('#icon-toggle-view').text('view_list');
        } else {
          $('#view-secoes').hide();
          $('#filtros-container').show();
          $('#view-lista').show();
          $('#icon-toggle-view').text('view_module');
        }
      }

      applyView(currentView);

      // ── Tempo filter (modal) ─────────────────────────────────────
      var tempoFiltroAtivo = 0;

      $('#btn-filtro-tempo').on('click', function() {
        $('#modal-filtro-tempo').css('display', 'flex');
      });
      $('#modal-tempo-close').on('click', function() {
        $('#modal-filtro-tempo').hide();
      });
      $('#modal-filtro-tempo').on('click', function(e) {
        if (e.target === this) $(this).hide();
      });

      $('.tempo-opt').on('click', function() {
        tempoFiltroAtivo = parseInt($(this).data('tempo')) || 0;
        $('.tempo-opt').css({
          border: '2px solid #c5cae9',
          background: '#f5f5ff',
          color: '#3f51b5'
        });
        $(this).css({
          border: '2px solid #3f51b5',
          background: '#e8eaf6',
          color: '#3f51b5'
        });
        if (tempoFiltroAtivo === 0) {
          $('#btn-filtro-tempo-label').text('Tempo');
          $('#btn-filtro-tempo').css({
            background: '#fff',
            color: '#3f51b5'
          });
        } else {
          var lbl = tempoFiltroAtivo >= 60 ? '> ' + Math.floor(tempoFiltroAtivo / 60) + 'h' : '> ' + tempoFiltroAtivo + 'min';
          $('#btn-filtro-tempo-label').text(lbl);
          $('#btn-filtro-tempo').css({
            background: '#3f51b5',
            color: '#fff'
          });
        }
        $('#modal-filtro-tempo').hide();
        var termo = $('#pesquisa').val() || '';
        if (currentView === 'lista') {
          var filtro = $('.chip-filtro.ativo').data('filtro');
          applyFilters(filtro, termo);
        } else {
          filterBySearch(termo);
        }
      });

      function applyFilters(filtro, termo) {
        var str = termo.toString().toLowerCase();
        $('#view-lista .btn-comanda').each(function() {
          var status = $(this).data('status');
          var numero = $(this).data('numero').toString();
          var mesa = ($(this).data('mesa') || '').toString();
          var tMin = parseInt($(this).attr('data-tempo-min')) || 0;
          var matchF = (filtro === 'todos' || status === filtro);
          var matchS = (str === '' || numero === str || mesa === str);
          var matchT = (tempoFiltroAtivo === 0 || tMin >= tempoFiltroAtivo);
          $(this).toggle(matchF && matchS && matchT);
        });
      }

      $('#btn-toggle-view').on('click', function() {
        currentView = (currentView === 'lista') ? 'secoes' : 'lista';
        localStorage.setItem(VIEW_KEY, currentView);
        applyView(currentView);
        var termo = $('#pesquisa').val();
        if (termo) filterBySearch(termo);
      });

      // ── Filter chips ─────────────────────────────────────────────
      $(document).on('click', '.chip-filtro', function() {
        $('.chip-filtro').removeClass('ativo');
        $(this).addClass('ativo');
        var filtro = $(this).data('filtro');
        var termo = $('#pesquisa').val().toLowerCase();
        applyFilters(filtro, termo);
      });

      // ── Search ───────────────────────────────────────────────────
      function filterBySearch(termo) {
        var str = termo.toString().toLowerCase();
        if (currentView === 'lista') {
          var filtro = $('.chip-filtro.ativo').data('filtro');
          applyFilters(filtro, str);
        } else {
          $('#view-secoes .btn-comanda').each(function() {
            var numero = $(this).data('numero').toString();
            var mesa = ($(this).data('mesa') || '').toString();
            var tMin = parseInt($(this).attr('data-tempo-min')) || 0;
            var matchS = (str === '' || numero === str || mesa === str);
            var matchT = (tempoFiltroAtivo === 0 || tMin >= tempoFiltroAtivo);
            $(this).toggle(matchS && matchT);
          });
          $('#count-abertas').text($('#secao-abertas .btn-comanda:visible').length);
          $('#count-pre-fechadas').text($('#secao-pre-fechadas .btn-comanda:visible').length);
        }
      }

      $('#pesquisa').on('input', function() {
        filterBySearch($(this).val());
      });

      // ── Reabrir comanda (btn-yellow) ──────────────────────────────
      $(document).on('click', '.btn-yellow', function(e) {
        e.preventDefault();
        var venda = $(this).data('venda');
        swal({
          title: 'Deseja reabrir a Comanda?',
          type: 'question',
          showCancelButton: true,
          confirmButtonColor: '#3085d6',
          cancelButtonColor: '#d33',
          confirmButtonText: 'Sim, Reabrir!',
          cancelButtonText: 'Não Reabrir!',
          confirmButtonClass: 'btn btn-success',
          cancelButtonClass: 'btn',
          buttonsStyling: false,
          reverseButtons: true
        }).then((result) => {
          if (result.value) {
            $.ajax({
              url: 'ajax_reabrir_venda.php',
              type: 'POST',
              dataType: 'json',
              data: {
                venda: venda
              },
              beforeSend: function() {
                ProcessingModal.show({
                  text: 'Aguarde ...'
                });
              },
              success: function(retorno) {
                if (retorno.status == 1) {
                  location.reload();
                } else {
                  ProcessingModal.hide();
                }
              }
            });
          }
        });
      });

      // ── Adicionar comanda ─────────────────────────────────────────
      $('.adicionar').on('click', function() {
        var htmlModal = "<input autofocus type='number' id='numero' placeholder='Informe a Comanda' class='inpt-cliente text-red' autocomplete='off' style='margin-bottom:14px'>";
        htmlModal += "<input type='number' id='mesa' placeholder='Informe a Mesa' class='inpt-cliente text-red' autocomplete='off'>";

        swal({
          title: 'Comanda / Mesa',
          html: htmlModal,
          showCancelButton: true,
          confirmButtonColor: '#3085d6',
          cancelButtonColor: '#d33',
          confirmButtonText: 'Abrir Comanda',
          cancelButtonText: 'Cancelar',
          confirmButtonClass: 'btn btn-success',
          cancelButtonClass: 'btn btn-danger',
          buttonsStyling: false,
          reverseButtons: true,
          focusConfirm: true,
        }).then((result) => {
          if (result.value) {
            var comanda = $('#numero').val();
            var mesa = $('#mesa').val();
            if (comanda != '' && mesa != '') {
              var destino = <?= json_encode(EXIGE_CADASTRO_CLIENTE) ?> ? './cliente_pesquisa.php' : './pedido.php';
              window.location = `${destino}?tipo=C&comanda=${comanda}&cliente=Mesa%20${mesa}`;
            } else {
              swal('Alerta', 'Informe a Comanda e a Mesa!', 'warning');
            }
          }
        });
      });
    });
  </script>
</body>

</html>