{{template "base/head" .}}
<div role="main" aria-label="{{.Title}}" class="page-content repository releases">
	{{template "repo/header" .}}
	<div class="ui container">
		{{template "base/alert" .}}
		{{template "repo/release_tag_header" .}}
		<ul id="release-list">
			{{range $idx, $info := .Releases}}
				{{$release := $info.Release}}
				<li class="release-entry">
					<div class="meta">
						<a class="muted" href="{{if not (and $release.Sha1 ($.Permission.CanRead ctx.Consts.RepoUnitTypeCode))}}#{{else}}{{$.RepoLink}}/src/tag/{{$release.TagName | PathEscapeSegments}}{{end}}" rel="nofollow">{{svg "octicon-tag" 16 "tw-mr-1"}}{{$release.TagName}}</a>
						{{if and $release.Sha1 ($.Permission.CanRead ctx.Consts.RepoUnitTypeCode)}}
							<a class="muted tw-font-mono" href="{{$.RepoLink}}/src/commit/{{$release.Sha1}}" rel="nofollow">{{svg "octicon-git-commit" 16 "tw-mr-1"}}{{ShortSha $release.Sha1}}</a>
							{{$compareTarget := ""}}
							{{if $release.IsDraft}}
									{{$compareTarget = $release.Target}}
							{{else if $release.TagName}}
									{{$compareTarget = $release.TagName}}
							{{else}}
								{{$compareTarget = $release.Sha1}}
							{{end}}
							{{template "repo/branch_dropdown" dict
								"ContainerClasses" "release-branch-tag-selector"
								"Repository" $.Repository
								"ShowTabTags" true
								"DropdownFixedText" (ctx.Locale.Tr "repo.release.compare")
								"RefLinkTemplate" (print "{RepoLink}/compare/{RefShortName}" "..." (PathEscapeSegments $compareTarget))
							}}
						{{end}}
					</div>
					<div class="ui segment detail">
						<div class="tw-flex tw-items-center tw-justify-between tw-flex-wrap tw-mb-2">
							<h4 class="release-list-title tw-break-anywhere">
								{{if $.PageIsSingleTag}}{{$release.Title}}{{else}}<a class="muted" href="{{$.RepoLink}}/releases/tag/{{$release.TagName | PathEscapeSegments}}">{{$release.Title}}</a>{{end}}
								{{template "repo/commit_statuses" dict "Status" $info.CommitStatus "Statuses" $info.CommitStatuses "AdditionalClasses" "tw-flex"}}
								{{template "repo/release/label" (dict "Release" $release)}}
							</h4>
							<div class="tw-flex tw-gap-2">
								{{if and $.CanCreateRelease (not $.PageIsSingleTag)}}
									{{if $release.IsArchived}}
										<form action="{{$.RepoLink}}/releases/{{$release.ID}}/unarchive" method="post">
											{{$.CsrfTokenHtml}}
											<button class="muted tw-border-0 tw-bg-transparent tw-cursor-pointer" type="submit" data-tooltip-content="{{ctx.Locale.Tr "repo.release.unarchive"}}">
												{{svg "octicon-archive" 16}}
											</button>
										</form>
									{{else}}
										<form action="{{$.RepoLink}}/releases/{{$release.ID}}/archive" method="post">
											{{$.CsrfTokenHtml}}
											<button class="muted tw-border-0 tw-bg-transparent tw-cursor-pointer" type="submit" data-tooltip-content="{{ctx.Locale.Tr "repo.release.archive"}}">
												{{svg "octicon-archive" 16}}
											</button>
										</form>
									{{end}}
									<a class="muted" data-tooltip-content="{{ctx.Locale.Tr "repo.release.edit"}}" href="{{$.RepoLink}}/releases/edit/{{$release.TagName | PathEscapeSegments}}" rel="nofollow">
										{{svg "octicon-pencil"}}
									</a>
								{{end}}
							</div>
						</div>
						<p class="text grey">
							<span class="author">
							{{if $release.OriginalAuthor}}
								{{svg (MigrationIcon $release.Repo.GetOriginalURLHostname) 20 "tw-mr-1"}}{{$release.OriginalAuthor}}
							{{else if $release.Publisher}}
								{{ctx.AvatarUtils.Avatar $release.Publisher 20 "tw-mr-1"}}
								{{if gt $release.PublisherID 0}}
									<a href="{{$release.Publisher.HomeLink}}">{{$release.Publisher.GetDisplayName}}</a>
								{{else}}
									{{$release.Publisher.GetDisplayName}}
								{{end}}
							{{else}}
								Ghost
							{{end}}
							</span>
							<span class="released">
								{{ctx.Locale.Tr "repo.released_this"}}
							</span>
							{{if $release.CreatedUnix}}
								<span class="time">{{DateUtils.TimeSince $release.CreatedUnix}}</span>
							{{end}}
							{{if and (gt $release.NumCommits 0) (not $release.IsDraft) ($.Permission.CanRead ctx.Consts.RepoUnitTypeCode)}}
								| <span class="ahead"><a href="{{$.RepoLink}}/compare/{{$release.TagName | PathEscapeSegments}}...{{$release.TargetBehind | PathEscapeSegments}}">{{ctx.Locale.Tr "repo.release.ahead.commits" $release.NumCommitsBehind}}</a> {{ctx.Locale.Tr "repo.release.ahead.target" $release.TargetBehind}}</span>
							{{end}}
						</p>
						<div class="render-content markup">
							{{$release.RenderedNote}}
						</div>
						<div class="divider"></div>

						{{/* For the first/latest release, show downloads directly without collapsible */}}
						{{if eq $idx 0}}
						<div class="download-section">
						{{else}}
						<details class="download">
							<summary>
								{{ctx.Locale.Tr "repo.release.downloads"}}
							</summary>
						{{end}}

							{{/* Group attachments by OS */}}
							{{$windowsFiles := newSlice}}
							{{$macosFiles := newSlice}}
							{{$linuxFiles := newSlice}}
							{{$otherFiles := newSlice}}

							{{range $att := $release.Attachments}}
								{{$name := StringUtils.ToLower $att.Name}}
								{{if or (StringUtils.Contains $name "windows") (StringUtils.Contains $name "win64") (StringUtils.Contains $name "win32") (StringUtils.Contains $name "-win.") (StringUtils.Contains $name "_win.") (StringUtils.Contains $name "-win-") (StringUtils.Contains $name "_win_") (StringUtils.Contains $name ".exe") (StringUtils.Contains $name ".msi")}}
									{{$windowsFiles = Append $windowsFiles $att}}
								{{else if or (StringUtils.Contains $name "darwin") (StringUtils.Contains $name "macos") (StringUtils.Contains $name "-mac.") (StringUtils.Contains $name "_mac.") (StringUtils.Contains $name "-mac-") (StringUtils.Contains $name "_mac_") (StringUtils.Contains $name "osx") (StringUtils.Contains $name ".dmg") (StringUtils.Contains $name ".pkg")}}
									{{$macosFiles = Append $macosFiles $att}}
								{{else if or (StringUtils.Contains $name "linux") (StringUtils.Contains $name "-lin.") (StringUtils.Contains $name "_lin.") (StringUtils.Contains $name "-lin-") (StringUtils.Contains $name "_lin_") (StringUtils.Contains $name ".deb") (StringUtils.Contains $name ".rpm") (StringUtils.Contains $name ".appimage")}}
									{{$linuxFiles = Append $linuxFiles $att}}
								{{else}}
									{{$otherFiles = Append $otherFiles $att}}
								{{end}}
							{{end}}

							{{/* Windows Downloads */}}
							{{if $windowsFiles}}
							<div class="tw-pt-2 tw-mb-3">
								<h5 class="tw-flex tw-items-center tw-gap-2 tw-mb-2 tw-font-medium">
									{{svg "octicon-device-desktop" 16}} Windows
								</h5>
								<ul class="ui divided list attachment-list tw-ml-4">
									{{range $att := $windowsFiles}}
										<li class="item">
											<a target="_blank" class="tw-flex-1 gt-ellipsis" rel="nofollow" download href="{{$att.DownloadURL}}">
												<strong class="flex-text-inline">{{svg "octicon-package" 16 "download-icon"}}<span class="gt-ellipsis">{{$att.Name}}</span></strong>
											</a>
											<div class="attachment-right-info flex-text-inline">
												<span class="tw-pl-5">{{$att.Size | FileSize}}</span>
												<span class="flex-text-inline" data-tooltip-content="{{ctx.Locale.Tr "repo.release.download_count" (ctx.Locale.PrettyNumber $att.DownloadCount)}}">
													{{svg "octicon-info"}}
												</span>
												<div class="tw-flex-1"></div>
												{{DateUtils.TimeSince $att.CreatedUnix}}
											</div>
										</li>
									{{end}}
								</ul>
							</div>
							{{end}}

							{{/* macOS Downloads */}}
							{{if $macosFiles}}
							<div class="tw-pt-2 tw-mb-3">
								<h5 class="tw-flex tw-items-center tw-gap-2 tw-mb-2 tw-font-medium">
									{{svg "octicon-device-desktop" 16}} macOS
								</h5>
								<ul class="ui divided list attachment-list tw-ml-4">
									{{range $att := $macosFiles}}
										<li class="item">
											<a target="_blank" class="tw-flex-1 gt-ellipsis" rel="nofollow" download href="{{$att.DownloadURL}}">
												<strong class="flex-text-inline">{{svg "octicon-package" 16 "download-icon"}}<span class="gt-ellipsis">{{$att.Name}}</span></strong>
											</a>
											<div class="attachment-right-info flex-text-inline">
												<span class="tw-pl-5">{{$att.Size | FileSize}}</span>
												<span class="flex-text-inline" data-tooltip-content="{{ctx.Locale.Tr "repo.release.download_count" (ctx.Locale.PrettyNumber $att.DownloadCount)}}">
													{{svg "octicon-info"}}
												</span>
												<div class="tw-flex-1"></div>
												{{DateUtils.TimeSince $att.CreatedUnix}}
											</div>
										</li>
									{{end}}
								</ul>
							</div>
							{{end}}

							{{/* Linux Downloads */}}
							{{if $linuxFiles}}
							<div class="tw-pt-2 tw-mb-3">
								<h5 class="tw-flex tw-items-center tw-gap-2 tw-mb-2 tw-font-medium">
									{{svg "octicon-terminal" 16}} Linux
								</h5>
								<ul class="ui divided list attachment-list tw-ml-4">
									{{range $att := $linuxFiles}}
										<li class="item">
											<a target="_blank" class="tw-flex-1 gt-ellipsis" rel="nofollow" download href="{{$att.DownloadURL}}">
												<strong class="flex-text-inline">{{svg "octicon-package" 16 "download-icon"}}<span class="gt-ellipsis">{{$att.Name}}</span></strong>
											</a>
											<div class="attachment-right-info flex-text-inline">
												<span class="tw-pl-5">{{$att.Size | FileSize}}</span>
												<span class="flex-text-inline" data-tooltip-content="{{ctx.Locale.Tr "repo.release.download_count" (ctx.Locale.PrettyNumber $att.DownloadCount)}}">
													{{svg "octicon-info"}}
												</span>
												<div class="tw-flex-1"></div>
												{{DateUtils.TimeSince $att.CreatedUnix}}
											</div>
										</li>
									{{end}}
								</ul>
							</div>
							{{end}}

							{{/* Other Downloads */}}
							{{if $otherFiles}}
							<div class="tw-pt-2 tw-mb-3">
								<h5 class="tw-flex tw-items-center tw-gap-2 tw-mb-2 tw-font-medium">
									{{svg "octicon-file" 16}} Other
								</h5>
								<ul class="ui divided list attachment-list tw-ml-4">
									{{range $att := $otherFiles}}
										<li class="item">
											<a target="_blank" class="tw-flex-1 gt-ellipsis" rel="nofollow" download href="{{$att.DownloadURL}}">
												<strong class="flex-text-inline">{{svg "octicon-package" 16 "download-icon"}}<span class="gt-ellipsis">{{$att.Name}}</span></strong>
											</a>
											<div class="attachment-right-info flex-text-inline">
												<span class="tw-pl-5">{{$att.Size | FileSize}}</span>
												<span class="flex-text-inline" data-tooltip-content="{{ctx.Locale.Tr "repo.release.download_count" (ctx.Locale.PrettyNumber $att.DownloadCount)}}">
													{{svg "octicon-info"}}
												</span>
												<div class="tw-flex-1"></div>
												{{DateUtils.TimeSince $att.CreatedUnix}}
											</div>
										</li>
									{{end}}
								</ul>
							</div>
							{{end}}

							{{/* Source Code Archives */}}
							{{if and (not $.DisableDownloadSourceArchives) (not $release.IsDraft) ($.Permission.CanRead ctx.Consts.RepoUnitTypeCode)}}
							<div class="tw-pt-2 tw-mb-3">
								<h5 class="tw-flex tw-items-center tw-gap-2 tw-mb-2 tw-font-medium">
									{{svg "octicon-code" 16}} Source Code
								</h5>
								<ul class="ui divided list attachment-list tw-ml-4">
									<li class="item">
										<a class="archive-link" download href="{{$.RepoLink}}/archive/{{$release.TagName | PathEscapeSegments}}.zip" rel="nofollow">
											<strong class="flex-text-inline">{{svg "octicon-file-zip" 16 "download-icon"}}{{ctx.Locale.Tr "repo.release.source_code"}} (ZIP)</strong>
										</a>
									</li>
									<li class="item">
										<a class="archive-link" download href="{{$.RepoLink}}/archive/{{$release.TagName | PathEscapeSegments}}.tar.gz" rel="nofollow">
											<strong class="flex-text-inline">{{svg "octicon-file-zip" 16 "download-icon"}}{{ctx.Locale.Tr "repo.release.source_code"}} (TAR.GZ)</strong>
										</a>
									</li>
								</ul>
							</div>
							{{end}}

						{{if eq $idx 0}}
						</div>
						{{else}}
						</details>
						{{end}}
					</div>
				</li>
			{{end}}
		</ul>

		{{template "base/paginate" .}}
	</div>
</div>

{{if (and ($.Permission.CanWrite ctx.Consts.RepoUnitTypeCode) .PageIsTagList)}}
	<div class="ui g-modal-confirm delete modal">
		<div class="header">
			{{svg "octicon-trash"}}
			{{ctx.Locale.Tr "repo.release.delete_tag"}}
		</div>
		<div class="content">
			<p>{{ctx.Locale.Tr "repo.release.deletion_tag_desc"}}</p>
		</div>
		{{template "base/modal_actions_confirm" .}}
	</div>
{{end}}

{{template "base/footer" .}}
