<ion-header class="header-subpage" no-border>
  <ion-toolbar>
    <ion-title class="titolo-sezione-head">{{ 'parere_titolo' | translate }}</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">
              <span class="search-date item-no-border">
                <div><strong>{{ 'cerca' | translate }}</strong> {{ 'titolo' | translate }} <input type="text" name="calendar" [(ngModel)]="titolo" title="{{ 'ricerca_titolo' | translate }}"></div>
              </span>
              <div class="clr"></div>
              <span class="search-date item-no-border">
                <ion-checkbox name="privacy" [(ngModel)]="archiviati" class="check"> </ion-checkbox>
                <ion-label class="text">{{ 'visualizza_archiviati' | translate }}</ion-label>
                <ion-button (click)="cercaPareri()" class="search-arrow" title="{{ 'cerca' | translate }}"><ion-icon class="button-icon" slot="icon-only" name="arrow-round-forward" title="{{ 'cerca' | translate }}"></ion-icon></ion-button>
              </span>
            </div>
            <div class="clr"></div>

            <span class="item-no-border" id="buttonsPareri" style="display:none">
              <div *ngIf="!archiviati" class="text">
                {{ 'archivia_pareri' | translate }}
                <ion-button (click)="archiviaPareri(true)" class="search-arrow" title="{{ 'archivia_pareri' | translate }}"><ion-icon class="button-icon" slot="icon-only" name="archive" title="{{ 'archivia_pareri' | translate }}"></ion-icon></ion-button>
              </div>
              <div *ngIf="archiviati" class="text">
                {{ 'undo_archivio_pareri' | translate }}
                <ion-button (click)="archiviaPareri(false)" class="search-arrow" title="{{ 'riattiva_pareri' | translate }}"><ion-icon class="button-icon" slot="icon-only" name="undo" title="{{ 'riattiva_pareri' | translate }}"></ion-icon></ion-button>
              </div>                
            </span>
          </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_dettagli' | translate }}">
                  <ion-icon name="arrow-round-forward"></ion-icon>
                </a>
                <a class="select" (click)="loadPareri('initial')" tappable title="{{ 'aggiorna' | translate }}">
                  <ion-icon name="refresh-circle"></ion-icon>
                </a>
                <div text-wrap>{{parere.titolo}}</div>
              </div>
            </div>
          </div>-->
          <span class="row-results">
            <div *ngFor="let parere of pareri; trackBy: trackByDoc" class="chat-list table-row">
              <div class="row-download-special">
                <div class="richieste-button group-icon2"> 
                  <a class="select" (click)="loadPareri('initial')" tappable title="{{ 'aggiorna' | translate }}">
                    <ion-icon name="refresh-circle"></ion-icon>
                  </a>
                  <ion-label>{{ 'refresh' | translate }}</ion-label>
                </div>
                <div class="richieste-button group-icon2">
                  <a class="select" (click)="apriParere(parere.idRichiesta)" tappable title="{{ 'visualizza_dettagli' | translate }}">
                    <ion-icon name="arrow-round-forward"></ion-icon>
                  </a>
                  <ion-label>{{ 'apri' | translate }}</ion-label>
                </div>
              </div>
              <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}}
                  <div text-wrap>{{parere.titolo}}</div>
                </div>
              </div>
            </div>
          </span>
          <!--<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="{{ 'back_pareri' | translate }}"></ion-icon>
            </a>
          </div>
          <div class="quesito">
            {{parereAttivo.titolo}}
          </div>
          <div class="from-me">
            <div class="io">{{ 'io' | translate }} - {{parereAttivo.data}}</div>
            <p>{{parereAttivo.testo}}</p>
            <div class="download-doc" *ngIf="parereAttivo.nomeFile != null">
              <div class="image" title="{{ 'scarica_allegato' | translate }}">
                <a *ngIf="!platform.is('desktop')" (click)="getFile(parereAttivo.idRichiesta, parereAttivo.nomeFile, true);" target="_blank" download><ion-icon name="share-alt" [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' | translate }}">
                <a *ngIf="!platform.is('desktop')" (click)="getFile(parereAttivo.interventi[0].idIntervento, parereAttivo.interventi[0].nomeFile, false);" target="_blank" download><ion-icon name="share-alt" [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="{{ 'back_pareri' | translate }}">
              <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_titolo' | translate }}" ngModel required></ion-input>
              </ion-item>
            </div>
            <div>
              <ion-item class="question-extended item-no-border">
                <ion-textarea name="question" placeholder="{{ 'inserire_richiesta' | translate }}" ngModel required></ion-textarea>
              </ion-item>
            </div>
            <ion-item class="item-no-border"><h4>{{ 'aggiungi_allegato' | translate }}</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' | translate }}</ion-button>
            </div>
            <div class="undo">
              <ion-button size="large" expand="block" (click)="apriLista()">{{ 'annulla' | translate }}</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="{{ 'aggiungi_richiesta' | translate }}">
        <ion-icon name="add" [style.color]="'#FFFFFF'"></ion-icon>
      </a>
    </div>
  </div>
</ion-footer>
