import frappe
from custom_ui.utils import get_manifest

def get_context(context):
    frappe.throw("Loading custom_ui context...")
    print("Loading custom_ui context with manifest...")
    manifest = get_manifest()
    
    context.template = "custom_ui/custom_ui/page/custom_ui/custom_ui.html"
    print("Manifest:", manifest)
    if manifest:
        js_file = manifest["src/main.js"]["file"]
        context.bundle_path = f"/assets/custom_ui/dist/{js_file}"
    else:
        print("ERROR: Manifest is missing or invalid.")
        frappe.log_error(message="Manifest file is missing or invalid for custom_ui", title="Context Load Failed")
        context.bundle_path = ""