{{template "base/head" .}}
<div role="main" aria-label="{{.Title}}" class="page-content repository settings edit">
	{{template "repo/header" .}}
	{{template "repo/settings/navbar" .}}
	<div class="ui container">
		{{template "base/alert" .}}
		{{if .Repository.IsArchived}}
			<div class="ui warning message">
				{{.locale.Tr "repo.settings.archive.branchsettings_unavailable"}}
			</div>
		{{else}}
			<h4 class="ui top attached header">
				{{.locale.Tr "repo.default_branch"}}
			</h4>
			<div class="ui attached segment">
				<p>
					{{.locale.Tr "repo.settings.default_branch_desc"}}
				</p>
				<form class="ui form" action="{{.Link}}" method="post">
					{{.CsrfTokenHtml}}
					<input type="hidden" name="action" value="default_branch">
					{{if not .Repository.IsEmpty}}
					<div class="required inline field">
						<div class="ui dropdown selection" tabindex="0">
							<select name="branch">
								<option value="{{.Repository.DefaultBranch}}">{{.Repository.DefaultBranch}}</option>
								{{range .Branches}}
									<option value="{{.}}">{{.}}</option>
								{{end}}
							</select>{{svg "octicon-triangle-down" 14 "dropdown icon"}}
							<div class="default text">{{.Repository.DefaultBranch}}</div>
							<div class="menu">
								{{range .Branches}}
									<div class="item" data-value="{{.}}">{{.}}</div>
								{{end}}
							</div>
						</div>
						<button class="ui green button">{{$.locale.Tr "repo.settings.branches.update_default_branch"}}</button>
					</div>
					{{end}}
				</form>
			</div>

			<h4 class="ui top attached header">
				{{.locale.Tr "repo.settings.protected_branch"}}
				<div class="ui right">
					<a class="ui primary tiny button" href="{{$.Repository.Link}}/settings/branches/edit">{{$.locale.Tr "repo.settings.branches.add_new_rule"}}</a>
				</div>
			</h4>

			<div class="ui attached table segment">
				<div class="ui grid padded">
					<div class="sixteen wide column">
						<table class="ui single line table padded">
							<tbody>
								{{range .ProtectedBranches}}
									<tr>
										<td><div class="ui basic primary label">{{.RuleName}}</div></td>
										<td class="right aligned">
										<a class="rm ui button" href="{{$.Repository.Link}}/settings/branches/edit?rule_name={{.RuleName}}">{{$.locale.Tr "repo.settings.edit_protected_branch"}}</a>
										<button class="ui red tiny button delete-button" data-url="{{$.Repository.Link}}/settings/branches/{{.ID}}/delete" data-id="{{.ID}}">
										{{$.locale.Tr "repo.settings.protected_branch.delete_rule"}}</button>
										</td>
									</tr>
								{{else}}
									<tr class="center aligned"><td>{{.locale.Tr "repo.settings.no_protected_branch"}}</td></tr>
								{{end}}
							</tbody>
						</table>
					</div>
				</div>
			</div>

			{{if $.Repository.CanCreateBranch}}
				<h4 class="ui top attached header">
					{{.locale.Tr "repo.settings.rename_branch"}}
				</h4>
				<div class="ui attached segment">
					<form class="ui form" action="{{$.Repository.Link}}/settings/rename_branch" method="post">
						{{.CsrfTokenHtml}}
						<div class="required field">
							<label for="from">{{.locale.Tr "repo.settings.rename_branch_from"}}</label>
							<input id="from" name="from" required>
						</div>
						<div class="required field {{if .Err_BranchName}}error{{end}}">
							<label for="to">{{.locale.Tr "repo.settings.rename_branch_to"}}</label>
							<input id="to" name="to" required>
						</div>
						<div class="field">
							<button class="ui green button">{{$.locale.Tr "repo.settings.update_settings"}}</button>
						</div>
					</form>
				</div>
			{{end}}
		{{end}}
	</div>
</div>

<div class="ui small basic delete modal">
	<div class="ui header">
		{{svg "octicon-trash" 16 "gt-mr-2"}}
		{{.locale.Tr "repo.settings.protected_branch_deletion"}}
	</div>
	<div class="content">
		<p>{{.locale.Tr "repo.settings.protected_branch_deletion_desc"}}</p>
	</div>
	{{template "base/delete_modal_actions" .}}
</div>

{{template "base/footer" .}}