<?php
defined('ABSPATH') || exit;

/**
 * 247ChatMate — Plan Access Partial
 * LICENCERENDERSAFETYFIX1
 */

$is_master = isset($is_master) ? (bool) $is_master : ('master' === ($mode ?? ''));
$is_dev_forced = isset($is_dev_forced) ? (bool) $is_dev_forced : false;

$trial_started_at = isset($trial_info['started_at']) ? (int) $trial_info['started_at'] : 0;
$trial_days       = defined('MATEWA_TRIAL_DAYS') ? max(0, (int) MATEWA_TRIAL_DAYS) : 0;
$trial_day_seconds = defined('DAY_IN_SECONDS') ? (int) DAY_IN_SECONDS : 86400;
$trial_end_at     = ($trial_started_at > 0 && $trial_days > 0)
    ? $trial_started_at + ($trial_days * $trial_day_seconds)
    : 0;
$trial_remaining_days = ($trial_end_at > 0)
    ? max(0, (int) ceil(($trial_end_at - time()) / $trial_day_seconds))
    : 0;
$trial_remaining_label = 1 === $trial_remaining_days ? '1 day remaining' : $trial_remaining_days . ' days remaining';
$trial_date_format = trim((string) get_option('date_format', 'Y-m-d') . ' ' . (string) get_option('time_format', 'H:i'));
$trial_started_display = $trial_started_at > 0
    ? wp_date($trial_date_format, $trial_started_at)
    : 'Not started';
$trial_end_display = $trial_end_at > 0
    ? wp_date($trial_date_format, $trial_end_at)
    : 'Not available';

$trial_registry_last = isset($trial_registry_last) && is_array($trial_registry_last)
    ? $trial_registry_last
    : (function_exists('matewa_pro_trial_registry_get_last_result') ? matewa_pro_trial_registry_get_last_result() : []);
$trial_registry_last = is_array($trial_registry_last) ? $trial_registry_last : [];
$trial_registry_configured = isset($trial_registry_configured)
    ? (bool) $trial_registry_configured
    : (function_exists('matewa_pro_trial_registry_is_configured') ? matewa_pro_trial_registry_is_configured() : false);
$trial_registry_endpoint = isset($trial_registry_endpoint)
    ? (string) $trial_registry_endpoint
    : (function_exists('matewa_pro_trial_registry_get_endpoint') ? matewa_pro_trial_registry_get_endpoint() : '');
$trial_registry_code = isset($trial_registry_last['code']) ? sanitize_key((string) $trial_registry_last['code']) : 'not_checked';
$trial_registry_status = isset($trial_registry_last['status']) ? sanitize_key((string) $trial_registry_last['status']) : '';
$trial_registry_reference = isset($trial_registry_last['trial_reference']) ? sanitize_text_field((string) $trial_registry_last['trial_reference']) : '';
$trial_registry_message = isset($trial_registry_last['message']) ? sanitize_text_field((string) $trial_registry_last['message']) : '';
$trial_registry_checked_at = isset($trial_registry_last['checked_at']) ? (int) $trial_registry_last['checked_at'] : 0;
$trial_registry_checked_display = $trial_registry_checked_at > 0
    ? wp_date($trial_date_format, $trial_registry_checked_at)
    : 'Not checked yet';
$trial_registry_started_at = isset($trial_registry_last['trial_started_at']) ? (int) $trial_registry_last['trial_started_at'] : 0;
$trial_registry_expires_at = isset($trial_registry_last['trial_expires_at']) ? (int) $trial_registry_last['trial_expires_at'] : 0;
$trial_registry_started_display = $trial_registry_started_at > 0 ? wp_date($trial_date_format, $trial_registry_started_at) : 'Not available';
$trial_registry_expires_display = $trial_registry_expires_at > 0 ? wp_date($trial_date_format, $trial_registry_expires_at) : 'Not available';
$trial_whatsapp_saved = function_exists('matewa_pro_trial_registry_normalise_whatsapp')
    ? ('' !== matewa_pro_trial_registry_normalise_whatsapp($number ?? ''))
    : ('' !== trim((string) ($number ?? '')));

$founder_beta_last = isset($founder_beta_last) && is_array($founder_beta_last)
    ? $founder_beta_last
    : (function_exists('matewa_founder_beta_get_last_result') ? matewa_founder_beta_get_last_result() : []);
