<script setup lang="ts">
import BootstrapModal from "@/components/modals/BootstrapModal.vue";
import type { S3ObjectMetaInformation } from "@/client/s3proxy";
import dayjs from "dayjs";
import { filesize } from "filesize";

const props = defineProps<{
  modalID: string;
  s3Object: S3ObjectMetaInformation;
}>();
</script>

<template>
  <bootstrap-modal
    :modalID="modalID"
    :static-backdrop="false"
    modal-label="Object Detail Modal"
  >
    <template v-slot:header>
      <h4>Object Details</h4>
    </template>
    <template v-slot:body>
      <div class="container-fluid">
        <table class="table table-hover table-sm table-borderless">
          <tbody>
            <tr>
              <th scope="row" class="col-4">Bucket</th>
              <td class="col-8">{{ props.s3Object.bucket }}</td>
            </tr>
            <tr>
              <th scope="row">Name</th>
              <td>{{ props.s3Object.key }}</td>
            </tr>
            <tr>
              <th scope="row">Content Type</th>
              <td>{{ props.s3Object.content_type }}</td>
            </tr>
            <tr>
              <th scope="row">Timestamp</th>
              <td>
                {{
                  dayjs(props.s3Object.last_modified).format(
                    "YYYY-MM-DD HH:mm:ss"
                  )
                }}
              </td>
            </tr>
            <tr>
              <th scope="row">Size</th>
              <td>{{ filesize(props.s3Object.size) }}</td>
            </tr>
          </tbody>
        </table>
      </div>
    </template>
    <template v-slot:footer>
      <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
        Close
      </button>
    </template>
  </bootstrap-modal>
</template>

<style scoped>
th {
  font-weight: bold;
  text-align: end;
}
</style>