<script setup>

import { ref, onMounted } from 'vue';
import Section from './Section.vue';
import SystemModel from '../models/SystemModel.js';
import DiskUsageItem from './DiskUsageItem.vue';

const systemModel = SystemModel.create();

const ready = ref(false);
const filesystems = ref([]);

onMounted(async () => {
  const [error, result] = await systemModel.filesystems();
  if (error) return console.error(error);

  filesystems.value = result;
  ready.value = true;
});

</script>

<template>
  <Section :title="$t('system.diskUsage.title')">
    <div>
      <DiskUsageItem v-for="filesystem in filesystems" :key="filesystem.filesystem" :filesystem="filesystem" />
    </div>
  </Section>
</template>

<style scoped>

.usage-bar {
  display: flex;
  flex-wrap: nowrap;
  width: 100%;
  height: 20px;
  background-color: #d8dee4;
  color: #7f7f7f;
}

@media (prefers-color-scheme: dark) {
  .usage-bar {
    background-color: white;
  }
}

.usage-bar-section {
  display: inline-block;
  height: 100%;
}

.usage-bar-section-remaining {
  display: inline-block;
  height: 100%;
  margin: auto;
}

.color-indicator {
  display: inline-block;
  width: 16px;
  height: 16px;
  border-radius: 3px;
  line-height: 16px;
  margin-right: 4px;
}

.disk-content {
  white-space: nowrap;
  overflow: auto;
}

.disk-content-size {
  color: #777;
  margin-left: 4px;
}

</style>
