{! #include "../ui-blob.h" !}

{!
	int ls_item(const struct object_id *oid, struct strbuf *base, const char *pathname, unsigned mode, void *cbdata) {
		tree_listing_item(oid, base, pathname, mode, true);  /* from tree_common.html */
		return 0;
	}
!}

{% block cgit_print_summary_impl %}
{! page_start(); !}
{! repo_header(); !}
		<main class="max-w-[1280px] mx-auto py-4">{# Main content #}
{! repo_description_panel(); !}
{! repo_summary_bar(); !}
			<div class="grid grid-cols-[auto_1fr_auto_auto] border border-gray-300 rounded-md mb-4">
				{# Latest commit panel (specify rounded-t-md so background does not cover border) #}
				{!
					char *hex = ctx.qry.oid;
					if (!hex) { hex = ctx.qry.head; }
					
					struct object_id oid;
					if (repo_get_oid(the_repository, hex, &oid)) {
						die("Bad object id");
					}
					struct commit *commit = lookup_commit_reference(the_repository, &oid);
					if (!commit) {
						die("Bad commit reference");
					}
					struct commitinfo *info = cgit_parse_commit(commit);
				!}
				<div class="col-span-4 rounded-t-md bg-gray-50 px-3 py-2 flex gap-x-1">
					<img src="{! gravatar_url(info->author_email); !}?s=24">
					<span class="font-semibold">{{ info->author }}</span>
					<a href="{! cgit_shared_reporevlink_url("commit", ctx.qry.head, oid_to_hex(&commit->object.oid), ctx.qry.vpath); !}" class="ml-2 text-gray-500 hover:text-blue-600 hover:underline">{{ info->subject }}</a>
					<div class="flex-1"></div>
					<span class="text-gray-500">
						<a href="{! cgit_shared_reporevlink_url("commit", ctx.qry.head, oid_to_hex(&commit->object.oid), ctx.qry.vpath); !}" class="font-mono hover:text-blue-600 hover:underline">
							{! short_commit_id(oid_to_hex(&commit->object.oid)); !}
						</a>
						&middot;
						{! cgit_print_age(info->committer_date, info->committer_tz, TM_WEEK * 2); !} ago
					</span>
				</div>
				{! cgit_free_commitinfo(info); !}
				{# Files #}
				{!
					const struct object_id *tree_oid = get_commit_tree_oid(commit);
					struct tree *tree = parse_tree_indirect(tree_oid);
					struct pathspec paths = {
						.nr = 0
					};
					read_tree(the_repository, tree, &paths, ls_item, NULL);
				!}
			</div>
			{% if ctx.repo->readme.nr > 0 %}
			{!
				char *filename = ctx.repo->readme.items[0].string;
				char *ref = ctx.repo->readme.items[0].util;
			!}
			<div class="flex flex-col border border-gray-300 rounded-md">
				{# Readme panel #}
				<div class="rounded-t-md bg-gray-50 px-3 py-2 flex gap-x-1 items-center">
					{# Heroicons micro book-open #}
					<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="currentColor" class="size-4"><path d="M7.25 3.688a8.035 8.035 0 0 0-4.872-.523A.48.48 0 0 0 2 3.64v7.994c0 .345.342.588.679.512a6.02 6.02 0 0 1 4.571.81V3.688ZM8.75 12.956a6.02 6.02 0 0 1 4.571-.81c.337.075.679-.167.679-.512V3.64a.48.48 0 0 0-.378-.475 8.034 8.034 0 0 0-4.872.523v9.268Z" /></svg>
					<span class="font-semibold text-sm">{{ filename }}</span>
				</div>
				{# Readme content #}
				<div class="rendered-file p-7 border-t border-gray-300">
					{!
						cgit_open_filter(ctx.repo->about_filter, filename);
						if (ref) {
							cgit_print_file(filename, ref, 1);
						} else {
							html_include(filename);
						}
						cgit_close_filter(ctx.repo->about_filter);
					!}
				</div>
			</div>
			{% endif %}
		</main>
{! page_end(); !}
{% endblock %}

{% page cgit_print_summary %}
{! cgit_print_summary_impl(); !}
{% endpage %}