{{template "base/head" .}}
{{$commitLinkBase := print $.RepoLink (Iif $.PageIsWiki "/wiki" "") "/commit"}}
<div role="main" aria-label="{{.Title}}" class="page-content repository diff">
	{{template "repo/header" .}}
	<div class="ui container fluid padded">
		<div class="ui top attached header clearing segment tw-relative commit-header">
			<div class="tw-flex tw-mb-4 tw-gap-1">
				<h3 class="tw-mb-0 tw-flex-1"><span class="commit-summary" title="{{.Commit.MessageTitle}}">{{ctx.RenderUtils.RenderCommitMessage .Commit.MessageUTF8 $.Repository}}</span>{{template "repo/commit_statuses" dict "Status" .CommitStatus "Statuses" .CommitStatuses "AdditionalClasses" "tw-inline"}}</h3>
				{{if not $.PageIsWiki}}
					<div class="commit-header-buttons">
						<a class="ui primary tiny button" href="{{.SourcePath}}">
							{{ctx.Locale.Tr "repo.diff.browse_source"}}
						</a>
						{{if and ($.Permission.CanWrite ctx.Consts.RepoUnitTypeCode) (not $.Repository.IsArchived) (not .IsDeleted)}}{{- /* */ -}}
							<div class="ui dropdown primary tiny button">
								{{ctx.Locale.Tr "repo.commit.operations"}}
								{{svg "octicon-triangle-down" 14 "dropdown icon"}}
								<div class="menu">
									<div class="header">{{ctx.Locale.Tr "repo.commit.operations"}}</div>
									<div class="divider"></div>
									<div class="item show-create-branch-modal"
										data-content="{{ctx.Locale.Tr "repo.branch.new_branch_from" (.CommitID)}}" {{/* used by the form */}}
										data-branch-from="{{ShortSha .CommitID}}"
										data-branch-from-urlcomponent="{{.CommitID}}"
										data-modal="#create-branch-modal">
										{{ctx.Locale.Tr "repo.branch.create_branch_operation"}}
									</div>
									<div class="item show-create-branch-modal"
										data-content="{{ctx.Locale.Tr "repo.branch.new_branch_from" (.CommitID)}}" {{/* used by the form */}}
										data-branch-from="{{ShortSha .CommitID}}"
										data-branch-from-urlcomponent="{{.CommitID}}"
										data-modal="#create-tag-modal"
										data-modal-from-span="#modal-create-tag-from-span"
										data-modal-form="#create-tag-form">
										{{ctx.Locale.Tr "repo.tag.create_tag_operation"}}
									</div>
									<div class="item show-modal revert-button"
										data-modal="#cherry-pick-modal"
										data-modal-cherry-pick-type="revert"
										data-modal-cherry-pick-header="{{ctx.Locale.Tr "repo.commit.revert-header" (ShortSha .CommitID)}}"
										data-modal-cherry-pick-content="{{ctx.Locale.Tr "repo.commit.revert-content"}}"
										data-modal-cherry-pick-submit="{{ctx.Locale.Tr "repo.commit.revert"}}">{{ctx.Locale.Tr "repo.commit.revert"}}</div>
									<div class="item cherry-pick-button show-modal"
										data-modal="#cherry-pick-modal"
										data-modal-cherry-pick-type="cherry-pick"
										data-modal-cherry-pick-header="{{ctx.Locale.Tr "repo.commit.cherry-pick-header" (ShortSha .CommitID)}}"
										data-modal-cherry-pick-content="{{ctx.Locale.Tr "repo.commit.cherry-pick-content"}}"
										data-modal-cherry-pick-submit="{{ctx.Locale.Tr "repo.commit.cherry-pick"}}">{{ctx.Locale.Tr "repo.commit.cherry-pick"}}</div>
									<div class="ui g-modal-confirm modal" id="cherry-pick-modal">
										<div class="header">
											<span id="cherry-pick-header"></span>
										</div>
										<div class="content">
											<p id="cherry-pick-content" class="branch-dropdown"></p>

											<form method="get">
												{{template "repo/branch_dropdown" dict
													"Repository" .Repository
													"ShowTabBranches" true
													"CurrentRefType" "branch"
													"CurrentRefShortName" $.Repository.DefaultBranch
													"RefFormActionTemplate" (print "{RepoLink}/_cherrypick/" .CommitID "/{RefShortName}")
												}}
												<input type="hidden" id="cherry-pick-type" name="cherry-pick-type"><br>
												<button type="submit" id="cherry-pick-submit" class="ui primary button"></button>
											</form>
										</div>
									</div>
									<div class="ui small modal" id="create-branch-modal">
										<div class="header">
											{{ctx.Locale.Tr "repo.branch.new_branch"}}
										</div>
										<div class="content">
											<form class="ui form" id="create-branch-form" action="" data-base-action="{{.RepoLink}}/branches/_new/commit/" method="post">
												<div class="field">
													<label>
														{{ctx.Locale.Tr "repo.branch.new_branch_from" (HTMLFormat `<span class="%s" id="%s"></span>` "text" "modal-create-branch-from-span")}}
													</label>
												</div>
												<div class="required field">
													<label for="new_branch_name">{{ctx.Locale.Tr "repo.branch.name"}}</label>
													<input id="new_branch_name" name="new_branch_name" required>
												</div>

												<div class="actions">
													<button class="ui cancel button">{{ctx.Locale.Tr "settings.cancel"}}</button>
													<button class="ui primary button">{{ctx.Locale.Tr "repo.branch.confirm_create_branch"}}</button>
												</div>
											</form>
										</div>
									</div>
									<div class="ui small modal" id="create-tag-modal">
										<div class="header">
											{{ctx.Locale.Tr "repo.tag.create_tag_operation"}}
										</div>
										<div class="content">
											<form class="ui form" id="create-tag-form" action="" data-base-action="{{.RepoLink}}/branches/_new/commit/" method="post">
												<input type="hidden" name="create_tag" value="true">
												<div class="field">
													<label>
														{{ctx.Locale.Tr "repo.tag.create_tag_from" (HTMLFormat `<span class="%s" id="%s"></span>` "text" "modal-create-tag-from-span")}}
													</label>
												</div>
												<div class="required field">
													<label for="new_branch_name">{{ctx.Locale.Tr "repo.release.tag_name"}}</label>
													<input id="new_branch_name" name="new_branch_name" required>
												</div>

												<div class="actions">
													<button class="ui cancel button">{{ctx.Locale.Tr "settings.cancel"}}</button>
													<button class="ui primary button">{{ctx.Locale.Tr "repo.tag.confirm_create_tag"}}</button>
												</div>
											</form>
										</div>
									</div>
								</div>
							</div>
						{{end}}
					</div>
				{{end}}
			</div>
			{{if .Commit.MessageBody}}
				<pre class="commit-body">{{ctx.RenderUtils.RenderCommitBody .Commit.MessageUTF8 $.Repository}}</pre>
			{{end}}
			{{template "repo/commit_load_branches_and_tags" .}}
		</div>

		<div class="ui bottom attached segment flex-text-block tw-flex-wrap">
			<div class="flex-text-inline">
				{{if .Author}}
					{{ctx.AvatarUtils.Avatar .Author 20}}
					<strong>{{.Author.GetShortDisplayNameLinkHTML}}</strong>
				{{else}}
					{{ctx.AvatarUtils.AvatarByEmail .Commit.Author.Email .Commit.Author.Email 20}}
					<strong>{{.Commit.Author.Name}}</strong>
				{{end}}
			</div>
			<span class="tw-text-text-light">{{DateUtils.TimeSince .Commit.Committer.When}}</span>

			{{$committerIsAuthor := and (eq .Commit.Committer.Name .Commit.Author.Name) (eq .Commit.Committer.Email .Commit.Author.Email)}}
			{{if not $committerIsAuthor}}
				<div class="flex-text-inline">
					<span class="tw-text-text-light">{{ctx.Locale.Tr "repo.diff.committed_by"}}</span>
					{{if and .Verification.CommittingUser}}
						{{ctx.AvatarUtils.Avatar .Verification.CommittingUser 20}}
						<strong>{{.Verification.CommittingUser.GetShortDisplayNameLinkHTML}}</strong>
					{{else}}
						{{ctx.AvatarUtils.AvatarByEmail .Commit.Committer.Email .Commit.Committer.Email 20}}
						<strong>{{.Commit.Committer.Name}}</strong>
					{{end}}
				</div>
			{{end}}

			{{if .CommitOtherParticipants}}
				<div class="flex-text-inline">
					<span class="tw-text-text-light">{{ctx.Locale.Tr "repo.diff.coauthored_by"}}</span>
					{{range $participant := .CommitOtherParticipants}}
						{{$user := $participant.GiteaUser}}
						{{$gitIdentity := $participant.GitIdentity}}
						{{if $user}}
							{{ctx.AvatarUtils.Avatar $user 20}}
							<strong>{{$user.GetShortDisplayNameLinkHTML}}</strong>
						{{else}}
							{{$gitName := $gitIdentity.Name}}
							{{$gitEmail := $gitIdentity.Email}}
							{{ctx.AvatarUtils.AvatarByEmail $gitEmail $gitEmail 20}}{{/* use the same layout as the "author" above */}}
							<strong>{{$gitName}}</strong>
						{{end}}
					{{end}}
				</div>
			{{end}}

			{{if .Verification}}
				{{template "repo/commit_sign_badge" dict "CommitSignVerification" .Verification}}
			{{end}}

			<div class="tw-flex-1"></div>

			<div class="flex-text-inline tw-gap-5">
				{{if .Parents}}
					<div class="flex-text-inline">
						<span>{{ctx.Locale.Tr "repo.diff.parent"}}</span>
						{{range .Parents}}
							<a class="ui label commit-id-short" href="{{$commitLinkBase}}/{{PathEscape .}}">{{ShortSha .}}</a>
						{{end}}
					</div>
				{{end}}
				<div class="flex-text-inline">
					<span>{{ctx.Locale.Tr "repo.diff.commit"}}</span>
					<a class="ui label commit-id-short" href="{{$commitLinkBase}}/{{PathEscape .CommitID}}">{{ShortSha .CommitID}}</a>
				</div>
			</div>
		</div>

		{{if .NoteRendered}}
			<div class="ui top attached header segment git-notes">
				{{svg "octicon-note" 16 "tw-mr-2"}}
				{{ctx.Locale.Tr "repo.diff.git-notes"}}:
				{{if .NoteAuthor}}
					<a href="{{.NoteAuthor.HomeLink}}">
						{{if .NoteAuthor.FullName}}
							<strong>{{.NoteAuthor.FullName}}</strong>
						{{else}}
							<strong>{{.NoteCommit.Author.Name}}</strong>
						{{end}}
					</a>
				{{else}}
					<strong>{{.NoteCommit.Author.Name}}</strong>
				{{end}}
				<span class="tw-text-text-light">{{DateUtils.TimeSince .NoteCommit.Author.When}}</span>
			</div>
			<div class="ui bottom attached info segment git-notes">
				<pre class="commit-body">{{.NoteRendered}}</pre>
			</div>
		{{end}}

		{{template "repo/diff/box" .}}
	</div>
</div>
{{template "base/footer" .}}
