<template>
  <header
    :class="
      pageRole === 'company' && $route.path === '/invest/company/main.page'
        ? 'company-header'
        : ''
    "
  >
    <div class="w1200">
      <div class="flex justify-between align-center">
        <div class="logo">
          <router-link
            :to="{ path: '/invest/company/main.page' }"
            v-if="pageRole === 'company'"
          >
            <img
              src="/invest/resources/img/logo_w.png"
              alt=""
              v-if="$route.path === '/invest/company/main.page'"
            />
            <img src="/invest/resources/img/logo.png" alt="" v-else />
          </router-link>
          <router-link :to="{ path: '/invest/government/main.page' }" v-else>
            <img src="/invest/resources/img/logo.png" alt="" />
          </router-link>
        </div>
        <div class="flex justify-end align-center">
          <div v-show="pageRole === 'company'" class="mobile-menu mr10">
            <!-- <p class="white detail-text">문의전화</p> -->
            <p
              :class="
                pageRole === 'company' &&
                $route.path === '/invest/company/main.page'
                  ? 'call white'
                  : 'call green'
              "
            >
              ☎ 054)639-6161~3
            </p>
          </div>
          <div
            class="user-info mobile-menu"
            v-if="this.$store.state.userType === 'government'"
          >
            <div class="flex align-center">
              <button class="user-name cursor" @click="fnLink">
                {{ mbrNm }}님
              </button>
              <button class="logout-btn" @click="fnlogOut">로그아웃</button>
            </div>
          </div>
          <UserMenu />
          <div
            class="user-info pc-menu"
            v-if="this.$store.state.userType === 'government'"
          >
            <div class="flex align-center">
              <button class="user-name cursor" @click="fnLink">
                {{ mbrNm }}님
              </button>
              <button class="logout-btn" @click="fnlogOut">로그아웃</button>
            </div>
          </div>
        </div>
        <div v-show="pageRole === 'company'" class="pc-menu">
          <!-- <p class="white detail-text">문의전화</p> -->
          <p
            :class="
              pageRole === 'company' &&
              $route.path === '/invest/company/main.page'
                ? 'call white'
                : 'call green'
            "
          >
            ☎ 054)639-6161~3
          </p>
        </div>
      </div>
    </div>
  </header>
</template>

<script>
import UserMenu from "./UserMenu.vue";
import { mapActions } from "vuex";

export default {
  props: {},
  components: {
    UserMenu: UserMenu,
  },
  data() {
    return {
      mbrId: this.$store.state.mbrId,
      mbrNm: this.$store.state.mbrNm,
      pageRole: this.$store.state.userType,
    };
  },
  methods: {
    ...mapActions(["logout"]),
    async fnlogOut() {
      await this.logout();
      this.$router.push({
        path: "/invest",
      });
    },

    // 사용자 정보 보기로 이동
    fnLink() {
      this.$router.push({
        path: "/invest/government/myInfo/view.page",
      });
    },
  },
};
</script>