<div id="tm-main" class=" uk-section  uk-margin-small-top tm-middle"   >
  <div uk-grid uk-grid>
   <div class="tm-main uk-width-1-1@s uk-width-1-1@m  uk-width-1-1@l uk-row-first ">
<div class="uk-container">

  <div *ngIf="accessStatus=='invalid'" class="uk-margin-top uk-width-medium-2-3 uk-container-center">
    <div class="uk-block uk-block-primary uk-block-large uk-contrast uk-text-center">
      <p class="uk-text-large">Oops! Your email does not give you the authority to view claims for the selected project. Please contact the administrators.</p>
    </div>
  </div>

  <div *ngIf="accessStatus=='valid'">
    <div class="uk-article-title custom-article-title">
        Claims Administrator
        <a *ngIf="project" [queryParams]="routerHelper.createQueryParam('projectId',project['openaireId'])"
            routerLinkActive="router-link-active"
            [routerLink]="properties.searchLinkToProject.split('?')[0]">
              {{project['name']}} ({{project['funderName']}})
        </a>

    </div>
    <ul class="uk-margin-large-top" uk-tab="connect: #tab-content">
      <li [class]="mode == 'pending' ? 'uk-active' : ''" (click)="mode='pending'"><a>Pending Claims</a></li>
      <li [class]="mode == 'curated' ? 'uk-active' : ''" (click)="mode='curated'"><a>Curated Claims</a></li>
    </ul>
    <ul class="uk-switcher uk-margin"><!-- uk-switcher="connect: #tab-content"-->
      <li [class]="mode == 'pending' ? 'uk-active' : ''" (click)="mode='pending'">
        <h3>Pending Claims</h3>
        <!-- <div *ngIf=" pending_claims && pending_claims.length == 0" >
          <div class = "uk-alert uk-alert-primary " >No pending claims found.</div>
        </div> -->
        <errorMessages [status]="[pending_status]" [type]="'pending claims'"></errorMessages>

        <div class="uk-overflow-container custom-dataTable-content">

          <div class="uk-alert-warning" uk-alert>Note that claims you do not select (approve or disapprove) are considered as approved (but not curated)</div>

          <div  class="uk-width-1-1  uk-margin uk-padding uk-panel  uk-background-muted">
            <form class="uk-text-center uk-panel">
              <input type="text" class="uk-input uk-width-1-3" placeholder="Type keywords..." aria-describedby="sizing-addon2"  [(ngModel)]="keyword1"  name="keyword" />
              <button (click)="refreshTable(1, 'pending')"  type="submit" class=" uk-button">
                 <span class="uk-icon">
                 <svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="search" ratio="1"><circle fill="none" stroke="#000" stroke-width="1.1" cx="9" cy="9" r="7"></circle><path fill="none" stroke="#000" stroke-width="1.1" d="M14,14 L18,18 L14,14 Z"></path></svg>
                 </span>Search
              </button>
            </form>
          </div>

          <span *ngIf="pending_claims && pending_claims.length > 0 && totalPendingResults.count > 0">
            {{totalPendingResults.count | number}} pending claims, page {{activePendingPage.page | number}} of {{totalPages(totalPendingResults.count) | number}}
            <paging-no-load class="uk-float-right" [currentPage]="activePendingPage.page" [totalResults]="totalPendingResults.count" [size]="rowsOnPage" (pageChange)="refreshTable($event.value, 'pending')"></paging-no-load>
          </span>
