import { __ } from '@wordpress/i18n'; import { escapeHTML } from '@wordpress/escape-html'; import { formatFileSize } from '../../utils'; import { UPGRADE_LINK } from '../../constants'; const notOptimizedTemplate = () => { return ` `; }; const loadingTemplate = ( action ) => { let buttonText; switch ( action ) { case 'restore': buttonText = __( 'Restoring…', 'image-optimization' ); break; case 'optimize': buttonText = __( 'Optimizing…', 'image-optimization' ); break; case 'reoptimize': buttonText = __( 'Reoptimizing…', 'image-optimization' ); break; default: buttonText = __( 'Loading…', 'image-optimization' ); } return ` `; }; const errorTemplate = ( message, imagesLeft ) => { return ` ${ imagesLeft === 0 ? ` ${ __( 'Upgrade', 'image-optimization' ) } ` : ` ` } `; }; const optimizedTemplate = ( data ) => { const absoluteValue = formatFileSize( data?.saved?.absolute, 1 ); return `
${ __( 'Image sizes optimized', 'image-optimization' ) }: ${ data?.sizesOptimized }
${ data?.saved?.absolute !== 0 ? `${ __( 'Overall saving', 'image-optimization' ) }: ${ data?.saved?.relative }% (${ absoluteValue })` : `${ __( 'Image is fully optimized', 'image-optimization' ) }` }
`; }; const listViewTemplates = Object.freeze( { notOptimizedTemplate, loadingTemplate, errorTemplate, optimizedTemplate, } ); export default listViewTemplates;