import { siteConfig } from '@/lib/config'
import { useGlobal } from '@/lib/global'
import dynamic from 'next/dynamic'
import { useRouter } from 'next/router'
import { useEffect, useState } from 'react'
import {
EmailIcon,
EmailShareButton,
FacebookIcon,
FacebookMessengerIcon,
FacebookMessengerShareButton,
FacebookShareButton,
HatenaIcon,
HatenaShareButton,
InstapaperIcon,
InstapaperShareButton,
LineIcon,
LineShareButton,
LinkedinIcon,
LinkedinShareButton,
LivejournalIcon,
LivejournalShareButton,
MailruIcon,
MailruShareButton,
OKIcon,
OKShareButton,
PinterestIcon,
PinterestShareButton,
PocketIcon,
PocketShareButton,
RedditIcon,
RedditShareButton,
TelegramIcon,
TelegramShareButton,
TumblrIcon,
TumblrShareButton,
TwitterIcon,
TwitterShareButton,
VKIcon,
VKShareButton,
ViberIcon,
ViberShareButton,
WeiboIcon,
WeiboShareButton,
WhatsappIcon,
WhatsappShareButton,
WorkplaceIcon,
WorkplaceShareButton
} from 'react-share'
const QrCode = dynamic(() => import('@/components/QrCode'), { ssr: false })
/**
* @author https://github.com/txs
* @param {*} param0
* @returns
*/
const ShareButtons = ({ post }) => {
const router = useRouter()
const [shareUrl, setShareUrl] = useState(siteConfig('LINK') + router.asPath)
const title = post.title || siteConfig('TITLE')
const image = post.pageCover
const body =
post?.title + ' | ' + title + ' ' + shareUrl + ' ' + post?.summary
const services = siteConfig('POSTS_SHARE_SERVICES').split(',')
const titleWithSiteInfo = title + ' | ' + siteConfig('TITLE')
const { locale } = useGlobal()
const [qrCodeShow, setQrCodeShow] = useState(false)
const copyUrl = () => {
navigator?.clipboard?.writeText(shareUrl)
alert(locale.COMMON.URL_COPIED + ' \n' + shareUrl)
}
const openPopover = () => {
setQrCodeShow(true)
}
const closePopover = () => {
setQrCodeShow(false)
}
useEffect(() => {
setShareUrl(window.location.href)
}, [])
return (
<>
{services.map(singleService => {
if (singleService === 'facebook') {
return (
)
}
if (singleService === 'messenger') {
return (
)
}
if (singleService === 'line') {
return (
)
}
if (singleService === 'reddit') {
return (
)
}
if (singleService === 'email') {
return (
)
}
if (singleService === 'twitter') {
return (
)
}
if (singleService === 'telegram') {
return (
)
}
if (singleService === 'whatsapp') {
return (
)
}
if (singleService === 'linkedin') {
return (
)
}
if (singleService === 'pinterest') {
return (
)
}
if (singleService === 'vkshare') {
return (
)
}
if (singleService === 'okshare') {
return (
)
}
if (singleService === 'tumblr') {
return (
)
}
if (singleService === 'livejournal') {
return (
)
}
if (singleService === 'mailru') {
return (
)
}
if (singleService === 'viber') {
return (
)
}
if (singleService === 'workplace') {
return (
)
}
if (singleService === 'weibo') {
return (
)
}
if (singleService === 'pocket') {
return (
)
}
if (singleService === 'instapaper') {
return (
)
}
if (singleService === 'hatena') {
return (
)
}
if (singleService === 'qq') {
return (
)
}
if (singleService === 'wechat') {
return (
)
}
if (singleService === 'link') {
return (
)
}
return <>>
})}
>
)
}
export default ShareButtons