<?php
global $wpdb, $post, $wp_query, $opt_themes;  
?>

	<!-- moddroid -->
<div id="accordion-versions" class="accordion mb-3">
	  
	<?php 
	/* $downloads_link = get_post_meta(get_the_ID(), 'group_downloads_links', true);
	if (empty($downloads_link)) {
		$downloads_link = get_post_meta(get_the_ID(), 'repeatable_fields', true);
	} */
	$downloads_link = get_post_meta(get_the_ID(), 'repeatable_fields', true);
	if (!empty($downloads_link) && is_array($downloads_link)) {
	$i = 1;
	foreach ($downloads_link as $key => $dw) { 
	$file_link = !empty($dw['url']) ? $dw['url'] : (!empty($dw['links']) ? $dw['links'] : '');
	$file_name = !empty($dw['name']) ? $dw['name'] : (!empty($dw['title']) ? $dw['title'] : 'Download File');
	$file_size = !empty($dw['sizes']) ? $dw['sizes'] : (!empty($dw['sizes1']) ? $dw['sizes1'] : (!empty($dw['size']) ? $dw['size'] : ''));
	$file_type = !empty($dw['tipes']) ? $dw['tipes'] : (!empty($dw['tipe']) ? $dw['tipe'] : '');
	$file_note = !empty($dw['notes']) ? $dw['notes'] : '';

	// Skip if no valid link
	if (empty($file_link)) continue;
	?> 
	<!-- downloadlink <?php echo $i; ?> -->
	<div class="border rounded mb-3">
	<div class="h6 font-weight-semibold rounded text-white bg-primary d-flex align-items-center py-2 px-3 mb-0 collapsed toggler" data-toggle="collapse" href="#dw_<?php echo $i; ?>"><?php echo esc_html($file_name); ?></div>
	<div id="dw_<?php echo $i; ?>" class="p-3 collapse" data-parent="#accordion-versions">
	
	<?php if($file_note){?>
	<div class="small bg-light p-2 mb-3">
	<?php echo wp_kses_post($file_note); ?>
	</div>
	<?php } ?>
	
	<a class="btn btn-light btn-sm btn-block text-left d-flex align-items-center px-3" style="min-height: 3.25rem;" href="<?php echo esc_url(get_permalink() . '/file/?link=' . ($key + 1)); ?>" target="_self">
	<svg class="svg-5 svg-primary mr-2" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512"><path d="M528 288h-92.1l46.1-46.1c30.1-30.1 8.8-81.9-33.9-81.9h-64V48c0-26.5-21.5-48-48-48h-96c-26.5 0-48 21.5-48 48v112h-64c-42.6 0-64.2 51.7-33.9 81.9l46.1 46.1H48c-26.5 0-48 21.5-48 48v128c0 26.5 21.5 48 48 48h480c26.5 0 48-21.5 48-48V336c0-26.5-21.5-48-48-48zm-400-80h112V48h96v160h112L288 368 128 208zm400 256H48V336h140.1l65.9 65.9c18.8 18.8 49.1 18.7 67.9 0l65.9-65.9H528v128zm-88-64c0-13.3 10.7-24 24-24s24 10.7 24 24-10.7 24-24 24-24-10.7-24-24z"></path></svg>
	<span class="d-block">
	<span class="text-uppercase d-block"><?php echo esc_html(!empty($opt_themes['exthemes_Download']) ? $opt_themes['exthemes_Download'] : 'Download'); ?></span>
	<span class="text-muted d-block"><?php if ($file_type) echo ' ' . esc_html($file_type); ?></span>
	</span>
	<span class="text-muted d-block ml-auto"><?php if ($file_size) echo ' (' . esc_html($file_size) . ')'; ?></span>
	</a>
	</div> 
	</div> 
	<?php $i++; } }  else {
		// Optional: Show a message if no downloads exist
		echo '<p class="text-muted">No download links available.</p>';
	} ?>
	   
	   
	</div>