import { Background, Flex, Padding, Position, TouchableOpacity } from '@/@dble_layout'; import { useJenga } from '@/libs/provider/JengaProvider'; import { mySite } from '@/libs/site/site'; import { useEffect, useState } from 'react'; export function FloatingShareTab({ title, description, imageUrl, }: { title?: string; description: string; imageUrl?: string; }) { const KAKAO_API_KEY = process.env.NEXT_PUBLIC_KAKAO_API_KEY; const { addToast } = useJenga(); const [isVisible, setIsVisible] = useState(true); useEffect(() => { let lastScrollY = window.scrollY; const handleScroll = () => { if (window.scrollY > lastScrollY) { setIsVisible(false); } else setIsVisible(true); lastScrollY = window.scrollY; }; window.addEventListener('scroll', handleScroll); return () => { window.removeEventListener('scroll', handleScroll); }; }, []); // 클립보드 공유 function copyCurrentURL() { if (typeof window !== 'undefined') { navigator.clipboard .writeText(window.location.href) .then(() => { addToast({ title: 'URL 복사 완료', description: '복사한 URL을 원하는 곳에 첨부하세요', }); }) .catch(err => { console.error('Failed to copy URL: ', err); }); } } // 카카오 공유 const content = { title: title ?? mySite.title, description: description ?? mySite.description, imageUrl: imageUrl ?? mySite.imageUrl, link: { mobileWebUrl: typeof window !== 'undefined' && window.location.href, webUrl: typeof window !== 'undefined' && window.location.href, }, }; const shareKakao = () => { if ((window as any)?.Kakao) { const kakao = (window as any).Kakao; if (!kakao.isInitialized()) kakao.init(KAKAO_API_KEY); kakao.Link.sendDefault({ objectType: 'feed', content, }); } }; return ( isVisible && ( ) ); }