<?php
/**
 * Rutas y URLs públicas de librerías en assets/vendor/ (sin CDN).
 */
declare(strict_types=1);

if (!defined('ANTARA_ROOT')) {
    define('ANTARA_ROOT', dirname(__DIR__));
}

const ANTARA_VENDOR_CROPPER_CSS = 'assets/vendor/cropperjs/1.6.2/cropper.min.css';
const ANTARA_VENDOR_CROPPER_JS = 'assets/vendor/cropperjs/1.6.2/cropper.min.js';
const ANTARA_VENDOR_INTL_TEL_CSS = 'assets/vendor/intl-tel-input/23.0.6/css/intlTelInput.min.css';
const ANTARA_VENDOR_INTL_TEL_JS = 'assets/vendor/intl-tel-input/23.0.6/js/intlTelInput.min.js';
const ANTARA_VENDOR_INTL_TEL_UTILS = 'assets/vendor/intl-tel-input/23.0.6/js/utils.js';

function antara_vendor_asset_version(string $relFromRoot): string
{
    $full = ANTARA_ROOT . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, ltrim($relFromRoot, '/'));
    if (!is_file($full)) {
        return '';
    }
    $mtime = @filemtime($full);

    return $mtime !== false ? (string)$mtime : '';
}

/**
 * URL pública con cache-bust (?v=mtime). $publicBase sin barra final (p. ej. '' o '/antaradata').
 */
function antara_vendor_asset_url(string $relFromRoot, string $publicBase = ''): string
{
    $rel = ltrim(str_replace('\\', '/', $relFromRoot), '/');
    $v = antara_vendor_asset_version($rel);
    $suffix = $v !== '' ? '?v=' . rawurlencode($v) : '';
    $base = rtrim(str_replace('\\', '/', $publicBase), '/');
    if ($base === '') {
        return '/' . $rel . $suffix;
    }

    return $base . '/' . $rel . $suffix;
}
