{{template "repo/settings/layout_head" (dict "ctxData" . "pageClass" "repository settings security")}}
<h4 class="ui top attached header">
	{{svg "octicon-shield" 16 "tw-mr-2"}}{{ctx.Locale.Tr "repo.settings.security"}}
</h4>
<div class="ui attached segment">
	<p class="text grey">{{ctx.Locale.Tr "repo.settings.security_desc"}}</p>

	{{if .AlertCounts}}
	<div class="tw-flex tw-gap-3 tw-mb-4">
		{{range $sev, $count := .AlertCounts}}
			<div class="ui mini {{if eq $sev "critical"}}red{{else if eq $sev "high"}}orange{{else if eq $sev "medium"}}yellow{{else if eq $sev "low"}}blue{{else}}grey{{end}} label">
				{{$sev}}: {{$count}}
			</div>
		{{end}}
	</div>
	{{end}}

	<form class="ui form" method="post" action="{{.RepoLink}}/settings/security">
		{{.CsrfTokenHtml}}
		<h5 class="ui dividing header">{{ctx.Locale.Tr "repo.settings.security_scanners"}}</h5>
		<div class="inline field">
			<div class="ui checkbox">
				<input name="enabled" type="checkbox" {{if .ScannerConfig.Enabled}}checked{{end}}>
				<label>{{ctx.Locale.Tr "repo.settings.security_enabled"}}</label>
			</div>
		</div>
		<div class="inline field">
			<div class="ui checkbox">
				<input name="secret_scanner" type="checkbox" {{if .ScannerConfig.SecretScanner}}checked{{end}}>
				<label>{{svg "octicon-key" 14}} {{ctx.Locale.Tr "repo.settings.security_secret_scanner"}}</label>
			</div>
		</div>
		<div class="inline field">
			<div class="ui checkbox">
				<input name="depend_scanner" type="checkbox" {{if .ScannerConfig.DependScanner}}checked{{end}}>
				<label>{{svg "octicon-package" 14}} {{ctx.Locale.Tr "repo.settings.security_depend_scanner"}}</label>
			</div>
		</div>
		<div class="inline field">
			<div class="ui checkbox">
				<input name="code_scanner" type="checkbox" {{if .ScannerConfig.CodeScanner}}checked{{end}}>
				<label>{{svg "octicon-code" 14}} {{ctx.Locale.Tr "repo.settings.security_code_scanner"}}</label>
			</div>
		</div>
		<div class="inline field">
			<div class="ui checkbox">
				<input name="config_scanner" type="checkbox" {{if .ScannerConfig.ConfigScanner}}checked{{end}}>
				<label>{{svg "octicon-gear" 14}} {{ctx.Locale.Tr "repo.settings.security_config_scanner"}}</label>
			</div>
		</div>
		<div class="inline field">
			<div class="ui checkbox">
				<input name="license_scanner" type="checkbox" {{if .ScannerConfig.LicenseScanner}}checked{{end}}>
				<label>{{svg "octicon-law" 14}} {{ctx.Locale.Tr "repo.settings.security_license_scanner"}}</label>
			</div>
		</div>
		<div class="divider"></div>
		<div class="inline field">
			<div class="ui checkbox">
				<input name="block_on_push" type="checkbox" {{if .ScannerConfig.BlockOnPush}}checked{{end}}>
				<label>{{ctx.Locale.Tr "repo.settings.security_block_on_push"}}</label>
			</div>
			<p class="help">{{ctx.Locale.Tr "repo.settings.security_block_on_push_help"}}</p>
		</div>
		<button class="ui primary button" type="submit">{{ctx.Locale.Tr "repo.settings.security_save"}}</button>
	</form>
</div>

<h4 class="ui top attached header tw-mt-4">
	{{ctx.Locale.Tr "repo.settings.security_alerts"}}
	<form method="post" action="{{.RepoLink}}/settings/security/scan" class="tw-float-right tw-inline">
		{{.CsrfTokenHtml}}
		<button class="ui mini primary button" type="submit">{{svg "octicon-sync" 14}} {{ctx.Locale.Tr "repo.settings.security_scan_now"}}</button>
	</form>
</h4>
<div class="ui attached segment">
	{{if .SecurityAlerts}}
	<table class="ui compact table">
		<thead>
			<tr>
				<th>{{ctx.Locale.Tr "repo.settings.security_severity"}}</th>
				<th>{{ctx.Locale.Tr "repo.settings.security_scanner_type"}}</th>
				<th>{{ctx.Locale.Tr "repo.settings.security_finding"}}</th>
				<th>{{ctx.Locale.Tr "repo.settings.security_file"}}</th>
				<th>{{ctx.Locale.Tr "repo.settings.security_status"}}</th>
				<th></th>
			</tr>
		</thead>
		<tbody>
			{{range .SecurityAlerts}}
			<tr {{if ne .Status "active"}}class="tw-opacity-50"{{end}}>
				<td>
					<span class="ui mini {{if eq .Severity "critical"}}red{{else if eq .Severity "high"}}orange{{else if eq .Severity "medium"}}yellow{{else if eq .Severity "low"}}blue{{else}}grey{{end}} label">
						{{.Severity}}
					</span>
				</td>
				<td>{{.Scanner}}</td>
				<td>
					<strong>{{.Title}}</strong>
					{{if .Description}}<br><small class="text grey">{{.Description}}</small>{{end}}
				</td>
				<td>
					{{if .FilePath}}
						<code class="tw-text-xs">{{.FilePath}}{{if .LineNumber}}:{{.LineNumber}}{{end}}</code>
					{{end}}
				</td>
				<td>
					{{if eq .Status "active"}}
						<span class="ui mini red label">Active</span>
					{{else if eq .Status "resolved"}}
						<span class="ui mini green label">Resolved</span>
					{{else}}
						<span class="ui mini grey label">Dismissed</span>
					{{end}}
				</td>
				<td class="tw-text-right">
					{{if eq .Status "active"}}
						<form method="post" action="{{$.RepoLink}}/settings/security/alert/{{.ID}}" class="tw-inline">
							{{$.CsrfTokenHtml}}
							<input type="hidden" name="status" value="resolved">
							<button class="ui tiny green icon button" type="submit" title="Resolve">{{svg "octicon-check" 14}}</button>
						</form>
						<form method="post" action="{{$.RepoLink}}/settings/security/alert/{{.ID}}" class="tw-inline">
							{{$.CsrfTokenHtml}}
							<input type="hidden" name="status" value="dismissed">
							<button class="ui tiny grey icon button" type="submit" title="Dismiss">{{svg "octicon-x" 14}}</button>
						</form>
					{{end}}
				</td>
			</tr>
			{{end}}
		</tbody>
	</table>
	{{else}}
	<div class="empty-placeholder">
		<p>{{ctx.Locale.Tr "repo.settings.security_no_alerts"}}</p>
	</div>
	{{end}}
</div>
{{template "repo/settings/layout_footer" .}}
