<script setup>

import {
  addUninscReq,
  editExempReqState,
  editScholarshipReq,
  getExempReq,
  getScholarshipReqById
} from "@/rest/requests.js";
import i18n from "@/i18n.js";
import {getUser} from "@/rest/Users.js";
import {reactive, ref} from "vue";
import AboutStudent from "@/Apps/Inscription/AboutStudent.vue";

const props = defineProps(["reqId"])

const req = ref(await getExempReq(props.reqId))

const profile = ref(false)

const windowState = defineModel("windowState")

async function editExemp(newstate){
  await editExempReqState(req.value.id, newstate)
}
</script>


<template>
  <div class="body" v-if="profile === false">
    <div class="container">
      <div class="globalInfos">
        <div class="infosContainer">
          <div>
            Firstname/Name : {{req.user.firstName}} {{req.user.lastName}}
          </div>
          <div>
            Course: {{req.course.title}}
          </div>
          <div>
            State : {{req.state}}
          </div>
          <div>
            <button @click="profile = !profile">Voir le profil</button>
          </div>
          <div>
            <button>Download justification document</button>
          </div>
          <div>
            <button v-if="req.state === 'Pending'" @click="req.state='Accepted';editExemp('Accepted')">Accept</button>
            <button v-if="req.state === 'Pending'" @click="req.state='Refused';editExemp('Refused')" style="margin-left: 2%;">Refuse</button>
          </div>
        </div>
      </div>
    </div>
  </div>
  <div v-else>
    <AboutStudent :target="req.user.regNo"></AboutStudent>
    <button @click="profile=!profile" style="margin-left: 17%;margin-top: 3%">Back to request</button>
  </div>
  <div>
    <button v-if="profile===false" @click="windowState = 0" style="margin-left: 31%">Back</button>
  </div>
</template>

<style scoped>
.container{
  min-width:675px;
  display:grid;
  grid-template-columns:10vw 50vw;
  grid-template-rows:200px auto;
  column-gap:2.7%;
  row-gap:45px;
  grid-template-areas:
  "profilPic globalInfos"
  "minfos minfos";
}

.profilPic{
  width:100%;
  grid-area:profilPic;
}

.globalInfos {
  grid-area:globalInfos;
  align-self :center;

}

.body {
  min-width:960px;
  width:100%;
  display:flex;
  align-items:center;
  justify-content:center;
  margin-top:7%;
}

.subContainter{
  width:100%;
  background-color:rgb(50,50,50);
  border-radius:20px;
  border:4px solid black;
}

.infosContainer {
  min-width:350px;
  padding-bottom:50px;
  border:2px solid black;
  font-size:25px;
  color:white;
  padding:20px;
  background-color:rgb(50,50,50);
  border-radius:20px;
}

button{
  border:none;
  background-color:rgb(239, 60, 168);
  border-radius:10px;
  height:35px;
  margin-top:10px;
}
</style>