<!-- Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements.  See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You 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. -->

<template>
  <div style="overflow: auto;height: 100%;" class="scroll_hide">
    <div class="rk-chart-slow clear">
      <div class="rk-chart-slow-i" v-for="(i, index) in data" :key="index">
        <svg class="icon vm r grey link-hover cp" @click="handleClick((i.traceIds && i.traceIds[0]) || i.name)">
          <use xlink:href="#review-list"></use>
        </svg>
        <div class="mb-5 ell" v-tooltip:top.ellipsis="i.name || ''">
          <span class="calls sm mr-10">{{ i.value }}</span>
          <span class="cp link-hover">{{ i.refId ? `${i.name}-${i.refId}` : i.name }}</span>
        </div>
        <RkProgress :precent="(i.value / maxValue) * 100" />
      </div>
    </div>
  </div>
</template>

<script lang="ts">
  import Vue from 'vue';
  import { Component, Prop } from 'vue-property-decorator';
  import copy from '@/utils/copy';

  @Component({})
  export default class ChartTrace extends Vue {
    @Prop() private intervalTime!: any;
    @Prop() private data!: any;
    @Prop() private item!: any;
    get maxValue() {
      if (!this.data.length) {
        return null;
      }
      const temp: number[] = this.data.map((i: any) => i.value);
      return Math.max.apply(null, temp);
    }
    private handleClick(i: any) {
      copy(i);
    }
  }
</script>
<style lang="scss">
  .rk-chart-slow {
    height: 100%;
    .calls {
      padding: 0 5px;
      display: inline-block;
      background-color: #40454e;
      color: #eee;
      border-radius: 4px;
    }
  }
  .rk-chart-slow-i {
    padding: 6px 0;
  }
</style>
