import { createRouter, createWebHistory } from 'vue-router';
import layout from '@/layouts/index.vue';
import Design from '@/views/Design/Index.vue';
import Redirect from '@/layouts/redirect.vue';
import type { title } from 'process';
import { getWXShareConfig } from '@/utils/share';

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: '/',
      component: layout,
      redirect: '/home',
      meta: {
        title: '伊调研'
      },
      children: []
    },
    {
      path: '/redirect',
      name: '/redirect',
      component: Redirect,
      redirect: '/survey',
      meta: {
        title: '伊调研'
      },
      children: [
        {
          path: '/home',
          name: 'home',
          meta: {
            title: '伊调研'
          },
          component: () => import('../views/Home/Index.vue')
        },
        {
          path: '/survey',
          name: 'survey',
          meta: {
            title: '我的'
          },
          component: () => import('../views/Survey/Index.vue')
        },
        {
          path: '/market',
          name: 'market',
          meta: {
            title: '模板'
          },
          component: () => import('../views/Market/Index.vue')
        },
        {
          path: '/create',
          name: 'create',
          meta: {
            title: '问卷编辑',
            pureBGC: true,
            bgc: '#71b73c',
            header: {
              bgc: 'green',
              pureBGC: false
            }
          },
          component: () => import('../views/Survey/views/Create/Index.vue')
        },
        {
          path: '/templatePreview',
          name: 'templatePreview',
          meta: {
            title: '模板预览',
            header: {
              bgc: 'green',
              pureBGC: false
            }
          },
          component: () => import('@/views/Design/Preview.vue')
        },
        {
          path: '/preview',
          name: 'preview',
          meta: {
            title: '预览',
            header: {
              bgc: 'green',
              pureBGC: false
            }
          },
          component: () => import('@/views/Survey/views/Preview/Index.vue')
        },
        {
          path: '/publish',
          name: 'publish',
          meta: { title: '问卷投放' },
          component: () => import('../views/Survey/views/Publish/Index.vue')
        },
        {
          path: '/intelligentGeneration',
          name: 'intelligentGeneration',
          meta: {
            title: '智能创建'
          },
          component: () =>
            import(
              '@/views/Home/components/CreateSurvey/components/IntelligentGeneration/Index.vue'
            )
        },
        {
          path: '/search',
          name: 'search',
          meta: {

          },
          component: () => import('@/views/HomeSearch/Index.vue')
        },
        {
          path: '/templateMarket',
          name: 'templateMarket',
          meta: {
            title: '更多模板',
            pureBGC: true,
            header: {
              pureBGC: true
            },
            bgc: 'transparent'
          },
          component: () => import('@/views/Home/components/Market/Index.vue')
        },
        {
          path: '/analysis',
          name: 'analysis',
          meta: {
            title: '统计分析'
          },
          component: () => import('@/views/Survey/views/Analysis/Index.vue')
        },
        {
          path: '/ad/:code',
          name: 'ad',
          meta: {
            pureBGC: true,
            title: '伊调研',
            shareAction: true,
            shareFunc: () => {
              if (window.ReactNativeWebView) {
                window.ReactNativeWebView.postMessage(
                  JSON.stringify(getWXShareConfig())
                );
              }
            }
          },
          component: () => import('@/views/AD/Index.vue')
        }
      ]
    },
    {
      path: '/design',
      name: 'design',
      meta: {},
      component: Design
    },
    {
      path: '/share/:code',
      name: 'share',
      meta: {},
      component: () => import('@/views/Share/Index.vue')
    }
  ]
});

export default router;
