<ion-header  class="ion-no-border">
  <ion-toolbar class="header-toolbar">
    <!-- <div #rectangle class="rectangle" (press)="handlePress()">
      Double click me to change the color
    </div> -->
    <div class="main-header">
      <div class="header-top">
        <div class="left">
          <button class="btn-no-color" (click)="close()">
            <!-- <ion-icon slot="end" src='assets/images/icons-arrow-arrow-left.svg'></ion-icon> -->
            <fa-icon icon="chevron-left" class="header-top-btn font-awesome-1"></fa-icon>
          </button>
        </div>
        <div class="middle-container" *ngIf="!showMessageOptions">
          <div class="middle" *ngFor="let users of dmUsers">
            <ion-label class="title">{{users.name}}</ion-label>
            <span><ion-icon class="{{users.status}}" name="ellipse"></ion-icon></span>
          </div>
        </div>
        <div class="middle-container-options" *ngIf="showMessageOptions">
          <fa-icon (click)="deleteMessage(selectedMsgId)" icon="trash" class="middle-container-options-icons"></fa-icon>
          <!-- <ion-icon name="trash"></ion-icon> -->
        </div>
        <div hidden class="right">
          <button class="btn-no-color" (click)="openMessagesOptions()">
            <ion-icon *ngIf="ThemeService.currentTheme == 'default' " src="assets/images/icons-menu.svg"></ion-icon>
            <ion-icon *ngIf="ThemeService.currentTheme == 'gov' " src="assets/images/theme/gov/icons-menu.svg"></ion-icon>
          </button>
        </div>
      </div>
      <div hidden class="header-bottom" (click)="addContacts()">
        <div class="header-bottom-icon">
          <ion-icon *ngIf="ThemeService.currentTheme == 'default' "  src="assets/icon/icons-user.svg"></ion-icon>
          <ion-icon *ngIf="ThemeService.currentTheme == 'gov' "  src="assets/icon/theme/gov/icons-user.svg"></ion-icon>
        </div>
        <div class="header-bottom-contacts">
          <ion-label class="text-color-blue">Adicionar contacto</ion-label>
        </div>
      </div>
    </div>
  </ion-toolbar>
</ion-header>

<ion-content>

  <!-- <ion-refresher  name="refresher" slot="fixed" (ionRefresh)="doRefresh($event)">
    <ion-progress-bar type="indeterminate" *ngIf="showLoader"></ion-progress-bar>
    <ion-refresher-content>
    </ion-refresher-content>
  </ion-refresher> -->
  <div (click)="handleClick()" class="messages" #scrollMe>
    <div class="messages-list-item-wrapper container-width-100" *ngFor="let msg of messages; let last = last"
    [class.messages-list-item-wrapper-active]="msg._id == selectedMsgId"  >
      <div (press)="handlePress(msg._id)" class='message-container incoming-{{msg.u.username!=loggedUser.me.username}}' (click)="openPreview(msg)" *ngIf="msg.msg !=''">
        <div class="title">
          <ion-label>{{msg.u.name}}</ion-label>
          <span class="time">{{showDateDuration(msg._updatedAt)}}</span>
        </div>
        <div>
          <ion-label>{{msg.msg}}</ion-label>
          <div *ngIf="msg.attachments" class="message-attachments">
            <div *ngFor="let file of msg.attachments let i = index">
              <div (click)="openPreview(msg)">
                <img *ngIf="file.image_url" src="{{file.image_url}}" alt="image">
              </div>
              <div>
                <div>
                  <div class="file">
                    <!-- <canvas id="pdf_canvas"></canvas> -->
                    <div (click)="docIndex(i); viewDocument(msg.file, file.title_link)" class="file-details add-ellipsis cursor-pointer" *ngIf="msg.file">
                      <span *ngIf="msg.file.type">
                        <fa-icon *ngIf="msg.file.type == 'application/pdf'" icon="file-pdf" class="pdf-icon"></fa-icon>
                        <fa-icon *ngIf="msg.file.type == 'application/word'" icon="file-word" class="word-icon"></fa-icon>
                        <fa-icon *ngIf="msg.file.type == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'" icon="file-word" class="excel-icon"></fa-icon>
                        <ion-icon *ngIf="msg.file.type == 'application/webtrix'" src="assets/icon/webtrix.svg"></ion-icon>
                      </span>
                      <ion-label class="file-title">{{file.title}}</ion-label>
                    </div>
                  </div>
                  <div class="file-details-optional">
                    <ion-label *ngIf="msg.file && msg.file != ''">
                      <span *ngIf="file.description">{{file.description}}</span>
                      <span *ngIf="file.description && msg.file.type != 'application/webtrix'"> • </span>
                      <span *ngIf="msg.file.type != 'application/webtrix'">{{msg.file.type.replace('application/','').toUpperCase()}}</span>
                    </ion-label>
                  </div>
                </div>
              </div>
            </div>
          </div>
          {{last ? scrollToBottom() : ''}}
        </div>
      </div>
      <div *ngIf="msg.file" class="info-meeting">
        <div *ngIf="msg.file.type == 'application/meeting'">
          <ion-label class="info-meeting-small">{{msg.u.name}} criou esta reunião</ion-label><br />
          <button (click)="goToEvent(msg.file.id)" class="btn-no-color info-meeting-normal"><ion-label class="info-meeting-normal">{{msg.file.subject}}</ion-label></button><br />
          <ion-label class="info-meeting-medium"><ion-icon name="calendar-outline"></ion-icon> De {{showDateDuration(msg.file.start_date)}} a {{showDateDuration(msg.file.end_date)}}</ion-label><br />
          <ion-label class="info-meeting-medium"><ion-icon></ion-icon><ion-icon name="location-outline"></ion-icon> {{msg.file.venue}}</ion-label><br />
        </div>
        {{last ? scrollToBottom() : ''}}
      </div>
    </div>
  </div>
  <ion-fab horizontal="end" vertical="bottom" slot="fixed">
    <ion-fab-button *ngIf="scrollToBottomBtn" (click)="scrollToBottomClicked()" color="light" size="small">
      <ion-icon name="chevron-down"></ion-icon>
    </ion-fab-button>
  </ion-fab>

