<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>Linda</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: 50px 175px;
    > div {
      background: #f4f7f9;
      border-radius: 20px;
      padding: 18px 20px;
      display: flex;
      .content_l {
        .content_l_t {
          width: 343px;
          height: 220px;
          background: linear-gradient(180deg, #60ab91, #84a86c);
          border-radius: 20px;
          text-align: center;
          padding-top: 32px;
          img {
            width: 100px;
            height: 100px;
            background: rgba(0, 0, 0, 0);
            border: 2px solid #ffffff;
            border-radius: 50%;
          }
          > div {
            font-size: 28px;
            font-family: Microsoft YaHei, Microsoft YaHei-Regular;
            text-align: center;
            color: #ffffff;
            line-height: 44px;
            letter-spacing: 0.08px;
          }
        }
        .content_l_b {
          margin-top: 20px;
          .content_l_b_item {
            width: 343px;
            height: 70px;
            border-radius: 20px;
            color: #1a1a1a;
            line-height: 70px;
            letter-spacing: 0.05px;
            font-size: 18px;
            padding-left: 63px;
            cursor: pointer;
            span {
              display: inline-block;
              margin-right: 15px;
              font-size: 20px;
              color: #1a1a1a;
            }
          }
          .active {
            background: linear-gradient(180deg, #60ab91, #84a86c);
            color: #ffffff;
            span {
              color: #ffffff;
            }
          }
        }
      }
      .content_r {
        flex: 1;
        background: #ffffff;
        border-radius: 20px;
        margin-left: 45px;
        padding: 30px 30px;
      }
    }
  }
}
@include responseTo("phone") {
  .page {
    .location {
      padding: 0;
      .location_l {
        margin-right: 15px;
      }
    }
    .mobile-container {
      .custom-tabs {
        .n-tab-pane {
          padding: 15px;
        }
      }
    }
  }
}
</style>
