<template>
  <div>
    <!-- 通訊錄functionBar -->
    <div class="shadow" v-show="$route.name === 'DirectoryInformationList'">
      <b-button
        class="btn1"
        @click="AddNewDirectoryModalOpen = true"
        :disabled = "this.directory.permission === 1"
      >
        <b-icon-person-plus-fill></b-icon-person-plus-fill>&ensp;新增聯絡人
      </b-button>

      <b-button
        class="btn_delete"
        @click="DeleteDirectoryModalOpen = true"
        :disabled = "this.directory.permission === 1"
      >
        <b-icon-trash-fill></b-icon-trash-fill>&ensp;刪除聯絡人
      </b-button>
    </div>

    <modal
      :isOpen="AddNewDirectoryModalOpen"
      title="新增聯絡人"
      v-on:closeEvent="AddNewDirectoryModalOpen = false"
    >
      <addNewDirectory @closeEvent="AddNewDirectoryModalOpen = false" />
    </modal>

    <modal
      :isOpen="DeleteDirectoryModalOpen"
      title="刪除聯絡人"
      v-on:closeEvent="DeleteDirectoryModalOpen = false"
    >
      <deleteDirectory @closeEvent="DeleteDirectoryModalOpen = false" />
    </modal>

  </div>
</template>

<script>
import addNewDirectory from '@/views/BasicSetting/DirectorySetting/ModalContent/addNewDirectory.vue'
import deleteDirectory from '@/views/BasicSetting/DirectorySetting/ModalContent/deleteDirectory.vue'
import { mapState } from 'vuex'

export default {
  data () {
    return {
      AddNewDirectoryModalOpen: false,
      DeleteDirectoryModalOpen: false,
      /// 權限
      directory: {}
    }
  },
  mounted () {
    this.usePermission()
  },
  methods: {
    usePermission () { // 確認權限
      Object.values(this.currentUser.tenderPermissions).forEach(obj => {
        if (obj.tenderId === this.currentUser.defaultTender) {
          let permission = obj.permission
            .filter(name => name.title === '基本設定')
            .map(val => { return val.functionItem })
          for (const element of permission) {
            for (const a of element) {
              if (a.name === '通訊錄') this.directory = a
            }
          }
        }
      })
    }
  },
  components: {
    modal: () => import('@/views/Modal/index.vue'),
    addNewDirectory,
    deleteDirectory
  },
  computed: {
    ...mapState({
      currentUser: (state) => state.user.current

    })
  }
}
</script>

<style scoped>
.shadow {
  background-color: #ffff;
  height: 60px;
  width: 100%;
  box-shadow: 2px 2px 20px rgba(0, 0, 0, 40);
  position: fixed;
  top: 55px;
  z-index: 500;
}
.btn1 {
  background-color: rgb(75, 102, 255);
  font-size: 16px;
  margin-top: 15px;
  margin-left: 15px;
  padding-left: 7px;
  padding-right: 7px;
  padding-top: 5px;
  padding-bottom: 5px;
  color: #ffffff;
  box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.3);
  border: none;
}
.btn1:hover {
  color: rgb(255, 255, 255);
  background-color: rgb(49, 68, 175);
  transform: translateY(0);
}
.btn1.btn-secondary[disabled] {
  background-color: rgb(224, 224, 224);
  color: rgb(150, 150, 150);
}
.btn_delete {
  background-color: rgb(255, 0, 0);
  font-size: 16px;
  margin-top: 15px;
  margin-left: 15px;
  padding-left: 7px;
  padding-right: 7px;
  padding-top: 5px;
  padding-bottom: 5px;
  color: #ffffff;
  box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.3);
  border: none;
}
.btn_delete:hover {
  color: rgb(255, 255, 255);
  background-color: rgb(199, 0, 0);
}
.btn_delete.btn-secondary[disabled] {
  background-color: rgb(224, 224, 224);
  color: rgb(150, 150, 150);
}
</style>
