<template>
  <!-- eslint-disable max-len -->
  <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>Contact Us Sources</h2>
            </div>
          </div>
        </div>
        <div v-if="checkAccess" class="row">
          <div class="col">
            <listView
              :items="contactUsSources"
              :showNew="true"
              :editable="true"
              :deleteable="true"
              :displayColumns="columns"
              :sortKey="'description'"
              @onEdit="Edit"
              @onDelete="Delete"
              @onNew="New"
            />
          </div>
        </div>
        <div v-else class="row">
          <div class="col">
            <alert
              :text="'You don\'t have permission to view this page'"
              :type="'ERROR'"
            />
          </div>
        </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: 'ContactUsSourceList',
  components: {
    listView,
    alert,
  },
  data() {
    return {
      columns: ['description'],
    }
  },
  methods: {
    ...mapActions('contactUsSources', [
      'getContactUsSources',
      'deleteContactUsSource',
    ]),
    selectSource() {},
    New() {
      this.$router.push('/contactUsSource/new')
    },
    Edit(item) {
      this.$router.push({
        path: `/contactUsSource/${item.id}`,
      })
    },
    Delete(item) {
      console.log('Delete')
      this.deleteContactUsSource(item.id)
    },
  },
  mounted() {
    this.getContactUsSources()
  },
  computed: {
    ...mapState('contactUsSources', ['contactUsSources']),
    checkAccess() {
      if (Log.getUser().role === 'Super Admin') {
        return true
      } else {
        return false
      }
    },
  },
}
</script>
