<?php
/**
 * 247ChatMate — Plan Access Actions Partial
 *
 * Phase 5-A-21P
 * Checkpoint: PLANLICENCECUSTOMERVIEW5A21P
 *
 * Purpose:
 * - Keep the customer-facing plan action area simple.
 * - Preserve existing trial and licence check handlers without exposing raw diagnostics.
 *
 * Does not:
 * - Validate licences directly, change entitlement decisions, alter trial rules or save settings.
 * - Change payment provider, Founder Beta, registry, widget, chip or lead-routing logic.
 */

defined('ABSPATH') || exit;
?>

<div
    id="matewa-plan-actions-card"
    class="matewa-plan-actions-card"
    data-matewa-license-check-card="1"
>
    <div class="matewa-plan-actions-card__copy">
        <h3>Licence Key &amp; refresh plan</h3>
        <p>Edit your key or refresh your plan.</p>
    </div>

    <div class="matewa-plan-actions-card__body">
        <div class="matewa-plan-action-row matewa-plan-action-row--tile">
            <div>
                <strong>Licence Key</strong>
                <span><?php echo $has_key ? 'Key saved.' : 'Add key in Setup.'; ?></span>
            </div>
            <a class="button button-secondary" href="#matewa_license_key"><?php echo $has_key ? 'View key field' : 'Add key'; ?></a>
        </div>

        <div class="matewa-plan-action-row matewa-plan-action-row--tile">
            <div>
                <strong>Refresh plan</strong>
                <span>Recheck saved access.</span>
            </div>

            <?php if (!$has_key) : ?>
                <button type="button" class="button button-secondary" disabled>Refresh plan</button>
            <?php elseif ($is_master) : ?>
                <button type="button" class="button button-secondary" disabled>Refresh plan</button>
            <?php elseif ($is_dev_forced) : ?>
                <button type="button" class="button button-secondary" disabled>Refresh plan</button>
            <?php else : ?>
                <form method="post" action="<?php echo esc_url(admin_url('admin.php?page=247chatmate')); ?>" data-matewa-license-check-form="1">
                    <?php wp_nonce_field('matewa_check_license_nonce', 'matewa_check_license_nonce'); ?>
                    <input type="hidden" name="matewa_check_license_action" value="1" />
                    <button type="submit" class="button button-secondary">Refresh plan</button>
                </form>
            <?php endif; ?>
        </div>
    </div>
</div>
