<?php
use App\Models\Role;
use Illuminate\Support\Facades\Auth;
?>
@php
$configData = Helper::appClasses();
$cucine = $cucine ?? collect();
@endphp

@extends('layouts/layoutMaster')

@section('title', 'Cassa')

@section('vendor-style')
@vite([
'resources/assets/vendor/libs/datatables-bs5/datatables.bootstrap5.scss',
'resources/assets/vendor/libs/datatables-responsive-bs5/responsive.bootstrap5.scss',
'resources/assets/vendor/libs/datatables-buttons-bs5/buttons.bootstrap5.scss',
'resources/assets/vendor/libs/flatpickr/flatpickr.scss',
'resources/assets/vendor/libs/@form-validation/form-validation.scss',
'resources/assets/vendor/scss/pages/front-page-payment.scss',
])
@endsection

<!-- Vendor Scripts -->
@section('vendor-script')
@vite([
'resources/assets/vendor/libs/moment/moment.js',
'resources/assets/vendor/libs/flatpickr/flatpickr.js',
'resources/assets/vendor/libs/@form-validation/popular.js',
'resources/assets/vendor/libs/@form-validation/bootstrap5.js',
'resources/assets/vendor/libs/@form-validation/auto-focus.js',
'resources/assets/vendor/libs/@form-validation/popular.js',
'resources/assets/vendor/libs/@form-validation/bootstrap5.js',
'resources/assets/vendor/libs/@form-validation/auto-focus.js',
'resources/assets/vendor/libs/datatables-bs5/datatables-bootstrap5.js'
])
@endsection

@section('pageTitle')
<div class="d-flex flex-column">
  <h4 class="mb-1"> 
    <i class="bx bx-store"></i> <span class="text-primary">{{ $punto_vendita->nome??'Punto di vendita ND' }}</span>
    <span class="text-muted fs-6 fw-normal">· Cassa</span>
  </h4>
</div>
@endsection

@section('content')
<style>
  div.upload button:first-child{
    display: none !important;
  }

.bx-chef-hat{
  --svg: url("data:image/svg+xml,%3csvg width='24' height='24' fill='currentColor' viewBox='0 0 24 24' transform='' xmlns='http://www.w3.org/2000/svg'%3e%3c!--Boxicons v3.0.8 https://boxicons.com %7c License https://docs.boxicons.com/free--%3e%3cpath d='M17.13 5.54C16.33 3.42 14.32 2 12 2S7.67 3.42 6.87 5.54A5.506 5.506 0 0 0 2 11c0 2.07 1.18 3.95 3 4.88V18c0 .55.45 1 1 1h12c.55 0 1-.45 1-1v-2.12c1.82-.93 3-2.81 3-4.88 0-2.82-2.13-5.15-4.87-5.46m.53 8.75c-.4.14-.67.52-.67.94v1.78H7v-1.78c0-.42-.27-.8-.67-.94-1.4-.5-2.33-1.82-2.33-3.28 0-1.93 1.57-3.5 3.42-3.5.04 0 .14.01.18.02.49 0 .9-.31 1-.78.36-1.61 1.76-2.73 3.41-2.73s3.05 1.12 3.41 2.73c.1.47.51.81 1 .78.06 0 .12 0 .09-.01 1.93 0 3.5 1.57 3.5 3.5 0 1.47-.94 2.79-2.33 3.28ZM5 20h14v2H5z'%3e%3c/path%3e%3c/svg%3e");
}
</style>

@include('_partials.status', ['success' => session('success'), 'error' => session('error')])

<div class="row g-4 justify-content-center mt-0">
  <div class="col-12 col-xl-8 d-flex">
    @include('punto_vendita.cassa._partials.menu_cucine', ['cucine' => $cucine, 'punto_vendita' => $punto_vendita])
  </div>
  <div class="col-12 col-xl-4 d-flex flex-column">
    <div class="card border shadow-sm w-100 h-100">
      <div class="card-body text-center pt-2 d-flex align-items-center justify-content-between">
        <i class="bx bx-cart fs-4 text-muted"></i>
        <h6 class="mt-2 mb-0">Carrello #({{ $ordine->id}})</h6>
        <div class="dropdown">
          <button class="btn text-muted p-0" type="button" id="transactionID" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
            <i class="bx bx-dots-vertical-rounded bx-lg text-primary fs-4"></i>
          </button>
          <div class="dropdown-menu dropdown-menu-end" aria-labelledby="transactionID">
            <a class="dropdown-item" href="javascript:void(0);" onclick="showInfoPuntoVendita()">Informazioni punto vendita</a>
            <a class="dropdown-item" href="javascript:void(0);" onclick="stampaRiepilogo()">Stampa riepilogo</a>
            <a class="dropdown-item" href="javascript:void(0);" onclick="chiudiPuntoVendita(alert('Chiudi {{ $punto_vendita->tipo}}'))">Chiudi {{ $punto_vendita->tipo}}</a>
          </div>
        </div>
      </div>
      <div class=" carrello-container card-body p-0 text-start">
        @include('punto_vendita.cassa._partials.carrello.riepilogo')
      </div>
      <div class=" carrello-container card-body pt-0 text-start">
      <div id="accordionPopoutIcon" class="accordion mt-3 accordion-popout">
        {{ $dataTable_rigaordine->table() }}
        <!-- @foreach($ordine->righe_ordine as $riga_ordine)
          @include('punto_vendita.cassa._partials.carrello.righe_ordine' , ['riga_ordine' => $riga_ordine])
        @endforeach -->
        </div>
      </div>
    </div>
  </div>
</div>


<!-- Modal basic -->
<div class="modal fade" id="basicModal" tabindex="-1" aria-hidden="true">
            <div class="modal-dialog" role="document">
              <div class="modal-content">
                <div class="modal-header">
                  <h5 class="modal-title" id="exampleModalLabel1"></h5>
                  <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                  
                </div>
                <div class="modal-footer">

              </div>
              </div>
            </div>
          </div>


@endsection

@section('footer')
  <div class="footer mt-4 text-center">
    <span class="text-muted fs-6 fw-normal">
      Stampa su: 
      {{ $punto_vendita->stampante_dispositivo()->nome?? 'ND' }}
      di ({{ $punto_vendita->stampante_dispositivo()->endpoint->label ?? 'ND' }})
    </span>
  </div>
@endsection

@section('page-script')


{{ $dataTable_rigaordine->scripts(attributes: ['type' => 'module']) }}
<script>

    
  document.querySelectorAll('.cassa-piatto-card').forEach(function (card) {
    card.addEventListener('click', function () {
      document.dispatchEvent(new CustomEvent('cassa-piatto-tap', {
        bubbles: true,
        detail: {
          piattoId: card.getAttribute('data-piatto-id'),
          nome: card.getAttribute('data-piatto-nome'),
          prezzo: card.getAttribute('data-piatto-prezzo'),
          cucinaId: card.getAttribute('data-cucina-id')
        }
      }));
    });
    card.addEventListener('keydown', function (e) {
      if (e.key === 'Enter' || e.key === ' ') {
        e.preventDefault();
        card.click();
      }
    });
  });
</script>

@include('punto_vendita.cassa._partials.scripts')

@endsection
