<template>
  <HeaderNav headerText="个人中心"></HeaderNav>
  <div class="user-center">
    <div class="user-info">
      <div class="info-left">
        <img src="../../assets/img/index/user/default-head.png" alt="" />
        <div class="left-message">
          <div class="name pf500 fs18 fc061237">用户昵称</div>
        </div>
      </div>
      <div class="info-right pf400 fs12 fcFFFFFF" @click="updateInfoFlag = true">
        编辑
      </div>
    </div>
    <div class="notifi-classifi">
      <div
        class="classifi-item"
        :class="current == 'userInfo' ? 'current-classifi' : 'pf600 fs14 fcA8A8A8'"
        @click="messageChange('userInfo')">
        个人资料
        <div class="active-line" v-if="current == 'userInfo'"></div>
      </div>
      <div
        class="classifi-item"
        :class="current == 'safetySet' ? 'current-classifi' : 'pf600 fs14 fcA8A8A8'"
        @click="messageChange('safetySet')">
        <div class="active-line" v-if="current == 'safetySet'"></div>
        安全设置
      </div>
      <div
        class="classifi-item"
        :class="current == 'hobbySet' ? 'current-classifi' : 'pf600 fs14 fcA8A8A8'"
        @click="messageChange('hobbySet')">
        <div class="active-line" v-if="current == 'hobbySet'"></div>
        偏好设置
      </div>
    </div>
    <component :is="currentComponent" />
  </div>
  <UpdateInfo v-show="updateInfoFlag" @updateInfoClose="updateInfoClose"></UpdateInfo>
</template>
<script setup>
  import HeaderNav from "./components/HeaderNav.vue";
  import HobbySet from "./user/HobbySet.vue";
  import SafetySet from "./user/SafetySet.vue";
  import UserInfo from "./user/UserInfo.vue";
  import UpdateInfo from "./dialog/UpdateInfo.vue";
  import { ref, computed } from "vue";

  const updateInfoFlag = ref(false);
  const updateInfoClose = () => {
    updateInfoFlag.value = false;
  };

  const current = ref("userInfo");
  const componentsMap = {
    hobbySet: HobbySet,
    safetySet: SafetySet,
    userInfo: UserInfo,
  };
  const currentComponent = computed(() => componentsMap[current.value]);

  const messageChange = (key) => {
    current.value = key;
  };
</script>
<style lang="less" scoped>
  .user-center {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    width: 100%;

    .user-info {
      display: flex;
      flex-direction: row;
      justify-content: space-between;
      align-items: center;
      margin-top: 48px;
      width: 345px;
      height: 56px;

      .info-left {
        display: flex;
        flex-direction: row;
        justify-content: flex-start;
        height: 56px;

        img {
          width: 56px;
          height: 56px;
        }

        .left-message {
          display: flex;
          flex-direction: column;
          justify-content: center;
          margin-left: 16px;
          height: 56px;
        }
      }

      .info-right {
        width: 60px;
        height: 24px;
        line-height: 24px;
        text-align: center;
        background: #df384c;
        border-radius: 5px;
      }
    }

    .notifi-classifi {
      display: flex;
      flex-direction: row;
      justify-content: flex-start;
      align-items: flex-end;
      margin-top: 15px;
      width: 349px;
      height: 24px;

      .classifi-item {
        position: relative;
        margin-left: 43px;

        .active-line {
          position: absolute;
          bottom: -6px;
          left: 50%;
          transform: translateX(-50%);
          width: 20px;
          height: 3px;
          background-color: #323233;
          border-radius: 2px;
        }

        &:first-child {
          margin-left: 0;
        }
      }

      .current-classifi {
        font-family: "PingFang SC";
        font-style: normal;
        font-weight: 600;
        font-size: 18px;
        color: #121212;
        transition: color 0.3s, font-size 0.3s;
      }
    }
  }
</style>
