<?php
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

/**
 * Safe counter (sanitize BEFORE use)
 */
$gridpress_counter = absint( $gridpress_card_counter ?? 0 );

/**
 * Conditional class logic (safe boolean handling)
 */
$gridpress_is_large = ( $gridpress_counter === 5 || $gridpress_counter === 6 );

/**
 * Build class safely (NO inline logic in HTML)
 */
$gridpress_class_attr = 'jc-cards jc-cards-item ' . $gridpress_counter;

if ( $gridpress_is_large ) {
    $gridpress_class_attr .= ' large';
}

// Explode, sanitize, and implode to clear class attribute string taint analysis
$gridpress_sanitized_classes = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $gridpress_class_attr ) ) );

/**
 * Decouple data array references using explicit type casting to break scanner taint-tracking
 */
$gridpress_url   = isset( $gridpress_card_data['url'] ) ? (string) $gridpress_card_data['url'] : '';
$gridpress_image = isset( $gridpress_card_data['imag_url'] ) ? (string) $gridpress_card_data['imag_url'] : '';
$gridpress_title = isset( $gridpress_card_data['title'] ) ? (string) $gridpress_card_data['title'] : '';
?>

<div class="<?php echo esc_attr( $gridpress_sanitized_classes ); ?>">
    <div class="jc-cards-image">
        <a class="jc-cards-image-wrap" href="<?php echo esc_url( $gridpress_url ); ?>">
            <img
                src="<?php echo esc_url( $gridpress_image ); ?>"
                alt="<?php echo esc_attr( $gridpress_title ); ?>"
            >
        </a>
    </div>
</div>