import { title } from 'radash'
import { cancelCircleReviewUpvote, cancelCircleUpvote, createCircleUpvote } from './requests'
import { useUserStore } from '@/store'
import { useRouter } from '../utils/router'
import { Coupon } from './models'
import { useMessage } from 'wot-design-uni'
import { MessageOptions, MessageResult } from 'wot-design-uni/components/wd-message-box/types'
import {AgreementType} from "@/core/libs/enums";

const toast = (title: string) => uni.showToast({ title, icon: 'none' })
export const handleUpvoteClick = async (
  {
    upvote,
    circleId,
    userId,
    userName,
  }: {
    upvote: boolean
    circleId: number
    userId: number
    userName: string
  },
  callback?: () => void,
) => {
  if (!upvote) {
    const { code, msg } = await createCircleUpvote({ circleId, userId, userName })
    code === 0 && toast('点赞成功')
  } else {
    const { code } = await cancelCircleUpvote({ id: circleId.toString() })
    code === 0 && toast('取消点赞成功')
  }
  callback && callback()
}
/**
 * 分享圈子
 */
export const handleShareClick = () => {
  const userStore = useUserStore()
  if (!userStore.isLogined) {
    return useRouter().push('/pages/login/index')
  }
  if (!userStore.isDesigner) {
    return useRouter().push('/pages/mine/authentication/index')
  }
  if (userStore.userInfo.level?.level < 2) {
    toast('请先升级为设计师')
    return false
  }
}
/**
 * 优惠券使用说明
 */
export const handleClickInstruction = (
  alert: (toastOptions: MessageOptions | string) => Promise<MessageResult>,
  coupon: Coupon,
) => {
  alert({
    title: '优惠券使用说明',
    msg: coupon.couponDO.couponDesc,
  })
}
