<?php

/**
 * Mix
 * @category Functions
 * @author Krik
 */

use Illuminate\Support\HtmlString;
use Illuminate\Support\Str;

function mix($path)
{
	static $manifest;

	if (!$manifest) {
		if (!file_exists($manifestPath = get_template_directory() . '/static/mix-manifest.json')) {
			pc('Mix manifest is missing');
		}

		$manifest = json_decode(file_get_contents($manifestPath), true);
	}

	if (!Str::startsWith($path, '/')) {
		$path = "/{$path}";
	}

	if (!array_key_exists($path, $manifest)) {
		pc('Mix resource is missing');
	}

	return new HtmlString(get_template_directory_uri() . '/static' . $manifest[$path]);
}
