<div class=" uk-section  uk-margin-small-top tm-middle uk-container" id="tm-main">

    <div class="uk-container  uk-margin-bottom">

        <article class="uk-article ">
          <div *ngIf="status == errorCodes.LOADING" class="uk-animation-fade uk-width-1-1" role="alert"><span class="loading-gif uk-align-center"></span></div>
          <div *ngIf="status == errorCodes.ERROR" class="uk-alert uk-alert-warning" style="margin-top:40px; padding-left:40px;">
              An error occured
          </div>
            <div *ngIf=" (status == errorCodes.DONE) && (!statisticsSum || !statisticsDisplay  || ((statisticsSum.total_projects==0) && (allowedEntities.length == 0)))" class="uk-alert uk-alert-info" style="margin-top:40px; padding-left:40px;">
                No statistics are available for {{ communityId.toUpperCase() }}
            </div>
            <div *ngIf="statisticsSum && (statisticsSum.total_projects>0) && statisticsDisplay" class="uk-margin uk-margin-top">
                <div class="uk-grid">
                    <div class="uk-width-1-6@m uk-visible@m uk-margin-top">
                      <div uk-sticky="offset: 120">
                        <ul class="uk-tab uk-tab-left" uk-tab="connect:#tabs">
                        <!-- <ul class="uk-tab uk-tab-left uk-width-1-6 uk-margin-top" data-uk-tab="{connect:'#tabs'}"> -->
                          <li *ngFor="let entity of allowedEntities"
                              (click)="onChangeEntity(entity)" [class]="displayedEntity == entity?'uk-active':''">

                              <a href="#">{{ entitiesMap.get(entity) }}</a>
                          </li>
                        </ul>
                      </div>
                    </div>

                    <div class="uk-hidden@m uk-clearfix uk-width-1-1 uk-margin-bottom">
                      <button class="uk-button uk-button-default uk-hidden@m " type="button">
                        <span uk-navbar-toggle-icon></span> <span class="uk-margin-small-left">{{entitiesMap.get(displayedEntity)}}</span>
                      </button>

                      <ul id="toggle-small-tabs" class="uk-subnav uk-subnav-pill uk-dropdown uk-hidden@m uk-margin-top"
                          uk-switcher="connect:#tabs; animation: uk-animation-fade"
                          uk-dropdown="mode: click" uk-toggle="target: #toggle-small-tabs">
                         <li *ngFor="let entity of allowedEntities"
                             (click)="onChangeEntity(entity)" [class]="displayedEntity == entity?'uk-active':''">
                             <a>{{ entitiesMap.get(entity) }}</a>
                         </li>
                       </ul>
                     </div>

                    <ul id="tabs" class="uk-switcher uk-margin uk-width-expand" style="min-height:450px; padding-left:40px;">
                        <li *ngFor="let entity of allowedEntities" [class]="displayedEntity == entity?'uk-active':''">
                            <div *ngIf="(displayedEntity == entity) && statisticsSum[entity]">
                                <div class="uk-text-uppercase uk-text-bold uk-heading-divider">
                                    <h3>{{ entitiesMap.get(entity) }} statistics</h3>

                                    <div *ngIf="!statisticsSum[entity] ||
                                                !statisticsDisplay.entities[entity] ||
                                                statisticsSum[entity].total==0"
                                         class="uk-alert uk-alert-info">

                                        No {{ entitiesMap.get(entity) }} statistics available
                                    </div>

                                    <div *ngIf="statisticsDisplay.entities[entity] && statisticsSum[entity].total>0">
                                        <span *ngIf="statisticsDisplay.entities[entity].numbers.map['total'][currentMode]">
                                            {{statisticsSum[entity].total|number}} {{ entity + ( (entity == 'software' || statisticsSum[entity].total == 1) ? '' : 's') }}
                                        </span>

                                        <span *ngIf="statisticsDisplay.entities[entity].numbers.map['project'][currentMode] &&
                                                     statisticsSum[entity].projects>0">
                                                     <span *ngIf="statisticsDisplay.entities[entity].numbers.map['total'][currentMode]">
                                                          linked to
                                                     </span>
                                            {{statisticsSum[entity].projects|number}} project{{ statisticsSum[entity].projects == 1 ? '' : 's' }}.
                                        </span><br>
                                        <span *ngIf="statisticsDisplay.entities[entity].numbers.map['open'][currentMode] &&
                                                     statisticsSum[entity].open_access>0">
                                            {{statisticsSum[entity].open_access|number}}
                                            {{statisticsSum[entity].open_access == 1 ? 'is' : 'are'}} OA
                                        </span>
                                        <span *ngIf="statisticsDisplay.entities[entity].numbers.map['closed'][currentMode] &&
                                                     statisticsSum[entity].closed_access>0">

                                            <span *ngIf="statisticsDisplay.entities[entity].numbers.map['open'][currentMode]">
                                                ,
                                            </span>

                                            {{statisticsSum[entity].closed_access|number}}
                                            {{statisticsSum[entity].closed_access == 1 ? 'is' : 'are'}} closed
                                        </span>
                                        <span *ngIf="statisticsDisplay.entities[entity].numbers.map['restricted'][currentMode] &&
                                                     statisticsSum[entity].restricted>0">

                                            <span *ngIf="statisticsDisplay.entities[entity].numbers.map['open'][currentMode] ||
                                                         statisticsDisplay.entities[entity].numbers.map['closed'][currentMode]">
                                                ,
                                            </span>

                                            {{statisticsSum[entity].restricted|number}}
                                            {{statisticsSum[entity].restricted == 1 ? 'is' : 'are'}} restricted
                                        </span>
                                        <span *ngIf="statisticsDisplay.entities[entity].numbers.map['embargo'][currentMode] &&
                                                     statisticsSum[entity].embargo>0">

                                            <span *ngIf="statisticsDisplay.entities[entity].numbers.map['open'][currentMode] ||
                                                         statisticsDisplay.entities[entity].numbers.map['closed'][currentMode] ||
                                                         statisticsDisplay.entities[entity].numbers.map['restricted'][currentMode]">
                                                 and
                                            </span>
                                            {{statisticsSum[entity].embargo|number}}
                                            {{statisticsSum[entity].embargo == 1 ? 'is' : 'are'}} still in embargo.
                                        </span>
                                    </div>
                                </div>
                                <div *ngIf="statisticsSum[entity].total>0 && allowedCharts[entity].length==0"
                                     class="uk-alert uk-alert-info">
                                    No charts available
                                </div>
                                <div *ngIf="statisticsSum[entity].total>0 && allowedCharts[entity].length>0">
                                    <div class="uk-grid">
                                        <div *ngIf="statisticsDisplay.entities[entity].charts.map['timeline'] &&
                                                    statisticsDisplay.entities[entity].charts.map['timeline'][currentMode] &&
                                                    chartsInfoMap[entity + 'Timeline'] &&
                                                    (displayedTimeline == (entity + 'Timeline'))">
                                            <iframe [src]=displayedTimelineUrl width="1000" height="450"></iframe>
                                        </div>
                                        <div *ngIf="statisticsDisplay.entities[entity].charts.map['graph'] &&
                                                    statisticsDisplay.entities[entity].charts.map['graph'][currentMode] &&
                                                    chartsInfoMap[entity + 'Graph'] &&
                                                    (displayedGraph == (entity + 'Graph'))">
                                            <iframe [src]=displayedGraphUrl width="1000" height="450"></iframe>
                                        </div>
                                    </div>
                                    <hr *ngIf="(statisticsDisplay.entities[entity].charts.map['timeline'] &&
                                                statisticsDisplay.entities[entity].charts.map['timeline'][currentMode] &&
                                                chartsInfoMap[entity + 'Timeline'] &&
                                                (displayedTimeline == (entity + 'Timeline'))) || (statisticsDisplay.entities[entity].charts.map['graph'] &&
                                                            statisticsDisplay.entities[entity].charts.map['graph'][currentMode] &&
                                                            chartsInfoMap[entity + 'Graph'] &&
                                                            (displayedGraph == (entity + 'Graph')))">

                                    <div *ngIf="statisticsDisplay.entities[entity].charts.map['projectColumn'][currentMode] ||
                                                statisticsDisplay.entities[entity].charts.map['projectPie'][currentMode] ||
                                                statisticsDisplay.entities[entity].charts.map['projectTable'][currentMode]">
                                        <div>
                                            <h4 class="uk-text-uppercase uk-text-bold">{{ entitiesMap.get(entity) }} per project</h4>
                                        </div>
                                        <div>
                                            <ul class="uk-tab uk-margin-top" data-uk-tab="{connect: '#projectChartTabs'">
                                                <li *ngIf=" statisticsDisplay.entities[entity].charts.map['projectColumn'] &&
                                                            statisticsDisplay.entities[entity].charts.map['projectColumn'][currentMode] &&
                                                            chartsInfoMap[entity + 'Projectcolumn']"
                                                    (click)="changeDisplayedProjectChart(entity + 'Projectcolumn')">

                                                    <a href="#">Columns</a>
                                                </li>
                                                <li *ngIf=" statisticsDisplay.entities[entity].charts.map['projectPie'] &&
                                                            statisticsDisplay.entities[entity].charts.map['projectPie'][currentMode] &&
                                                            chartsInfoMap[entity + 'Projectpie']"
                                                    (click)="changeDisplayedProjectChart(entity + 'Projectpie')">

                                                    <a href="#">Pie</a>
                                                </li>
                                                <li *ngIf=" statisticsDisplay.entities[entity].charts.map['projectTable'] &&
                                                            statisticsDisplay.entities[entity].charts.map['projectTable'][currentMode] &&
                                                            chartsInfoMap[entity + 'Projecttable']"
                                                    (click)="changeDisplayedProjectChart(entity + 'Projecttable')">

                                                    <a href="#">Table</a>
                                                </li>
                                            </ul>
                                            <ul id="projectChartTabs" class="uk-switcher uk-margin">
                                                <li *ngIf="statisticsDisplay.entities[entity].charts.map['projectColumn'][currentMode]">
                                                    <div *ngIf="displayedProjectChart == (entity + 'Projectcolumn')">
                                                        <iframe [src]=displayedProjectChartUrl width="1000" height="450"></iframe>
                                                    </div>
                                                </li>
                                                <li *ngIf="statisticsDisplay.entities[entity].charts.map['projectPie'][currentMode]">
                                                    <div *ngIf="displayedProjectChart == (entity + 'Projectpie')">
                                                        <iframe [src]=displayedProjectChartUrl width="1000" height="450"></iframe>
                                                    </div>
                                                </li>
                                                <li *ngIf="statisticsDisplay.entities[entity].charts.map['projectTable'][currentMode]">
                                                    <div *ngIf="displayedProjectChart == (entity + 'Projecttable')">
                                                        <iframe [src]=displayedProjectChartUrl width="1000" height="450"></iframe>
                                                    </div>
                                                </li>
                                            </ul>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </li>
                    </ul>
                </div>
            </div>
        </article>
    </div>
</div>
