<div class="row g-4 mt-1">
  <div class="col-12 col-lg-4 col-xl-3">
    <div class="card h-100">
      <div class="card-body text-center pt-4 pb-3">
        <div class="avatar avatar-xl mx-auto mb-3">
          <span class="avatar-initial rounded-circle bg-label-warning">
            <i class="bx bxs-user-badge bx-lg"></i>
          </span>
        </div>
        <h5 class="mb-1">{{ $attivita->nome }}</h5>
        <p class="text-muted small mb-2">Saltacoda cliente</p>

        @if($saltacoda->is_attivo)
          <span class="badge bg-label-success mb-3">Servizio attivo</span>
        @else
          <span class="badge bg-label-danger mb-3">Servizio disattivato</span>
        @endif

        <ul class="list-unstyled text-start small mb-0">
          <li class="d-flex justify-content-between py-2 border-bottom">
            <span class="text-muted">Pre-ordini in coda</span>
            <span class="badge bg-label-primary">{{ $stats['pre_ordini_in_coda'] ?? 0 }}</span>
          </li>
          <li class="d-flex justify-content-between py-2 border-bottom">
            <span class="text-muted">Max ordini</span>
            <span class="fw-medium">{{ $saltacoda->max_ordini ?: 'Illimitato' }}</span>
          </li>
          <li class="d-flex justify-content-between py-2 border-bottom">
            <span class="text-muted">Cucine attive</span>
            <span class="badge bg-label-info">{{ $stats['cucine_attive'] ?? 0 }}</span>
          </li>
          <li class="d-flex justify-content-between py-2">
            <span class="text-muted">Piatti attivi</span>
            <span class="badge bg-label-info">{{ $stats['piatti_attivi'] ?? 0 }}</span>
          </li>
        </ul>
      </div>
      <div class="card-body border-top pt-3 d-grid gap-2">
        @if($saltacoda->is_attivo)
          <a href="{{ $clienteUrl }}" target="_blank" rel="noopener" class="btn btn-primary btn-sm">
            <i class="bx bx-link-external me-1"></i> Anteprima cliente
          </a>
        @else
          <button type="button" class="btn btn-primary btn-sm" disabled title="Attiva il servizio per aprire l'anteprima">
            <i class="bx bx-link-external me-1"></i> Anteprima cliente
          </button>
        @endif
        <button type="button" class="btn btn-label-secondary btn-sm" data-sc-go-tab="#sc-tab-generali">
          <i class="bx bx-cog me-1"></i> Modifica impostazioni
        </button>
      </div>
    </div>
  </div>

  <div class="col-12 col-lg-8 col-xl-9">
    <div class="row g-4">
      <div class="col-md-6">
        <div class="card h-100">
          <div class="card-header">
            <h5 class="card-title mb-0">
              <i class="bx bx-info-circle text-primary me-1"></i>
              Stato servizio
            </h5>
          </div>
          <div class="card-body">
            <dl class="row mb-0">
              <dt class="col-sm-5 text-muted">Attività</dt>
              <dd class="col-sm-7 fw-medium">{{ $attivita->nome }}</dd>
              <dt class="col-sm-5 text-muted">Stato</dt>
              <dd class="col-sm-7">
                @if($saltacoda->is_attivo)
                  <span class="badge bg-label-success">Abilitato</span>
                @else
                  <span class="badge bg-label-danger">Disabilitato</span>
                @endif
              </dd>
              <dt class="col-sm-5 text-muted">Limite coda</dt>
              <dd class="col-sm-7">{{ $saltacoda->max_ordini > 0 ? $saltacoda->max_ordini . ' ordini' : 'Nessun limite' }}</dd>
              <dt class="col-sm-5 text-muted">Ultimo aggiornamento</dt>
              <dd class="col-sm-7">{{ $saltacoda->updated_at?->format('d/m/Y H:i') ?? '—' }}</dd>
            </dl>
          </div>
        </div>
      </div>

      <div class="col-md-6">
        <div class="card h-100">
          <div class="card-header">
            <h5 class="card-title mb-0">
              <i class="bx bx-restaurant text-primary me-1"></i>
              Menu cliente
            </h5>
          </div>
          <div class="card-body d-flex flex-column">
            <p class="text-muted small mb-3">
              Il menu del saltacoda mostra le cucine e i piatti attivi dell'attività corrente.
            </p>
            @if(($stats['piatti_attivi'] ?? 0) === 0)
              <div class="alert alert-warning py-2 px-3 small mb-3" role="alert">
                Nessun piatto attivo: il menu cliente risulterà vuoto.
              </div>
            @endif
            <div class="d-flex flex-wrap gap-2 mt-auto">
              <a href="{{ route('cucina.index') }}" class="btn btn-sm btn-outline-primary">
                <i class="bx bx-food-menu me-1"></i> Cucine
              </a>
              <a href="{{ route('piatto.index') }}" class="btn btn-sm btn-outline-primary">
                <i class="bx bx-dish me-1"></i> Piatti
              </a>
            </div>
          </div>
        </div>
      </div>

      <div class="col-12">
        <div class="card">
          <div class="card-header">
            <h5 class="card-title mb-0">
              <i class="bx bx-link text-primary me-1"></i>
              Link per i clienti
            </h5>
          </div>
          <div class="card-body">
            <p class="text-muted small mb-2">URL diretto al menu saltacoda (da QR code o messaggio):</p>
            <div class="input-group">
              <input type="text" class="form-control form-control-sm" id="sc-cliente-url" readonly value="{{ $clienteUrl }}">
              <button type="button" class="btn btn-outline-primary btn-sm" id="sc-copy-cliente-url">
                <i class="bx bx-copy me-1"></i> Copia
              </button>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
