<?php
/**
 * 247ChatMate — Plan Access Overview Partial
 *
 * Phase 5-A-21P
 * Checkpoint: PLANLICENCECUSTOMERVIEW5A21P
 *
 * Purpose:
 * - Keep the public admin Plan & Licence view customer-safe and calm.
 * - Show only the plan, countdown/action and practical inclusions.
 *
 * Does not:
 * - Validate licences, start trials, call registries, save settings or change entitlement decisions.
 * - Change widget, chip, WhatsApp handoff, phone selector or lead routing behaviour.
 */

defined('ABSPATH') || exit;

$matewa_is_founder_beta_plan = ('founder_beta_registry' === ($license_source ?? '')) || !empty($founder_beta_is_registered);
$matewa_pro_like_access      = in_array($mode, ['trial_active', 'pro', 'master'], true) || $matewa_is_founder_beta_plan;

$matewa_plan_title       = 'Free plan';
$matewa_plan_message     = 'Start your trial when you are ready. Your saved settings stay safe.';
$matewa_next_step        = 'Start trial or add a licence key.';
$matewa_plan_tone        = 'is-free';
$matewa_countdown_label  = $trial_days . '-day trial available';
$matewa_countdown_detail = 'Your countdown starts only when you activate the trial.';
$matewa_primary_action   = 'Open setup to add a key';
$matewa_primary_href     = '#matewa_license_key';

if ($matewa_is_founder_beta_plan) {
    $matewa_plan_title       = 'Founder Beta is active';
    $matewa_plan_message     = 'Founder Beta is giving this site Pro access while the beta window remains active.';
    $matewa_next_step        = $founder_beta_is_registered ? 'Keep building and convert before expiry.' : 'No action needed right now.';
    $matewa_plan_tone        = 'is-pro';
    $matewa_countdown_label  = $founder_beta_is_registered ? $founder_beta_days_label : 'Active';
    $matewa_countdown_detail = $founder_beta_is_registered ? 'Founder Beta expiry: ' . $founder_beta_expiry_display : 'Founder Beta status is active.';
    $matewa_primary_action   = '';
    $matewa_primary_href     = '#matewa-plan-actions-card';
} elseif ('pro' === $mode) {
    $matewa_plan_title       = 'Pro is active';
    $matewa_plan_message     = 'Your saved licence has moved this site into Pro. Your lead tools and widget settings remain in place.';
    $matewa_next_step        = 'No action needed.';
    $matewa_plan_tone        = 'is-pro';
    $matewa_countdown_label  = 'Active';
    $matewa_countdown_detail = 'No trial countdown needed while Pro is active.';
    $matewa_primary_action   = '';
    $matewa_primary_href     = '#matewa-plan-actions-card';
} elseif ('master' === $mode) {
    $matewa_plan_title       = 'Master access is active';
    $matewa_plan_message     = 'Master access is enabled on this site.';
    $matewa_next_step        = 'No licence check needed.';
    $matewa_plan_tone        = 'is-master';
    $matewa_countdown_label  = 'Active';
    $matewa_countdown_detail = 'Master access does not use a customer countdown.';
    $matewa_primary_action   = 'Open setup';
    $matewa_primary_href     = '#matewa-core-settings-section';
} elseif ('trial_active' === $mode) {
    $matewa_plan_title       = 'Trial is active';
    $matewa_plan_message     = $trial_remaining_label . '. Add a licence before the trial ends to keep Pro active.';
    $matewa_next_step        = 'Add a licence before expiry.';
    $matewa_plan_tone        = 'is-trial';
    $matewa_countdown_label  = $trial_remaining_label;
    $matewa_countdown_detail = 'Trial ends: ' . $trial_end_display;
    $matewa_primary_action   = 'Open setup to add a key';
    $matewa_primary_href     = '#matewa_license_key';
} elseif ('trial_expired' === $mode) {
    $matewa_plan_title       = 'Trial has expired';
    $matewa_plan_message     = 'Your saved setup is preserved. Add a valid licence to reactivate Pro.';
    $matewa_next_step        = 'Add a valid licence key.';
    $matewa_plan_tone        = 'is-expired';
    $matewa_countdown_label  = 'Expired';
    $matewa_countdown_detail = 'Your saved settings are still preserved.';
    $matewa_primary_action   = 'Open setup to add a key';
    $matewa_primary_href     = '#matewa_license_key';
}

$matewa_feature_status = $matewa_pro_like_access ? 'Included' : 'Pro';
$matewa_key_status     = $has_key ? 'Key saved' : 'No key saved';
?>

<div class="matewa-plan-overview matewa-plan-overview--customer <?php echo esc_attr($matewa_plan_tone); ?>" aria-label="Plan and licence overview">
    <div class="matewa-plan-overview__copy">
        <span class="matewa-status-badge <?php echo esc_attr($status_badge_class); ?>">
            <?php echo esc_html($status_badge_text); ?>
        </span>
        <h3><?php echo esc_html($matewa_plan_title); ?></h3>
        <p><?php echo esc_html($matewa_plan_message); ?></p>
    </div>
</div>

<div class="matewa-plan-feature-grid" aria-label="What your plan includes">
    <div class="matewa-plan-feature-card">
        <span class="dashicons dashicons-format-chat" aria-hidden="true"></span>
        <strong>Website widget</strong>
        <small>Visitors can start the WhatsApp enquiry flow.</small>
    </div>

    <div class="matewa-plan-feature-card">
        <span class="dashicons dashicons-email-alt" aria-hidden="true"></span>
        <strong>Lead emails</strong>
        <small><?php echo esc_html($matewa_feature_status); ?> for lead capture and follow-up.</small>
    </div>

    <div class="matewa-plan-feature-card">
        <span class="dashicons dashicons-chart-line" aria-hidden="true"></span>
        <strong>Weekly summary</strong>
        <small><?php echo esc_html($matewa_feature_status); ?> to show value without logging in.</small>
    </div>

    <div class="matewa-plan-feature-card">
        <span class="dashicons dashicons-admin-network" aria-hidden="true"></span>
        <strong>Settings preserved</strong>
        <small>Your setup stays in place across plan changes.</small>
    </div>
</div>

<div class="matewa-plan-next-step" aria-label="Recommended next step">
    <div>
        <span>Next step</span>
        <strong><?php echo esc_html($matewa_next_step); ?></strong>
        <small><?php echo esc_html($matewa_key_status); ?></small>
    </div>
    <?php if ('' !== $matewa_primary_action) : ?>
        <a class="button button-secondary" href="<?php echo esc_url($matewa_primary_href); ?>">
            <?php echo esc_html($matewa_primary_action); ?>
        </a>
    <?php endif; ?>
</div>
