<template>
  <div class="flexcr dashboard">
    <div class="dashboard-item" v-for="(item, index) in dashboard" :key="index">
      <div class="item-value">{{info[item.key] || "0"}}</div>
      <div class="item-title">{{item.title}}</div>
      <el-button
        type="primary"
        class="item-button"
        :disabled="!enable"
        @click="item.onClick">
        {{item.button}}
      </el-button>
    </div>
  </div>
</template>

<script>
  export default {
    name: "Dashboard",
    props: {
      siteId: String|Number,
      info: {
        type: Object,
        default: {}
      },
      enable: {
        type: Boolean,
        default: false
      },
      v2: {
        type: Boolean,
        default: false
      }
    },
    data() {
      return {
        siteInfo: {},
        dashboard: [{
          key: "stations",
          title: "Stations",
          button: "Configure Station",
          onClick: () => this.toStations()
        },{
          key: "connectors",
          title: "Connectors",
          button: "View Connectors",
          onClick: () => this.toConnectors()
        },{
          key: "activeTransaction",
          title: "Active Transaction",
          button: "View Transactions",
          onClick: () => this.toTransactions()
        },{
          key: "reservationsMade",
          title: "Reservations Made",
          button: "View Reservations",
          onClick: () => this.toReservations()
        }]
      };
    },
    mounted() {
      
    },
    methods: {
      toStations() {
        if (this.v2) {
          this.$router.push({
            path: "/site-management/stations/" + this.siteId
          })
        } else {
          this.$router.push({
            path: "/charge-station-management/registered-charge-stations"
          })
        }
      },
      toConnectors() {
        if (this.v2) {
          this.$router.push({
            path: "/site-management/connectors/" + this.siteId
          })
        } else {
          this.$router.push({
            path: "/charge-station-management/connectors"
          })
        }
      },
      toTransactions() {
        this.$router.push({
          path: "/station-activities/transactions"
        })
      },
      toReservations() {
        this.$router.push({
          path: "/station-activities/reservations"
        })
      }
    }
  }
</script>

<style scoped>
.dashboard {
  zoom: 0.88;
}
.dashboard-item {
  flex: 1;
  display: flex;
  margin: 5px 8px;
  align-items: center;
  flex-direction: column;
}
.item-value {
  color: #333;
  font-size: 22px;
  font-weight: bold;
  line-height: 30px;
}
.item-title {
  color: #333;
  font-size: 14px;
  line-height: 20px;
  white-space: nowrap;
  text-transform: uppercase;
}
.item-button {
  width: 100%;
  max-width: 200px;
  font-size: 13px;
  margin-top: 10px;
  padding: 12px 10px;
  text-transform: uppercase;
}
</style>