<template>
  <view class="mx-30 mt-40">
    <!-- <ie-image :is-oss="true" src="/banner/index-banner-4.png" :round="10" customClass="w-full h-178" mode="widthFix" /> -->
    <view class="grid grid-cols-2 gap-x-30">
      <view class="rounded-12 bg-[#F0FFF2] py-40 pl-22 pr-8 flex items-center" @click="handleOpenPlan">
        <!-- /pagesStudy/pages/study-plan-edit/study-plan-edit -->
        <view class="flex-1">
          <view class="text-30 text-fore-title font-bold flex items-center">
            <text class="mr-2">定制学习计划</text>
            <uv-icon name="arrow-right" size="12" color="#808080" />
          </view>
          <view class="mt-4 text-24 text-fore-tip">提升学习效率</view>
        </view>
        <ie-image :is-oss="true" src="/study-bg3.png" customClass="w-92 h-92" />
      </view>
      <view v-if="showCoursePractice" class="rounded-12 bg-[#FFF6F0] py-40 pl-22 pr-8 flex items-center" @click="handleTest">
        <view class="flex-1">
          <view class="text-30 text-fore-title font-bold flex items-center">
            <text class="mr-2">教材同步练习</text>
            <uv-icon name="arrow-right" size="12" color="#808080" />
          </view>
          <view class="mt-4 text-24 text-fore-tip">随课即时练习</view>
        </view>
        <ie-image :is-oss="true" src="/study-bg4.png" customClass="w-92 h-92" />
      </view>
    </view>
  </view>
</template>
<script lang="ts" setup>
import { useTransferPage } from '@/hooks/useTransferPage';
import { getStudyPlan, getDirectedSchool } from '@/api/modules/study';
import { OPEN_VIP_POPUP } from '@/types/injectionSymbols';
import { useUserStore } from '@/store/userStore';
import { EnumExamType } from '@/common/enum';

const { transferTo } = useTransferPage();
const userStore = useUserStore();
const openVipPopup = inject(OPEN_VIP_POPUP);

const showCoursePractice = computed(() => {
  return userStore.getExamType !== EnumExamType.VHS;
});

const handleOpenPlan = async () => {
  const { data } = await getStudyPlan();
  if (data) {
    transferTo('/pagesStudy/pages/study-plan/study-plan', {
      data: {
        ...data
      }
    });
  } else {
    transferTo('/pagesStudy/pages/study-plan-edit/study-plan-edit');
  }
};
const handleTest = () => {
  if (userStore.isVip || userStore.isTeacher) {
    transferTo('/pagesStudy/pages/textbooks-practice/textbooks-practice');
  } else {
    openVipPopup?.();
  }
};
</script>
<style lang="scss" scoped></style>