import React from 'react'; import { __, sprintf } from '@wordpress/i18n'; import { Crown, ArrowRight, X, HeartPulse, Sparkles } from 'lucide-react'; import { COMPRESSION_CHECK_PRO_LINK, compressionCheckCtaLabel, leadsWithPercent } from './compression-check'; import type { CompressionCheckResult, CompressionCheckSample } from '../../api'; import { numberFormat, formatBytes, percentFormat } from '../../lib/i18n'; /** * The check's result: the saving up front, the tested images before and after, * and one way forward. Numbers are only ever the measured, rounded-down ones. */ const CompressionCheckModal = ( { result, samples, healthGain, onClose }: { result: CompressionCheckResult; samples: CompressionCheckSample[]; healthGain: number; onClose: () => void; } ) => { const totalBefore = samples.reduce( ( sum, sample ) => sum + sample.before, 0 ); const totalAfter = samples.reduce( ( sum, sample ) => sum + sample.after, 0 ); const totalPct = totalBefore > 0 ? Math.floor( ( ( totalBefore - totalAfter ) * 100 ) / totalBefore ) : 0; const byPercent = leadsWithPercent( result.saved_bytes ); return (
{/* Hero */}

{ byPercent ? __( 'Make your images', 'image-sizes' ) : __( 'You can save', 'image-sizes' ) }

{ byPercent ? percentFormat( result.saved_pct ) : sprintf( /* translators: %s: estimated size saved, e.g. "640 MB". */ __( '~%s', 'image-sizes' ), formatBytes( result.saved_bytes, true ), ) }

{ byPercent ? __( 'smaller with ThumbPress Pro, plus every thumbnail and new upload', 'image-sizes' ) : sprintf( /* translators: %s: number of images. */ __( 'across your %s images with ThumbPress Pro', 'image-sizes' ), numberFormat( result.image_count ), ) }

{ ! byPercent && result.saved_pct > 0 && ( { sprintf( /* translators: %s: percentage, e.g. "35%". */ __( '%s smaller', 'image-sizes' ), percentFormat( result.saved_pct ), ) } ) } { healthGain > 0 && ( { sprintf( /* translators: %s: number of health score points. */ __( '+%s health score', 'image-sizes' ), numberFormat( healthGain ), ) } ) }
{/* Before / after */}
{ samples.map( ( sample ) => ( ) ) }
{ __( 'Before', 'image-sizes' ) } { __( 'After', 'image-sizes' ) } { __( 'Saved', 'image-sizes' ) }
{ { formatBytes( sample.before ) } { { formatBytes( sample.after ) } { sprintf( /* translators: %s: percentage, e.g. "65%". */ __( '−%s', 'image-sizes' ), percentFormat( sample.saved_pct ), ) }
{ formatBytes( totalBefore ) } { formatBytes( totalAfter ) } { sprintf( /* translators: %s: percentage, e.g. "65%". */ __( '−%s', 'image-sizes' ), percentFormat( totalPct ), ) }
{/* CTA */}
{ compressionCheckCtaLabel() }

{ sprintf( /* translators: %s: number of images tested. */ __( 'Estimate from %s of your images.', 'image-sizes' ), numberFormat( result.samples_tested ), ) } { ' ' }

); }; export default CompressionCheckModal;