<?php

function fetchTemplates_details($institution_id, $conn_rjllearning)
{
    $sql = "SELECT id, template_name, description, preview_image, path 
            FROM template_info 
            WHERE institution_id = ? OR institution_id IS NULL";

    $stmt = $conn_rjllearning->prepare($sql);
    $stmt->execute([$institution_id]);
    $result_total = $stmt->fetchAll();

    $templates = [];

    foreach ($result_total as $row) {
        $templates[] = [
            'template_id' => $row['id'],
            'preview' => $row['path'] . '/' . $row['preview_image'], // Combine path with image
            'template_name' => $row['template_name'],
            'template_description' => $row['description']
        ];
    }

    return $templates;
}
