@php
$videoUrls = [];
$rawVideos = $product->Embedded_videos ?? [];
// If JSON string, decode to PHP array
if (is_string($rawVideos)) {
$trimmed = trim($rawVideos);
if ($trimmed !== '' && (str_starts_with($trimmed, '[') || str_starts_with($trimmed, '{'))) {
$decoded = json_decode($trimmed, true);
if (json_last_error() === JSON_ERROR_NONE) {
$rawVideos = $decoded;
}
}
}
if (is_array($rawVideos)) {
foreach ($rawVideos as $entry) {
if (is_string($entry)) {
$u = trim($entry);
if ($u !== '') { $videoUrls[] = $u; }
} elseif (is_array($entry)) {
// Handle ['url' => '...'] structure or nested arrays
if (isset($entry['url']) && is_string($entry['url'])) {
$u = trim($entry['url']);
if ($u !== '') { $videoUrls[] = $u; }
} else {
foreach ((array)$entry as $v) {
if (is_string($v)) {
$u = trim($v);
if ($u !== '') { $videoUrls[] = $u; }
} elseif (is_array($v) && isset($v['url']) && is_string($v['url'])) {
$u = trim($v['url']);
if ($u !== '') { $videoUrls[] = $u; }
}
}
}
}
}
} elseif (is_string($rawVideos) && $rawVideos !== '') {
// Allow CSV string
$parts = array_map('trim', explode(',', $rawVideos));
foreach ($parts as $u) { if ($u !== '') { $videoUrls[] = $u; } }
}
// De-duplicate
$videoUrls = array_values(array_unique($videoUrls));
$modalId = 'videos-modal-' . $product->id;
// pass raw, non-unique array to modal (cleaning happens in JS)
@endphp
@if(count($videoUrls) > 0)
@endif