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

@extends('layouts/layoutMaster')

@section('title', 'Attività - '.$attivita->nome)

@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'
])
@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-aperture"></i>
    <span class="text-muted">Stai gestendo</span>
    <span class="text-primary fw-bold text-uppercase">{{ $attivita->nome }}</span></h4>
</div>
@endsection

@section('content')
<div class="row g-3">
  {{-- Dispositivi --}}
  <div class="col-lg-3 col-sm-6">
    <div class="card card-border-shadow-info h-100">
      <div class="card-body">
        <div class="d-flex align-items-center mb-2">
          <div class="avatar me-4">
            <span class="avatar-initial rounded bg-label-info"><i class="bx bx-devices bx-lg"></i></span>
          </div>
          <h4 class="mb-0">{{ $attivita->dispositivi->count() }}</h4>
        </div>
        <p class="mb-2">Dispositivi associati</p>
        @if($attivita->dispositivi->count() > 0)
          <ul class="list-unstyled mb-0 ps-1">
            @foreach($attivita->dispositivi->take(3) as $dispositivo)
              <li><i class="bx bx-dots-horizontal-rounded small"></i> {{ $dispositivo->nome ?? $dispositivo->id }}</li>
            @endforeach
            @if($attivita->dispositivi->count() > 3)
              <li class="text-muted small">+ altri {{ $attivita->dispositivi->count() - 3 }}</li>
            @endif
          </ul>
        @else
          <p class="mb-0 text-muted small">Nessun dispositivo associato.</p>
        @endif
      </div>
    </div>
  </div>

  {{-- Eventi --}}
  <div class="col-lg-3 col-sm-6">
    <div class="card card-border-shadow-primary h-100">
      <div class="card-body">
        <div class="d-flex align-items-center mb-2">
          <div class="avatar me-4">
            <span class="avatar-initial rounded bg-label-primary"><i class="bx bx-calendar-event bx-lg"></i></span>
          </div>
          <h4 class="mb-0">{{ $attivita->eventi->count() }}</h4>
        </div>
        <p class="mb-2">Eventi associati</p>
        @if($attivita->eventi->count() > 0)
          <ul class="list-unstyled mb-0 ps-1">
            @foreach($attivita->eventi->take(3) as $evento)
              <li><i class="bx bx-dots-horizontal-rounded small"></i> {{ $evento->nome ?? $evento->id }}</li>
            @endforeach
            @if($attivita->eventi->count() > 3)
              <li class="text-muted small">+ altri {{ $attivita->eventi->count() - 3 }}</li>
            @endif
          </ul>
        @else
          <p class="mb-0 text-muted small">Nessun evento associato.</p>
        @endif
      </div>
    </div>
  </div>

  {{-- Prenotazioni --}}
  <div class="col-lg-3 col-sm-6">
    <div class="card card-border-shadow-success h-100">
      <div class="card-body">
        <div class="d-flex align-items-center mb-2">
          <div class="avatar me-4">
            <span class="avatar-initial rounded bg-label-success"><i class="bx bx-book-content bx-lg"></i></span>
          </div>
          <h4 class="mb-0">{{ $attivita->prenotazioni->count() }}</h4>
        </div>
        <p class="mb-2">Prenotazioni</p>
        @if($attivita->prenotazioni->count() > 0)
          <ul class="list-unstyled mb-0 ps-1">
            @foreach($attivita->prenotazioni->take(3) as $prenotazione)
              <li><i class="bx bx-dots-horizontal-rounded small"></i>
                @php $label = trim(($prenotazione->nome ?? '').' '.($prenotazione->cognome ?? '')); @endphp
                {{ $label !== '' ? $label : ('#'.$prenotazione->id) }}
              </li>
            @endforeach
            @if($attivita->prenotazioni->count() > 3)
              <li class="text-muted small">+ altre {{ $attivita->prenotazioni->count() - 3 }}</li>
            @endif
          </ul>
        @else
          <p class="mb-0 text-muted small">Nessuna prenotazione.</p>
        @endif
      </div>
    </div>
  </div>

  {{-- Piatti --}}
  <div class="col-lg-3 col-sm-6">
    <div class="card card-border-shadow-warning h-100">
      <div class="card-body">
        <div class="d-flex align-items-center mb-2">
          <div class="avatar me-4">
            <span class="avatar-initial rounded bg-label-warning"><i class="bx bx-food-menu bx-lg"></i></span>
          </div>
          <h4 class="mb-0">{{ $attivita->piatti->count() }}</h4>
        </div>
        <p class="mb-2">Piatti</p>
        @if($attivita->piatti->count() > 0)
          <ul class="list-unstyled mb-0 ps-1">
            @foreach($attivita->piatti->take(3) as $piatto)
              <li><i class="bx bx-dots-horizontal-rounded small"></i> {{ $piatto->nome ?? $piatto->id }}</li>
            @endforeach
            @if($attivita->piatti->count() > 3)
              <li class="text-muted small">+ altri {{ $attivita->piatti->count() - 3 }}</li>
            @endif
          </ul>
        @else
          <p class="mb-0 text-muted small">Nessun piatto associato.</p>
        @endif
      </div>
    </div>
  </div>

  {{-- Fornitori --}}
  <div class="col-lg-3 col-sm-6">
    <div class="card card-border-shadow-secondary h-100">
      <div class="card-body">
        <div class="d-flex align-items-center mb-2">
          <div class="avatar me-4">
            <span class="avatar-initial rounded bg-label-secondary"><i class="bx bx-store bx-lg"></i></span>
          </div>
          <h4 class="mb-0">{{ $attivita->fornitori->count() }}</h4>
        </div>
        <p class="mb-2">Fornitori associati</p>
        @if($attivita->fornitori->count() > 0)
          <ul class="list-unstyled mb-0 ps-1">
            @foreach($attivita->fornitori->take(3) as $fornitore)
              <li><i class="bx bx-dots-horizontal-rounded small"></i> {{ $fornitore->nome ?? $fornitore->id }}</li>
            @endforeach
            @if($attivita->fornitori->count() > 3)
              <li class="text-muted small">+ altri {{ $attivita->fornitori->count() - 3 }}</li>
            @endif
          </ul>
        @else
          <p class="mb-0 text-muted small">Nessun fornitore associato.</p>
        @endif
      </div>
    </div>
  </div>
