<h4 class="ui top attached header">
	{{ctx.Locale.Tr "actions.scoped_workflows"}}
</h4>
<div class="ui attached segment">
	<p>{{.ScopedWorkflowsDesc}}</p>
	<p>{{ctx.Locale.Tr "actions.scoped_workflows.add_help" .ScopedWorkflowDirs}}</p>
	<div class="ui warning message">{{ctx.Locale.Tr "actions.scoped_workflows.security_note"}}</div>
	<form class="ui form form-fetch-action flex-text-block" method="post" action="{{.Link}}/add">
		<div data-global-init="initSearchRepoBox" data-uid="{{.RepoSearchUID}}"{{if .ScopedWorkflowsSearchExclusive}} data-exclusive="true"{{end}}{{if .ScopedWorkflowsSearchFullName}} data-full-name="true"{{end}} class="ui search tw-flex-1">
			<div class="ui input tw-w-full">
				<input class="prompt" name="repo_name" required placeholder="{{ctx.Locale.Tr "search.repo_kind"}}" autocomplete="off">
			</div>
		</div>
		<button class="ui primary button">{{ctx.Locale.Tr "actions.scoped_workflows.source.add"}}</button>
	</form>
</div>

{{if .ScopedWorkflowSources}}
<div class="ui attached segment">
	{{range $i, $src := .ScopedWorkflowSources}}
		{{if $i}}<div class="ui divider"></div>{{end}}
		<div class="flex-text-block tw-justify-between">
			<a class="tw-font-semibold gt-ellipsis tw-min-w-0" href="{{$src.Repo.Link}}">{{$src.Repo.FullName}}</a>
			<form class="ui form form-fetch-action" method="post" action="{{$.Link}}/remove">
				<input type="hidden" name="repo_id" value="{{$src.Repo.ID}}">
				<button class="ui red tiny button">{{ctx.Locale.Tr "remove"}}</button>
			</form>
		</div>
		{{if $src.ScopedWorkflowInfos}}
			<form class="ui form form-fetch-action tw-mt-3" method="post" action="{{$.Link}}/required" data-global-init="initScopedWorkflowRequired">
				<input type="hidden" name="repo_id" value="{{$src.Repo.ID}}">
				<div class="text grey tw-mb-2">{{ctx.Locale.Tr "actions.scoped_workflows.required.label"}}</div>
				<table class="ui table tw-table-fixed">
					<thead>
						<tr>
							<th class="tw-w-1/5">{{ctx.Locale.Tr "actions.runs.workflow_file"}}</th>
							<th class="tw-w-24 tw-pr-4">{{ctx.Locale.Tr "actions.workflow.required"}}</th>
							<th>{{ctx.Locale.Tr "actions.scoped_workflows.required.patterns"}} <span class="tw-font-normal tw-text-text-light-2">({{ctx.Locale.Tr "actions.scoped_workflows.required.patterns_note"}})</span></th>
						</tr>
					</thead>
					<tbody>
						{{range $src.ScopedWorkflowInfos}}
							<tr>
								<td>{{.EntryName}}{{if .Missing}} <span class="ui red mini label">{{ctx.Locale.Tr "actions.scoped_workflows.required.missing_file"}}</span>{{end}}<input type="hidden" name="workflow_ids" value="{{.EntryName}}"></td>
								<td class="collapsing tw-pr-4">
									<div class="ui checkbox">
										<input type="checkbox" class="js-scoped-required-toggle" name="required_workflow_ids" value="{{.EntryName}}" aria-label="{{.EntryName}}"{{if .Required}} checked{{end}}>
										<label></label>
									</div>
								</td>
								<td>
									<textarea class="js-scoped-required-patterns{{if not .Required}} tw-hidden{{end}}" name="required_patterns[{{.EntryName}}]" rows="2" aria-label="{{ctx.Locale.Tr "actions.scoped_workflows.required.patterns_aria" .EntryName}}" data-default-pattern="{{$src.Repo.FullName}}: {{.DisplayName}} / *" placeholder="{{$src.Repo.FullName}}: {{.DisplayName}} / *">{{.Patterns}}</textarea>
									<span class="js-scoped-required-hint text grey{{if .Required}} tw-hidden{{end}}">{{ctx.Locale.Tr "actions.scoped_workflows.required.patterns_hint"}}</span>
									{{if or .Contexts (not .Missing)}}
										<table class="ui celled table js-scoped-required-contexts tw-mt-2{{if not .Required}} tw-hidden{{end}}">
											<thead>
												<tr><th>{{ctx.Locale.Tr "actions.scoped_workflows.required.expected_contexts"}}</th></tr>
											</thead>
											<tbody>
												{{if .Contexts}}
													{{range .Contexts}}
														<tr>
															<td>
																<span class="js-scoped-context" data-context="{{.}}">{{.}}</span>
																<span class="js-scoped-context-matched tw-font-semibold tw-italic tw-hidden">{{ctx.Locale.Tr "repo.settings.protect_status_check_matched"}}</span>
															</td>
														</tr>
													{{end}}
												{{else}}
													<tr><td class="tw-text-red">{{ctx.Locale.Tr "actions.scoped_workflows.required.no_status_contexts"}}</td></tr>
												{{end}}
											</tbody>
										</table>
									{{end}}
								</td>
							</tr>
						{{end}}
					</tbody>
				</table>
				<div class="text grey tw-mb-2">{{ctx.Locale.Tr "actions.scoped_workflows.required.patterns_help"}}</div>
				<button class="ui tiny primary button">{{ctx.Locale.Tr "save"}}</button>
			</form>
		{{else}}
			<div class="text grey tw-mt-2">{{ctx.Locale.Tr "actions.scoped_workflows.no_files"}}</div>
		{{end}}
	{{end}}
</div>
{{end}}
