<template>
  <div>
    <div
    v-show="$route.name === 'Overview'"
    class="shadow"
    >
      <b-button
        @click="AddConference()"
        class="btn1"
        :disabled="fileManagement.permission === 1"
      >
        <b-icon-file-earmark-plus /> 建立會議
      </b-button>
      <b-button
        @click="AddType()"
        class="btn"
        :disabled="fileManagement.permission === 1"
      >
        <b-icon-tools></b-icon-tools> 參數設置
      </b-button>
    </div>
    <div
    v-show="$route.name === 'Agenda'"
    class="shadow"
    >
     <b-button class="btn" @click="ExportListModalOpen = true">
        <b-icon-list-check /> 匯出列表
      </b-button>
    </div>
    <modal
      :is-open="AddConferenceModalOpen"
      title="建立會議"
      @closeEvent="AddConferenceModalOpen = false"
    >
    <addConference @closeEvent="closeConference"/>
    </modal>
    <modal
      :is-open="AddAgendaModalOpen"
      title="建立議題"
      @closeEvent="AddAgendaModalOpen = false"
    >
    <addAgenda @closeEvent="AddAgendaModalOpen = false" />
    </modal>
    <modal
      :is-open="AddTypeModalOpen"
      title="參數設置"
      @closeEvent="AddTypeModalOpen = false"
    >
    <addType @closeEvent="AddTypeModalOpen = false" />
    </modal>
     <modal
      :isOpen="ExportListModalOpen"
      title="匯出列表"
      v-on:closeEvent="ExportListModalOpen = false"
    >
      <exportList @closeEvent="ExportListModalOpen = false" />
    </modal>
  </div>
</template>

<script>
import addConference from '@/views/ConferenceManagement/ModalContent/addConference.vue'
import addAgenda from '@/views/ConferenceManagement/ModalContent/addAgenda.vue'
import addType from '@/views/ConferenceManagement/ModalContent/addType.vue'
import exportList from '@/views/ConferenceManagement/ModalContent/exportList.vue'
import { mapActions, mapState } from 'vuex'

export default {
  components: {
    modal: () => import('@/views/Modal/index.vue'), // 不用寫在import只需寫在這邊
    addConference,
    addAgenda,
    addType,
    exportList
  },
  data () {
    return {
      ExportListModalOpen: false,
      AddConferenceModalOpen: false,
      AddAgendaModalOpen: false,
      AddTypeModalOpen: false,
      fileManagement: {}
    }
  },
  mounted () {
    this.usePermission()
  },
  methods: {
    ...mapActions('conference', ['initConference']),
    ...mapActions('issue', ['initIssue']),
    async AddConference () { // 新增會議
      await this.initConference()
      this.AddConferenceModalOpen = true
    },
    async AddAgenda () {
      await this.initIssue()
      this.AddAgendaModalOpen = true
    },
    async AddType () {
      this.AddTypeModalOpen = true
    },
    async closeConference () {
      this.AddConferenceModalOpen = false
      this.$emit('reload')
    },
    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.fileManagement = a
            }
          }
        }
      })
    }
  },
  computed: {
    ...mapState({
      conference: (state) => state.conference.Conference,
      issue: (state) => state.issue.Issue,
      currentUser: (state) => state.user.current
    })
  }
}
</script>

<style lang="scss" scoped>
.shadow {
  background-color: #ffff;
  height: 65px;
  width: 100%;
  box-shadow: 2px 2px 20px rgba(0, 0, 0, 40);
  /* border-bottom-width:3px;
    border-bottom-color:#1D325F;
    border-bottom-style:solid */
  position: fixed;
  top: 55px;
  z-index: 500;
}
.btn {
  background-color: white;
  font-size: 16px;
  margin-top: 15px;
  margin-left: 15px;
  padding-left: 7px;
  padding-right: 7px;
  padding-top: 5px;
  padding-bottom: 5px;
  color: #383838;
  box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.3);
  border: none;
  hover{
    color: black;
    background-color: rgb(228, 228, 228);
  }
}
.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;
  hover{
    color: rgb(255, 255, 255);
    background-color: rgb(49, 68, 175);
  }
}
.btn1.btn-secondary[disabled] {
  background-color: rgb(224, 224, 224);
  color: rgb(150, 150, 150);
}
.btn.btn-secondary[disabled] {
  background-color: rgb(224, 224, 224);
  color: rgb(150, 150, 150);
}
</style>
