{{template "base/head" .}}
<div role="main" aria-label="{{.Title}}" class="page-content organization teams">
	{{template "org/header" .}}
	<div class="ui container">
		{{template "base/alert" .}}
		{{if .IsOrganizationOwner}}
			<div class="flex-text-block">
				<div class="tw-flex-1">{{ctx.Locale.Tr "org.teams.manage_team_member_prompt"}}</div>
				<a class="ui primary button" href="{{.OrgLink}}/teams/new">{{svg "octicon-plus"}} {{ctx.Locale.Tr "org.create_new_team"}}</a>
			</div>
			<div class="divider"></div>
		{{end}}

		<div class="ui two column stackable grid">
			{{range .Teams}}
				<div class="column">
					<div class="ui top attached header">
						<a class="tw-text-text" href="{{$.OrgLink}}/teams/{{.LowerName | PathEscape}}"><strong>{{.Name}}</strong></a>
						<div class="ui right">
							<a class="ui primary mini compact button" href="{{$.OrgLink}}/teams/{{.LowerName | PathEscape}}">{{ctx.Locale.Tr "view"}}</a>
							{{if .IsMember ctx $.SignedUser.ID}}
								<form>
									<button class="ui red mini compact button delete-button" data-modal-id="leave-team"
										data-url="{{$.OrgLink}}/teams/{{.LowerName | PathEscape}}/action/leave" data-datauid="{{$.SignedUser.ID}}"
										data-name="{{.Name}}">{{ctx.Locale.Tr "org.teams.leave"}}</button>
								</form>
							{{else if $.IsOrganizationOwner}}
								<form method="post" action="{{$.OrgLink}}/teams/{{.LowerName | PathEscape}}/action/join">
									<button type="submit" class="ui primary mini compact button" name="uid" value="{{$.SignedUser.ID}}">{{ctx.Locale.Tr "org.teams.join"}}</button>
								</form>
							{{end}}
						</div>
					</div>
					<div class="ui attached segment members">
						{{range .Members}}
							{{template "shared/user/avatarlink" dict "user" . "size" 32 "tooltip" true}}
						{{end}}
					</div>
					<div class="ui bottom attached header">
						<p class="team-meta"><a class="muted" href="{{$.OrgLink}}/teams/{{.LowerName | PathEscape}}">{{.NumMembers}} {{ctx.Locale.Tr "org.lower_members"}}</a> · <a class="muted" href="{{$.OrgLink}}/teams/{{.LowerName | PathEscape}}/repositories">{{.NumRepos}} {{ctx.Locale.Tr "org.lower_repositories"}}</a></p>
					</div>
				</div>
			{{end}}
		</div>
	</div>
</div>
<div class="ui g-modal-confirm delete modal" id="leave-team">
	<div class="header">
		{{ctx.Locale.Tr "org.teams.leave"}}
	</div>
	<div class="content">
		<p>{{ctx.Locale.Tr "org.teams.leave.detail" (HTMLFormat `<span class="%s"></span>` "name")}}</p>
	</div>
	{{template "base/modal_actions_confirm" .}}
</div>
{{template "base/footer" .}}
