<?php namespace MeowCrew\CancellationOffers\Offer\CPT\Columns;

use MeowCrew\CancellationOffers\Offer\Entity\Offer;

class RetentionRateColumn {
	
	public function getName(): string {
		return __( 'Retention Rate', 'cancellation-surveys-offers-woocommerce-subscriptions' );
	}
	
	public function render( Offer $offer ) {
		
		$retentionRateAllCases  = $offer->getStatistics()->getRetentionRate();
		$discountsRetentionRate = $offer->getStatistics()->getRetentionRate( true );
		
		if ( ! $retentionRateAllCases || ! $offer->getDiscountOffer()->isEnabled() ) {
			esc_html_e( 'N/A', 'cancellation-surveys-offers-woocommerce-subscriptions' );
			
			return;
		}
		?>

		<div style="display: flex; justify-content: space-around; cursor: help">
			<div style="width: 40%; font-size: 1em;"
				 title="<?php esc_html_e( 'All Cases', 'cancellation-surveys-offers-woocommerce-subscriptions' ); ?>">

				<div class="cancellation-offer-popup-survey__retention-rate"
					 data-retention-rate="<?php echo esc_attr( $retentionRateAllCases ); ?>"
					 style="--retention-rate:<?php echo esc_attr( $retentionRateAllCases ); ?>%; font-size: 1.1em;">
					<progress value="<?php echo esc_attr($retentionRateAllCases); ?>" max="100"
							  style="visibility:hidden;height:0;width:0;">
						<?php echo esc_html( $retentionRateAllCases ); ?>%
					</progress>
				</div>
			</div>

			<div style="width: 40%; font-size: 1em;" title="<?php esc_html_e( 'When discount was offered', 'cancellation-surveys-offers-woocommerce-subscriptions' ); ?>">

				<div class="cancellation-offer-popup-survey__retention-rate"
					 data-retention-rate="<?php echo esc_attr( $discountsRetentionRate ); ?>"
					 style="--retention-rate:<?php echo esc_attr( $discountsRetentionRate ); ?>%; font-size: 1.1em;">
					<progress value="<?php echo esc_attr($discountsRetentionRate); ?>" max="100"
							  style="visibility:hidden;height:0;width:0;">
						<?php echo esc_html( $discountsRetentionRate ); ?>%
					</progress>
				</div>
			</div>
		</div>
		<br>
		<?php
	}
}
