<route lang="json5">
{
  layout: 'tabbar',
  style: {
    navigationStyle: 'custom',
    navigationBarTitleText: '首页',
  },
}
</route>

<script lang="ts" setup>
import useRequest from '../../hooks/useRequest'
import dayjs from 'dayjs'
import { getCircles } from '../../core/libs/requests'
import SectionHeading from '@designer-hub/app/src/components/section-heading.vue'
import Card from '@designer-hub/app/src/components/card.vue'
import { merchantPageHeaderBg, scanIcon, bookIcon } from '@designer-hub/assets/src/svgs'
import { useUserStore } from '../../store'
import { storeToRefs } from 'pinia'

defineOptions({
  name: 'Home',
})
const userStore = useUserStore()
const { isLogined, userInfo } = storeToRefs(userStore)
// 测试 uni API 自动引入
const { data } = useRequest(async () => ({ code: 0, msg: '', data: {} }) as IResData<any>, {
  initialData: {
    banners: [],
    hots: [
      {
        id: 1,
        title: '日本研学·东京艺术大学游学',
        img: '',
        start: dayjs('2024-07-15').toDate(),
        end: dayjs('2024-08-10').toDate(),
      },
      {
        id: 1,
        title: '日本研学·东京艺术大学游学',
        img: '',
        start: dayjs('2024-07-15').toDate(),
        end: dayjs('2024-08-10').toDate(),
      },
    ],
    dynamics: [
      {
        author: {
          avatar: 'https://via.placeholder.com/35x35',
          nickname: '苏小萌',
          level: '0',
        },
        content: '用心做好设计，为客户创造美好家居环境',
        images: ['https://via.placeholder.com/165x220'],
        tags: ['意大利游学设计班'],
        shares: 0,
        comments: 0,
        likes: 0,
        createdAt: dayjs('2024-07-15').toDate(),
      },
      {
        author: {
          avatar: 'https://via.placeholder.com/35x35',
          nickname: '苏小萌',
          level: '0',
        },
        content: '用心做好设计，为客户创造美好家居环境',
        images: ['https://via.placeholder.com/220x165'],
        tags: ['意大利游学设计班'],
        shares: 0,
        comments: 0,
        likes: 0,
        createdAt: dayjs('2024-07-15').toDate(),
      },
      {
        author: {
          avatar: 'https://via.placeholder.com/35x35',
          nickname: '苏小萌',
          level: '0',
        },
        content: '用心做好设计，为客户创造美好家居环境',
        images: [
          'https://via.placeholder.com/104x104',
          'https://via.placeholder.com/104x204',
          'https://via.placeholder.com/204x104',
        ],
        tags: ['意大利游学设计班'],
        shares: 0,
        comments: 0,
        likes: 0,
        createdAt: dayjs('2024-07-15').toDate(),
      },
    ],
    studyTour: null,
  },
})
const { data: circlesData, run } = useRequest(() => getCircles({}), { initialData: { list: [] } })
console.log(data.value)
const toDesigner = () => {
  uni.navigateTo({ url: '/pages/designer/index' })
}
const toSettlement = async () => {
  console.log('11')

  await uni.navigateTo({ url: '/pages/home/merchant/settlement' })
}
onShow(async () => {
  // await run()
  console.log(circlesData.value)
})
onLoad(() => {
  console.log(isLogined.value)
  if (!isLogined.value) {
    uni.reLaunch({ url: '/pages/login/index' })
  }
})
onShareAppMessage(() => ({}))
</script>