</ion-content>

<!-- <ion-footer>
  <ion-toolbar>
    <ion-row align-items-center class="row">
      <ion-col size="1">
        <ion-label class="ion-no-padding" lines="none">
          <ion-icon (click)="openChatOptions()" class="chat-icon-options" src="assets/icon/icons-chat-options.svg"></ion-icon>
        </ion-label>
      </ion-col>
      <ion-col size="9">
        <ion-item class="ion-no-padding type-message" lines="none">
          <ion-textarea clearOnEdit="true" placeholder="Escrever uma mensagem" auto-grow class="message-input" rows="1" [(ngModel)]="message"></ion-textarea>
          <ion-icon slot="end" src="assets/icon/icons-chat-mic.svg"></ion-icon>
        </ion-item>
      </ion-col>
      <ion-col size="2">
        <ion-label>
          <ion-icon (click)="sendMessage()" class="chat-icon-send" src="assets/icon/icons-chat-send.svg"></ion-icon>
        </ion-label>
      </ion-col>
    </ion-row>
  </ion-toolbar>
</ion-footer> -->

<ion-footer>
  <ion-list hidden>
    <ion-item (click)="playFile(storedFileNames)">
      {{storedFileNames}}
    </ion-item>
    <ion-item (click)="playFile(storedFileNames)">
      {{storedFileNames}}
    </ion-item>
  </ion-list>
  <audio hidden controls>
    <source src="https://www.tabularium.pt/file-upload/5g6DkyMC4MHcuaDyp/Audio%20record.mp3" type="audio/mpeg">
  </audio>
  <!-- <button (click)="startRecording()">Start Recording</button>
  <button (click)="stopRecording()">Stop Recording</button> -->
  <div class="container width-100 d-flex">
    <div>

      <button class="btn-no-color" (click)="openChatOptions()">
        <ion-icon *ngIf="ThemeService.currentTheme == 'default' " class="chat-icon-options" src="assets/images/icons-add.svg"></ion-icon>
        <ion-icon *ngIf="ThemeService.currentTheme == 'gov' " class="chat-icon-options" src="assets/images/theme/gov/icons-add.svg"></ion-icon>
      </button>
    </div>
    <div class="width-70">
      <ion-item class="ion-no-padding ion-no-margin type-message" lines="none">
        <ion-textarea *ngIf="!recording" clearOnEdit="true" placeholder="Escrever uma mensagem" auto-grow class="message-input" rows="1" [(ngModel)]="message"></ion-textarea>
        <ion-textarea *ngIf="recording" clearOnEdit="true" placeholder="Escrever uma mensagem" auto-grow class="message-input" rows="1" [(ngModel)]="durationDisplay"></ion-textarea>
        <button hidden #recordbtn class="btn-no-color" (click)="notImplemented()">
          <ion-icon slot="end" src="assets/icon/icons-chat-mic.svg"></ion-icon>
        </button>
      </ion-item>
    </div>
    <div>
      <button *ngIf="message" class="btn-no-color" (click)="sendMessage()">
        <ion-icon  *ngIf="ThemeService.currentTheme == 'default' " class="chat-icon-send" src="assets/icon/theme/gov/icons-chat-send.svg"></ion-icon>
        <ion-icon  *ngIf="ThemeService.currentTheme == 'gov' " class="chat-icon-send" src="assets/icon/theme/gov/icons-chat-send.svg"></ion-icon>
      </button>
      <button *ngIf="!message" class="btn-no-color">
        <ion-icon  *ngIf="ThemeService.currentTheme == 'default' " class="chat-icon-send" src="assets/icon/theme/gov/icons-chat-send.svg"></ion-icon>
        <ion-icon  *ngIf="ThemeService.currentTheme == 'gov' " class="chat-icon-send" src="assets/icon/theme/gov/icons-chat-send.svg"></ion-icon>
      </button>
    </div>
  </div>

</ion-footer>
