<?php
/**
 * Carte plugin — catalogue Découvrir.
 *
 * @package Volade\SDK
 * @license GPL-2.0-or-later
 * @var array $plugin
 */

defined( 'ABSPATH' ) || exit;

$slug       = $plugin['slug'] ?? '';
$name       = $plugin['name'] ?? '';
$icon       = $plugin['icon'] ?? '🔌';
$is_live    = ! empty( $plugin['is_live'] );
$installed  = ! empty( $plugin['is_installed'] );
$tier       = $plugin['tier'] ?? 'free';
$search_blob = strtolower( $name . ' ' . ( $plugin['category_label'] ?? '' ) . ' ' . ( $plugin['blurb'] ?? '' ) );
?>
<article class="volade-discover-card-v2 <?php echo $is_live ? 'is-live' : 'is-planned'; ?> <?php echo $installed ? 'is-installed' : ''; ?>"
         data-slug="<?php echo esc_attr( $slug ); ?>"
         data-live="<?php echo $is_live ? '1' : '0'; ?>"
         data-installed="<?php echo $installed ? '1' : '0'; ?>"
         data-category="<?php echo esc_attr( $plugin['category'] ?? '' ); ?>"
         data-search="<?php echo esc_attr( $search_blob ); ?>">
    <div class="volade-discover-card-v2-glow" aria-hidden="true"></div>
    <div class="volade-discover-card-v2-top">
        <div class="volade-discover-card-v2-icon"><?php echo esc_html( $icon ); ?></div>
        <div class="volade-discover-card-v2-badges">
            <?php if ( $installed ) : ?>
                <span class="volade-discover-badge volade-discover-badge--installed"><?php esc_html_e( 'Actif ici', 'php-compatibility-checker-by-volade' ); ?></span>
            <?php endif; ?>
            <?php if ( $is_live ) : ?>
                <span class="volade-discover-badge volade-discover-badge--live"><?php esc_html_e( 'Disponible', 'php-compatibility-checker-by-volade' ); ?></span>
            <?php elseif ( ! empty( $plugin['status'] ) && in_array( $plugin['status'], array( 'development', 'planned' ), true ) ) : ?>
                <span class="volade-discover-badge volade-discover-badge--planned"><?php esc_html_e( 'En développement', 'php-compatibility-checker-by-volade' ); ?></span>
            <?php else : ?>
                <span class="volade-discover-badge volade-discover-badge--planned"><?php esc_html_e( 'Bientôt', 'php-compatibility-checker-by-volade' ); ?></span>
            <?php endif; ?>
        </div>
    </div>
    <h3 class="volade-discover-card-v2-title"><?php echo esc_html( $name ); ?></h3>
    <p class="volade-discover-card-v2-blurb"><?php echo esc_html( $plugin['blurb'] ?? '' ); ?></p>
    <div class="volade-discover-card-v2-meta">
        <span class="volade-discover-tag"><?php echo esc_html( $plugin['category_label'] ?? '' ); ?></span>
        <span class="volade-discover-tier volade-discover-tier--<?php echo esc_attr( $tier ); ?>">
            <?php echo esc_html( $plugin['tier_label'] ?? '' ); ?>
        </span>
    </div>
    <div class="volade-discover-card-v2-actions">
        <?php if ( $installed && ! empty( $plugin['settings_url'] ) ) : ?>
            <a href="<?php echo esc_url( $plugin['settings_url'] ); ?>" class="volade-btn volade-btn-sm volade-btn-primary">
                <?php esc_html_e( 'Ouvrir', 'php-compatibility-checker-by-volade' ); ?>
            </a>
        <?php elseif ( $is_live ) : ?>
            <a href="<?php echo esc_url( $plugin['catalog_url'] ?? ( function_exists( 'volade_extension_catalog_url' ) ? volade_extension_catalog_url() : 'https://volade.com/fr/cms/wordpress/extensions' ) ); ?>" class="volade-btn volade-btn-sm volade-btn-secondary" target="_blank" rel="noopener">
                <?php esc_html_e( 'En savoir plus', 'php-compatibility-checker-by-volade' ); ?>
            </a>
        <?php else : ?>
            <span class="volade-discover-soon"><?php esc_html_e( 'En développement', 'php-compatibility-checker-by-volade' ); ?></span>
        <?php endif; ?>
    </div>
</article>