<template>
  <view class="flex-grow relative">
    <template v-if="userInfo.appLoginType === 1">
      <div class="aspect-[0.96/1] absolute left-0 right-0 top--1">
        <wd-img
          width="100%"
          height="100%"
          :src="merchantPageHeaderBg"
          custom-class="vertical-bottom"
        ></wd-img>
      </div>
      1
      <wd-navbar custom-class="bg-transparent!" safe-area-inset-top :bordered="false">
        <template #left>
          <div
            class="ml-1 text-center text-white text-lg font-normal font-['PingFang SC'] leading-relaxed"
          >
            今日待办
          </div>
        </template>
      </wd-navbar>
      <div class="flex flex-col gap-8 p-4 relative box-border">
        <div>
          <SectionHeading
            title="渠道任务"
            path="/pages/home/tasks/index"
            end-text="查看全部"
            custom-class="mb-5"
          ></SectionHeading>
          <Card><wd-status-tip image="search" tip="当前暂无未开始/进行中的任务" /></Card>
        </div>
        <div>
          <SectionHeading title="设计师" path="" custom-class="mb-5"></SectionHeading>
          <div class="flex flex-col gap-4">
            <template
              v-for="{ label, color } of [
                { label: '重点跟进设计师', color: '#FF523F' },
                { label: '全部设计师', color: '#7199FF' },
                { label: '本月新增设计师', color: '#FFE786' },
                { label: '超过30天未跟进', color: '#89F4E3' },
                { label: '超过60天未产生积分设计师', color: '#FFBA6A' },
                { label: '超过60天未消耗积分设计师', color: '#C494FF' },
                { label: '未成交过设计师', color: '#FF9EE2' },
              ]"
              :key="label"
            >
              <div
                class="h-12 bg-white rounded-lg shadow flex items-center hover:bg-[#fff6f5]"
                @click="toDesigner"
              >
                <div
                  class="w-1.5 h-12 rounded-tl-lg rounded-bl-lg shadow"
                  :style="{ background: color }"
                ></div>
                <div class="flex-1 mx-3">
                  <SectionHeading
                    :title="label"
                    path="/pages/designer/index"
                    size="sm"
                  ></SectionHeading>
                </div>
              </div>
            </template>
          </div>
        </div>
        <div>
          <SectionHeading title="设计师最新动态" path="" custom-class="mb-5"></SectionHeading>
          <div class="flex flex-col gap-4">
            <template
              v-for="{ title, date } of [
                { title: '苏小萌报名了日本设计游学', date: new Date() },
                { title: '苏小萌报名了骑行活动', date: new Date() },
                { title: '苏小萌获取imola16000积分', date: new Date() },
              ]"
              :key="title"
            >
              <Card>
                <div class="text-black/90 text-sm font-normal font-['PingFang SC'] leading-none">
                  {{ title }}
                </div>
                <div
                  class="mt-3 text-black/30 text-xs font-normal font-['PingFang SC'] leading-none"
                >
                  {{ dayjs(date).format('YYYY-MM-DD hh:mm') }}
                </div>
              </Card>
            </template>
          </div>
        </div>
      </div>
    </template>
    <template v-if="userInfo.appLoginType === 2">
      <div
        class="bg-white backdrop-blur-[60px] my-[16px] flex flex-col justify-center items-center p-[16px] mt-[20px]"
      >
        <div
          class="w-[68px] h-[68px] bg-[#2357e9] rounded-full mt-[37px] flex items-center justify-center"
        >
          <wd-img width="36px" height="36px" :src="scanIcon"></wd-img>
        </div>
        <div class="w-full mt-[45px]">
          <wd-button block :round="false">
            <div
              class="text-center text-white text-base font-normal font-['PingFang SC'] leading-normal"
            >
              扫码验券
            </div>
          </wd-button>
        </div>
      </div>
      <div
        class="bg-white backdrop-blur-[60px] flex flex-col justify-center items-center p-[16px] mt-[20px]"
      >
        <div
          class="w-[68px] h-[68px] bg-[#2357e9] rounded-full mt-[34px] flex items-center justify-center"
        >
          <wd-img width="36px" height="36px" :src="bookIcon"></wd-img>
        </div>
        <div class="w-full flex items-center mt-[40px]">
          <div
            class="text-black/90 text-base font-normal font-['PingFang SC'] leading-relaxed width-[96px]"
          >
            输入订单金额
          </div>
          <div class="bg-[#f5f7f9] rounded-lg flex items-center flex-1 ml-[16px]">
            <wd-input type="number" no-border placeholder="请输金额" />
          </div>
        </div>
        <div class="w-full flex items-center mt-[20px]">
          <div
            class="text-black/90 text-base font-normal font-['PingFang SC'] leading-relaxed width-[96px]"
          >
            需支付积分
          </div>
          <div
            class="text-[#ff2d2d] text-base font-normal font-['PingFang SC'] leading-relaxed ml-[20px]"
          >
            3400 积分
          </div>
        </div>
        <div class="w-full mt-[45px]">
          <wd-button block :round="false" @click="toSettlement">
            <div
              class="text-center text-white text-base font-normal font-['PingFang SC'] leading-normal"
            >
              积分结账
            </div>
          </wd-button>
        </div>
      </div>
    </template>
  </view>
</template>

<style>
/* :deep(.wd-input) {
  background: transparent;
  height: 100%;
  border: none;
  width: 100%;
} */
</style>
