<!--
  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 color="secondary">
    <ion-buttons slot="start">
      <ion-button (click)="close()">
        <ion-icon name="close" size="large"></ion-icon>
      </ion-button>
    </ion-buttons>
    @if (date.app_id <= 0) {
      <ion-title>Nuovo Evento</ion-title>
    }
    @if (date.app_id > 0) {
      <ion-title>Dettagli Evento</ion-title>
    }
  </ion-toolbar>
</ion-header>

<ion-content>
  <!--<ion-item *ngIf="(!date.app_id || (date.app_id && (my_user.usr_id == date.usr_id || (tipo_utenza == 'ADMIN' || tipo_utenza == 'ISPAR'))))">
  <ion-select label="Scegliere la commessa di cui si vuole prendere appuntamento" label-placement="stacked" interface="popover" [(ngModel)]="date.comm_id">
    <ion-select-option [value]="-1"> -------------------- </ion-select-option>
    <ion-select-option *ngFor="let c of lstCommesse" [value]="c?.id">{{c?.nome}}</ion-select-option>
  </ion-select>
</ion-item>-->
<ion-item>
  <ion-label>Titolo</ion-label>
  <ion-input [readonly]="date?.stato?.id && date?.stato?.id !== 1" [(ngModel)]="date.title"></ion-input>
</ion-item>
<!-- <ion-item>
<ion-label>Data Inizio</ion-label>
<ion-datetime [(ngModel)]="date.start" displayFormat="MM/DD/YYYY HH:mm"></ion-datetime>
</ion-item>
<ion-item>
  <ion-label>Data Fine</ion-label>
  <ion-datetime [(ngModel)]="date.end" displayFormat="MM/DD/YYYY HH:mm"></ion-datetime>
</ion-item> -->
<ion-item>
  <ion-label><b>{{slotText}}</b></ion-label>
</ion-item>
<ion-item>
  <ion-label><b>{{durationText}}</b></ion-label>
</ion-item>
@if (date.app_id > 0 && (my_user.usr_id == date.usr_id || (tipo_utenza == 'ADMIN'))) {
  <ion-item>
    <ion-label>Prenotato da: <b>{{date.usr_displayname}}</b></ion-label>
  </ion-item>
}
@if (date.app_id > 0 && (tipo_utenza == 'ADMIN')) {
  <ion-item>
    <ion-select label="Stato appuntamento" label-placement="stacked" interface="popover" [(ngModel)]="date.stato.id">
      <ion-select-option [value]="-1"> -------------------- </ion-select-option>
      @for (s of lstStati; track s) {
        <ion-select-option [value]="s?.id">{{s?.nome}}</ion-select-option>
      }
    </ion-select>
  </ion-item>
}
@if ((date.app_id < 0) || (date.app_id && (my_user.usr_id === date.usr_id || tipo_utenza === 'ADMIN') && date.stato.id === 1)) {
  <ion-button
    expand="full"
    (click)="save()"
    >
    Salva
  </ion-button>
}
@if (date.app_id && my_user.usr_id === date.usr_id && date.stato.id === 1) {
  <ion-button
    expand="full"
    (click)="delete()"
    >
    Elimina
  </ion-button>
}
</ion-content>