$founder_beta_last = is_array($founder_beta_last) ? $founder_beta_last : [];
$founder_beta_configured = isset($founder_beta_configured)
    ? (bool) $founder_beta_configured
    : (function_exists('matewa_founder_beta_is_configured') ? matewa_founder_beta_is_configured() : false);
$founder_beta_endpoint = isset($founder_beta_endpoint)
    ? (string) $founder_beta_endpoint
    : (function_exists('matewa_founder_beta_get_endpoint') ? matewa_founder_beta_get_endpoint() : '');
$founder_beta_success = !empty($founder_beta_last['success']);
$founder_beta_code = isset($founder_beta_last['code']) ? sanitize_key((string) $founder_beta_last['code']) : 'not_checked';
$founder_beta_status = isset($founder_beta_last['status']) ? sanitize_key((string) $founder_beta_last['status']) : '';
$founder_beta_message = isset($founder_beta_last['message']) ? sanitize_text_field((string) $founder_beta_last['message']) : '';
$founder_beta_checked_at = isset($founder_beta_last['checked_at']) ? (int) $founder_beta_last['checked_at'] : 0;
$founder_beta_checked_display = $founder_beta_checked_at > 0
    ? wp_date($trial_date_format, $founder_beta_checked_at)
    : 'Not checked yet';
$founder_beta_start = isset($founder_beta_last['beta_start']) ? sanitize_text_field((string) $founder_beta_last['beta_start']) : '';
$founder_beta_expiry = isset($founder_beta_last['beta_expiry']) ? sanitize_text_field((string) $founder_beta_last['beta_expiry']) : '';
$founder_beta_start_display = '' !== $founder_beta_start ? $founder_beta_start : 'Not available';
$founder_beta_expiry_display = '' !== $founder_beta_expiry ? $founder_beta_expiry : 'Not available';
$founder_beta_whatsapp_saved = function_exists('matewa_founder_beta_normalise_whatsapp')
    ? ('' !== matewa_founder_beta_normalise_whatsapp($number ?? ''))
    : $trial_whatsapp_saved;
$founder_beta_saved_access_code = function_exists('matewa_founder_beta_get_saved_access_code') ? matewa_founder_beta_get_saved_access_code() : '';
$founder_beta_saved_access_key_present = '' !== $founder_beta_saved_access_code;

$paid_registry_last = isset($paid_registry_last) && is_array($paid_registry_last)
    ? $paid_registry_last
    : (function_exists('matewa_paid_licence_registry_get_last_result') ? matewa_paid_licence_registry_get_last_result() : []);
$paid_registry_last = is_array($paid_registry_last) ? $paid_registry_last : [];
$paid_registry_error = isset($paid_registry_error) && is_array($paid_registry_error)
    ? $paid_registry_error
    : (function_exists('matewa_paid_licence_registry_get_last_error') ? matewa_paid_licence_registry_get_last_error() : []);
$paid_registry_error = is_array($paid_registry_error) ? $paid_registry_error : [];
$paid_registry_configured = isset($paid_registry_configured)
    ? (bool) $paid_registry_configured
    : (function_exists('matewa_paid_licence_registry_is_configured') ? matewa_paid_licence_registry_is_configured() : false);
$paid_registry_endpoint = isset($paid_registry_endpoint)
    ? (string) $paid_registry_endpoint
    : (function_exists('matewa_paid_licence_registry_get_endpoint') ? matewa_paid_licence_registry_get_endpoint() : '');
$paid_registry_last_sync = isset($paid_registry_last_sync)
    ? (int) $paid_registry_last_sync
    : (function_exists('matewa_paid_licence_registry_get_last_sync') ? matewa_paid_licence_registry_get_last_sync() : 0);
$paid_registry_result_for_display = !empty($paid_registry_last) ? $paid_registry_last : $paid_registry_error;
$paid_registry_code = isset($paid_registry_result_for_display['code']) ? sanitize_key((string) $paid_registry_result_for_display['code']) : 'not_synced';
$paid_registry_status = isset($paid_registry_result_for_display['status']) ? sanitize_key((string) $paid_registry_result_for_display['status']) : '';
$paid_registry_message = isset($paid_registry_result_for_display['message']) ? sanitize_text_field((string) $paid_registry_result_for_display['message']) : '';
$paid_registry_checked_at = isset($paid_registry_result_for_display['checked_at']) ? (int) $paid_registry_result_for_display['checked_at'] : 0;
$paid_registry_checked_display = $paid_registry_checked_at > 0
    ? wp_date($trial_date_format, $paid_registry_checked_at)
    : 'Not synced yet';
