@php

$riga_ordine = \App\Models\RigaOrdine::find($riga_ordine_id)??null;
$piatto = $riga_ordine->piatto??null;
@endphp

@switch($cmd)
    @case('aumenta')
        <button 
        class="btn btn-sm btn-success d-flex align-items-center justify-content-center p-0" 
        style="width: 32px; height: 32px;" 
        onclick="aumentaQuantita({{ $piatto_id }}, {{ $riga_ordine_id }})" 
        data-action="aumenta" data-piatto-id="{{ $piatto_id }}" data-riga-ordine-id="{{ $riga_ordine_id }}">
            <i class="bx fs-xlarge bx-plus"></i>
        </button>
        @break
    @case('diminuisci')
        <button 
        class="btn btn-sm btn-warning d-flex align-items-center justify-content-center p-0" 
        style="width: 32px; height: 32px;" 
        onclick="diminuisciQuantita({{ $piatto_id }}, {{ $riga_ordine_id }})" 
        data-action="diminuisci" data-piatto-id="{{ $piatto_id }}" data-riga-ordine-id="{{ $riga_ordine_id }}">
            <i class="bx fs-xlarge bx-minus"></i>
        </button>
        @break
    @case('elimina')
        <button 
        class="btn btn-sm btn-danger d-flex align-items-center justify-content-center p-0" 
        style="width: 32px; height: 32px;" 
        onclick="eliminaRiga({{ $piatto_id }}, {{ $riga_ordine_id }})" 
        data-action="elimina" data-piatto-id="{{ $piatto_id }}" data-riga-ordine-id="{{ $riga_ordine_id }}">
            <i class="bx fs-xlarge  bx-trash"></i>
        </button>
        @break
    
    @case('quantita')
        <button 
        class="col col-sm-4 col-4 col-md-4 col-xl-4 col-xxl-4 btn btn-sm btn-warning align-items-center justify-content-center p-0" 
        style="width: 32px; height: 32px;" 
        onclick="diminuisciQuantita({{ $piatto_id }}, {{ $riga_ordine_id }})" 
        data-action="diminuisci" data-piatto-id="{{ $piatto_id }}" data-riga-ordine-id="{{ $riga_ordine_id }}">
            <i class="bx fs-xlarge bx-minus"></i>
        </button>
        
        <span class="mx-4 fw-bolder fs-5 col col-sm-4 col-4 col-md-4 col-xl-4 col-xxl-4 text-center">{{ $riga_ordine->quantita }}</span>

        <button 
        class="col col-sm-4 col-4 col-md-4 col-xl-4 col-xxl-4 btn btn-sm btn-success align-items-center justify-content-center p-0" 
        style="width: 32px; height: 32px;" 
        onclick="aumentaQuantita({{ $piatto_id }}, {{ $riga_ordine_id }})" 
        data-action="aumenta" data-piatto-id="{{ $piatto_id }}" data-riga-ordine-id="{{ $riga_ordine_id }}">
            <i class="bx fs-xlarge bx-plus"></i>
        </button>
        @break

    @case('piatto')
        <!-- <i class="bx bx-dish me-2"></i> -->
        {{$riga_ordine->piatto->nome}}
        <br>

        <small class="">
            @if($riga_ordine->note)
                <i class="bx bx-note me-2 text-warning" aria-label="Nota"></i> {{ $riga_ordine->note }}
            @else
            <button title="Aggiungi nota" class="btn-expand-hover btn btn-primary mt-1" style="padding:revert;" onclick="aggiungiNota({{ $piatto_id }}, {{ $riga_ordine_id }}, '')" data-action="aggiungi_nota" data-piatto-id="{{ $piatto_id }}" data-riga-ordine-id="{{ $riga_ordine_id }}">
                <i class="bx bx-note me-1" aria-label="Nota"></i>
                <span class="btn-expand-label">nota</span>
            </button>
            @endif

            @if($riga_ordine->quantita > 1)
            <button title="Aggiungi variante" class="btn-expand-hover btn btn-primary mt-1" style="padding:revert;" onclick="aggiungiVariante({{ $piatto_id }}, {{ $riga_ordine_id }})" data-action="aggiungi_variante" data-piatto-id="{{ $piatto_id }}" data-riga-ordine-id="{{ $riga_ordine_id }}">
                <i class="bx bx-category-alt me-1" aria-label="Variante"></i>
                <span class="btn-expand-label">variante</span>
            </button>
            @endif
            <!-- <button 
            title="Elimina dal carrello"
                class="btn-expand-hover btn btn-danger mt-1"
                style="padding:revert;"
                onclick="eliminaRiga({{ $piatto->id }}, {{ $riga_ordine_id }})" 
                data-action="elimina" data-piatto-id="{{ $piatto->id }}" data-riga-ordine-id="{{ $riga_ordine_id }}">
                <i class="bx bx-trash"></i>
                <span class="btn-expand-label">elimina</span>
            </button> -->
            
        <!-- </small>
        <small> -->
            @if($riga_ordine->piatto->elencoAllergeni->isNotEmpty())
            <button class=" badge p-1 btn bg-warning text-white align-items-center justify-content-center p-0">
                <i class="bx bx-info-circle me-1 " aria-label="Allergeni"></i> allergeni
            </button>
            @endif
        <!-- </small> -->
        @break


        @case('colonna_action')

            <small>
                @if($riga_ordine->note)
                    <span class="text-muted small">{{ $riga_ordine->note }}</span>
                @else
                <span class="text-muted small fst-italic">—</span>
                @endif

                @if($riga_ordine->quantita > 1)
                <button title="Aggiungi variante" class="btn-expand-hover btn btn-primary mt-1" style="padding:revert;" onclick="aggiungiVariante({{ $piatto_id }}, {{ $riga_ordine_id }})" data-action="aggiungi_variante" data-piatto-id="{{ $piatto_id }}" data-riga-ordine-id="{{ $riga_ordine_id }}">
                    <i class="bx bx-category-alt me-1" aria-label="Variante"></i>
                    <span class="btn-expand-label">variante</span>
                </button>
                @endif
                <button 
                title="Elimina dal carrello"
                    class="btn-expand-hover btn btn-danger mt-1"
                    style="padding:revert;"
                    onclick="eliminaRiga({{ $piatto->id }}, {{ $riga_ordine_id }})" 
                    data-action="elimina" data-piatto-id="{{ $piatto->id }}" data-riga-ordine-id="{{ $riga_ordine_id }}">
                    <i class="bx bx-trash"></i>
                    <span class="btn-expand-label">elimina</span>
                </button>

            </small>

        @break

    @case('note')
        @if($riga_ordine && $riga_ordine->note)
            <span class="text-muted small">{{ $riga_ordine->note }}</span>
        @else
            <span class="text-muted small fst-italic">—</span>
        @endif
        @break

    @case('menu')
    
