import './_usage-graphs.sass'
import templateUrl from './usage-graphs.html'

export const UsageGraphsComponent = {
  bindings: {
    cpuChart: '<',
    memoryChart: '<',
    storageChart: '<',
    titleDetails: '@?'
  },
  controller: ComponentController,
  controllerAs: 'vm',
  templateUrl
}

/** @ngInject */
function ComponentController () {
  const vm = this
  vm.$onChanges = activate

  function activate () {
    angular.extend(vm, {
      cpuChart: vm.cpuChart || {data: {total: 0}},
      memoryChart: vm.memoryChart || {data: {total: 0}},
      storageChart: vm.storageChart || {data: {total: 0}},
      cpuDataExists: true,
      memoryDataExists: true,
      storageDataExists: true,
      emptyState: {icon: 'pficon pficon-help', title: 'No Information Available'}

    })

    if (vm.cpuChart.data.total === 0) {
      vm.cpuDataExists = false
    }
    if (vm.memoryChart.data.total === 0) {
      vm.memoryDataExists = false
    }
    if (vm.storageChart.data.total === 0) {
      vm.storageDataExists = false
    }
    vm.availableCPU = vm.cpuChart.data.total - vm.cpuChart.data.used
    vm.availableMemory = vm.memoryChart.data.total - vm.memoryChart.data.used
    vm.availableStorage = vm.storageChart.data.total - vm.storageChart.data.used
  }
}

@@ -379,40 +379,13 @@
 s = 
-activate%0A%0A  function activate ()
+() =%3E
  %7B%0A 
@@ -588,35 +588,36 @@
  cpuDataExists: 
-tru
+fals
 e,%0A      memoryD
@@ -619,35 +619,36 @@
 moryDataExists: 
-tru
+fals
 e,%0A      storage
@@ -663,11 +663,12 @@
 ts: 
-tru
+fals
 e,%0A 
@@ -720,16 +720,19 @@
  title: 
+__(
 'No Info
@@ -749,19 +749,19 @@
 ailable'
+)
 %7D%0A
-%0A
     %7D)%0A%0A
@@ -783,35 +783,33 @@
 hart.data.total 
-===
+%3E
  0) %7B%0A      vm.c
@@ -827,103 +827,91 @@
 s = 
-false%0A    %7D%0A    if (vm.memoryChart.data.total === 0) %7B%0A      vm.memoryDataExists = fal
+true%0A      vm.availableCPU = vm.cpuChart.data.total - vm.cpuChart.data.u
 se
+d
 %0A    %7D%0A
+%0A
     
@@ -917,23 +917,22 @@
  if (vm.
-storage
+memory
 Chart.da
@@ -944,11 +944,9 @@
 tal 
-===
+%3E
  0) 
@@ -956,23 +956,22 @@
      vm.
-storage
+memory
 DataExis
@@ -979,20 +979,15 @@
 s = 
-false%0A    %7D%0A
+true%0A  
     
@@ -994,36 +994,42 @@
 vm.available
-CPU = vm.cpu
+Memory = vm.memory
 Chart.data.t
@@ -1030,35 +1030,38 @@
 data.total - vm.
-cpu
+memory
 Chart.data.used%0A
@@ -1068,82 +1068,89 @@
     
-vm.availableMemory = vm.memoryChart.data.total - vm.memoryChart.data.used%0A
+%7D%0A%0A    if (vm.storageChart.data.total %3E 0) %7B%0A      vm.storageDataExists = true%0A  
     
@@ -1226,14 +1226,20 @@
 ta.used%0A
+    %7D%0A
   %7D%0A%7D%0A

Refactor graph component to break less