/* eslint-disable @typescript-eslint/no-unsafe-call */ /* eslint-disable @typescript-eslint/no-unsafe-argument */ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ import { cloneElement } from 'react' import FacebookSVG from '#assets/share/facebook.svg' import LinkedinSVG from '#assets/share/linkedin.svg' import TelegramSVG from '#assets/share/telegram.svg' import TwitterSVG from '#assets/share/twitter.svg' import WhatsappSVG from '#assets/share/whatsapp.svg' import XingSVG from '#assets/share/xing.svg' const platformConfigs = { facebook: { shareUrl: 'https://www.facebook.com/sharer/sharer.php?u={url}', icon: Facebook, bgColor: '#3b5998', }, twitter: { shareUrl: 'https://twitter.com/intent/tweet?text={title}:%20{url}', icon: Twitter, bgColor: '#55acee', }, linkedin: { shareUrl: 'http://www.linkedin.com/shareArticle?mini=true&url={url}&title={title}', icon: Linkedin, bgColor: '#4875b4', }, xing: { shareUrl: 'https://www.xing-share.com/app/user?op=share;sc_p=xing-share;url={url}', icon: Xing, bgColor: '#026466', }, whatsapp: { shareUrl: 'https://api.whatsapp.com/send?text={title}%20{url}', icon: Whatsapp, bgColor: '#25D366', }, telegram: { shareUrl: 'https://t.me/share/url?url={url}&text={title}', icon: Telegram, bgColor: '#0088cc', }, } const SocialShareButton = ({ platform, url, title, }: { platform: string url: string title: string }) => { // eslint-disable-next-line security/detect-object-injection const config = platformConfigs[platform] if (!config) { return null } const { shareUrl, icon, bgColor } = config const finalShareUrl = shareUrl .replace('{url}', encodeURIComponent(url)) .replace('{title}', encodeURIComponent(title)) return ( {cloneElement(icon, { className: 'tw:w-4 tw:h-4 tw:fill-current' })} ) } export default SocialShareButton