<?php
	if(isset($search_result) && !empty($search_result)){
		foreach ($search_result as $key => $value) {
			$title = $value->folder_name;
			$url = base_url().$value->secure_token;
			$target = "";
			if($value->type === "file"){
				$title = $value->file_name;
				$target = 'target="_blank"';
			}


			$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 = $url;
					if(isset($value->has_lock) && $value->has_lock == 1){
						$icon = base_url().'assets/img/icons/file.svg';
					}
				}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{
					$url = base_url()."login?redirect_url=".$value->secure_token;
				}
			}
?>
	        <a href="<?php echo $url; ?>" <?php echo $target; ?> class="list-group-item list-group-item-action border-0">
	            <div class="d-flex align-items-center gap-3 <?php echo $lock; ?>">
	                <!-- <i class="fa fa-file fs-2"></i> -->
	                <img style="height: 40px;" src="<?php echo $icon; ?>" />
	                <div>
	                    <div class="fw-bold fs-14"><?php echo $title; ?></div>
	                    <?php
	                    	$folder_names = array_map(function($item) {
							    return $item->folder_name;
							}, $value->path_array);

							$folder_path = implode(' / ', $folder_names);
	                    ?>
	                    <div class="text-muted fs-14" title="<?php echo $value->product_data->title.' / '.$folder_path; ?>">in <?php echo $value->product_data->title.' / '.mb_strimwidth($folder_path, 0, 100, "..."); ?></div>
	                </div>
	            </div>
	        </a>
<?php
		}
	}
?>
