<!--
  #%L
  thinkbig-ui-operations-manager
  %%
  Copyright (C) 2017 ThinkBig Analytics
  %%
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
  
      http://www.apache.org/licenses/LICENSE-2.0
  
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  #L%
  -->

<div class="feed-stats">
  <div layout="column" ng-if="vm.dataLoaded" layout-padding>


    <div flex>
      <md-card layout-align="center center">
        <md-card-content layout="column" style="width:100%;">
          <div layout="row" class="layout-padding-left">
            <span flex layout-align="end top" class="md-button-group layout-padding feed-stats-filter" layout-padding>
              <md-button flex="none" class="border-btn small" ng-repeat="opt in vm.timeFrameOptions track by opt.value" ng-class="{'selected': vm.timeFrame == opt.value}"
                         ng-click="vm.onTimeFrameClick(opt.value)">{{opt.label}}</md-button>
            </span>
            <span flex></span>
            <div layout="column">
              <div layout="column" class="layout-padding-right">
                <span class="hint">{{vm.lastRefreshTime | date:'HH:mm:ss'}}</span>
                <span class="md-caption">Last Refreshed</span>
              </div>
              <div flex="20" class="md-block layout-padding-top-bottom" ng-if="vm.showProcessorChartLoading || vm.showFeedTimeChartLoading">
                <div layout="column">
                  <span style="padding-top:30px;">&nbsp;</span>
                  <md-progress-linear md-mode="indeterminate"></md-progress-linear>
                </div>

              </div>


            </div>

          </div>

        </md-card-content>
      </md-card>
    </div>

    <div layout="row" layout-sm="column" layout-xs="column">
      <div flex layout="column" flex-gt-sm="70" flex="100" flex-order="1" flex-order-xs="2" flex-order-sm="2">
        <!-- THE KPIs -->
        <div layout="row" layout-xs="column" layout-wrap layout-align="space-between center" class="kpi-row">

          <div flex-gt-md="33" flex-gt-xs="50" class="service-wrapper kpi" layout-wrap>
            <md-card layout-align="center center" class="kpi">
              <md-card-title layout="column" layout-align="center center" style="width:100%;">
                <span class="md-display-1">{{vm.eventSuccessKpi.value}}% </span>
              </md-card-title>
              <md-card-title-media class="icon">
                <div class="md-media-sm card-media">
                  <ng-md-icon icon="{{vm.eventSuccessKpi.icon}}" style="fill:{{vm.eventSuccessKpi.color}}" size="50">
                  </ng-md-icon>
                </div>
              </md-card-title-media>
              <md-card-content layout="column" layout-align="center center">
                <span class="md-title">Success Rate</span>
              </md-card-content>
            </md-card>
          </div>

          <div flex-gt-md="33" flex-gt-xs="50" class="kpi" layout-wrap>
            <md-card layout-align="center center">
              <md-card-title layout="column" layout-align="center center" style="width:100%;">
                <span class="md-display-1">{{vm.flowRateKpi.value}}/sec </span>
              </md-card-title>
              <md-card-title-media class="icon">
                <div class="md-media-sm card-media">
                  <ng-md-icon icon="{{vm.flowRateKpi.icon}}" style="fill:{{vm.flowRateKpi.color}}" size="50">
                  </ng-md-icon>
                </div>
              </md-card-title-media>
              <md-card-content layout="column" layout-align="center center">
                <span class="md-title">Incoming Flow Rate</span>
              </md-card-content>
            </md-card>
          </div>

          <div flex-gt-md="33" flex-gt-xs="50" class="kpi" layout-wrap>
            <md-card layout-align="center center">
              <md-card-title layout="column" layout-align="center center" style="width:100%;">
                <span class="md-display-1">{{vm.avgDurationKpi.value}}</span>
              </md-card-title>
              <md-card-title-media class="icon">
                <div class="md-media-sm card-media">
                  <ng-md-icon icon="{{vm.avgDurationKpi.icon}}" style="fill:{{vm.avgDurationKpi.color}}" size="50">
                  </ng-md-icon>
                </div>
              </md-card-title-media>
              <md-card-content layout="column" layout-align="center center">
                <span class="md-title">Flow Duration</span>
              </md-card-content>
            </md-card>
          </div>
        </div>
        <!-- END KPIs -->

        <div flex>
          <md-card layout-align="start start" style="margin-left: 0px;margin-right: 0px;">
            <span class="card-title kpi-header layout-padding-left">Flow Rate</span>
            <span class="md-caption kpi-subtitle layout-padding-top layout-padding-left">Monitor the rate of the feed flows</span>
            <md-card-content style="width:100%;">
              <nvd3 options="vm.feedChartOptions" data="vm.feedChartData" api="vm.feedChartApi"></nvd3>

            </md-card-content>
          </md-card>
        </div>


        <div>
          <md-card layout-align="center center" style="margin-left: 0px;margin-right: 0px;">
            <span class="card-title kpi-header">Feed Processor Metrics</span>
            <md-card-content style="width:100%;">
              <md-input-container class="md-block layout-padding-top-bottom">
                <label class="md-container-ignore label-small layout-padding-top">Processor Metric</label>
                <md-select ng-model="vm.selectedProcessorStatisticFunction" ng-change="vm.onProcessorChartFunctionChanged()" aria-label="Rule Type">
                  <md-option value="{{opt}}" ng-repeat="opt in vm.processorStatsFunctions">{{ opt }}</md-option>
                </md-select>
              </md-input-container>
              <div flex layout="row" layout-align="start end">
                <span flex></span>
                <span flex="20" ng-if="vm.showProcessorChartLoading">
          <md-progress-linear md-mode="indeterminate"></md-progress-linear>
        </span>
              </div>
              <nvd3 flex options="vm.processorChartOptions" data="vm.processorChartData" api="vm.processorChartApi" config="{deepWatchOptions:true}"></nvd3>

            </md-card-content>
          </md-card>
        </div>


      </div>

      <div flex="100" flex-gt-sm="30" flex-order="2" flex-order-xs="1" flex-order-sm="1" class="layout-padding-left">
        <card-layout class="right-card">
          <header-section>
            <div layout="column">
              <div class="card-title right-card-title-text">Feed Details</div>
            </div>
            <div layout="column">
              <span class="item-title" class="layout-padding-top-bottom">{{vm.feedName}}</span>
            </div>
          </header-section>
          <body-section>
            <div>
              <md-divider></md-divider>
              <md-list layout-fill layout="column" class="list-item-table">

                <md-list-item>
                  <div layout="column" class="item-column md-list-item-text ">
                        <span class="item-title" ng-class="{'healthy':vm.feed.displayStatus == 'COMPLETED' || vm.feed.displayStatus =='RUNNING'}">
                         {{vm.feed.displayStatus}}</span>
                    <span class="column-title column-title-bottom">Status</span>
                  </div>
                  <md-divider></md-divider>
                </md-list-item>

                <md-list-item>
                  <div layout="column" class="item-column md-list-item-text ">
                    <span class="item-title">{{vm.summaryStatistics.flowsStarted | number}}</span>
                    <span class="column-title column-title-bottom">Flows Started</span>
                  </div>
                  <md-divider></md-divider>
                </md-list-item>

                <md-list-item>
                  <div layout="column" class="item-column md-list-item-text ">
                    <span class="item-title">{{vm.summaryStatistics.flowsFinished | number}}</span>
                    <span class="column-title column-title-bottom">Flows Finished</span>
                  </div>
                  <md-divider></md-divider>
                </md-list-item>

                <md-list-item>
                  <div layout="column" class="item-column md-list-item-text ">
                    <span class="item-title">{{vm.summaryStatistics.flowsRunning | number}}</span>
                    <span class="column-title column-title-bottom">Flows Running</span>
                  </div>
                  <md-divider></md-divider>
                </md-list-item>

                <md-list-item>
                  <div layout="column" class="item-column md-list-item-text ">
                    <span class="item-title">{{vm.summaryStatistics.flowsStartedPerSecond | number}} / sec</span>
                    <span class="column-title column-title-bottom">Flows Rate</span>
                  </div>
                  <md-divider></md-divider>
                </md-list-item>

                <md-list-item>
                  <div layout="column" class="item-column md-list-item-text ">
                    <span class="item-title">{{vm.avgDurationKpi.value}}</span>
                    <span class="column-title column-title-bottom">Flow Duration</span>
                  </div>
                  <md-divider></md-divider>
                </md-list-item>

                <md-list-item>
                  <div layout="column" class="item-column md-list-item-text ">
                    <span class="item-title">{{vm.eventSuccessKpi.value }}%</span>
                    <span class="column-title column-title-bottom">Successful Events</span>
                  </div>
                  <md-divider></md-divider>
                </md-list-item>

                <md-list-item>
                  <div layout="column" class="layout-padding-top-bottom layout-padding-left-right"  layout-align="space-between start">
                    <div class="md-subheader layout-padding-bottom">Feed Manager</div>
                    <span class="layout-padding-bottom">
                       <a href ng-click="vm.gotoFeedDetails($event)">Feed Details</a>
                    </span>
                  </div>
                </md-list-item>





              </md-list>
            </div>
          </body-section>
        </card-layout>
      </div>

    </div>


  </div>
  <div ng-if="!vm.dataLoaded" class="kpi-loading" layout-align="center center" layout="column">
    <md-progress-circular md-mode="indeterminate" md-diameter="60"></md-progress-circular>
  </div>
</div>
