import React, { useState } from 'react'; import { __ } from '@wordpress/i18n'; import { X, Copy, Check, Tag } from 'lucide-react'; import { toast } from 'sonner'; const COUPON_CODE = 'TPTHANKS'; interface Props { onClose: () => void; onScrollToPricing: () => void; } export default function EvergreenExitIntentPopup( { onClose, onScrollToPricing }: Props ) { const [ copied, setCopied ] = useState( false ); const copyCode = ( onDone?: () => void ) => { const done = () => { onDone?.(); }; if ( navigator.clipboard ) { navigator.clipboard.writeText( COUPON_CODE ).then( done ).catch( () => fallbackCopy( done ) ); } else { fallbackCopy( done ); } }; const handleCopy = () => { copyCode( () => { setCopied( true ); setTimeout( () => setCopied( false ), 2000 ); } ); }; const fallbackCopy = ( done: () => void ) => { const el = document.createElement( 'textarea' ); el.value = COUPON_CODE; el.style.position = 'fixed'; el.style.opacity = '0'; document.body.appendChild( el ); el.focus(); el.select(); try { document.execCommand( 'copy' ); done(); } catch {} document.body.removeChild( el ); }; const handleGetDiscount = () => { copyCode( () => toast.success( __( 'Coupon code TPTHANKS copied!', 'image-sizes' ), { description: __( 'Paste it at checkout for 20% off.', 'image-sizes' ) } ) ); onScrollToPricing(); }; return (
{ __( 'As an existing user, we\'re giving you an exclusive 20% discount on ThumbPress Pro. Copy the code and use it at checkout!', 'image-sizes' ) }