<script setup>

import {
  addUninscReq,
  editScholarshipReq,
  editUnregReq,
  getScholarshipReqById,
  getUnregisterbyId
} from "@/rest/requests.js";
import i18n from "@/i18n.js";
import {getUser} from "@/rest/Users.js";
import {reactive, ref} from "vue";

const props = defineProps(["reqId"])
const req = ref(await getUnregisterbyId(props.reqId))

function getPP(){
  if(user.profilePictureUrl === null){
    return "/Clyde.png"
  }
  return user.profilePictureUrl
}

async function uploadandrefreshUnregRequest(state){
  await editUnregReq(req.value.id, state)
  req.value.state = state
}
</script>


<template>
  <div class="body">
    <div class="container">
      <div class="globalInfos">
        <div class="infosContainer">
          <div>
            Firstname/Name : {{req.firstName}} {{req.lastName}}
          </div>
          <div>
            E-mail: {{req.email}}
          </div>
          <div>
            regNo : {{req.regNo}}
          </div>
          <div>
            Reason :
            <input type="text" v-model="req.reason" readonly/>
          </div>
          <div>
            <button v-if="req.state === 'Pending'" @click="req.state='Accepted';uploadandrefreshUnregRequest('Accepted')">Accept</button>
            <button v-if="req.state === 'Pending'" @click="req.state='Refused';uploadandrefreshUnregRequest('Refused')" style="margin-left: 2%;">Refuse</button>
          </div>
        </div>
      </div>
    </div>
  </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;
}
</style>