<!--
   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>
    <div v-if="seminary" class="grid">
      <table class="table table-borderless table-sm full-width">
        <thead>
          <tr>
            <th>Seminary Type</th>
            <th>Years Completed</th>
            <th>Attendance</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>{{seminary.seminaryType}}</td>
            <td>{{seminary.yearsCompleted}}</td>
            <td>{{seminary.attendancePercentage}}</td>
          </tr>
        </tbody>
      </table>
      <table v-if="!hideRecommendation && seminary.recommendation && consolidateHeaders" class="table table-borderless table-sm full-width">
        <thead>
          <tr>
            <th>Instructor</th>
            <th>Email</th>
            <th>Years Teaching</th>
            <th>Will Graduate?</th>
          </tr>
        </thead>
        <tbody>
          <tr v-if="seminary.recommendation.instructor">
            <td>{{seminary.recommendation.instructor.name.response}}</td>
            <td>{{seminary.recommendation.instructor.email.response}}</td>
            <td>{{seminary.recommendation.instructor.yearsTeaching.response}}</td>
            <td>{{seminary.recommendation.graduate.response}}</td>
          </tr>
        </tbody>
      </table>
      <template v-if="seminary.seminaryExplanation">
        <h6 class="full-width">Explanation</h6>
        <p class="full-width"> {{ seminary.seminaryExplanation }} </p>
      </template>
      <template v-if="!hideClasses">
        <div v-for="(c, i) of seminary.seminaryClasses" :key="i" class="card">
          <h6 class="card-header">{{c.seminaryClass}}</h6>
          <div class="card-body">
            <h6>{{c.academicYear}}</h6>
            <div v-for="termInfo of c.termInfo" :key="termInfo.term">
              Term {{termInfo.term}}
              <br>
              Reading: {{termInfo.reading}}
              <br>
              {{termInfo.attendance}} attendance
              <br>
              <span v-if="termInfo.grade">Grade: {{termInfo.grade}}</span>
            </div>
          </div>
        </div>
      </template>
      <div v-if="!hideRecommendation && seminary.recommendation" class="full-width">
        <h4>Seminary Recommendation</h4>
        <table v-if="!consolidateHeaders" class="table table-sm">
          <thead>
            <tr>
              <th>Instructor</th>
              <th>Email</th>
              <th>Years Teaching</th>
              <th>Will Graduate?</th>
            </tr>
          </thead>
          <tbody>
            <tr v-if="seminary.recommendation.instructor">
              <td>{{seminary.recommendation.instructor.name.response}}</td>
              <td>{{seminary.recommendation.instructor.email.response}}</td>
              <td>{{seminary.recommendation.instructor.yearsTeaching.response}}</td>
              <td>{{seminary.recommendation.graduate.response}}</td>
            </tr>
          </tbody>
        </table>
        <table class="table table-borderless table-sm">
          <thead>
            <tr>
              <template v-for="(c, i) of seminary.recommendation.responseCriteria">
                <th class="selection-cell">
                  <span v-html="c"></span>
                </th>
                <th v-if="i === 0">
                  Prompt
                </th>
              </template>
            </tr>
          </thead>
          <tbody>
            <tr v-for="q of seminary.recommendation.questions" :key="q.id">
              <template v-for="(c, i) of seminary.recommendation.responseCriteria">
                <td :class="{ 'selected': i === q.response, 'selection-cell': true }">
                  <FontAwesomeIcon v-if="i === q.response" :icon="checkIcon" />
                  <span class="alt-text">{{ (i === q.response) ? c: '' }}</span>
                </td>
                <td v-if="i === 0">
                  {{ q.prompt }}
                </td>
              </template>
            </tr>
          </tbody>
        </table>

        <div v-if="seminary.recommendation.comments">
          {{ seminary.recommendation.comments.response }}
        </div>
      </div>
    </div>
    <div v-else>
      No seminary information reported.
    </div>
  </div>
</template>
<script>
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
import { faCheck } from '@fortawesome/free-solid-svg-icons'
import { mapState } from 'vuex'

export default {
  name: 'DetailsSeminary',
  components: { FontAwesomeIcon },
  props: {
    hideClasses: Boolean,
    hideRecommendation: Boolean,
    consolidateHeaders: Boolean
  },
  computed: {
    ...mapState({
      seminary: state => state.application.seminary
    }),
    checkIcon () {
      return faCheck
    }
  }
}
</script>
<style scoped>
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr));
  grid-auto-rows: auto;
  grid-gap: 0.5rem;
  /* grid-auto-flow: dense; */
}
.full-width {
  grid-column: 1 / -1;
}
h6 {
  font-weight: bold;
}
th.selection-cell {
  min-width: 5rem;
}
td.selection-cell {
  text-align: center;
}
td.selected {
  color: var(--primary, blue);
}
.alt-text {
  font-size: 0;
}
@media only speech {
  .alt-text { font-size: 1rem; }
}
</style>
