<ion-header class="header-subpage" no-border>
  <ion-toolbar>
    <ion-title class="titolo-sezione-head">voglio un parere</ion-title>
  </ion-toolbar>
</ion-header>

<ion-content class="chats">
  <div class="contenitore-home">
    <div class="central-doc">
      <div [ngSwitch]="parere" ngDefaultControl>
        
        <div *ngSwitchCase="'lista'">
          <div class="search-date  date-div">
            <div class="float-date">
              <ion-item class="item-no-border">
                <ion-checkbox name="privacy" [(ngModel)]="archiviati" class="check"> </ion-checkbox>
                <ion-label>Visualizza Archiviati</ion-label>
              </ion-item>
              <ion-item class="item-no-border">
                <ion-button (click)="cercaPareri()" class="search-arrow" title="Cerca pareri"><ion-icon class="button-icon" slot="icon-only" name="arrow-round-forward" title="Cerca documenti"></ion-icon></ion-button>
              </ion-item>
            </div>
            <div class="clr"></div>

            <ion-item class="item-no-border" id="buttonsPareri" style="display:none">
                <div *ngIf="!archiviati">
                  Archivia Pareri
                  <ion-button (click)="archiviaPareri(true)" class="search-arrow" title="Archivia Pareri"><ion-icon class="button-icon" slot="icon-only" name="archive" title="Archivia Pareri"></ion-icon></ion-button>
                </div>
                <div *ngIf="archiviati">
                  Togli pareri dall'archivio
                  <ion-button (click)="archiviaPareri(false)" class="search-arrow" title="Riattiva Pareri"><ion-icon class="button-icon" slot="icon-only" name="undo" title="Riattiva documenti"></ion-icon></ion-button>
                </div>                
            </ion-item>
          </div>
          <div *ngFor="let parere of pareri; trackBy: trackByDoc" class="chat-list"> 
            <ion-checkbox name="privacy" [(ngModel)]="parere.checked" class="check" (click)="checkSelected(parere.idRichiesta)"> </ion-checkbox>          
            <div class="row-chat-list">
              <div class="data" text-wrap>
                {{parere.data}}
                <a class="select" (click)="apriParere(parere.idRichiesta)" tappable title="Visualizza dettaglio">
                  <ion-icon name="arrow-round-forward"></ion-icon>
                </a>
                <a class="select" (click)="loadPareri('initial')" tappable title="Aggiorna pareri">
                  <ion-icon name="refresh-circle"></ion-icon>
                </a>
                <div text-wrap>{{parere.titolo}}</div>
              </div>
            </div>
          </div>
          <!--<div class="foo-button" center>
            <div class="round-btn">
              <a (click)="createNuovoParere()" tappable>
                <ion-icon name="add" [style.color]="'#FFFFFF'"></ion-icon>
              </a>
            </div>
          </div>-->
        </div>

        <div *ngSwitchCase="'dettaglio'">
          <div class="back">
            <a (click)="apriLista()" tappable>
              <ion-icon name="arrow-round-back" [style.color]="'#2b94d1'" title="Torna alla lista dei pareri"></ion-icon>
            </a>
          </div>
          <div class="quesito">
            {{parereAttivo.titolo}}
          </div>
          <div class="from-me">
            <div class="io">io - {{parereAttivo.data}}</div>
            <p>{{parereAttivo.testo}}</p>
            <div class="download-doc" *ngIf="parereAttivo.nomeFile != null">
              <div class="image" title="Scarica allegato">
                <a *ngIf="!platform.is('desktop')" (click)="getFile(parereAttivo.idRichiesta, parereAttivo.nomeFile, true);" target="_blank" download><ion-icon name="cloud-download" [style.color]="'#e5e5ea'"></ion-icon></a>
                <a *ngIf="platform.is('desktop')" href="{{parereAttivo.url}}" target="_blank" download><ion-icon name="cloud-download" [style.color]="'#e5e5ea'"></ion-icon></a>
              </div>
              <div class="filename">{{parereAttivo.nomeFile}}</div>
            </div>
          </div>
          <div class="clr"></div>
          <div class="from-them" *ngIf="parereAttivo.interventi.length > 0">
            <div class="operatore">{{parereAttivo.interventi[0].utente}} - {{parereAttivo.interventi[0].data}}</div>
            <p>{{parereAttivo.interventi[0].testo}}</p>
            <div *ngIf="parereAttivo.interventi[0].nomeFile != null" class="download-doc">
              <div class="image" title="Scarica allegato">
                <a *ngIf="!platform.is('desktop')" (click)="getFile(parereAttivo.interventi[0].idIntervento, parereAttivo.interventi[0].nomeFile, false);" target="_blank" download><ion-icon name="cloud-download" [style.color]="'#2b94d1'"></ion-icon></a>
                <a *ngIf="platform.is('desktop')" href="{{parereAttivo.interventi[0].url}}" target="_blank" download><ion-icon name="cloud-download" [style.color]="'#2b94d1'"></ion-icon></a>
              </div>
              <div class="filename">{{parereAttivo.interventi[0].nomeFile}}</div>
            </div>
          </div>	
          <div class="clr"></div>
        </div>

        <div *ngSwitchCase="'new'">
          <div class="back">
            <a (click)="apriLista()" tappable title="Torna alla lista dei pareri">
              <ion-icon name="arrow-round-back" [style.color]="'#2b94d1'"></ion-icon>
            </a>
          </div>
          <div class="clr"></div>
          <form #form="ngForm" (ngSubmit)="creaParere(form)">
            <div>
              <ion-item class="title-question">
                <ion-input class="item-no-border" name="title" type="text" placeholder="inserire qui il titolo" ngModel required></ion-input>
              </ion-item>
            </div>
            <div>
              <ion-item class="question-extended item-no-border">
                <ion-textarea name="question" placeholder="inserire qui la richiesta" ngModel required></ion-textarea>
              </ion-item>
            </div>
            <ion-item class="item-no-border"><h4>Aggiungi Allegato</h4></ion-item>
            <div class="clr"></div>
            <ion-item class="item-no-border">
              <ion-input id="file" type="file" name="file" ngModel (ionChange)="loadFile();"></ion-input>
            </ion-item>
            <div class="send">
              <ion-button type="submit" size="large" [disabled]="form.invalid" expand="block" color="#fcc73d">invia</ion-button>
            </div>
            <div class="undo">
              <ion-button size="large" expand="block" (click)="apriLista()">annulla</ion-button>
            </div>
          </form>
        </div>

      </div>
    </div>
  </div>
  <!--<ion-menu side="start" menu-id="pareri" content-id="parere">
    <ion-header>
      <ion-toolbar color="primary">
        <ion-title>Topics</ion-title>
      </ion-toolbar>
    </ion-header>
    <ion-content>
      <ion-button expand="block" (click)="createNuovoParere()">Chiedi Nuovo Parere</ion-button>
      <ion-list *ngFor="let parere of pareri; trackBy: trackByDoc">
        <div>
          <ion-item (click)="apriParere(parere.idRichiesta)">{{parere.titolo}}</ion-item>
        </div>
      </ion-list>
    </ion-content>
  </ion-menu>-->
  <!--<div class="chats" main>
    <div class="back">
      <a href="">
        <ion-icon name="arrow-round-forward" color="#2b94d1"></ion-icon>
      </a>
    </div>
    <ion-content padding id="parere">
      <ion-button expand="block" (click)="openSideMenu()">Apri Lista Pareri</ion-button>
      <h1>{{parereAttivo.titolo}}</h1>
      <h2>Domanda</h2>
      <ion-item>
        <ion-textarea name="question" placeholder="" ngModel [readonly]="true">{{parereAttivo.testo}}</ion-textarea> 
      </ion-item>
      <div *ngIf="parereAttivo != null">
        <ion-item *ngIf="parereAttivo.nomeFile != null"> 
          <a *ngIf="!platform.is('desktop')" (click)="getFile(parereAttivo.idRichiesta, parereAttivo.nomeFile, true);" target="_blank" download>Clicca per scaricare il documento</a>
          <a *ngIf="platform.is('desktop')" href="{{parereAttivo.url}}" target="_blank" download>Clicca per scaricare il documento che hai caricato ({{parereAttivo.nomeFile}})</a>
        </ion-item>
      
        <div *ngIf="parereAttivo.interventi.length > 0">
          <h2>Risposta</h2>
          <ion-item>
            <ion-textarea name="response" placeholder="" ngModel [readonly]="true">{{parereAttivo.interventi[0].testo}}</ion-textarea>
          </ion-item>
          <ion-item *ngIf="parereAttivo.interventi[0].nomeFile != null">
            <a *ngIf="!platform.is('desktop')" (click)="getFile(parereAttivo.interventi[0].idIntervento, parereAttivo.interventi[0].nomeFile, false);" target="_blank" download>Clicca per scaricare il documento</a>
            <a *ngIf="platform.is('desktop')" href="parereAttivo.interventi[0].url" target="_blank" download>Clicca per scaricare il documento caricato dall'operatore ({{parereAttivo.interventi[0].nomeFile}})</a>
        </ion-item>
        </div>
      </div>
    </ion-content>
  </div>
  <div id="modal"></div>-->
  <!--<div id="content"></div>-->
</ion-content>

<ion-footer class="footer-parere" no-border *ngIf="bottoneVisibile">
  <div class="foo-button" center>
    <div class="round-btn">
      <a (click)="createNuovoParere()" tappable title="Richiedi un nuovo parere">
        <ion-icon name="add" [style.color]="'#FFFFFF'"></ion-icon>
      </a>
    </div>
  </div>
</ion-footer>
