<script lang="ts" setup>

import {useMainLayoutStore} from "~/strores/UseMainLayoutStore";
import {useDataStore} from "~/strores/DataStore";
import AreaChart2 from "~/components/Charts/AreaChart2.vue";

type diskInfo = {
  name: string,
  value: string
}
const id = toRef(useRoute().params.id);
const lsDisk = ref<diskInfo[]>([])
const mainLayoutStore = useMainLayoutStore()
const dataStore = useDataStore()
onMounted(() => {
  $fetch('/Api/Server/GetServerDiskInfo', {
    method: 'GET',
    params: {
      ServerId: mainLayoutStore.SelectServer.value,
      DiskId: id.value
    },
    headers: {
      'Content-Type': 'application/json',
      'Authorization': "Bearer " + useCookie('token').value
    },
    baseURL: useRuntimeConfig().public.baseUrl
  }).then(res => {
    lsDisk.value = res as diskInfo[]
  })
})
</script>

<template>
  <div class="disk-layout">
    <div class="left-chart">
      <div class="disk-title">
        <h1>驱动器 {{ $route.params.id }}</h1>
        <h2>{{ lsDisk.find(x => x.name === 'Device_Model' || x.name === 'Model_Number')?.value }}</h2>
      </div>
      <div class="disk-chart-top">
        <p>活动时间</p>
        <p>100%</p>
      </div>
      <div class="disk-chart">
        <AreaChart2 :bg-color="'rgba(38,153,100,0.3)'" :colors="['#269964']" :value-ids="[`DiskUtil-${$route.params.id}`]"
                    :configs="[
                        {
                          areaStyle: {}
                        }
                    ]"
                    :value-names="['磁盘使用率']"/>
      </div>
      <div class="disk-chat-bottom">
        <p>更早</p>
        <p>0</p>
      </div>
      <div class="disk-chart-top">
        <p>吞吐量</p>
        <p></p>
      </div>
      <div class="disk-chart">
        <AreaChart2 :bg-color="'rgba(38,153,100,0.3)'" :colors="['#269964']" :min="null" :max="null" :configs="[{},{lineStyle: {type: 'dashed'},type: 'line'}]"
                    :value-ids="[`DiskReadKB-${$route.params.id}`,`DiskWriteKB-${$route.params.id}`]" :value-names="['磁盘读取KB','磁盘写入KB']"/>
      </div>
      <div class="disk-chat-bottom">
        <p>更早</p>
        <p>0</p>
      </div>
    </div>
    <div class="right-info">
      <div class="info-title-box">
        <div class="info-title">
          <p>使用率</p>
          <h2>{{ dataStore.data[`DiskUtil-${id}`] }}%</h2>
        </div>
        <div class="info-title">
          <p>平均响应时间</p>
          <h2>{{ dataStore.data[`DiskAwait-${id}`] }} ms</h2>
        </div>
        <div class="infos">
          <div class="info2">
            <div></div>
            <p>读取速度</p>
            <h2>{{ dataStore.data[`DiskReadKB-${id}`] }} KiB/s</h2>
          </div>
          <div class="info2">
            <div></div>
            <p>写入速度</p>
            <h2>{{ dataStore.data[`DiskWriteKB-${id}`] }} KiB/s</h2>
          </div>
        </div>
      </div>
      <div class="other-info-box">
        <div v-for="value in lsDisk" class="other-info">
          <p>{{ value.name }}</p>
          <p>{{ value.value }}</p>
        </div>
      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
@import "base";

.disk-layout {
  padding: $padding*1.5;
  display: grid;
  grid-template-columns: 1fr 300px;
  grid-template-rows: 1fr;
  gap: $gap*4;
}

.left-chart {
  display: flex;
  flex-direction: column;
  gap: $gap;

  .disk-title {
    display: flex;
    justify-content: space-between;
    align-items: center;

    .dark-mode & {
      h1, h2 {
        color: $dark-text-color;
      }
    }

    h1, h2 {
      color: $light-text-color;
    }

    h1 {
      font-size: 32px;
    }
  }
}

.disk-chart-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.disk-chart {
  flex: 1;
  border: 4px solid #269964;
  border-radius: $radius*2;
  height: min-content;
  max-height: 32rem;
  min-height: 32rem;
  overflow: hidden;
}

.disk-chat-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.info-title-box {
  display: flex;
  flex-wrap: wrap;
  gap: $gap*2;

  .info-title {
    display: flex;
    flex-direction: column;
    gap: $gap*.5;
  }

  .info-title:nth-of-type(2) {
    width: 60%;
  }
}

.other-info-box {
  display: flex;
  flex-direction: column;
  gap: $gap*.5;

  .other-info {
    display: flex;
    gap: $gap;
    overflow: hidden;
    p:first-of-type {
      font-weight: 500;
    }

    p {
      flex: 1;
      //文本换行
      word-wrap: break-word;
      max-width: 50%;
    }
  }
}

.right-info {
  display: flex;
  flex-direction: column;
  gap: $gap*2;
}

.infos {
  display: flex;
  flex-direction: column;
  gap: $gap*2;

  .info2 {
    display: grid;
    grid-template-columns: 4px 1fr;
    grid-template-rows: 1fr 1fr;
    grid-column-gap: $gap*2;

    & > div {
      height: 100%;
      border: 3px solid #269964;
      grid-row: 1/3;
    }
  }

  .info2:last-of-type {
    & > div {
      height: 100%;
      border: 3px dashed #269964;
      grid-row: 1/3;
    }
  }
}
</style>