// Icons import CopyBlueD from "@/components/icons/CopyBlueD"; import DownloadBlue from "@/components/icons/DownloadBlue"; import WhatsappBlueD from "@/components/icons/WhatsappBlueD"; import TelegramBlueD from "@/components/icons/TelegramBlueD"; import LinkedingBlueD from "@/components/icons/LinkedingBlueD"; // Packages import html2canvas from "html2canvas"; import jsPDF from "jspdf"; import { Button } from "@mui/material"; import { toast } from "react-toastify"; function List({ hiddenRef, data }) { const handleDownloadPDF = async () => { const element = hiddenRef.current; if (!element) return; const canvas = await html2canvas(element, { backgroundColor: "#ffffff", useCORS: true, scale: 2, }); const imgData = canvas.toDataURL("image/png"); const imgWidth = 210; const imgProps = canvas; const pxPerMm = imgProps.width / imgWidth; const imgHeight = canvas.height / pxPerMm; const pdf = new jsPDF({ orientation: "portrait", unit: "mm", format: [imgWidth, imgHeight], }); pdf.addImage(imgData, "PNG", 0, 0, imgWidth, imgHeight); pdf.save("poster.pdf"); }; const getShareUrl = () => typeof window !== "undefined" ? window.location.href : ""; const getShareText = () => data?.name ? `معرفی ${data.name} در نوبت 724` : "معرفی پزشک در نوبت 724"; const openShareWindow = (url) => { if (typeof window !== "undefined") { window.open(url, "_blank", "noopener,noreferrer"); } }; const handleWhatsapp = () => { const text = encodeURIComponent(`${getShareText()}\n${getShareUrl()}`); openShareWindow(`https://wa.me/?text=${text}`); }; const handleTelegram = () => { const url = encodeURIComponent(getShareUrl()); const text = encodeURIComponent(getShareText()); openShareWindow(`https://t.me/share/url?url=${url}&text=${text}`); }; const handleLinkedin = () => { const url = encodeURIComponent(getShareUrl()); openShareWindow( `https://www.linkedin.com/sharing/share-offsite/?url=${url}` ); }; const handleCopyLink = async () => { try { await navigator.clipboard.writeText(getShareUrl()); toast.success("لینک کپی شد"); } catch { toast.error("کپی لینک ناموفق بود"); } }; const listIcons = [ { name: "واتساپ", icon: , onClick: handleWhatsapp }, { name: "تلگرام", icon: , onClick: handleTelegram }, { name: "لینکدین", icon: , onClick: handleLinkedin }, { name: "کپی لینک", icon: , onClick: handleCopyLink }, { name: "دانلود", icon: , onClick: handleDownloadPDF }, ]; return ( <>
    {listIcons.map((item, idx) => (
  • {item.name}
  • ))}
); } export default List;