<template>
  <div class="page" id="page">
    <div class="location">
      <div class="location_l"> <span class="iconfont icon-weizhi"></span></div>
      <div class="location_r"> Current Location ： Home <span class="iconfont icon-dkw_guanbi-"></span> <span>User Center</span></div>
    </div>
    <div class="content" v-if="pcShow">
      <div>
        <div class="content_l">
          <div class="content_l_t">
            <img src="@/assets/images/avatar.png" alt="">
            <div>{{user.name}}</div>
          </div>
          <div class="content_l_b">
            <div class="content_l_b_item" :class="{active:currentTab.index==0}" @click="handleTab(0)">
              <span class="iconfont icon-wo_wodexinxi"></span>
              My information
            </div>
            <div class="content_l_b_item" :class="{active:currentTab.index==1}" @click="handleTab(1)">
              <span class="iconfont icon-wodedingdan-dingdan"></span>
              My order
            </div>
            <div class="content_l_b_item" :class="{active:currentTab.index==2}" @click="handleTab(2)">
              <span class="iconfont icon-wodexiazai"></span>
              My download
            </div>
          </div>
        </div>
        <div class="content_r">
          <ClientOnly>
            <UserInfo v-if="currentTab.index == 0"></UserInfo>
            <OrderList ref="orderRef" v-if="currentTab.index == 1"></OrderList>
            <DownList v-if="currentTab.index == 2"></DownList>
          </ClientOnly>
        </div>
      </div>
    </div>
    <div class="mobile-container" v-if="!pcShow">
      <n-tabs justify-content="space-evenly" type="line" size="large" class="custom-tabs" :name="currentTab.index">
        <n-tab-pane v-for="(item, index) in tabList" :name="index" :tab="item.label" :key="item.value">
          <UserInfo isMobile v-if="index == 0"></UserInfo>
          <OrderList ref="orderRef" isMobile v-if="index == 1"></OrderList>
          <DownList isMobile v-if="index == 2"></DownList>
        </n-tab-pane>
      </n-tabs>
    </div>
  </div>
</template>

 <script lang="ts" setup>
import { useI18n } from "#imports";
import { ref, reactive, onMounted, computed, watch } from "vue";
import {
  NIcon,
  NBreadcrumb,
  NBreadcrumbItem,
  NButton,
  NInput,
  NImage,
  NTabs,
  NTabPane,
  createDiscreteApi,
} from "naive-ui";
import { MdContact, MdHome, MdImage } from "@vicons/ionicons4";
import UserInfo from "./modules/user-info.vue";
import OrderList from "./modules/order.vue";
import DownList from "./modules/down.vue";
import { useUserStore } from "@/store/user";
import { useRouter, useRoute } from "vue-router";
import ClientOnly from "@duannx/vue-client-only";
const { t } = useI18n();
const userStore = useUserStore();
const lang = userStore.getLang;
const route = useRoute();
const pcShow = ref<boolean>(true);
const user = computed(() => userStore.getUserInfo);

const tabList = reactive<object[]>([
  {
    label: "My information",
    value: 0,
    name: "user",
  },
  {
    label: "My order",
    value: 1,
    name: "order",
  },
  {
    label: "My download",
    value: 2,
    name: "down",
  },
]);
interface currentTabObj {
  index?: number;
  title?: string;
}
const currentTab = reactive<currentTabObj>({
  index: 0,
  // title: t("myInfo.myInformation"),
});

const researchBriefReportId = ref("");
const orderRef = ref();
const isShow = ref(false);

watch(
  () => route.params.active,
  (val) => {
    currentTab.index = val || 0;
    currentTab.title = t("myInfo.myInformation");
  }
);

const handleTab = (index: number) => {
  if (currentTab.index == index) {
    return false;
  }
  currentTab.index = index;
};

const handleSearch = () => {
  orderRef.value.searchData(researchBriefReportId.value);
};
isShow.value = true;
// currentTab.index = route.params.active || 0;
currentTab.title = t("myInfo.myInformation");
onMounted(() => {
  pcShow.value = !isMobile();
});
</script>

<style lang="scss" scoped>
@import "~/assets/css/tool.scss";
.page {
  margin-top: var(--size-130);
  .location {
    display: flex;
    border-bottom: 1px solid #e6e6e6;
    padding: 0 var(--size-160);
    background: #ffffff;
    .location_l {
      width: var(--size-60);
      height: var(--size-60);
      background: #dcdcdc;
      color: #383838;
      font-size: var(--size-16);
      text-align: center;
      line-height: var(--size-60);
      margin-right: var(--size-30);
    }
    .location_r {
      font-size: var(--size-14);
      font-family: Arial, Arial-Regular;
      color: #666666;
      line-height: var(--size-59);
      span {
        color: #639e57;
        font-family: Microsoft YaHei, Microsoft YaHei-Regular;
      }
      .icon-dkw_guanbi- {
        color: #666666;
        font-size: var(--size-12);
      }
    }
  }
  .content {
    padding: var(--size-50) var(--size-175);
    > div {
      background: #f4f7f9;
      border-radius: var(--size-20);
      padding: var(--size-18) var(--size-20);
      display: flex;
      .content_l {
        .content_l_t {
          width: var(--size-343);
          height: var(--size-220);
          background: linear-gradient(180deg, #60ab91, #84a86c);
          border-radius: var(--size-20);
          text-align: center;
          padding-top: var(--size-32);
          img {
            width: var(--size-100);
            height: var(--size-100);
            background: rgba(0, 0, 0, 0);
            border: var(--size-2) solid #ffffff;
            border-radius: 50%;
          }
          > div {
            font-size: var(--size-28);
            font-family: Microsoft YaHei, Microsoft YaHei-Regular;
            text-align: center;
            color: #ffffff;
            line-height: var(--size-44);
            letter-spacing: 0.08px;
          }
        }
        .content_l_b {
          margin-top: var(--size-20);
          .content_l_b_item {
            width: var(--size-343);
            height: var(--size-70);
            border-radius: var(--size-20);
            color: #1a1a1a;
            line-height: var(--size-70);
            letter-spacing: 0.05px;
            font-size: var(--size-18);
            padding-left: var(--size-63);
            cursor: pointer;
            span {
              display: inline-block;
              margin-right: var(--size-15);
              font-size: var(--size-20);
              color: #1a1a1a;
            }
          }
          .active {
            background: linear-gradient(180deg, #60ab91, #84a86c);
            color: #ffffff;
            span {
              color: #ffffff;
            }
          }
        }
      }
      .content_r {
        flex: 1;
        background: #ffffff;
        border-radius: var(--size-20);
        margin-left: var(--size-45);
        padding: var(--size-30);
      }
    }
  }
}
@include responseTo("phone") {
  .page {
    .location {
      padding: 0;
      .location_l {
        margin-right: var(--size-15);
      }
    }
    .mobile-container {
      .custom-tabs {
        .n-tab-pane {
          padding: var(--size-15);
        }
      }
    }
  }
}
</style>
