<div>
  <div class="uk-width-xlarge@l uk-width-large" [ngClass]="centerAlign ? 'uk-align-center':''">
    <advanced-search-input>
        <div input type="select" [(value)]="showOptions.show" placeholder="Type" hint="Select..."
             [options]="showOptions.selectOptions" class="uk-width-2-5"></div>
        <div class="uk-width-expand" input type="text" [(value)]="keyword" [searchable]="true" placeholder="Entities to link"
             [hint]="'Search for ' + openaireEntities.COMMUNITIES + '...'" tooltip="true"></div>
    </advanced-search-input>
  </div>
  <div *ngIf="communities"class="uk-padding">
    <div class="uk-grid uk-child-width-1-3" uk-height-match=".uk-card" uk-grid>
    <div *ngFor="let community of filter()">
      <a class="uk-link-reset uk-height-1-1" (click)="select(community.id, community.label)">
        <div [title]="(this.results.length>=basketLimit)?'Basket reached the size limit':''"
           class="uk-card uk-card-default uk-card-hover uk-padding-small uk-text-center">
        <div class="uk-text-right">
          <button class="linking-add-button uk-icon-button-small" [class.uk-disabled]="(this.results.length>=basketLimit)" *ngIf="!isSelected(community.id)">
            <icon name="add" [flex]="true"></icon>
          </button>
          <button *ngIf="isSelected(community.id)" class="linking-selected-button uk-icon-button-small">
            <icon name="check" [flex]="true"></icon>
          </button>
        </div>
        <img *ngIf="communityLogos && communityLogos[community.id]"
             [src]="communityLogos[community.id] | logoUrl"
             class="uk-blend-multiply"
             [alt]="((community.title)?community.title:(community.shortTitle?community.shortTitle:'')) + ' logo'"
             loading="lazy" style="max-height:70px">
        <div class="uk-margin-small-top">
          {{community.label}}
        </div>
      </div>
      </a>
    </div>
  </div>
  </div>
  <ng-container *ngIf="filter().length == 0">
    <div class="uk-alert uk-alert-primary"
         role="alert">No Results found
    </div>
  </ng-container>
