import { shareCircle, shareDesignerHome } from '@/core/libs/requests'
import { messages } from '@/core/libs/messages'

export const useShare = () => {
  const shareAppMessage = async ({ from, target }) => {
    // const res: Page.CustomShareContent = {}
    // if (from === 'button') {
    //   console.log(target)
    //
    //   if (target.dataset.type === 'homepage') {
    //     res.title = `${userInfo.value.nickname}: “${designerInfo.value.designDesc}”`
    //     res.imageUrl = designerInfo.value?.sharePageUrl
    //     res.path = `/pages/mine/homepage/index?id=${id.value}&isShared=true`
    //   } else {
    //     await shareCircle(target.dataset.options.id)
    //     res.path = `/pages/home/moment/index?id=${target.dataset.options.id}&isShared=true`
    //     res.imageUrl = target.dataset.options.bannerUrls[0]
    //     res.title = `${target.dataset.options.stylistName}: ${target.dataset.options.circleDesc}`
    //   }
    // }
    // if (from === 'menu') {
    //   res.title = `${userInfo.value.nickname}: “${designerInfo.value.designDesc}”`
    //   res.imageUrl = designerInfo.value?.sharePageUrl
    //   res.path = `/pages/mine/homepage/index?id=${id.value}&isShared=true`
    // }
    // return res

    console.log('from', from)
    console.log('target', target)
    const res: Page.CustomShareContent = {}
    if (from === 'button') {
      if (target.dataset.type === 'homepage') {
        await shareDesignerHome({
          stylistId: target.dataset.options.homepageId,
          bizId: target.dataset.options.userId,
        })
        res.title = target.dataset.shareContent.title
        res.imageUrl = target.dataset.shareContent.imageUrl
        res.path = target.dataset.shareContent.path
      } else {
        if (['1', '2'].includes(target.dataset.options.circleType)) {
          await shareCircle(target.dataset.options.id)
        }
        res.path = `/pages/home/moment/index?id=${target.dataset.options.id}&isShared=true`
        res.imageUrl = target.dataset.options.bannerUrls[0]
        res.title = `${target.dataset.options.stylistName}: ${target.dataset.options.circleDesc}`
      }
    }
    if (from === 'menu') {
      res.title = messages.home.shareTitle
    }
    return res
  }
  return { shareAppMessage }
}
