<?php
/**
 * Template utility helper functions.
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Get all bundled templates.
 *
 * @return array List of bundled templates with metadata.
 */
function hundred_prints_get_bundled_templates() {
	$manifest_file = HUNDRED_PRINTS_PATH . 'templates/meta/index.json';
	if ( ! file_exists( $manifest_file ) ) {
		return [];
	}

	$json = file_get_contents( $manifest_file );
	$data = json_decode( $json, true );

	if ( ! is_array( $data ) ) {
		return [];
	}

	return $data;
}

/**
 * Get a specific bundled template by ID.
 *
 * @param string $id Template ID/slug.
 * @return array|false The template JSON contents, or false if not found.
 */
function hundred_prints_get_bundled_template_data( $id ) {
	$bundled_ids = [
		'admission-ticket',
		'course-completion',
		'event-pass',
		'membership-card',
		'participant-certificate'
	];

	if ( ! in_array( $id, $bundled_ids, true ) ) {
		return false;
	}

	$file_path = HUNDRED_PRINTS_PATH . 'templates/bundled/' . $id . '.json';

	if ( ! file_exists( $file_path ) ) {
		return false;
	}

	$json = file_get_contents( $file_path );
	return json_decode( $json, true ) ?: false;
}
