<?php
if (!defined('ABSPATH')) {
    exit;
}
$receipt_id_encoded = $receipt_id = $type = $payment_status = $subscription_status = $total_display = $email = $full_name = $total_display = '';

// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$receipt_id_encoded = isset($_GET['receipt-id']) ? sanitize_text_field( wp_unslash( $_GET['receipt-id'] ) ) : '';
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$type = isset($_GET['type']) ? sanitize_text_field( wp_unslash( $_GET['type'] ) ) : '';

 if ($receipt_id_encoded && $type) {
    $receipt_id        = base64_decode($receipt_id_encoded);
    $email = get_post_meta($receipt_id, 'chama_email', true);
    $full_name = get_post_meta($receipt_id, 'chama_full_name', true);
    $payment_status = get_post_meta($receipt_id, 'chama_payment_status', true);
    $user_id = get_post_meta($receipt_id, 'chama_user_id', true);
    $subscription_status = get_post_meta($receipt_id, 'chama_subscription_status', true);
    $description = '';
    $total = '';
    $total_display = '';
    $sub_total_label = '';
    $total_label = '';
    $description_label = '';
    $thank_you_message = '';
    $display_sub_total = false;
    $order_summary = array();
    $thank_you_message = 'Thank you for your monthly contribution!';
    $total = get_post_meta($receipt_id, 'chama_subscription_total_amount', true);
    $description_label = 'Membership Tier';
    $description = get_post_meta($receipt_id, 'chama_subscription_description', true);
    $renewal_date_label = 'Renewal Date';
    $today = gmdate('Y-m-d');
    $renewal_date = gmdate("F, j, Y", strtotime('+1 month', strtotime($today)));
    $sub_total_label = 'Monthly Subscription Amount';
    $total_label = 'Subscription Total';

    $total_display = CHAMA_SYMBOL . number_format((float) $total, 2, '.', '');
}
?>


    <div class="chama-card">
    <div class="chama-card-body">

            <h3>Receipt</h3>
            <em><?php echo esc_html($thank_you_message); ?></em>
            <hr class="chama-hr chama-receipt-hr" />
            <dl class="chama-receipt-table">
            <div class="chama-receipt-details-row">
                <dt class="chama-receipt-detail">Email Address</dt>
                <dd class="chama-receipt-value"><?php echo esc_html($email); ?></dd>
                </div>
                <?php if ($full_name): ?>
                    <div class="chama-receipt-details-row">
                <dt class="chama-receipt-detail">Full Name</dt>
                <dd class="chama-receipt-value"><?php echo esc_html($full_name); ?></dd>
                </div>
                    <?php endif;?>
                <div class="chama-receipt-details-row chama-receipt-payment-status <?php echo esc_attr($payment_status); ?>">
                <dt class="chama-receipt-detail">Payment Status</dt>
                <dd class="chama-receipt-value"><?php echo esc_html(ucwords($payment_status)); ?>	</dd>
                </div>
                <div class="chama-receipt-details-row chama-receipt-subscription-status <?php echo esc_attr($subscription_status); ?>">
                <dt class="chama-receipt-detail">Subscription Status</dt>
                <dd class="chama-receipt-value"><?php echo esc_html(ucwords($subscription_status)); ?>	</dd>
                </div>
                <?php if ($description): ?>
                    <div class="chama-receipt-details-row">
                <dt class="chama-receipt-detail"><?php echo esc_html($description_label) ?></dt>
                <dd class="chama-receipt-value"><?php echo esc_attr($description); ?></dd>
                </div>
                <?php endif;?>
                <?php if( $subscription_status != 'canceled'): ?>
                <div class="chama-receipt-details-row">
                <dt class="chama-receipt-detail"><?php echo esc_html($renewal_date_label) ?></dt>
                <dd class="chama-receipt-value"><?php echo esc_attr($renewal_date); ?></dd>
                </div>
                <?php endif;?>
                <?php if ($display_sub_total): ?>
                <div class="chama-receipt-details-row">
                <dt class="chama-receipt-detail"><?php echo esc_html($sub_total_label) ?></dt>
                <dd class="chama-receipt-value"><?php echo esc_attr($total_display); ?></dd>
                </div>
                <?php endif;?>

                <div class="chama-receipt-details-row chama-receipt-total">
                <dt class="chama-receipt-detail"><?php echo esc_html($total_label) ?></dt>
                <dd class="chama-receipt-value"><?php echo esc_attr($total_display); ?></dd>
                </div>

            </dl>


    </div>
    </div>
