import { title } from 'radash'
import { cancelCircleReviewUpvote, cancelCircleUpvote, createCircleUpvote } from './requests'

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()
}
