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

{% block ls_item_impl(const struct object_id *oid, struct strbuf *base, const char *pathname, unsigned mode, void *cbdata) %}
				{!
					unsigned long size = 0;
					if (!S_ISGITLINK(mode)) {
						oid_object_info(the_repository, oid, &size);
					}
				!}
				<div class="pl-3 pr-1 py-2 border-t border-gray-300">
					{% if S_ISDIR(mode) %}
					{# Heroicons solid folder #}
					<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="size-5 text-blue-400 mt-[0.1rem]"><path d="M19.5 21a3 3 0 0 0 3-3v-4.5a3 3 0 0 0-3-3h-15a3 3 0 0 0-3 3V18a3 3 0 0 0 3 3h15ZM1.5 10.146V6a3 3 0 0 1 3-3h5.379a2.25 2.25 0 0 1 1.59.659l2.122 2.121c.14.141.331.22.53.22H19.5a3 3 0 0 1 3 3v1.146A4.483 4.483 0 0 0 19.5 9h-15a4.483 4.483 0 0 0-3 1.146Z" /></svg>
					{% else %}
					{# Heroicons outline document #}
					<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-5 text-gray-500 mt-[0.1rem]"><path stroke-linecap="round" stroke-linejoin="round" d="M19.5 14.25v-2.625a3.375 3.375 0 0 0-3.375-3.375h-1.5A1.125 1.125 0 0 1 13.5 7.125v-1.5a3.375 3.375 0 0 0-3.375-3.375H8.25m2.25 0H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 0 0-9-9Z" /></svg>
					{% endif %}
				</div>
				<div class="pr-3 py-2 border-t border-gray-300">
					<a href="{! cgit_shared_reporevlink_url("tree", ctx.qry.head, ctx.qry.oid, pathname); !}" class="hover:text-blue-600 hover:underline">
						{{ pathname }}
					</a>
				</div>
				<div class="pr-3 py-2 border-t border-gray-300 text-gray-500 font-mono">{! cgit_print_filemode(mode); !}</div>
				<div class="pr-3 py-2 border-t border-gray-300 text-gray-500 text-end">{% if !S_ISDIR(mode) %}{{ size|%ld }}{% endif %}</div>
{% endblock %}
{!
	int ls_item(const struct object_id *oid, struct strbuf *base, const char *pathname, unsigned mode, void *cbdata) {
		ls_item_impl(oid, base, pathname, mode, cbdata);
		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 %}