<?php
	//echo "<pre>";print_r($data);echo "</pre>";
	if(isset($data) && !empty($data)){

		foreach ($data as $key => $value) {


			$product_id = "";
			$parent = "";
			$box_click = "";
			$link = "javascript:;";
			$redirect_url = '';
			$folder_id = 0;
			$new_tab = '';

			if($value->type == "product"){
				$product_id = $value->id;
				$parent_id = 0;
				$box_click = "product_click";
				$link = $redirect_url = $value->slug;
			}else if($value->type == "folder"){
				$product_id = $value->product_id;
				$parent_id = $value->id;
				$box_click = "folder_click";
				$link = $redirect_url = $value->secure_token;
				$folder_id = $value->id;
			}else if($value->type == "file"){
				$product_id = $value->product_id;
				$parent_id = $value->id;
				$box_click = "file_click";
				$folder_id = $value->id;
				$link = $redirect_url = $value->secure_token;
				$new_tab = 'target="_blank"';
				$value->folder_name = $value->file_name;
			}

			$icon = base_url().'assets/img/icons/folder.svg';
			if($value->type == 'file'){
				$fileExtension = pathinfo($value->folder_name, PATHINFO_EXTENSION);
				$icon = base_url().'assets/img/icons/file.svg';

				if(strtolower($fileExtension) == 'pdf'){
					$icon = base_url().'assets/img/icons/pdf.jpg';
				}else if(in_array(strtolower($fileExtension), ['jpg', 'jpeg', 'png', 'gif'])){
					$icon = base_url().$link;
				}else{
					$icon = base_url().'assets/img/icons/file.svg';
				}
			}

			$lock = "";
			if(isset($value->has_lock) && $value->has_lock == 1){
				$lock = 'lock';
				if(isset($user_data) && !empty($user_data)){
					$lock = '';
				}else{
					$link = "login?redirect_url=".$redirect_url;
				}
			}

			$count_object = array();

			foreach ($count_result as $key1 => $value1) {
				if($value1->folder_id == $value->id){
					$count_object = $value1;
					
				}
			}

			$countText = "";

			if(isset($count_object->size_only) && $count_object->size_only != 0){
				$countText = $count_object->size;
			}

			$favorites_class = '';
			$favorites_action_class = 'add_favorites';
			$favorites_id = '';

			if(isset($value->favorites_id) && $value->favorites_id != ""){
				$favorites_class = 'favorite';
				$favorites_action_class = 'remove_favorites';
				$favorites_id = $value->favorites_id;
			}
				
?>

			<div class="col-6 col-sm-4 col-md-3">
			    <div class="applications__box <?php echo $lock; ?> <?php echo $favorites_class; ?>">
			        <a href="<?php echo base_url().$link; ?>" <?php echo $new_tab; ?> class="<?php echo $box_click; ?>" data-product-id="<?php echo $product_id; ?>" data-parent-id="<?php echo $parent_id; ?>">
			            <div class="applications__imgBox">
			                <img src="<?php echo $icon; ?>" alt="">
			            </div>
			            <div class="applications__text">
			                <h3 title="<?php echo $value->folder_name; ?>"><span><?php echo $value->folder_name; ?></span></h3>
			            </div>
			        </a>
			        <div class="favoritesBtn <?php echo $favorites_action_class; ?>" data-favorites-id="<?php echo $favorites_id; ?>" data-product-id="<?php echo $product_id; ?>" data-folder-id="<?php echo $folder_id; ?>"></div>

			        <!-- Download icon -->
			        <?php
			        	if($value->type != "product" && $lock === ""){
			        ?>
					        <div class="downloadBtn" data-token="<?php echo $value->secure_token; ?>" title="Download">
					            <!-- <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
					                <path d="M12 2a10 10 0 0 0-10 10 10 10 0 0 0 10 10 10 10 0 0 0 10-10 10 10 0 0 0-10-10zm0 18.5a8.5 8.5 0 1 1 8.5-8.5 8.5 8.5 0 0 1-8.5 8.5zm0-14a1 1 0 0 0-.707.293l-4 4a1 1 0 0 0 1.414 1.414L11 9.414V16a1 1 0 0 0 2 0V9.414l1.293 1.293a1 1 0 0 0 1.414-1.414l-4-4A1 1 0 0 0 12 6.5z"/>
					            </svg> -->

					            <svg xmlns="http://www.w3.org/2000/svg" width="16px" viewBox="0 0 24 24"><path d="M11,4H13V16L18.5,10.5L19.92,11.92L12,19.84L4.08,11.92L5.5,10.5L11,16V4Z"></path></svg>
					        </div>

					        <div class="checkboxBtn" title="Download">
					        	<input type="checkbox" class="form-check-input folder-checkbox" name="folder_checkbox[]" value="<?php echo $value->secure_token; ?>" />
					        </div>
					<?php
						}
					?>

					<div class="displaySize <?php echo $value->type == "product" ? 'displayProductSize' : ''; ?>" title="Size"><?php echo $value->size; ?></div>
			    </div>
			</div>
<?php
		}
	}else{
?>
		<p class="text-center">No items to display.</p>
<?php
	}
?>