<?php
/**
 * Preview Publisher Card (read-only)
 *
 * Used on the pre-connection onboarding screens (Dashboard + Network)
 * to show real verified publishers BEFORE the user connects. No actions:
 * this is a look-but-do-not-touch preview that raises time-to-value.
 *
 * Expected in scope:
 * - $consolety_pub (array) one publisher from the /network/showcase endpoint
 *
 * @package Consolety
 */

if (!defined('ABSPATH')) {
    exit;
}

if (empty($consolety_pub) || !is_array($consolety_pub)) {
    return;
}

$consolety_pub_domain   = $consolety_pub['domain'] ?? '';
$consolety_pub_desc      = $consolety_pub['description'] ?? '';
$consolety_pub_lang      = strtoupper((string) ($consolety_pub['language'] ?? ''));
$consolety_pub_clicks    = (int) ($consolety_pub['monthly_clicks'] ?? 0);
$consolety_pub_impr      = (int) ($consolety_pub['monthly_impressions'] ?? 0);
$consolety_pub_cat       = $consolety_pub['category']['name'] ?? '';
$consolety_pub_sub       = $consolety_pub['subcategory']['name'] ?? '';
$consolety_pub_is_new    = !empty($consolety_pub['is_new_partner']);
$consolety_pub_reqs      = $consolety_pub['requirements'] ?? [];
$consolety_pub_minwords  = (int) ($consolety_pub_reqs['min_words'] ?? 0);
$consolety_pub_maxlinks  = (int) ($consolety_pub_reqs['max_dofollow_links'] ?? 0);
?>
<div class="vp-preview-card">
    <div class="vp-preview-card-top">
        <span class="vp-preview-domain"><?php echo esc_html($consolety_pub_domain); ?></span>
        <?php if ($consolety_pub_is_new): ?>
            <span class="vp-preview-badge vp-preview-badge-new"><?php esc_html_e('New', 'consolety'); ?></span>
        <?php endif; ?>
    </div>

    <?php if ($consolety_pub_cat || $consolety_pub_lang): ?>
    <div class="vp-preview-meta">
        <?php if ($consolety_pub_cat): ?>
            <span class="vp-preview-chip">
                <span class="dashicons dashicons-category"></span>
                <?php echo esc_html($consolety_pub_cat); ?><?php echo $consolety_pub_sub ? ' / ' . esc_html($consolety_pub_sub) : ''; ?>
            </span>
        <?php endif; ?>
        <?php if ($consolety_pub_lang): ?>
            <span class="vp-preview-chip">
                <span class="dashicons dashicons-translation"></span>
                <?php echo esc_html($consolety_pub_lang); ?>
            </span>
        <?php endif; ?>
    </div>
    <?php endif; ?>

    <?php if ($consolety_pub_desc): ?>
        <p class="vp-preview-bio"><?php echo esc_html($consolety_pub_desc); ?></p>
    <?php endif; ?>

    <div class="vp-preview-stats">
        <div class="vp-preview-stat">
            <span class="vp-preview-stat-value"><?php echo esc_html(number_format_i18n($consolety_pub_clicks)); ?></span>
            <span class="vp-preview-stat-label"><?php esc_html_e('Clicks / mo', 'consolety'); ?></span>
        </div>
        <div class="vp-preview-stat">
            <span class="vp-preview-stat-value"><?php echo esc_html(number_format_i18n($consolety_pub_impr)); ?></span>
            <span class="vp-preview-stat-label"><?php esc_html_e('Impressions / mo', 'consolety'); ?></span>
        </div>
    </div>

    <?php if ($consolety_pub_minwords || $consolety_pub_maxlinks): ?>
    <div class="vp-preview-reqs">
        <?php if ($consolety_pub_minwords): ?>
            <span class="vp-preview-req-tag"><?php
                /* translators: %s: minimum word count */
                printf(esc_html__('%s+ words', 'consolety'), esc_html(number_format_i18n($consolety_pub_minwords))); ?></span>
        <?php endif; ?>
        <?php if ($consolety_pub_maxlinks): ?>
            <span class="vp-preview-req-tag"><?php
                /* translators: %d: maximum number of dofollow links allowed */
                printf(esc_html(_n('%d link', '%d links', $consolety_pub_maxlinks, 'consolety')), $consolety_pub_maxlinks); ?></span>
        <?php endif; ?>
    </div>
    <?php endif; ?>
</div>
