<template>
  <view>
    <view class="activities_header">
      <view class="activities_name_time">
        <view class="name"> {{ useModel?.showData?.value?.title }} </view>
        <view class="time">
          活动时间：{{ showDay(useModel?.showData?.value?.start_time) }} 至
          {{ showDay(useModel?.showData?.value?.end_time) }}
        </view>
      </view>
      <view :class="`status event_status_${useModel?.showData?.value?.status}`">
        <hs-enum-tag
          :value="useModel?.showData?.value?.status"
          :Enums="ActivitiesStatusEnum"
        />
      </view>
    </view>
    <view class="activities_content">
      <up-parse :content="useModel?.showData?.value?.content"></up-parse>
    </view>




<template v-if="useModel?.showData?.value?.status !== 'Finished'">
    <view class="footer" v-if="!useModel?.showData?.value?.result">
      <view class="btn">
        <hs-button size="md" type="display" label="分享活动" openType="share" />
      </view>
      <view class="btn" v-if="useModel?.showData?.value?.is_enroll">
        <hs-button
          size="md"
          type="primary"
          :disabled="
            !getIsInRangeInclusive(
              useModel?.showData?.value?.start_time,
              useModel?.showData?.value?.end_time
            )
          "
          label="立即报名"
          @click="method?.handleSignUp"
        />
      </view>
    </view>

    <view class="footer" v-else>
      <view
        class="btn"
        v-if="useModel?.showData?.value?.result?.status === 'Cancelled' && useModel?.showData?.value?.is_enroll && getIsInRangeInclusive(useModel?.showData?.value?.start_time,useModel?.showData?.value?.end_time)">
        <hs-button
          size="md"
          type="display"
          label="重新报名"
          @click="method?.handleCancelSignUp('Success')"
        />
      </view>
      <view class="btn" v-if="useModel?.showData?.value?.result?.status === 'Success'">
        <hs-button
          size="md"
          type="display"
          :disabled="
            !getIsInRangeInclusive(
              useModel?.showData?.value?.start_time,
              useModel?.showData?.value?.end_time
            )
          "
          label="取消报名"
          @click="method?.handleCancelSignUp('Cancelled')"
        />
      </view>
      <view class="btn">
        <hs-button size="md" type="primary" label="分享活动" openType="share" />
      </view>
    </view>
  </template>
  </view>
</template>

<script setup lang="ts">
import { onLoad, onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app'
import method from './method'
import useModel from './model'
import { showDay } from '@/common/libraries/day'
import { ActivitiesStatusEnum } from '@/gen/Enums'
import { getIsInRangeInclusive } from '@/common/libraries/day'
onLoad((e: any) => {
  method?.getShow(e?.id)
})

onShareAppMessage(() => {
  return {
    title: `您的好友邀请你报名${useModel?.showData?.value?.title}`,
    path: `/INDEX/activities_show/index?id=${useModel?.showData?.value?.id}`,
    imageUrl: useModel?.showData?.value?.cover_image[0]?.url
  }
})
onShareTimeline(() => {
  return {
    title: `您的好友邀请你报名${useModel?.showData?.value?.title}`,
    path: `/INDEX/activities_show/index?id=${useModel?.showData?.value?.id}`,
    imageUrl: useModel?.showData?.value?.cover_image[0]?.url
  }
})
</script>

<style lang="scss">
@import './style.scss';
</style>