</div>

{{-- Placeholder: da collegare a dati reali in seguito --}}
<div class="row g-3 mt-1">
  <div class="col-lg-4 col-md-6">
    <div class="card card-border-shadow-danger h-100">
      <div class="card-body">
        <div class="d-flex align-items-center mb-2">
          <div class="avatar me-3">
            <span class="avatar-initial rounded bg-label-danger"><i class="bx bx-transfer-alt bx-lg"></i></span>
          </div>
          <h5 class="mb-0">Movimenti del giorno</h5>
        </div>
        <p class="text-muted small mb-0">Placeholder: elenco movimenti della giornata corrente (da implementare).</p>
      </div>
    </div>
  </div>
  <div class="col-lg-4 col-md-6">
    <div class="card card-border-shadow-dark h-100">
      <div class="card-body">
        <div class="d-flex align-items-center mb-2">
          <div class="avatar me-3">
            <span class="avatar-initial rounded bg-label-dark"><i class="bx bx-line-chart bx-lg"></i></span>
          </div>
          <h5 class="mb-0">Bilancio anno solare</h5>
        </div>
        <p class="text-muted small mb-0">Placeholder: sintesi bilancio per l’anno solare in corso (da implementare).</p>
      </div>
    </div>
  </div>
  <div class="col-lg-4 col-md-12">
    <div class="card card-border-shadow-primary h-100">
      <div class="card-body">
        <div class="d-flex align-items-center mb-2">
          <div class="avatar me-3">
            <span class="avatar-initial rounded bg-label-primary"><i class="bx bx-wallet bx-lg"></i></span>
          </div>
          <h5 class="mb-0">Incasso giornaliero per tipo di pagamento</h5>
        </div>
        <p class="text-muted small mb-0">Placeholder: incassi di oggi ripartiti per metodo di pagamento (da implementare).</p>
      </div>
    </div>
  </div>
</div>
@endsection

@section('page-script')

@endsection
