import qs from 'qs'

const useShare = () => {
  const shareFacebook = ({ text, shareUrl }: { text: string; shareUrl: string }) => {
    window.open(
      `https://www.facebook.com/dialog/share?${qs.stringify({
        app_id: process.env.NEXT_PUBLIC_FACEBOOK_APP_ID,
        redirect_uri: 'https://www.facebook.com',
        display: 'page',
        href: shareUrl,
        quote: text,
      })}`,
      '_blank'
    )
  }

  const shareTwitter = ({ text, shareUrl }: { text: string; shareUrl: string }) => {
    window.open(
      `https://twitter.com/intent/tweet?${qs.stringify({
        text: `${text} ${shareUrl}`,
      })}`,
      '_blank'
    )
  }

  return {
    shareFacebook,
    shareTwitter,
  }
}

export default useShare
