import { getAgentShareInfo } from "@/service/agent"
import { isSuccess } from "@/utils"


export const getAvatarImageSrc = (avatarImg: string)=> {
    const mp4SuffixIndex = avatarImg.lastIndexOf('.mp4')
    if(mp4SuffixIndex > -1){
      return avatarImg.slice(0, mp4SuffixIndex) + '_cover.jpg'
    }
    return avatarImg
}

// 生成分享信息
export const getSharePromise = async (agentId:string, shareTitle: string, tmpImage: string) => {
  const response = await getAgentShareInfo(agentId);
  console.log('share:', response)
  if( isSuccess(response.status) ){
    const encodeShareKey = encodeURIComponent(response.data.shareKey??"")
    const o = {
      title: shareTitle,
      path: `/pages/profile/index?agentId=${agentId}&shareKey=${encodeShareKey}`,
      imageUrl: tmpImage,
      promise: response,
    };
    return o
  }
  return {
    title: shareTitle,
    imageUrl: tmpImage,
    path: `/pages/profile/index?agentId=${agentId}`,
  };
}