{{template "base/head" .}}
<div class="page-content organization teams">
	{{template "org/header" .}}
	<div class="ui container">
		{{template "base/alert" .}}
		{{if .IsOrganizationOwner}}
			<div class="text right">
				<a class="ui green button" href="{{.OrgLink}}/teams/new">{{svg "octicon-plus"}} {{.i18n.Tr "org.create_new_team"}}</a>
			</div>
			<div class="ui divider"></div>
		{{end}}

		<div class="ui two column grid">
			{{range .Teams}}
				<div class="column">
					<div class="ui top attached header">
						<a class="text black" href="{{$.OrgLink}}/teams/{{.LowerName | PathEscape}}"><strong>{{.Name}}</strong></a>
						<div class="ui right">
							{{if .IsMember $.SignedUser.ID}}
								<form>
									<button class="ui red tiny button delete-button" data-modal-id="leave-team"
										data-url="{{$.OrgLink}}/teams/{{.LowerName | PathEscape}}/action/leave" data-datauid="{{$.SignedUser.ID}}"
										data-name="{{.Name}}">{{$.i18n.Tr "org.teams.leave"}}</button>
								</form>
							{{else if $.IsOrganizationOwner}}
								<form method="post" action="{{$.OrgLink}}/teams/{{.LowerName | PathEscape}}/action/join">
									{{$.CsrfTokenHtml}}
									<button type="submit" class="ui blue small button" name="uid" value="{{$.SignedUser.ID}}">{{$.i18n.Tr "org.teams.join"}}</button>
								</form>
							{{end}}
						</div>
					</div>
					<div class="ui attached segment members">
						{{range .Members}}
							<a href="{{.HomeLink}}" title="{{.Name}}">
								{{avatar .}}
							</a>
						{{end}}
					</div>
					<div class="ui bottom attached header">
						<p class="team-meta">{{.NumMembers}} {{$.i18n.Tr "org.lower_members"}} ยท {{.NumRepos}} {{$.i18n.Tr "org.lower_repositories"}}</p>
					</div>
				</div>
			{{end}}
		</div>
	</div>
</div>
<div class="ui small basic delete modal" id="leave-team">
	<div class="ui icon header">
		{{svg "octicon-x" 16 "close inside"}}
		{{$.i18n.Tr "org.teams.leave"}}
	</div>
	<div class="content">
		<p>{{$.i18n.Tr "org.teams.leave.detail" `<span class="name"></span>` | Safe}}</p>
	</div>
	{{template "base/delete_modal_actions" .}}
</div>
{{template "base/footer" .}}