<template>
  <main id="main" style="margin-top: -20px; padding-bottom: 50px;">
    <div class="container">
      <div class="form">
        <div class="row">
          <div class="col-md-12 col-lg-8">
            <div class="section-header">
              <h2>Status List</h2>
            </div>
          </div>
        </div>
        <div v-if="checkAccess" class="row">
          <div class="col">
            <ListView
              :items="statusList"
              :showColumnChooser="false"
              :displayColumns="columns"
              :sortkey="'description'"
              :showNew="true"
              :editable="true"
              :deleteable="true"
              @onEdit="Edit"
              @onDelete="Delete"
              @onNew="New"
            />
          </div>
        </div>
        <div v-else>
          <alert
            :text="'You don\'t have permission to view this page'"
            :type="'ERROR'"
          />
        </div>
      </div>
    </div>
  </main>
</template>

<script>
/* eslint-disable */
import { mapState, mapActions } from 'vuex'

import Log from '../../../assets/Log'
import alert from '../../shared/alert'
import ListView from '../../shared/listView.vue'

export default {
  name: 'StatusList',
  components: {
    ListView,
    alert,
  },
  data() {
    return {
      columns: ['code', 'description', 'display'],
    }
  },
  created() {
    this.getStatusList()
  },
  computed: {
    ...mapState('status', ['statusList']),
    checkAccess() {
      if (Log.getUser().role === 'Super Admin') {
        return true
      } else {
        return false
      }
    },
  },
  methods: {
    ...mapActions('status', ['getStatusList', 'deleteStatus']),
    New() {
      this.$router.push('/status/new')
    },
    Edit(item) {
      this.$router.push({
        path: `/status/Edit/${item.id}`,
      })
    },
    Delete(item) {
      this.deleteStatus(item.id)
    },
  },
}
</script>
<style></style>