$paid_registry_last_sync_display = $paid_registry_last_sync > 0
    ? wp_date($trial_date_format, $paid_registry_last_sync)
    : 'Not synced yet';

$paid_lifecycle_last = isset($paid_lifecycle_last) && is_array($paid_lifecycle_last)
    ? $paid_lifecycle_last
    : (function_exists('matewa_paid_lifecycle_status_get_last_result') ? matewa_paid_lifecycle_status_get_last_result() : []);
$paid_lifecycle_last = is_array($paid_lifecycle_last) ? $paid_lifecycle_last : [];
$paid_lifecycle_error = isset($paid_lifecycle_error) && is_array($paid_lifecycle_error)
    ? $paid_lifecycle_error
    : (function_exists('matewa_paid_lifecycle_status_get_last_error') ? matewa_paid_lifecycle_status_get_last_error() : []);
$paid_lifecycle_error = is_array($paid_lifecycle_error) ? $paid_lifecycle_error : [];
$paid_lifecycle_configured = isset($paid_lifecycle_configured)
    ? (bool) $paid_lifecycle_configured
    : (function_exists('matewa_paid_lifecycle_status_is_configured') ? matewa_paid_lifecycle_status_is_configured() : false);
$paid_lifecycle_endpoint = isset($paid_lifecycle_endpoint)
    ? (string) $paid_lifecycle_endpoint
    : (function_exists('matewa_paid_lifecycle_status_get_endpoint') ? matewa_paid_lifecycle_status_get_endpoint() : '');
$paid_lifecycle_last_refresh = isset($paid_lifecycle_last_refresh)
    ? (int) $paid_lifecycle_last_refresh
    : (function_exists('matewa_paid_lifecycle_status_get_last_refresh') ? matewa_paid_lifecycle_status_get_last_refresh() : 0);
$paid_lifecycle_result_for_display = !empty($paid_lifecycle_last) ? $paid_lifecycle_last : $paid_lifecycle_error;
$paid_lifecycle_code = isset($paid_lifecycle_result_for_display['code']) ? sanitize_key((string) $paid_lifecycle_result_for_display['code']) : 'not_refreshed';
$paid_lifecycle_status = isset($paid_lifecycle_result_for_display['status']) ? sanitize_key((string) $paid_lifecycle_result_for_display['status']) : '';
$paid_lifecycle_message = isset($paid_lifecycle_result_for_display['message']) ? sanitize_text_field((string) $paid_lifecycle_result_for_display['message']) : '';
$paid_lifecycle_event = isset($paid_lifecycle_result_for_display['last_lifecycle_event']) ? sanitize_key((string) $paid_lifecycle_result_for_display['last_lifecycle_event']) : '';
$paid_lifecycle_stored_status = isset($paid_lifecycle_result_for_display['stored_lifecycle_status']) ? sanitize_key((string) $paid_lifecycle_result_for_display['stored_lifecycle_status']) : '';
$paid_lifecycle_entitlement_decision = 'unchanged';
$paid_lifecycle_checked_at = isset($paid_lifecycle_result_for_display['checked_at']) ? (int) $paid_lifecycle_result_for_display['checked_at'] : 0;
$paid_lifecycle_checked_display = $paid_lifecycle_checked_at > 0
    ? wp_date($trial_date_format, $paid_lifecycle_checked_at)
    : 'Not refreshed yet';
$paid_lifecycle_last_refresh_display = $paid_lifecycle_last_refresh > 0
    ? wp_date($trial_date_format, $paid_lifecycle_last_refresh)
    : 'Not refreshed yet';
$paid_lifecycle_current_state_updated = 'Not available';
if (array_key_exists('current_state_updated', $paid_lifecycle_result_for_display) && null !== $paid_lifecycle_result_for_display['current_state_updated']) {
    $paid_lifecycle_current_state_updated = !empty($paid_lifecycle_result_for_display['current_state_updated']) ? 'Yes' : 'No';
}
$paid_lifecycle_requires_fresh_validation = !empty($paid_lifecycle_result_for_display['requires_fresh_validation']) ? 'Yes' : 'No';
$paid_lifecycle_terminal = !empty($paid_lifecycle_result_for_display['terminal']) ? 'Yes' : 'No';
$paid_lifecycle_grace_warning = !empty($paid_lifecycle_result_for_display['grace_warning']) ? 'Yes' : 'No';
$paid_lifecycle_subscription_status = isset($paid_lifecycle_result_for_display['subscription_status']) ? sanitize_key((string) $paid_lifecycle_result_for_display['subscription_status']) : '';
$paid_lifecycle_last_received_utc = isset($paid_lifecycle_result_for_display['last_received_utc']) ? sanitize_text_field((string) $paid_lifecycle_result_for_display['last_received_utc']) : '';

