<template>
  <div class="flex flex-col gap-2 h-full w-full overflow-y-auto">
    <div v-if="activeEquipmentObj != null" class="flex flex-col gap-2 w-full">
      <div>
        <label for="type">Typ</label>
        <input type="text" id="type" :value="activeEquipmentObj.equipmentType.type" readonly />
      </div>
      <div>
        <label for="name">Bezeichnung</label>
        <input type="text" id="name" :value="activeEquipmentObj.name" readonly />
      </div>
      <div>
        <label for="code">Code</label>
        <input type="text" id="code" :value="activeEquipmentObj.code" readonly />
      </div>
      <div>
        <label for="location">Verortung</label>
        <input type="text" id="location" :value="activeEquipmentObj.location" readonly />
      </div>
    </div>

    <Spinner v-if="loadingActive == 'loading'" class="mx-auto" />
    <p v-else-if="loadingActive == 'failed'" @click="fetchEquipmentByActiveId" class="cursor-pointer">
      &#8634; laden fehlgeschlagen
    </p>
  </div>
</template>

<script setup lang="ts">
import { defineComponent } from "vue";
import { mapActions, mapState } from "pinia";
import Spinner from "@/components/Spinner.vue";
import { useEquipmentStore } from "@/stores/admin/unit/equipment/equipment";
</script>

<script lang="ts">
export default defineComponent({
  props: {
    equipmentId: String,
  },
  computed: {
    ...mapState(useEquipmentStore, ["activeEquipmentObj", "loadingActive"]),
  },
  mounted() {
    this.fetchEquipmentByActiveId();
  },
  methods: {
    ...mapActions(useEquipmentStore, ["fetchEquipmentByActiveId"]),
  },
});
</script>
