<template>
  <div class="flex flex-col w-full h-full gap-2 justify-center">
    <Pagination
      :items="repairs"
      :totalCount="totalCount"
      :indicateLoading="loading == 'loading'"
      @load-data="(offset, count, search) => fetchOpenRepairs(offset, count, search)"
      @search="(search) => fetchOpenRepairs(0, maxEntriesPerPage, search, true)"
    >
      <template #pageRow="{ row }: { row: RepairViewModel }">
        <RepairListItem :repair="row" />
      </template>
    </Pagination>
  </div>
</template>

<script setup lang="ts">
import { defineComponent } from "vue";
import { mapActions, mapState } from "pinia";
import MainTemplate from "@/templates/Main.vue";
import { useAbilityStore } from "@/stores/ability";
import { useRepairStore } from "@/stores/admin/unit/repair";
import type { RepairViewModel } from "@/viewmodels/admin/unit/repair.models";
import Pagination from "@/components/Pagination.vue";
import RepairListItem from "@/components/admin/unit/repair/RepairListItem.vue";
</script>

<script lang="ts">
export default defineComponent({
  data() {
    return {
      maxEntriesPerPage: 25,
    };
  },
  computed: {
    ...mapState(useRepairStore, ["repairs", "totalCount", "loading"]),
    ...mapState(useAbilityStore, ["can"]),
  },
  mounted() {
    this.fetchOpenRepairs(0, this.maxEntriesPerPage, "", true);
  },
  methods: {
    ...mapActions(useRepairStore, ["fetchOpenRepairs"]),
  },
});
</script>
