<script lang="ts" setup>
import {useUserStore} from "@/store";

const {t} = useI18n()
const userStore = useUserStore()
const emits = defineEmits(['changeStore'])

function clickChangeStore() {
  // 当前用户已经有店铺
  if (userStore.merchants.length !== 0) {
    emits('changeStore')
  } else {
    userStore.getFirstShopSettled()
    nextTick(() => {
      console.log('hhhhhhhhhhhhhh', userStore.firstShopSettled)
      // 判断当前用户是否已经认证过了（进入首次创建店铺流程）
      if (userStore.firstShopSettled) {
        uni.navigateTo({
          url: '/pages-user/pages/store-settle-in/list',
        })
      } else {
        uni.navigateTo({
          url: '/pages-user/pages/store-settle-in/index?from=top',
        })
      }
    })
  }
}
</script>

<template>
  <view>
    <view v-if="userStore.isLogin" class="flex items-center" @click="clickChangeStore">
      <view class="text-36rpx text-#333 lh-36rpx tracking-[.04em] mr-12rpx font-bold">
        <template v-if="userStore.merchants.length === 0">
          {{ t('pages.home.createStore') }}
        </template>
        <template v-else>
          <template v-if="userStore.currenMerchantInfo && userStore.currenMerchantInfo.merchantName">
            {{ userStore.currenMerchantInfo.merchantName }}
          </template>
          <template v-else>
            {{ t('toast.pleaseSelectStore') }}
          </template>
        </template>
      </view>
      <image v-if="userStore.merchants.length !== 0" class="w-14rpx h-14rpx" src="@img/chef/108.png"></image>
    </view>
  </view>
</template>

<style lang="scss" scoped>

</style>