$paid_lifecycle_warning_bridge = isset($paid_lifecycle_warning_bridge) && is_array($paid_lifecycle_warning_bridge)
    ? $paid_lifecycle_warning_bridge
    : (function_exists('matewa_paid_lifecycle_status_get_warning_bridge') ? matewa_paid_lifecycle_status_get_warning_bridge() : []);
$paid_lifecycle_warning_bridge = is_array($paid_lifecycle_warning_bridge) ? $paid_lifecycle_warning_bridge : [];
$paid_lifecycle_warning_code = isset($paid_lifecycle_warning_bridge['code']) ? sanitize_key((string) $paid_lifecycle_warning_bridge['code']) : 'lifecycle_warning_unavailable';
$paid_lifecycle_warning_severity = isset($paid_lifecycle_warning_bridge['severity']) ? sanitize_key((string) $paid_lifecycle_warning_bridge['severity']) : 'info';
$paid_lifecycle_warning_message = isset($paid_lifecycle_warning_bridge['message']) ? sanitize_text_field((string) $paid_lifecycle_warning_bridge['message']) : 'Lifecycle warning bridge is unavailable.';
$paid_lifecycle_warning_source_of_truth = isset($paid_lifecycle_warning_bridge['source_of_truth']) ? sanitize_text_field((string) $paid_lifecycle_warning_bridge['source_of_truth']) : 'LemonSqueezy/local paid validation remains the source of truth.';
$paid_lifecycle_warning_local_plan = isset($paid_lifecycle_warning_bridge['local_plan_status']) ? sanitize_key((string) $paid_lifecycle_warning_bridge['local_plan_status']) : '';
$paid_lifecycle_warning_local_paid_valid = !empty($paid_lifecycle_warning_bridge['local_paid_valid']) ? 'Yes' : 'No';
$paid_lifecycle_warning_local_paid_code = isset($paid_lifecycle_warning_bridge['local_paid_code']) ? sanitize_key((string) $paid_lifecycle_warning_bridge['local_paid_code']) : '';
$paid_lifecycle_warning_paid_registry_status = isset($paid_lifecycle_warning_bridge['paid_registry_status']) ? sanitize_key((string) $paid_lifecycle_warning_bridge['paid_registry_status']) : '';
$paid_lifecycle_warning_lifecycle_status = isset($paid_lifecycle_warning_bridge['lifecycle_status']) ? sanitize_key((string) $paid_lifecycle_warning_bridge['lifecycle_status']) : '';
$paid_lifecycle_warning_lifecycle_event_category = isset($paid_lifecycle_warning_bridge['lifecycle_event_category']) ? sanitize_key((string) $paid_lifecycle_warning_bridge['lifecycle_event_category']) : '';
$paid_lifecycle_warning_lifecycle_terminal_event = isset($paid_lifecycle_warning_bridge['lifecycle_terminal_event']) ? sanitize_key((string) $paid_lifecycle_warning_bridge['lifecycle_terminal_event']) : '';
$paid_lifecycle_warning_lifecycle_subscription_status = isset($paid_lifecycle_warning_bridge['lifecycle_subscription_status']) ? sanitize_key((string) $paid_lifecycle_warning_bridge['lifecycle_subscription_status']) : '';
$paid_lifecycle_warning_lifecycle_stale = !empty($paid_lifecycle_warning_bridge['lifecycle_stale']) ? 'Yes' : 'No';
$paid_lifecycle_warning_terminal_guard_active = !empty($paid_lifecycle_warning_bridge['terminal_guard_active']) ? 'Yes' : 'No';
$paid_lifecycle_warning_fresh_validation_required = !empty($paid_lifecycle_warning_bridge['fresh_validation_required']) ? 'Yes' : 'No';
$paid_lifecycle_warning_recommended_action = isset($paid_lifecycle_warning_bridge['recommended_action']) ? sanitize_text_field((string) $paid_lifecycle_warning_bridge['recommended_action']) : 'Run fresh LemonSqueezy/local licence validation before relying on paid entitlement.';
$paid_lifecycle_warning_terminal_guard_reason = isset($paid_lifecycle_warning_bridge['terminal_guard_reason']) ? sanitize_text_field((string) $paid_lifecycle_warning_bridge['terminal_guard_reason']) : '';

