{{$isActionsEnabled := .Repository.UnitEnabled ctx ctx.Consts.RepoUnitTypeActions}}
<div class="repo-setting-content">
	<!-- Enable/Disable Actions Section (First) -->
	<h4 class="ui top attached header">
		{{ctx.Locale.Tr "actions.general.enable_actions"}}
	</h4>
	<div class="ui attached segment">
		<form class="ui form" action="{{.Link}}/actions_unit" method="post">
			{{$isActionsGlobalDisabled := ctx.Consts.RepoUnitTypeActions.UnitGlobalDisabled}}
			<div class="inline field">
				<label>{{ctx.Locale.Tr "actions.actions"}}</label>
				<div class="ui checkbox{{if $isActionsGlobalDisabled}} disabled{{end}}"{{if $isActionsGlobalDisabled}} data-tooltip-content="{{ctx.Locale.Tr "repo.unit_disabled"}}"{{end}}>
					<input name="enable_actions" type="checkbox" {{if $isActionsGlobalDisabled}}disabled{{end}} {{if $isActionsEnabled}}checked{{end}}>
					<label>{{ctx.Locale.Tr "repo.settings.actions_desc"}}</label>
				</div>
			</div>
			{{if not $isActionsGlobalDisabled}}
			<div class="divider"></div>
				<div class="field">
				<button class="ui primary button">{{ctx.Locale.Tr "repo.settings.update_settings"}}</button>
			</div>
			{{end}}
		</form>
	</div>

{{if $isActionsEnabled}}
	<!-- Token Permissions Section -->
	<h4 class="ui top attached header">
		{{ctx.Locale.Tr "actions.general.permissions"}}
	</h4>
	<div class="ui attached segment">
		<form class="ui form" action="{{.RepoLink}}/settings/actions/general/token_permissions" method="post" data-global-init="initRepoActionsPermissionsForm">
			<!-- Override Owner Configuration -->
			<div class="field">
				<div class="ui checkbox">
					<input type="checkbox" name="override_owner_config" {{if .OverrideOwnerConfig}}checked{{end}}>
					<label><strong>{{ctx.Locale.Tr "actions.general.token_permissions.override_owner"}}</strong></label>
				</div>
				<div class="help">{{ctx.Locale.Tr "actions.general.token_permissions.override_owner_desc"}}</div>
			</div>

			<div class="divider"></div>

			<div class="field js-repo-token-permissions-config">
				{{template "shared/actions/permission_mode_select" .}}
				<div class="divider"></div>
				{{template "shared/actions/permissions_table" .}}
			</div>

			<div class="field">
				<button class="ui primary button">{{ctx.Locale.Tr "repo.settings.update_settings"}}</button>
			</div>
		</form>
	</div>
{{end}}

{{if $isActionsEnabled}}
	{{if .Repository.IsPrivate}}
	<!-- Collaborative Owners Section -->
	<h4 class="ui top attached header">
		{{ctx.Locale.Tr "actions.general.collaborative_owners_management"}}
	</h4>
	{{if len .CollaborativeOwners}}
	<div class="ui attached segment">
		<div class="flex-list">
			{{range .CollaborativeOwners}}
			<div class="flex-item tw-items-center">
				<div class="flex-item-leading">
					<a href="{{.HomeLink}}">{{ctx.AvatarUtils.Avatar . 32}}</a>
				</div>
				<div class="flex-item-main">
					<div class="flex-item-title">
						{{template "shared/user/name" .}}
					</div>
				</div>
				<div class="flex-item-trailing">
					<button class="ui red tiny button inline link-action"
						data-url="{{$.Link}}/collaborative_owner/delete?id={{.ID}}"
						data-modal-confirm-header="{{ctx.Locale.Tr "actions.general.remove_collaborative_owner"}}"
						data-modal-confirm-content="{{ctx.Locale.Tr "actions.general.remove_collaborative_owner_desc"}}"
					>{{ctx.Locale.Tr "remove"}}</button>
				</div>
			</div>
			{{end}}
		</div>
	</div>
	{{end}}
	<div class="ui bottom attached segment">
		<form class="ui form form-fetch-action" action="{{.Link}}/collaborative_owner/add" method="post">
			<div id="search-user-box" class="ui search input tw-align-middle" data-include-orgs="true">
				<input class="prompt" name="collaborative_owner" placeholder="{{ctx.Locale.Tr "search.user_kind"}}" autocomplete="off" autofocus required>
			</div>
			<button class="ui primary button">{{ctx.Locale.Tr "actions.general.add_collaborative_owner"}}</button>
		</form>
		<br>
		{{ctx.Locale.Tr "actions.general.collaborative_owners_management_help"}}
	</div>
	{{end}}
{{end}}
</div>
