{{template "base/head" .}}
<div role="main" aria-label="{{.Title}}" class="page-content organization wiki">
	{{template "org/header" .}}
	{{template "org/menu" .}}
	<div class="ui container">
		{{if .WikiEmpty}}
			<div class="ui placeholder segment">
				<div class="ui icon header">
					{{svg "octicon-book" 48}}
					<br>
					This organization doesn't have a wiki yet.
				</div>
				<p class="tw-text-center">
					Enable the wiki on the <code>.mokogitea</code> (public) or <code>.mokogitea-private</code> (members-only)
					repository to get started.
				</p>
			</div>
		{{else}}
			<div class="repo-button-row tw-flex tw-items-center tw-gap-2 tw-mb-4">
				<div class="tw-flex-1 tw-flex tw-items-center tw-gap-2">
					{{svg "octicon-book" 16}}
					<strong>{{.CurrentPage}}</strong>
				</div>
				{{if .ShowWikiViewSelector}}
					<div class="ui dropdown jump">
						{{- $viewAsRole := Iif (.IsViewingWikiAsMember) (ctx.Locale.Tr "org.members.member") (ctx.Locale.Tr "settings.visibility.public") -}}
						<span class="text">{{svg "octicon-eye"}} {{ctx.Locale.Tr "org.view_as_role" $viewAsRole}}</span>
						{{svg "octicon-triangle-down" 14 "dropdown icon"}}
						<div class="menu">
							<a href="{{$.Org.HomeLink}}/-/wiki/{{.CurrentPage}}?view_as=public" class="item {{if not .IsViewingWikiAsMember}}selected{{end}}">
								{{svg "octicon-check" 14 (Iif (not .IsViewingWikiAsMember) "" "tw-invisible")}} {{ctx.Locale.Tr "settings.visibility.public"}}
							</a>
							<a href="{{$.Org.HomeLink}}/-/wiki/{{.CurrentPage}}?view_as=member" class="item {{if .IsViewingWikiAsMember}}selected{{end}}">
								{{svg "octicon-check" 14 (Iif .IsViewingWikiAsMember "" "tw-invisible")}} {{ctx.Locale.Tr "org.members.member"}}
							</a>
						</div>
					</div>
				{{end}}
			</div>

			{{if .WikiPageNotFound}}
				<div class="ui segment">
					<div class="ui icon message">
						{{svg "octicon-alert" 24}}
						<div class="content">
							<div class="header">Page not found</div>
							<p>The page "{{.CurrentPage}}" does not exist in this wiki.</p>
						</div>
					</div>
					{{if .WikiTree}}
						<h4>Available pages:</h4>
						<ul>
							{{range .WikiTree}}
								{{if .IsDir}}
									{{range .Children}}
										<li><a href="{{$.Org.HomeLink}}/-/wiki/{{.SubURL}}">{{.Name}}</a></li>
									{{end}}
								{{else}}
									<li><a href="{{$.Org.HomeLink}}/-/wiki/{{.SubURL}}">{{.Name}}</a></li>
								{{end}}
							{{end}}
						</ul>
					{{end}}
				</div>
			{{else}}
				<div class="wiki-content-parts">
					<div class="render-content markup wiki-content-main {{if or .WikiSidebarHTML .WikiTree}}with-sidebar{{end}}">
						{{.WikiContent}}
					</div>

					{{if or .WikiSidebarHTML .WikiTree}}
					<div class="render-content markup wiki-content-sidebar">
						{{if .WikiSidebarHTML}}
							{{.WikiSidebarHTML}}
						{{else if .WikiTree}}
							<strong>{{svg "octicon-list-unordered" 14}} Pages</strong>
							<ul class="wiki-tree-list">
								{{range .WikiTree}}
									<li>
										{{if .IsDir}}
											<details open>
												<summary>{{svg "octicon-file-directory" 14}} <strong>{{.Name}}</strong></summary>
												{{if .Children}}
												<ul>
													{{range .Children}}
														<li>
															{{if .IsDir}}
																{{svg "octicon-file-directory" 14}}
																<a href="{{$.Org.HomeLink}}/-/wiki/{{.SubURL}}"><strong>{{.Name}}</strong></a>
															{{else}}
																{{svg "octicon-file" 14}}
																<a href="{{$.Org.HomeLink}}/-/wiki/{{.SubURL}}" {{if eq $.CurrentPage .Name}}class="active"{{end}}>{{.Name}}</a>
															{{end}}
														</li>
													{{end}}
												</ul>
												{{end}}
											</details>
										{{else}}
											{{svg "octicon-file" 14}}
											<a href="{{$.Org.HomeLink}}/-/wiki/{{.SubURL}}" {{if eq $.CurrentPage .Name}}class="active"{{end}}>{{.Name}}</a>
										{{end}}
									</li>
								{{end}}
							</ul>
						{{end}}
					</div>
					{{end}}

					<div class="tw-clear-both"></div>

					{{if .WikiFooterHTML}}
						<div class="render-content markup wiki-content-footer">
							{{.WikiFooterHTML}}
						</div>
					{{end}}
				</div>
			{{end}}
		{{end}}
	</div>
</div>
{{template "base/footer" .}}