<button 
    title="Elimina dal carrello"
    class="btn-expand-hover btn btn-danger mt-1"
    style="padding:revert;"
    onclick="eliminaRiga({{ $piatto->id }}, {{ $riga_ordine_id }})" 
    data-action="elimina" data-piatto-id="{{ $piatto->id }}" data-riga-ordine-id="{{ $riga_ordine_id }}">
    <i class="bx bx-trash"></i>
    <span class="btn-expand-label">elimina</span>
</button>
<button 
    class="mb-4 details-control col col-sm-4 col-4 col-md-4 col-xl-4 col-xxl-4 btn btn-sm  align-items-center justify-content-center p-0" 
    style="width: 32px; height: 32px;" 
    data-action="menu" 
    data-bs-toggle="collapse" data-bs-target="#accordionPopoutIcon-{{ $riga_ordine_id }}" aria-expanded="true" aria-controls="accordionPopoutIcon-{{ $riga_ordine_id }}"
    >
        <i class="bx fs-xlarge bx-chevron-down"></i>
</button>

    @break

    @case('dettagli')

    @if($riga_ordine->piatto->descrizione || $riga_ordine->piatto->elencoAllergeni->isNotEmpty())
    @if($riga_ordine->piatto->descrizione)
    <div class="mb-4 row justify-content-between px-5 col-sm-12 col-md-12 col-lg-12 col-xl-12">
        <div class="col-auto">
            <small><span class="fw-bold">Descrizione:</span> {!! $riga_ordine->piatto->descrizione !!}</small>
        </div>
        @endif
        @if($riga_ordine->piatto->elencoAllergeni->isNotEmpty())
        <div class="col-auto">
            <small>
             <span class="fw-bold">Allergeni:</span> {{ $riga_ordine->piatto->elencoAllergeni->pluck('nome')->implode(', ') }}
            </small>
        </div>
        @endif
    </div>
    @endif
    <div class="row justify-content-between px-5 col-sm-12 col-md-12 col-lg-12 col-xl-12">
        <div class="col-auto mt-2">
            <button 
                    class="badge bg-warning d-flex align-items-center justify-content-center p-2 w-auto" 
                    onclick="aggiungiNota({{ $piatto->id }}, {{ $riga_ordine_id }}, '{{ $riga_ordine->note }}')" 
                    data-action="aggiungi_nota" data-piatto-id="{{ $piatto->id }}" data-riga-ordine-id="{{ $riga_ordine_id }}">
                    @if($riga_ordine->note)
                        <i class="bx bx-pencil me-2"></i> <span class="fw-bold">Nota: &nbsp;</span> {{ $riga_ordine->note }}
                    @else
                        <i class="bx bx-plus me-2"></i> Aggiungi nota
                    @endif
                </button>
        </div>
        <div class="col-auto mt-2">
                <button 
                class="col-auto badge bg-danger d-flex align-items-center justify-content-center p-2 w-auto" 
                onclick="eliminaRiga({{ $piatto->id }}, {{ $riga_ordine_id }})" 
                data-action="elimina" data-piatto-id="{{ $piatto->id }}" data-riga-ordine-id="{{ $riga_ordine_id }}">
                <i class="bx bx-trash"></i>
                Elimina dal carrello
            </button>
        </div>
</div>
        @break

    @default
    ND
    @break
@endswitch