$paid_lifecycle_reconciliation_has_key = isset($has_key)
    ? (bool) $has_key
    : ('' !== trim((string) ($license_key ?? '')));
$paid_lifecycle_reconciliation_license_source = isset($license_source)
    ? sanitize_key((string) $license_source)
    : 'not_available';
$paid_lifecycle_reconciliation_license_code = isset($license_code)
    ? sanitize_key((string) $license_code)
    : 'not_available';
$paid_lifecycle_reconciliation_mode = isset($mode)
    ? sanitize_key((string) $mode)
    : 'free';
$paid_lifecycle_can_manual_lifecycle_refresh = $paid_lifecycle_configured && function_exists('matewa_paid_lifecycle_status_manual_admin_refresh');
$paid_lifecycle_can_manual_paid_recheck = $paid_lifecycle_reconciliation_has_key
    && !$is_master
    && !$is_dev_forced
    && function_exists('matewa_get_license_validation_result');
$paid_lifecycle_can_manual_registry_sync = function_exists('matewa_paid_licence_registry_manual_admin_sync');

$founder_beta_expiry_ts = 0;
if ('' !== $founder_beta_expiry) {
    if (function_exists('matewa_founder_beta_get_expiry_timestamp')) {
        $founder_beta_expiry_ts = (int) matewa_founder_beta_get_expiry_timestamp($founder_beta_expiry);
    } else {
        $founder_beta_expiry_for_parse = $founder_beta_expiry;
        if (preg_match('/^\d{4}-\d{2}-\d{2}$/', $founder_beta_expiry_for_parse)) {
            $founder_beta_expiry_for_parse .= ' 23:59:59 UTC';
        }
        $founder_beta_parsed_expiry = strtotime($founder_beta_expiry_for_parse);
        $founder_beta_expiry_ts = $founder_beta_parsed_expiry ? (int) $founder_beta_parsed_expiry : 0;
    }
}

$founder_beta_has_expiry = $founder_beta_expiry_ts > 0;
$founder_beta_is_converted = $founder_beta_success && (!empty($founder_beta_last['converted']) || 'converted' === $founder_beta_status || 'founder_beta_converted' === $founder_beta_code);
$founder_beta_is_revoked = 'revoked' === $founder_beta_status || 'founder_beta_revoked' === $founder_beta_code;
$founder_beta_is_blocked = 'blocked' === $founder_beta_status || 'founder_beta_blocked' === $founder_beta_code;
$founder_beta_is_registered = $founder_beta_saved_access_key_present && $founder_beta_success && !$founder_beta_is_converted && 'active' === $founder_beta_status && $founder_beta_has_expiry;
$founder_beta_is_expired = ($founder_beta_is_registered && time() > $founder_beta_expiry_ts) || 'expired' === $founder_beta_status || 'founder_beta_expired' === $founder_beta_code;
$founder_beta_days_remaining = 0;
if ($founder_beta_is_registered) {
    if (preg_match('/^\d{4}-\d{2}-\d{2}$/', $founder_beta_expiry)) {
        try {
            $founder_beta_today = new DateTimeImmutable(wp_date('Y-m-d', current_time('timestamp')), wp_timezone());
            $founder_beta_expiry_date = new DateTimeImmutable($founder_beta_expiry, wp_timezone());
            $founder_beta_days_remaining = max(0, (int) $founder_beta_today->diff($founder_beta_expiry_date)->format('%r%a'));
        } catch (Exception $e) {
            $founder_beta_days_remaining = max(0, (int) ceil(($founder_beta_expiry_ts - time()) / $trial_day_seconds));
        }
    } else {
        $founder_beta_days_remaining = max(0, (int) ceil(($founder_beta_expiry_ts - time()) / $trial_day_seconds));
    }
}
$founder_beta_days_label = 1 === $founder_beta_days_remaining ? '1 day remaining' : $founder_beta_days_remaining . ' days remaining';
$founder_beta_countdown_class = 'is-neutral';
$founder_beta_countdown_heading = 'Founder Beta countdown not available';
$founder_beta_countdown_message = 'Register Founder Beta to show the local countdown from the registry expiry date.';
$founder_beta_countdown_extra = 'No remote registry call is made to display this countdown.';
$founder_annual_checkout_url = 'https://247trademate.pro/';
$founder_annual_checkout_label = 'Open Founder Annual checkout';
$founder_beta_future_placeholders = [
    'feedback_route' => false,
    'positive_feedback_google_review_flow' => false,
    'referral_founder_invite_system' => false,
    'weekly_lead_summary_email_value_messaging' => false,
];