</div>
<!-- Categories modal-->
<modal-alert #modal large="true">
  <div class="uk-modal-body uk-height-min-medium uk-width-expand">
    <div class="uk-margin-bottom">
      <input [ngModel]="isSelected(selectedCommunityId)" type="checkbox"
             (ngModelChange)="isSelected(selectedCommunityId)?removeById(selectedCommunityId):select(selectedCommunityId,
      selectedCommunityLabel);">
      <span class="uk-margin-small-left">{{selectedCommunityLabel}}</span>
    </div>
    <div *ngIf="loading" class="uk-alert uk-alert-primary" role="alert">Loading communities information...</div>
    <div *ngIf="error" class="uk-alert uk-alert-warning"
         role="alert">An error occurred while loading communities...
    </div>
    <div class="uk-margin-small-top uk-text-small uk-text-meta" *ngIf="categories[selectedCommunityId] &&
    categories[selectedCommunityId].length > 0 ">
      Optionally, you can <span class="uk-text-bold">specify additional</span> Community's <span
      class="uk-text-bold">paths</span> to link your
      sources.
    </div>
    <div *ngIf="categories[selectedCommunityId] && categories[selectedCommunityId].length == 0 "
         class="  uk-text-small uk-text-muted">
      No additional community paths found for this community.
    </div>
    <ul *ngIf="categories[selectedCommunityId] && categories[selectedCommunityId].length > 0 "
        class=" uk-list uk-margin-small-top  uk-margin-left uk-animation-fade uk-overflow-auto uk-height-medium">
      <li *ngFor="let category of categories[selectedCommunityId]">
        <div (click)="browseConcepts(category.id)">
          <input [ngModel]="isSelected(category.id)" type="checkbox"
             (ngModelChange)="isSelected(category.id)?removeById(category.id):addNewContext(selectedCommunityLabel,category.label,{'id':category.id, 'label':category.label});">
          <span class="uk-margin-small-left">{{category.label}} </span>
          <span *ngIf="!conceptsClassDisplay[category.id]" uk-icon="icon:chevron-down; ratio:0.7"></span>
          <span *ngIf="conceptsClassDisplay[category.id]" uk-icon="icon:chevron-up; ratio:0.7"></span>
          </div>

        <div *ngIf="conceptsCategoryLoading[category.id]" class="uk-alert uk-alert-primary"
             role="alert">Loading category information...
        </div>
        <div>

          <div
            *ngIf="conceptsClass[category.id] && conceptsClass[category.id].length == 0 && conceptsClassDisplay[category.id]">No more paths found
          </div>
          <ul *ngIf="conceptsClass[category.id] && conceptsClassDisplay[category.id]"
              class="uk-list  uk-animation-fade uk-margin-left  uk-margin-top" id="ul_{{category.id}}">
            <li *ngFor="let concept1 of conceptsClass[category.id]">
                <div (click)="displaySubcategory(concept1.id)">
                  <input [ngModel]="isSelected(concept1.id)" type="checkbox"
                         (ngModelChange)="isSelected(concept1.id)?removeById(concept1.id):addNewContext(selectedCommunityLabel,category.label,concept1);">
                  <span class="uk-margin-small-left">{{concept1.label}}</span>
                  <span *ngIf="concept1.concepts && concept1.concepts.length==0">
                    <span *ngIf="!conceptsClassDisplay[concept1.id]" uk-icon="icon:chevron-down; ratio:0.7"></span>
                    <span *ngIf="conceptsClassDisplay[concept1.id]" uk-icon="icon:chevron-up; ratio:0.7"></span>
                  </span>
                 </div>
              <div>
                <div
                  *ngIf="concept1.concepts && concept1.concepts.length==0 &&  conceptsClassDisplay[concept1.id]">No more paths found
                </div>
                <ul *ngIf="concept1.concepts &&  conceptsClassDisplay[concept1.id] "
                    class="uk-list uk-animation-fade uk-margin-left  uk-margin-top">
                  <li *ngFor="let concept2 of concept1.concepts">
                    <div (click)="displaySubcategory(concept2.id)">
                      <input [ngModel]="isSelected(concept2.id)" type="checkbox"
                             (ngModelChange)="isSelected(concept2.id)?removeById(concept2.id):addNewContext(selectedCommunityLabel,category.label,concept2);" >
                      <span *ngIf="concept2.concepts && concept2.concepts.length==0">
                        <span class="uk-margin-small-left">{{concept2.label}}</span><span *ngIf="!conceptsClassDisplay[concept1.id]" uk-icon="icon:chevron-down; ratio:0.7"></span>
                        <span *ngIf="conceptsClassDisplay[concept1.id]" uk-icon="icon:chevron-up; ratio:0.7"></span>
                      </span>
                    </div>
                    <ul *ngIf="concept2.concepts &&  conceptsClassDisplay[concept2.id] "
                        class="uk-list uk-animation-fade uk-margin-left  uk-margin-top">
                      <li *ngFor="let concept3 of concept2.concepts">
                        <input [ngModel]="isSelected(concept3.id)" type="checkbox"
                               (ngModelChange)="isSelected(concept3.id)?removeById(concept2.id):addNewContext(selectedCommunityLabel,category.label,concept3);">
                        <span class="uk-margin-small-left">{{concept3.label}}</span>
                      </li>
                    </ul>
                  </li>
                </ul>
              </div>
            </li>
          </ul>
        </div>
      </li>

    </ul>
  </div>
  <div *ngIf="warningMessage.length > 0" class="uk-alert uk-alert-warning" role="alert">{{warningMessage}}</div>
  <div *ngIf="infoMessage.length > 0" class="uk-alert uk-alert-primary" role="alert">{{infoMessage}}</div>
</modal-alert>
    
