<script setup>
  import i18n from "@/i18n.js"
  import {getSelf, getUser} from '../../rest/Users.js'
  import {getSomeonesCurriculumList} from "@/rest/curriculum.js";
  import {ref} from "vue";
  import ExternalCurriculumList from "@/Apps/Inscription/ExternalCurriculumList.vue";
  import {getExternalCurriculumByUser} from "@/rest/externalCurriculum.js";

  const props = defineProps(['target'])
  const user = await getUser(props.target)
  const UserCurriculum = await getSomeonesCurriculumList(props.target)
  const externalcurrlist = await getExternalCurriculumByUser(user.regNo)
  const extercurrlist = ref(false)

  const watchingUser = await getSelf()
  function getPP(){
    if(user.profilePictureUrl === null){
      return "/Clyde.png"
    }
    return user.profilePictureUrl
  }
</script>

<template>
  <div class="body" v-if="extercurrlist==false">
    <div class="container">
      <div class="profilPic">
        <img class="subContainter" :src=getPP()>
      </div>
      <div class = "globalInfos">
        <div class="infosContainer">
          <div>
            {{ i18n("firstname/name") }} : {{user.firstName}} {{user.lastName}}
          </div>
          <div>
            {{ i18n("login.guest.email") }}: {{user.email}}
          </div>
          <div>
            {{ i18n("login.guest.address") }} : {{user.address}}
          </div>
          <div>
            {{ i18n("login.guest.country") }} : {{user.country}}
          </div>
          <div>
            {{ i18n("login.guest.birthday") }} : {{user.birthDate}}
          </div>
          <div>
            <button v-if="watchingUser.role === 'Admin' || watchingUser.role === 'InscriptionService' || watchingUser.role === 'Secretary' || watchingUser.regNo === user.regNo"><a :href="user.identityCard">{{i18n("dlidentitycard")}}</a></button>
          </div>
          <div>
            <button @click="extercurrlist=!extercurrlist">{{i18n("seeextcur")}}</button>
          </div>
        </div>
      </div>
      <div class="moreInfos" style="margin-top: 15%">
        <div class = "oldcursus">
          <div class="listTitle">
            {{ i18n("oldcursus") }}
          </div>
          <div  class="listElement">
            <div class=" containerElement" v-for="item in UserCurriculum.curriculumList">
              <div class="year" v-if="item.actual === false">Bac {{item.year}}</div>
              <div class="option" v-if="item.actual === false">{{item.option}}</div>
              <div class="dateyear" v-if="item.actual === false">{{ i18n("year") }} {{item.dateyear}}-{{item.dateyear+1}}</div>
            </div>
          </div>
        </div>
        <div class="newcursus">
          <div class="listTitle">
            {{ i18n("newcursus") }}
          </div>
          <div  class="listElement">
            <div class=" containerElement" v-for="item in UserCurriculum.curriculumList" >
                <div class="year" v-if="item.actual === true">Bac {{item.year}}</div>
                <div class="option" v-if="item.actual === true">{{item.option}}</div>
                <div class="dateyear" v-if="item.actual === true">{{ i18n("year") }} {{item.dateyear}}-{{item.dateyear+1}}</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
  <div v-if="extercurrlist==true">
      <ExternalCurriculumList :ext-curr-list="externalcurrlist" :mode="1"></ExternalCurriculumList>
  </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";
}

.profilPic{
  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:5%;
}

.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:inline-grid;
  column-gap:50px;
  grid-template-areas:
  "oldcursus newcursus";
  grid-template-columns:600px 600px;
  align-items:center;
  justify-content:center;
  margin-left: 320%;
}

.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;
}

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