<template>
  <div id="info-card-body">
    <div style="font-weight: bold">SEECODER</div>
    <div v-if="isLogin" id="info-card-circle">
      <span>{{ name.substring(0, 1) }}</span>
    </div>
    <div v-else>
      <svg height="50" viewBox="0 0 1024 1024" width="50" xmlns="http://www.w3.org/2000/svg">
        <path
          d="M511.999723 331.913794m-117.748854 0a117.748854 117.748854 0 1 0 235.497708 0 117.748854 117.748854 0 1 0-235.497708 0Z"
          fill="#82BAD8"></path>
        <path
          d="M511.999723 0.000554A511.999723 511.999723 0 1 0 1025.10767 512.000277 512.276779 512.276779 0 0 0 511.999723 0.000554zM792.380524 779.636496a24.935051 24.935051 0 0 1-24.935052-24.935052 255.445749 255.445749 0 0 0-510.614442 0 24.935051 24.935051 0 0 1-49.870103 0 304.76174 304.76174 0 0 1 205.29859-288.138372 167.896013 167.896013 0 1 1 199.480412 0 304.76174 304.76174 0 0 1 205.575646 288.138372 24.935051 24.935051 0 0 1-24.935051 24.935052z"
          fill="#82BAD8"></path>
      </svg>
    </div>
    <div v-if="isLogin" id="info-card-name-id">
      <div>{{ name }}</div>
      <div style="font-size: x-small">{{ email }}</div>
    </div>
    <el-button class="info-card-button" v-if="isLogin" plain round size="small" type="primary" @click="signOut">登出</el-button>
    <el-button class="info-card-button" v-else plain round size="small" type="primary" @click="this.$router.push('/auth')">登录/注册</el-button>
  </div>
</template>

<script>
export default {
  name: "InfoCard",
  computed: {
    isLogin() {
      return this.$store.state.user.token !== undefined;
    },
    name() {
      return this.$store.state.user.name;
    },
    email() {
      return this.$store.state.user.email;
    }
  },

  methods: {
    signOut() {
      this.$store.commit("state_reset_user");
      this.$store.commit("storage_delete_user");
      this.$router.push("/portal");
      setTimeout(() => {
        location.reload();
      }, 0);
    },
  },
};
</script>

<style scoped>
#info-card-body {
  min-height: 180px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  align-items: center;
  border-radius: 4px;
}

#info-card-circle {
  height: 50px;
  width: 50px;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 50%;
  background: #619dc9;
}

#info-card-circle span {
  color: white;
  font-weight: bold;
  font-size: 24px;
}

#info-card-name-id {
  text-align: center;
}

.info-card-button {
  width: 120px;
}
</style>