<!--
   Copyright 2018 Brigham Young University

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
-->
<template>
  <div class="p-2">
    <span :class="statusClass">
      <font-awesome-icon :icon="icon" />

      {{endorsementStatus}}
      <small>
        <a :href="endorseHref" target="_blank" data-disable-navigate="true">
          (view details)
        </a>
      </small>
    </span>
  </div>
</template>
<script>
  import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
  import { faCheck, faHourglassHalf, faExclamationTriangle } from '@fortawesome/free-solid-svg-icons'
  import { mapState, mapGetters } from 'vuex'

  export default {
    name: 'DetailsEndorsement',
    components: { FontAwesomeIcon },
    computed: {
      ...mapState({
        env: 'environment',
        byuId: state => state.application.applicantId
      }),
      ...mapGetters([ 'flagByValue' ]),
      endorsementPendingFlag () { return this.flagByValue('EP') },
      endorsementDeniedFlag () { return this.flagByValue('ED') },
      endorsementIssuesFlag () { return this.flagByValue('EI') },
      icon () {
        if (this.endorsementDeniedFlag.isActive) return faExclamationTriangle
        else if (this.endorsementIssuesFlag.isActive) return faExclamationTriangle
        else if (this.endorsementPendingFlag.isActive) return faHourglassHalf
        return faCheck
      },
      statusClass () {
        if (this.endorsementDeniedFlag.isActive) return { 'text-danger': true }
        else if (this.endorsementIssuesFlag.isActive) return { 'text-danger': true }
        else if (this.endorsementPendingFlag.isActive) return { 'text-dark': true, 'font-weight-bold': true }
        return { 'text-success': true }
      },
      endorsementStatus () {
        if (this.endorsementDeniedFlag.isActive) return `Endorsement Denied`
        else if (this.endorsementIssuesFlag.isActive) return `Endorsement Issues`
        else if (this.endorsementPendingFlag.isActive) return `Endorsement Pending`
        return `Endorsement Complete`
      },
      endorseHref () {
        return this.env !== 'development'
          ? `https://endorse.byu.edu/admin?byuId=${this.byuId}`
          : `https://endorse-dev.byu.edu/admin?byuId=${this.byuId}`
      }
    }
  }
</script>
<style scoped>
</style>
