<script setup>
  import i18n from "@/i18n.js"
  import {getUser} from '../rest/Users.js'
  import {getSomeonesCurriculumList} from "@/rest/curriculum.js";

  const props = defineProps(['target']);
  let user = await getUser(props.target);
  let UserCurriculum = await getSomeonesCurriculumList(props.target);

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

  //Cette function renvoie l'année académique concernée si on est dans l'année 2023-2024 elle renvoie 2023
  //car dans la db l'année scolaire 2023-2024 est representée juste par 2023 (le même système s'applique pour chaque années on prend la borne inférieure
  function getYear(){
    let date = new Date();
    if (date.getMonth() <= 6){
      return date.getFullYear()-1
    }
    return date.getFullYear()
  }

</script>

<template>
  <div class="body">
    <div class="container">
      <div class="profilPic">
        <img class="subContainter" :src=getPP()>
      </div>
      <div class = "globalInfos">
        <div class="infosContainer">
          <div>
            FirstName/Name : {{user.firstName}} {{user.lastName}}
          </div>
          <div>
            E-mail: {{user.email}}
          </div>
          <div>
            Adresse : {{user.address}}
          </div>
          <div>
            Pays : {{user.country}}
          </div>
          <div>
            Date de naissance : {{user.birthDate}}
          </div>
        </div>
      </div>
      <div class="moreInfos">
        <div class = "oldcursus">
          <div class="listTitle">
            Anciens Cursus
          </div>
          <div  class="listElement">
            <div class=" containerElement" v-for="item in UserCurriculum.curriculumList">
              <div class="year" v-if="parseInt(item.dateyear) !== getYear()">Bac {{item.year}}</div>
              <div class="option" v-if="parseInt(item.dateyear) !== getYear()">{{item.option}}</div>
              <div class="dateyear" v-if="parseInt(item.dateyear) !== getYear()">Année {{item.dateyear}}-{{item.dateyear+1}}</div>
            </div>
          </div>
        </div>
        <div class="newcursus"  >
          <div class="listTitle">
            Cursus Actuel
          </div>
          <div  class="listElement">
            <div class=" containerElement" v-for="item in UserCurriculum.curriculumList" >
                <div class="year" v-if="parseInt(item.dateyear) === getYear()">Bac {{item.year}}</div>
                <div class="option" v-if="parseInt(item.dateyear) === getYear()">{{item.option}}</div>
                <div class="dateyear" v-if="parseInt(item.dateyear) === getYear()">Année {{item.dateyear}}-{{item.dateyear+1}}</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>

</template>


<style scoped>
.container{
  display:grid;
  grid-template-columns:200px 900px;
  grid-template-rows:200px auto;
  column-gap:30px;
  row-gap:45px;
  grid-template-areas:
  "profilPic globalInfos"
  "minfos minfos";
}

.profilPic{
  grid-area:profilPic;
}

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

}

.body {
  width:100%;
  margin-bottom:10px;
}

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

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

.moreInfos {
  display:grid;
  grid-template-rows:200px auto;
  column-gap:50px;
  row-gap:45px;
  grid-template-areas:
  "minfos minfos";
  grid-template-columns:600px 600px;
}

.listTitle{
  display: flex;
  justify-content: center;
  align-items: center;
  width:250px;
  margin-left:auto;
  margin-right:auto;
  border:2px solid black;
  font-size:25px;
  color:white;
  padding:20px;
  background-color:rgb(50,50,50);
  border-radius:20px;margin-bottom:10px;
}

.listElement{
  border:2px solid black;
  font-size:25px;
  color:white;
  padding:20px;
  background-color:rgb(50,50,50);
  border-radius:20px;
  margin-bottom:10px;
}

.containerElement{
  justify-content:center;
  display:grid;
  grid-template-columns:100px 100px 300px;
  grid-template-areas:
    "year option dateyear";
  column-gap:40px;
  padding-left: 25px;
}
</style>