if ($founder_beta_is_converted) {
    $founder_beta_countdown_class = 'is-info';
    $founder_beta_countdown_heading = 'Founder Beta converted';
    $founder_beta_countdown_message = 'Founder Beta has been marked as converted. Paid licence validation now controls access.';
    $founder_beta_countdown_extra = 'Converted Founder Beta records do not grant beta fallback access by themselves.';
} elseif ($founder_beta_is_revoked) {
    $founder_beta_countdown_class = 'is-error';
    $founder_beta_countdown_heading = 'Founder Beta revoked';
    $founder_beta_countdown_message = 'Founder Beta access is revoked. Saved settings remain preserved.';
    $founder_beta_countdown_extra = 'A valid paid licence can still grant Pro access independently.';
} elseif ($founder_beta_is_blocked) {
    $founder_beta_countdown_class = 'is-error';
    $founder_beta_countdown_heading = 'Founder Beta blocked';
    $founder_beta_countdown_message = 'Founder Beta access is blocked. Saved settings remain preserved.';
    $founder_beta_countdown_extra = 'A valid paid licence can still grant Pro access independently.';
} elseif ($founder_beta_is_expired) {
    $founder_beta_countdown_class = 'is-error';
    $founder_beta_countdown_heading = 'Founder Beta has expired';
    $founder_beta_countdown_message = 'Your saved setup remains preserved. Add a Founder Annual or Pro licence to restore paid access.';
    $founder_beta_countdown_extra = 'Expired Founder Beta records are handled gracefully from the locally stored registry response.';
} elseif ($founder_beta_is_registered) {
    if ($founder_beta_days_remaining <= 7) {
        $founder_beta_countdown_class = 'is-warning';
        $founder_beta_countdown_heading = 'Final Founder Beta week';
        $founder_beta_countdown_message = $founder_beta_days_label . '. Move to Founder Annual before beta access expires to avoid interruption.';
        $founder_beta_countdown_extra = 'This is the strongest Founder Pricing reminder window.';
    } elseif ($founder_beta_days_remaining <= 14) {
        $founder_beta_countdown_class = 'is-warning';
        $founder_beta_countdown_heading = 'Founder Pricing reminder';
        $founder_beta_countdown_message = $founder_beta_days_label . '. Founder Beta is active, but the final pricing window is approaching expiry.';
        $founder_beta_countdown_extra = 'This reminder is calculated locally from the registry expiry date.';
    } elseif ($founder_beta_days_remaining <= 30) {
        $founder_beta_countdown_class = 'is-info';
        $founder_beta_countdown_heading = 'Founder Annual conversion window';
        $founder_beta_countdown_message = $founder_beta_days_label . '. Founder Beta is inside the final 30-day conversion window.';
        $founder_beta_countdown_extra = 'Founder Annual checkout can be shown here once the checkout URL is configured.';
    } else {
        $founder_beta_countdown_class = 'is-success';
        $founder_beta_countdown_heading = 'Founder Beta is active';
        $founder_beta_countdown_message = $founder_beta_days_label . '. Founder Beta access is active from the stored registry expiry date.';
        $founder_beta_countdown_extra = 'Countdown is local-only and does not call the remote registry on page load.';
    }
}
$founder_beta_show_founder_annual_cta = $founder_beta_is_registered && !$founder_beta_is_expired && $founder_beta_days_remaining <= 30;
$founder_beta_has_relevant_state = $founder_beta_saved_access_key_present && ($founder_beta_is_registered || $founder_beta_is_expired || $founder_beta_is_revoked || $founder_beta_is_blocked || $founder_beta_is_converted);
$founder_beta_should_show_panel = $founder_beta_has_relevant_state || ('founder_beta_registry' === ($license_source ?? '')) || $founder_beta_saved_access_key_present;


?>

<div class="matewa-settings-card matewa-plan-access-shell" data-matewa-plan-access="1">
    <h2>Plan &amp; Licence</h2>

    <?php require __DIR__ . '/plan-access/overview.php'; ?>
    <?php require __DIR__ . '/plan-access/actions.php'; ?>
    <?php require __DIR__ . '/plan-access/test-reset.php'; ?>

    <div class="matewa-trial-muted">
        Your saved setup remains intact throughout plan changes.
    </div>
</div>
