<!--
 This file is part of the Meeds project (https://meeds.io/).
 
 Copyright (C) 2020 - 2022 Meeds Association contact@meeds.io
 
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License as published by the Free Software Foundation; either
 version 3 of the License, or (at your option) any later version.
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 Lesser General Public License for more details.
 
 You should have received a copy of the GNU Lesser General Public License
 along with this program; if not, write to the Free Software Foundation,
 Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
-->
<template>
  <v-data-table
    :headers="headers"
    :items="deeds"
    :group-by="groupBy"
    item-key="date"
    class="content-box-sizing"
    disable-sort
    disable-pagination
    disable-filtering
    hide-default-header
    hide-default-footer>
    <template #header>
      <tr>
        <th
          v-for="header in headers"
          :key="header.value"
          :id="header.value"
          :style="`width: ${header.width};`"
          role="columnheader"></th>
      </tr>
      <tr v-if="!hideLoading">
        <td :colspan="headers.length">
          <v-progress-linear v-if="loading" indeterminate />
          <div v-else class="pt-1"></div>
        </td>
      </tr>
    </template>
    <template #[`group.header`]="{group, items}">
      <td :colspan="headers.length">
        {{ $t(group) }} ({{ items.length }})
      </td>
    </template>
    <template #[`item.avatar`]="{header, item}">
      <deed-provisioning-management-tenants-item
        :status="status"
        :deed="item"
        :column="header.value" />
    </template>
    <template #[`item.nftId`]="{header, item}">
      <deed-provisioning-management-tenants-item
        :status="status"
        :deed="item"
        :column="header.value" />
    </template>
    <template #[`item.title`]="{header, item}">
      <deed-provisioning-management-tenants-item
        :status="status"
        :deed="item"
        :column="header.value"
        :static-elements="staticElements" />
    </template>
    <template #[`item.date`]="{header, item}">
      <deed-provisioning-management-tenants-item
        :status="status"
        :deed="item"
        :column="header.value" />
    </template>
    <template #[`item.actions`]="{header, item}">
      <deed-provisioning-management-tenants-item
        :status="status"
        :deed="item"
        :column="header.value" />
    </template>
    <template #[`item.taskLink`]="{header, item}">
      <deed-provisioning-management-tenants-item
        :status="status"
        :deed="item"
        :column="header.value" />
    </template>
  </v-data-table>
</template>
<script>
export default {
  props: {
    status: {
      type: String,
      default: null,
    },
    deeds: {
      type: Array,
      default: function() {
        return [];
      },
    },
    hideLoading: {
      type: Boolean,
      default: false,
    },
    loading: {
      type: Boolean,
      default: false,
    },
    staticElements: {
      type: Boolean,
      default: false,
    },
    options: {
      type: Object,
      default: function() {
        return {};
      },
    },
    groupBy: {
      type: String,
      default: null,
    },
    headers: {
      type: Array,
      default: function() {
        return [{
          text: '',
          align: 'center',
          value: 'avatar',
          width: '60px',
          class: 'pxdddd-0',
        }, {
          text: '',
          align: 'center',
          value: 'nftId',
          width: '60px',
          class: 'pxddd-0',
        }, {
          text: '',
          align: 'left',
          value: 'title',
          width: 'auto',
        }, {
          text: '',
          align: 'left',
          value: 'date',
          width: '150px',
        }, {
          text: '',
          align: 'center',
          value: 'actions',
          width: '150px',
        }];
      },
    },
  },
  computed: {
    title() {
      return this.$t(`deeds.provisioning.management.${this.status}`);
    },
    displayedSize() {
      return this.deeds.length || 0;
    },
    hasDeeds() {
      return this.displayedSize > 0;
    },
  },
};
</script>