<!-- *ngIf="showTables"  -->
          <table #table1 datatable class="uk-table uk-table-striped divider-table" [dtOptions]="dtOptions[0]" [dtTrigger]="dtTrigger[0]" dtInstance="dtInstanceCallback" id="table1">
            <thead>
               <tr>
                  <th> Research Result </th>
                  <th class="uk-text-center">Claimed By </th>
                  <th class="uk-text-center">Claimed Date </th>
                  <th class="uk-text-center">Approve</th>
               </tr>
            </thead>
            <tbody>
                <tr class="uk-table-middle" *ngFor="let claim of pending_claims">
                  <td  class="uk-width-2-5" *ngIf="claim.targetType != 'project'"><claim-entity [entity]="claim.target" [type]="claim.targetType" [(properties)]=properties> </claim-entity></td>
                  <td class="uk-width-2-5 uk-text-center" *ngIf="claim.sourceType != 'project'"><claim-entity [entity]="claim.source" [type]="claim.sourceType" [(properties)]=properties> </claim-entity></td>
                  <td class="uk-width-1-5 uk-text-center">{{claim.userMail}}</td>
                  <td class="uk-width-1-5 uk-text-center">{{claim.date}}</td>
                  <td class="uk-width-1-5 uk-text-center">

                    <label>
                      Yes <input [id]="claim.id" type="checkbox" (click)="selectApprove(claim.id,$event,'pending')"  [ngModel]="isSelected(claim.id, selectedRight_PendingMode)"/>
                    </label>
                    <label>
                      No  <input [id]="claim.id" type="checkbox" (click)="selectDisapprove(claim.id,$event,'pending')"  [ngModel]="isSelected(claim.id, selectedWrong_PendingMode)"/>
                    </label>
                  </td>
                </tr>
            </tbody>
          </table>
         </div>

         <div *ngIf="(selectedWrong_PendingMode.size+selectedRight_PendingMode.size) > 0" class="uk-alert-primary" uk-alert>
             You have selected <span class="uk-badge">{{(selectedWrong_PendingMode.size+selectedRight_PendingMode.size)}}</span> claim(s) to curate
         </div>
         <div *ngIf="totalPendingResults.count > 0" class="uk-float-right">
           <button (click)="clearCheckboxes()" [class]="((selectedWrong_PendingMode.size+selectedRight_PendingMode.size) == 0) ? 'uk-button uk-disabled' : 'uk-button'">Reset</button>

           <span title="Approve or dissaprove at least one claim"
                [attr.uk-tooltip]="((selectedWrong_PendingMode.size+selectedRight_PendingMode.size) == 0) ? 'pos:right; cls: uk-active' : 'cls: uk-invisible'">
              <button [class]="((selectedWrong_PendingMode.size+selectedRight_PendingMode.size) == 0) ? 'uk-disabled uk-button uk-button-primary' : 'uk-button uk-button-primary'"
                      type="submit" (click)="saveChanges()">
              <!-- <button class="uk-button uk-button-primary" type="submit" (click)="saveChanges()"> -->
               Save Changes
             </button>
           </span>
         </div>
      </li>
      <li [class]="mode == 'curated' ? 'uk-active' : ''" (click)="mode='curated'">
        <h2>Curated Claims</h2>

        <!-- <div *ngIf=" curated_claims && curated_claims.length == 0" >
          <div class = "uk-alert uk-alert-primary " >No curated claims found.</div>
        </div> -->

        <errorMessages [status]="[curated_status]" [type]="'curated claims'"></errorMessages>

        <div class="uk-overflow-container custom-dataTable-content">

          <div  class="uk-width-1-1  uk-margin uk-padding uk-panel  uk-background-muted">
            <form class="uk-text-center uk-panel">
              <input type="text" class="uk-input uk-width-1-3" placeholder="Type keywords..." aria-describedby="sizing-addon2"  [(ngModel)]="keyword2"  name="keyword" />
              <button (click)="refreshTable(1, 'curated')"  type="submit" class=" uk-button">
                 <span class="uk-icon">
                   <svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="search" ratio="1"><circle fill="none" stroke="#000" stroke-width="1.1" cx="9" cy="9" r="7"></circle><path fill="none" stroke="#000" stroke-width="1.1" d="M14,14 L18,18 L14,14 Z"></path></svg>
                 </span>Search
              </button>
            </form>
          </div>

          <span *ngIf="curated_claims && curated_claims.length > 0 && totalCuratedResults.count > 0">
            {{totalCuratedResults.count | number}} curated claims, page {{activeCuratedPage.page | number}} of {{totalPages(totalCuratedResults.count) | number}}
            <paging-no-load class="uk-float-right" [currentPage]="activeCuratedPage.page" [totalResults]="totalCuratedResults.count" [size]="rowsOnPage"  (pageChange)="refreshTable($event.value, 'curated')"> </paging-no-load>
          </span>

           <!-- [dtTrigger]="dtTrigger2" dtInstance="dtInstanceCallback" -->
           <!-- *ngIf="showTables" -->
          <table #table2 datatable class="uk-table uk-table-striped divider-table" [dtOptions]="dtOptions[1]" [dtTrigger]="dtTrigger[1]" dtInstance="dtInstanceCallback" id="table2">
            <thead>
              <tr>
                <th>Research Result</th>
                <th class="uk-text-center">Claimed by </th>
                <th class="uk-text-center">Claimed Date </th>
                <th class="uk-text-center">Curated by </th>
                <th class="uk-text-center">Curation Date </th>
                <th class="uk-text-center">Approved</th>
                <th class="uk-text-center">Actions</th>
              </tr>
            </thead>
            <tbody>
                <tr class="uk-table-middle" *ngFor="let claim of curated_claims let i=index">
                  <td class="uk-width-1-6" *ngIf="claim.targetType != 'project'"><claim-entity [entity]="claim.target" [type]="claim.targetType" [(properties)]=properties> </claim-entity></td>
                  <td class="uk-width-1-6" *ngIf="claim.sourceType != 'project'"><claim-entity [entity]="claim.source" [type]="claim.sourceType" [(properties)]=properties> </claim-entity></td>
                  <td class="uk-width-1-6 uk-text-center">{{claim.userMail}}</td>
                  <td class="uk-width-1-6 uk-text-center">{{claim.date}}</td>
                  <td class="uk-width-1-6 uk-text-center">{{claim.curatedBy}}</td>
                  <td class="uk-width-1-6 uk-text-center">{{claim.curationDate}}</td>
                  <td class="uk-width-1-6 uk-text-center uk-form-controls">
                   <label [class]="!editable.has(i) ? 'uk-disabled' : ''">
                      Yes <input [id]="claim.id" class="uk-radio" type="radio" [disabled]="!editable.has(i)" [checked]="isRight_CuratedMode(claim)" (click)="selectApprove(claim.id,$event,'curated')"/>
                    </label>

                    <label [class]="!editable.has(i) ? 'uk-disabled' : ''">
                      No  <input [id]="claim.id" class="uk-radio" type="radio" [disabled]="!editable.has(i)" [checked]="isWrong_CuratedMode(claim)" (click)="selectDisapprove(claim.id,$event,'curated')"/>
                    </label>

                  </td>
                  <!-- <td><input [id]="claim.id" type="checkbox" [disabled]="!editable.has(i)" (click)="selectDisapprove(claim.id,$event)"  [ngModel]="isWrong(claim)"/></td> -->
                  <td class="uk-text-center">
                    <span *ngIf="!editable.has(i)"><button class="uk-button" (click)="editable.add(i)">Edit</button></span>
                     <!-- class="uk-button-group" -->
                    <span *ngIf="editable.has(i)">
                      <!-- [disabled]="!selectedRight_CuratedMode.has(claim.id) && !selectedWrong_CuratedMode.has(claim.id)"  -->
                      <button class="uk-width-1-1 uk-button uk-button-primary uk-button-small" type="submit" (click)="saveEdited(claim, i)">Save</button>
                      <button class="uk-width-1-1 uk-button uk-button-small" (click)="editable.delete(i); cancelEditOfCuration(claim)">Cancel</button>
                    </span>
                  </td>
                </tr>
            </tbody>
          </table>
        </div>
      </li>
    </ul>

    <modal-loading [message]= "'Loading...'"></modal-loading>
  </div>

</div>
</div>
</div>
</div>
