<ng-template #selected_filters_pills let-margin="margin">
  <!--  <div class="uk-grid uk-grid-small uk-text-small" uk-grid>-->
  <span *ngIf="periodFilter.selectedFromAndToValues.length > 0" class="uk-grid-margin">
        <a (click)="clearPeriodFilter()" [class]="((loading)?'  uk-disabled':'  ')+' uk-link-text '"> <span
            class="selectedFilterLabel" [class.uk-margin-small-left]="margin"
            title="Remove {{periodFilter.selectedFromAndToValues}}">
          <i uk-icon="close"></i>
          <span class="uk-margin-small-left">{{periodFilter.selectedFromAndToValues}}</span>
        </span></a>
    </span>
  <ng-container *ngFor="let filter of filters ">
    <ng-container *ngIf="filter.countSelectedValues > 0">
      <ng-container *ngFor="let value of filter.values; let i = index;  let end = last; ">
        <ng-container *ngIf="value.selected">
             <span class="uk-grid-margin">
                          <!-- if no grid on the div above, remove it and move class 'selectedFilterLabel' on top span -->
              <span class="selectedFilterLabel " [class.uk-margin-small-left]="margin" [title]="'Remove '+value.name"
                    (click)="value.selected = false; filter.radioValue=''; filter.countSelectedValues=
                    filter.countSelectedValues -1;
                    filterChanged({value:filter}) ">
                <a [class]="((loading)?'  uk-disabled':'  ')+' uk-link-text '">
                  <span class=" clickable" aria-hidden="true">
                    <span class="uk-icon">
                      <svg width="16" height="16" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"
                           icon="close" ratio="0.8"><path fill="none" stroke="#000" stroke-width="1.6"
                                                          d="M16,16 L4,4"></path><path fill="none"
                                                                                       stroke="#000"
                                                                                       stroke-width="1.6"
                                                                                       d="M16,4 L4,16"></path></svg>
                    </span>
                  </span>
                  <span class="uk-margin-small-left"
                        [innerHtml]="(value.name.length > 34)?value.name.substring(0,34)+'...':value.name"></span>
                </a>
              </span>
            </span>
        </ng-container>
      </ng-container>
    </ng-container>
  </ng-container>
  <!--  </div>-->
