<!--
   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>
  <section class="content-padding">
    <div v-if="applicantName || !loading">
      <div v-if="errorText" class="alert alert-danger" role="alert">
        {{errorText}}
      </div>
      <div data-v-else class="grid">
        <DetailsHeader class="header bg-dark text-white" />
        <DetailsDecision class="decision" />
        <DetailsContact class="contact" />
        <DetailsActions class="actions" />
        <DetailsCollege class="college" />
        <DetailsBackground class="background" />
        <DetailsEndorsement class="endorsement" />
        <DetailsNotes class="notes" />
      </div>
      <button class="btn btn-outline-primary" @click="goBack">Back</button>
    </div>
    <div v-else style="margin-top: 25rem;">
      Applicant Name: {{applicantName}}
    </div>
    <v-dialog />
    <FlagDialog />
    <DecisionDialog />
    <NoteDialog />
    <SupportDialog />
  </section>
</template>
<script>
  import safeGet from 'lodash.get'
  import { dateTimeFilter } from './dateTimeFormat'
  import Spinner from './Spinner'
  import DetailsHeader from './DetailsHeader'
  import DetailsContact from './DetailsContact'
  import DetailsDecision from './DetailsDecision'
  import DetailsCollege from './DetailsCollege'
  import DetailsBackground from './DetailsBackground'
  import DetailsEndorsement from './DetailsEndorsement'
  import DetailsActions from './DetailsActions'
  import DetailsNotes from './DetailsNotes'
  import FlagDialog from './FlagDialog'
  import DecisionDialog from './DecisionDialog'
  import NoteDialog from './NoteDialog'
  import SupportDialog from './SupportDialog'
  import { mapState, mapGetters, mapActions } from 'vuex'

  export default {
    name: "Details",
    props: ["application_uuid"],
    components: {
      DetailsHeader,
      DetailsContact,
      DetailsDecision,
      DetailsCollege,
      DetailsBackground,
      DetailsEndorsement,
      DetailsActions,
      DetailsNotes,
      FlagDialog,
      DecisionDialog,
      NoteDialog,
      SupportDialog,
      Spinner
    },
    created() {
      this.fetchApplication(this.application_uuid)
    },
    computed: {
      ...mapGetters(['loading']),
      ...mapState({
        errorText: state => state.apiError.message,
        applicantName: state => state.application.applicantName
      })
    },
    methods: {
      ...mapActions({
        fetchApplication: 'fetchApplication'
      }),
      safeGet,
      goBack () {
        window.history.back()
      }
    }
  }
</script>
<style scoped>
  .grid {
    display: grid;
    grid-template-columns: 1fr minmax(15rem, 20rem);
    grid-gap: 0.5rem;
    grid-auto-rows: auto;
    grid-template-areas:
    "header decision"
    "contact contact"
    "college actions"
    "background actions"
    "endorsement action"
    "notes notes";
    margin-bottom: 0.5rem;
  }
  .header { grid-area: header; }
  .decision { grid-area: decision; }
  .contact { grid-area: contact; }
  .college { grid-area: college; }
  .background { grid-area: background; }
  .endorsement { grid-area: endorsement; }
  .actions { grid-area: actions; }
  .notes { grid-area: notes; }
</style>
