import type { PopupProps } from '../_shared/Popup' import { createSocialShare, TWITTER, VK, FACEBOOK, TELEGRAM } from '@solid-primitives/share' import { createEffect, createSignal } from 'solid-js' import { useLocalize } from '../../context/localize' import { useSnackbar } from '../../context/snackbar' import { Icon } from '../_shared/Icon' import { Popup } from '../_shared/Popup' import styles from '../_shared/Popup/Popup.module.scss' type SharePopupProps = { title: string shareUrl?: string imageUrl: string description: string onVisibilityChange?: (value: boolean) => void } & Omit export const getShareUrl = (params: { pathname?: string } = {}) => { if (typeof location === 'undefined') return '' const pathname = params.pathname ?? location.pathname return location.origin + pathname } export const SharePopup = (props: SharePopupProps) => { const { t } = useLocalize() const [isVisible, setIsVisible] = createSignal(false) const { actions: { showSnackbar }, } = useSnackbar() createEffect(() => { if (props.onVisibilityChange) { props.onVisibilityChange(isVisible()) } }) const [share] = createSocialShare(() => ({ title: props.title, url: props.shareUrl, description: props.description, })) const copyLink = async () => { await navigator.clipboard.writeText(props.shareUrl) showSnackbar({ body: t('Link copied') }) } return ( setIsVisible(value)}> ) }