</ng-template>
<div page-content [class.greyOut]="filterToggle" (click)=" (filterToggle)?filterToggle = false:filterToggle">
  <div *ngIf="activeTopic && activeTopic.categories.length > 0" header>
    <nav class=" ">
      <div *ngIf="stakeholder && status === errorCodes.DONE && activeTopic" class="">
        <ul
            class="customTabs uk-tab  ">
          <ng-template ngFor [ngForOf]="activeTopic.categories" let-category let-i="index">
            <li *ngIf="isPublicOrIsMember(category.visibility)"
                [class.uk-active]="category.alias ===
                 activeCategory.alias">
              <a (click)="navigateTo(stakeholder.alias,activeTopic.alias, category.alias)">
                <span class="title">{{category.name}}</span>
              </a>
            </li>
          </ng-template>
        </ul>
      </div>
    </nav>
    <ul *ngIf="activeCategory && countSubCategoriesToShow(activeCategory) > 1"
        class="uk-subnav uk-subnav-pill subCategoriesTabs ">
      <ng-template ngFor [ngForOf]="activeCategory.subCategories" let-subCategory let-i="index">
        <li *ngIf="isPublicOrIsMember(subCategory.visibility)"
            [ngClass]="(subCategory.alias === activeSubCategory.alias)?'uk-active':''">
          <a (click)="navigateTo(stakeholder.alias,activeTopic.alias,activeCategory.alias, subCategory.alias)"
             class="uk-margin-remove-bottom"
          ><span>{{subCategory.name}}</span></a>
        </li>
      </ng-template>
    </ul>
    <div *ngIf="countSelectedFilters() > 0" class="uk-grid uk-grid-small uk-margin-bottom uk-text-small">
      <span class="uk-grid-margin">Filters: </span>
      <ng-container *ngTemplateOutlet="selected_filters_pills; context: {margin:true}"></ng-container>
    </div>
  </div>
  <div inner>
    <div [class.uk-padding]="!isSmallScreen" class="uk-padding-remove-vertical">
      <div *ngIf="privateStakeholder" class="message">
        <div class="uk-text-center">
          <h3><i>
            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="black" width="24px" height="24px">
              <path d="M0 0h24v24H0z" fill="none"/>
              <path
                  d="M18 8h-1V6c0-2.76-2.24-5-5-5S7 3.24 7 6v2H6c-1.1 0-2 .9-2 2v10c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V10c0-1.1-.9-2-2-2zm-6 9c-1.1 0-2-.9-2-2s.9-2 2-2 2 .9 2 2-.9 2-2 2zm3.1-9H8.9V6c0-1.71 1.39-3.1 3.1-3.1 1.71 0 3.1 1.39 3.1 3.1v2z"/>
            </svg>
          </i>
            Private data
          </h3>
          <div class="uk-text-large "></div>
        </div>
      </div>
      <div *ngIf="!privateStakeholder && stakeholder">
        <div *ngIf="(activeSubCategory && (activeSubCategory.charts.length == 0 ||
          (activeSubCategory.charts.length == 1 && countIndicatorsToShow(activeSubCategory.charts[0].indicators) == 0)))
          &&  ((activeSubCategory &&
        activeSubCategory.description &&
        activeSubCategory.description.length > 0) ||
          (activeCategory && activeCategory.description && activeCategory.description.length > 0) ||
          (activeTopic && activeTopic.description && activeTopic.description.length > 0))"
             class="uk-text-center">
          <div class="uk-height-small uk-margin-large-top uk-margin-xlarge-right  uk-margin-xlarge-left">
            {{activeSubCategory && activeSubCategory.description && activeSubCategory.description.length > 0 ? activeSubCategory.description
              : (activeCategory && activeCategory.description && activeCategory.description.length > 0 ? activeCategory.description :
                  (activeTopic.description && activeTopic.description.length > 0 ? activeTopic.description : ""))}}
          </div>

        </div>
        <ng-template [ngIf]="!loading && !privateStakeholder &&
                    (!activeSubCategory ||
                    (
                      (activeSubCategory.numbers.length == 0 || (activeSubCategory.numbers.length == 1 && countIndicatorsToShow(activeSubCategory.numbers[0].indicators) == 0))
                      &&
                      (activeSubCategory.charts.length == 0 || (activeSubCategory.charts.length == 1 && countIndicatorsToShow(activeSubCategory.charts[0].indicators) == 0))
                    ) || !activeTopic || !activeCategory || !activeSubCategory)" [ngIfElse]="content">
          <div class="message uk-text-center">
            <h3>
              No indicators available yet. Stay tuned!
            </h3>
          </div>
        </ng-template>
        <ng-template #content>
          <div *ngFor="let number of activeSubCategory.numbers; let i = index;"
               class="uk-grid uk-grid-small uk-margin-bottom uk-margin-top"
               uk-height-match="target: .uk-card">
            <h5 *ngIf="countIndicatorsToShow(number.indicators)> 0 "
                class="uk-width-1-1 uk-margin-bottom">{{number.title}}</h5>
            <ng-template ngFor [ngForOf]="number.indicators" let-indicator let-j="index">
              <div *ngIf="isPublicOrIsMember(indicator.visibility)"
                   [ngClass]="getNumberClassBySize(indicator.width)" class=" uk-margin-bottom">
                <div class="uk-card uk-card-default"
                     [class.uk-disabled]="indicator.indicatorPaths[0].filtersApplied < countSelectedFilters()"
                     [class.semiFiltered]="indicator.indicatorPaths[0].filtersApplied < countSelectedFilters()">
                  <div class="uk-card-body uk-text-center">
                    <div *ngIf="properties.environment == 'development'">Filtered:
                      {{indicator.indicatorPaths[0].filtersApplied}}
                      out of
                      {{countSelectedFilters()}}</div>
                    <div class="uk-text-bold ">{{indicator.name}}</div>
                    <h3 class="uk-margin-medium-top uk-text-bold">
                      <span *ngIf="numberResults.get(i + '-' + j)">{{numberResults.get(i + '-' + j) | number}}</span>
                      <span *ngIf="!numberResults.get(i + '-' + j)">--</span>
                    </h3>
                    <!--<ng-container *ngTemplateOutlet="description; context: {indicator:indicator}"></ng-container>-->
                  </div>
                </div>
              </div>
            </ng-template>
          </div>
          <div [class.uk-margin-large-top]="activeSubCategory.numbers.length > 0">
            <div *ngFor="let chart of activeSubCategory.charts; let i = index;"
                 class="uk-grid uk-grid-small uk-margin-bottom uk-flex uk-flex-middle "
                 uk-height-match="target: .uk-card">
              <h5 *ngIf="chart.title && chart.title.length > 0 && countIndicatorsToShow(chart.indicators) > 0 "
                  class="uk-width-1-1 uk-margin-bottom">{{chart.title}}</h5>
              <ng-template ngFor [ngForOf]="chart.indicators" let-indicator let-j="index">
                <div
                    *ngIf="isPublicOrIsMember(indicator.visibility) && chartsActiveType.get(i + '-' + j)"
                    [ngClass]="getChartClassBySize(indicator.width)" class="uk-margin-bottom">
                  <div class="uk-card uk-card-default"
                       [class.uk-disabled]="chartsActiveType.get(i + '-' + j).filtersApplied < countSelectedFilters()"
                       [class.semiFiltered]="chartsActiveType.get(i + '-' + j).filtersApplied < countSelectedFilters()">
                    <div class="uk-card-body uk-text-center">
                      <h4 class="uk-margin-bottom chartTitle uk-flex uk-flex-bottom ">
                        <div>{{indicator.name + " "}}</div>
                      </h4>
                      <div *ngIf="indicator.indicatorPaths.length > 1" class="uk-button-group">
                        <button *ngFor="let indicatorPath of indicator.indicatorPaths;"
                                class="uk-button"
                                (click)="setActiveChart(i, j, indicatorPath.type)"
                                [class.uk-button-secondary]="chartsActiveType.get(i + '-' + j).url === indicatorPath.url">
                          {{indicatorPath.type}}
                        </button>
                      </div>
                      <div *ngIf="properties.environment == 'development'">
                        Filtered: {{chartsActiveType.get(i + '-' + j).filtersApplied}}  out of
                        {{countSelectedFilters()}}</div>
                      <iframe *ngIf=" !properties.disableFrameLoad && chartsActiveType.get(i + '-' + j).source !==
                      'image'"
                              [src]="chartsActiveType.get(i + '-' + j).safeResourceUrl"
                              [class]="' uk-width-1-1 uk-height-' +
                        (indicator.height?indicator.height.toLowerCase():'medium')"></iframe>
                      <div *ngIf="properties.disableFrameLoad && chartsActiveType.get(i + '-' + j).source !==
                      'image'" class="uk-alert uk-alert-danger uk-text-center">I frames preview is disabled</div>
                      <!--                                        {{chartsActiveType.get(i).safeResourceUrl}}-->
                      <!--                    <a [href]="chartsActiveType.get(i).safeResourceUrl" target="_blank" > ChartuURL</a>-->
                      <img *ngIf="chartsActiveType.get(i + '-' + j).source === 'image'"
                           [src]="chartsActiveType.get(i + '-' + j).safeResourceUrl"
                           [class]="' uk-width-1-1 uk-height-' +
                        (indicator.height?indicator.height.toLowerCase():'medium')">
                      <!--<ng-container *ngTemplateOutlet="description; context: {indicator:indicator}"></ng-container>-->
                    </div>
                  </div>
                </div>
              </ng-template>
            </div>
          </div>
          <div class="uk-margin-medium-top uk-flex">
            <!-- Last Stats Date-->
            <div class="uk-width-2-3@m uk-width-1-2">
              <img src="assets/common-assets/graph.svg" style="opacity: 0.4">
              <span class="uk-margin-small-left uk-text-baseline uk-text-muted">Powered by <a
                  href="https://graph.openaire.eu" class="graph-color">OpenAIRE Research Graph</a></span>
              <span *ngIf="statsUpdateDate" class="uk-text-baseline uk-text-muted">
                . Last update of statistics in OpenAIRE: {{statsUpdateDate | date: 'MMM dd, yyyy'}}
              </span>
            </div>
            <!--Feedback-->
            <div class="uk-width-expand uk-text-right">
              <span class="uk-text-muted">Send us your <a [href]="mailText" target="_self"
                                                          (click)="mailMe()">feedback</a>.</span>
            </div>
          </div>
        </ng-template>
      </div>
    </div>
  </div>
