<?php
declare(strict_types=1);

function nestor_line_clamp(string $text, int $max = 88): string
{
    $t = trim(preg_replace('/\s+/u', ' ', strip_tags($text)));
    if (mb_strlen($t) <= $max) {
        return $t;
    }
    return mb_substr($t, 0, $max - 1) . '…';
}

/**
 * Картка проєкту: один прозорий PNG-мокап, без CSS-пристроїв.
 *
 * @param array<string, mixed> $p
 */
function nestor_project_mockup_card(array $p, int $idx): void
{
    $href = nestor_url('projects/' . $p['slug'] . '/');
    $delay = $idx * 0.06;
    $title = (string)$p['title'];
    $mockupSrc = nestor_project_mockup_composite_src($p);

    echo '<article class="case-project-card reveal" style="--stagger:' . e((string)$delay) . 's">';
    echo '<div class="case-project-card__head">';
    echo '<span class="case-project-card__label">' . e((string)$p['type']) . '</span>';
    echo '<h2 class="case-project-card__title">' . e($title) . '</h2>';
    echo '<p class="case-project-card__desc">' . e(nestor_line_clamp((string)$p['description'], 140)) . '</p>';
    echo '</div>';

    echo '<a class="case-project-card__media" href="' . e($href) . '" aria-label="Переглянути кейс ' . e($title) . '">';
    echo '<img src="' . e($mockupSrc) . '" alt="' . e($title . ' — превʼю сайту') . '" width="1600" height="900" loading="lazy" decoding="async">';
    echo '</a>';

    echo '<div class="case-project-card__foot">';
    echo '<a class="btn btn--ghost btn--sm" href="' . e($href) . '">Переглянути</a>';
    echo '</div>';
    echo '</article>';
}
