<?php namespace MeowCrew\CancellationOffers\SurveyAnswers\SurveyAnswersPage\Columns;

use MeowCrew\CancellationOffers\SurveyAnswers\SurveyAnswer;

class RetentionOfferColumn extends SurveyAnswerListColumn {

	public function getName(): string {
		return __( 'Retention Offer', 'cancellation-surveys-offers-woocommerce-subscriptions' );
	}

	public function renderContent( SurveyAnswer $surveyAnswer ) {

		if ( ! csows_fs()->can_use_premium_code() ) {
			?>
			<a href="<?php echo esc_attr( csows_upgrade_url() ); ?>" target="_blank"
			   style="color: #d63638; font-weight: bold;">
				<?php esc_html_e( 'Upgrade to use retention offers', 'cancellation-surveys-offers-woocommerce-subscriptions' ); ?>
			</a>
			<?php
			return;
		}

		if ( ! $surveyAnswer->isDiscountOfferEnabled() ) {
			esc_html_e( 'Retention did not offered', 'cancellation-surveys-offers-woocommerce-subscriptions' );

			return;
		}

		if ( $surveyAnswer->getCouponId() === - 1 ) {
			?>
			<code style="
			display: block;
			text-align: center;
			border-radius: 6px;">
				<?php esc_html_e( 'Skip renewal', 'cancellation-surveys-offers-woocommerce-subscriptions' ); ?>
			</code>
			<?php
			return;
		}

		$coupon = new \WC_Coupon( $surveyAnswer->getCouponId() );

		if ( $coupon->get_code() ) {
			?>
			<a target="_blank" href="<?php echo esc_attr( get_edit_post_link( $coupon->get_id() ) ); ?>">
				<code style="display: block;
	text-align: center;
	border-radius: 6px;">
					<?php echo esc_html( $coupon->get_code() ); ?>
				</code>
			</a>
			<?php
		} else {
			echo esc_html( '-' );
		}
	}

	public function getSlug(): string {
		return 'cos_retention_offer';
	}
}