</div>
<!--(click)="filterToggle= !filterToggle"
     [style.display]="(filterToggle?'none':'inherit')"-->
<div *ngIf="stakeholder && !privateStakeholder " href="#style_switcher" uk-toggle="" id="filters_switcher_toggle">
  <i class="  uk-text-muted">
    <svg style="margin-top: 8px;" xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24"
         viewBox="0 0 20 20"
         fill="white" width="24px" height="16px">
      <g>
        <path d="M0,0h24 M24,24H0" fill="none"/>
        <path
            d="M4.25,5.61C6.57,8.59,10,13,10,13v5c0,1.1,0.9,2,2,2h0c1.1,0,2-0.9,2-2v-5c0,0,3.43-4.41,5.75-7.39 C20.26,4.95,19.79,4,18.95,4H5.04C4.21,4,3.74,4.95,4.25,5.61z"/>
        <path d="M0,0h24v24H0V0z" fill="none"/>
      </g>
    </svg>
  </i>
</div>
<div *ngIf="stakeholder && !privateStakeholder" id="style_switcher" class=" uk-offcanvas filters_switcher"
     uk-offcanvas="flip:true" mode="slide" overlay="" style="z-index:982;">

  <div class="uk-offcanvas-bar offcanvas-white">
    <div class="uk-float-right">
      <button class="uk-offcanvas-close uk-close uk-icon" type="button" uk-close=""></button>

    </div>
    <div class="uk-padding">
      <div class="uk-grid uk-flex uk-flex-middle">
        <h5>Filters</h5>
        <a *ngIf="countSelectedFilters() > 1"
           class="  portal-link uk-width-1-2" (click)="clearAll()"> Clear All </a>
      </div>
      <div class="uk-grid uk-grid-small uk-text-small" uk-grid>
        <ng-container *ngTemplateOutlet="selected_filters_pills; context: {margin:false}"></ng-container>
      </div>
      <div *ngIf="user || countSelectedFilters() > 0 " class="uk-margin-small-top"><i
        class="uk-text-muted uk-text-small"> If your filter
        selection cannot be
        applied to a chart, that chart will appear grayed-out.</i></div>
      <div
        *ngIf="!user" class="uk-margin-top uk-alert uk-alert-warning"> Sign in to apply filters</div>
      <ul *ngIf="user" class="uk-list uk-list-divider  uk-margin-medium">
        <li>
          <range-filter [filter]="periodFilter" yearMin="2000" [yearMax]="currentYear" [mandatoryRange]="true"
                        (onFilterChange)="filter()"></range-filter>
        </li>
        <ng-container *ngFor="let filter of filters ">
          <li *ngIf="filter.values.length >0">
            <search-filter [filter]="filter" [showResultCount]=false
                           (onFilterChange)="filterChanged($event)"></search-filter>
          </li>
        </ng-container>
      </ul>

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

<ng-template #description let-indicator="indicator">
<span class="descriptionIcon"
      *ngIf="(indicator.description && indicator.description.length > 0)
                       || (indicator.additionalDescription && indicator.additionalDescription.length > 0)"
      uk-icon="info"
      [attr.uk-tooltip]="'title:<div class=\'uk-padding-small\'>'+
  (indicator.description&& indicator.description.length > 0?indicator.description:'') +'<br>'+
(indicator.additionalDescription && indicator.additionalDescription.length?indicator.additionalDescription:'')
  +'</div>'">
  </span>
</ng-template>
