<template>
	<view class="index" :style="{
    backgroundImage: tabIndex === 4 ? `url('https://xy.wenlvti.net/app_static/images/mine/TopBanner.png')` : `url('https://xy.wenlvti.net/app_static/images/dig/TopBanner.png')`,
    backgroundRepeat: 'no-repeat',
    backgroundSize: '100% auto',
    backgroundPosition: 'top center',
    backgroundColor: themeContext.resolveThemeColor('background.primary'),
  }">
    <CommonRoot>
      <StatusBarSpace backgroundColor="transparent" />
      <NavBar
        :titleScroll="false"
        backgroundColor="transparent"
        textColor="whweixinite"
        align="left"
      />
      <HomeIndex v-show="tabIndex === 0" @goVillage="tabIndex = 1" />
      <VillageIndex v-if="tabIndex === 1" showSwitch />
      <DigIndex v-else-if="tabIndex === 2" />
      <DiscoverIndex v-else-if="tabIndex === 3" />
      <UserIndex v-else-if="tabIndex === 4" @goSubmit="tabIndex = 2" />
      <TabBar
        v-model:selectedTabIndex="tabIndex"
        fixed
        xbarSpace
        :innerStyle="{
          backgroundColor: '#ffead8',
        }"
      >
        <TabBarItem icon="https://xy.wenlvti.net/app_static/images/tabs/TabIconHome.png" activeIcon="https://xy.wenlvti.net/app_static/images/tabs/TabIconHomeActive.png" text="首页" :iconSize="70" />
        <TabBarItem icon="https://xy.wenlvti.net/app_static/images/tabs/TabIconVillage.png" activeIcon="https://xy.wenlvti.net/app_static/images/tabs/TabIconVillageActive.png" text="乡源" :iconSize="70" />
        <TabBarItem icon="https://xy.wenlvti.net/app_static/images/tabs/TabIconDig.png" activeIcon="https://xy.wenlvti.net/app_static/images/tabs/TabIconDigActive.png" text="挖掘" :iconSize="70" />
        <TabBarItem icon="https://xy.wenlvti.net/app_static/images/tabs/TabIconDiscover.png" activeIcon="https://xy.wenlvti.net/app_static/images/tabs/TabIconDiscoverActive.png" text="发现" :iconSize="70" />
        <TabBarItem icon="https://xy.wenlvti.net/app_static/images/tabs/TabIconMine.png" activeIcon="https://xy.wenlvti.net/app_static/images/tabs/TabIconMineActive.png" text="我的" :iconSize="70" />
      </TabBar>
    </CommonRoot>
	</view>
</template>

<script setup lang="ts">
import { onMounted, ref } from 'vue';
import { onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app';
import { useTheme } from '@/components/theme/ThemeDefine';
import StatusBarSpace from '@/components/layout/space/StatusBarSpace.vue';
import NavBar from '@/components/nav/NavBar.vue';
import TabBar from '@/components/nav/TabBar.vue';
import TabBarItem from '@/components/nav/TabBarItem.vue';
import DigIndex from './home/dig.vue';
import UserIndex from './user/index.vue';
import HomeIndex from './home/index.vue';
import DiscoverIndex from './home/discover/index.vue';
import VillageIndex from './home/village/index.vue';
import CommonRoot from '@/components/dialog/CommonRoot.vue';
import { isDevEnv } from '@/common/config/AppCofig';
import { useLoadQuerys } from '@/components/composeabe/LoadQuerys';
import { navTo } from '@/components/utils/PageAction';

const tabIndex = ref(0);
const themeContext = useTheme();

useLoadQuerys({ 
  openLogin: false,
}, (querys) => {
  if (querys.openLogin) {
    navTo('/pages/user/login');
  }
});

defineExpose({
  onPageBack: (name: string, data: Record<string, unknown>) => {
    if (data.type === 'goVillage') {
      tabIndex.value = 1;
    }
  }
})
onShareAppMessage(() => {
  return {
    title: '村社文化资源挖掘平台',
    path: '/pages/index',
    imageUrl: 'https://mn.wenlvti.net/app_static/xiangyuan/images/index-post.jpg',
  }
})
onShareTimeline(() => {
  return {
    title: '村社文化资源挖掘平台',
    path: '/pages/index',
    imageUrl: 'https://mn.wenlvti.net/app_static/xiangyuan/images/index-post.jpg',
  }
})
onMounted(() => {
  if (isDevEnv) {
    //tabIndex.value = 1;
  }
})
</script>