import { copyText } from "@/utils/clipboard"; import { formatCode } from "@/utils/format"; import { notify } from "@/utils/notifications"; import { useState } from "react"; import { Voucher } from "@/types/voucher"; import { useRouter } from "next/navigation"; type Props = { voucher: Voucher; contentClassName?: string; }; export default function VoucherCode({ voucher, contentClassName = "" }: Props) { const code = formatCode(voucher.code); const [copied, setCopied] = useState(false); const router = useRouter(); const handleCopy = async () => { if (await copyText(voucher.code)) { setCopied(true); setTimeout(() => setCopied(false), 1500); notify("Code copied to clipboard!", "success"); } else { notify("Failed to copy code", "error"); } }; const handlePrint = () => { const vouchersParam = encodeURIComponent(JSON.stringify([voucher])); const printUrl = `/print?vouchers=${vouchersParam}&mode=list`; router.replace(printUrl); }; return (