<!--
  Questo file fa parte di MyTown.
  MyTown è software libero: puoi ridistribuirlo e/o modificarlo secondo
  i termini della GNU Affero General Public License come pubblicata dalla
  Free Software Foundation, versione 3.
  Distribuito senza ALCUNA GARANZIA; vedi la GNU AGPL v3 per i dettagli.
  Copyright (C) Kondor Consulting & Services S.r.l.
  SPDX-License-Identifier: AGPL-3.0-or-later
-->
<ion-header>
  <ion-toolbar>
    <ion-segment [(ngModel)]="selectedSegment" (ionChange)="onSegmentChange()">
      <ion-segment-button value="tutte">
        <ion-label>Tutte</ion-label>
      </ion-segment-button>
      <ion-segment-button value="attive">
        <ion-label>Attive</ion-label>
      </ion-segment-button>
      <ion-segment-button value="completate">
        <ion-label>Completate</ion-label>
      </ion-segment-button>
    </ion-segment>
  </ion-toolbar>
</ion-header>

<ion-content>
  <ion-refresher slot="fixed" (ionRefresh)="loadBookings($event)">
    <ion-refresher-content></ion-refresher-content>
  </ion-refresher>

  <ion-list>
    @for (booking of filteredBookings; track booking) {
      <ion-item button (click)="goToDettaglio(booking)" detail [ngClass]="'item-' + booking.bkb_status.toLowerCase()">
        <ion-label>
          <h2>{{ ((booking.bkb_resource_ids?.length || 0) >= 2 && booking.bkb_resource_alias) ? booking.bkb_resource_alias : (booking.bkr_name || 'Risorsa non assegnata') }}</h2>
          <p>{{ booking.bkb_date | date:'dd/MM/yyyy' }} &bull; {{ booking.bkts_name || booking.bkb_start_time }}</p>
          <p>{{ booking.bkb_customer_name }} &bull; {{ booking.bkb_guests_count }} ospiti</p>
        </ion-label>
        <ion-badge slot="end" [color]="getStatusColor(booking.bkb_status)">
          {{ getStatusLabel(booking.bkb_status) }}
        </ion-badge>
        @if (fatturaStampabile(booking)) {
          <ion-button slot="end" fill="clear" size="small" title="Fattura prenotazione"
                      (click)="$event.stopPropagation(); printInvoice(booking)">
            <ion-icon slot="icon-only" name="document-text-outline"></ion-icon>
          </ion-button>
        }
        @if (fatturaOrdineStampabile(booking)) {
          <ion-button slot="end" fill="clear" size="small" title="Fattura ordine"
                      (click)="$event.stopPropagation(); printInvoiceOrder(booking)">
            <ion-icon slot="icon-only" name="receipt-outline"></ion-icon>
          </ion-button>
        }
      </ion-item>
    }
  </ion-list>

  @if (filteredBookings.length === 0) {
    <div class="ion-text-center ion-padding">
      <ion-icon name="calendar-outline" size="large" color="medium"></ion-icon>
      <p color="medium">Nessuna prenotazione trovata</p>
    </div>
  }
</ion-content>
