<!--
Copyright (C) 2024 Nicola Murino

This WebUI uses the KeenThemes Mega Bundle, a proprietary theme:

https://keenthemes.com/products/templates-mega-bundle

KeenThemes HTML/CSS/JS components are allowed for use only within the
SFTPGo product and restricted to be used in a resealable HTML template
that can compete with KeenThemes products anyhow.

This WebUI is allowed for use only within the SFTPGo product and
therefore cannot be used in derivative works/products without an
explicit grant from the SFTPGo Team (support@sftpgo.com).
-->
{{template "base" .}}

{{- define "page_body"}}
<div class="card shadow-sm">
    <div class="card-header bg-light">
        <h3 data-i18n="{{.Title}}" class="card-title section-title"></h3>
    </div>
    <div class="card-body">
        {{- template "errmsg" .Error}}
        <form id="eventrule_form" action="{{.CurrentURL}}" method="POST" autocomplete="off">

            <div class="form-group row">
                <label for="idName" data-i18n="general.name" class="col-md-3 col-form-label">Name</label>
                <div class="col-md-9">
                    <input id="idName" type="text" placeholder="" name="name" value="{{.Rule.Name}}" maxlength="255" autocomplete="off"
                        spellcheck="false" required {{if eq .Mode 2}}class="form-control-plaintext readonly-input" readonly{{else}}class="form-control"{{end}} />
                </div>
            </div>

            <div class="form-group row mt-10">
                <label for="idStatus" data-i18n="general.status" class="col-md-3 col-form-label">Status</label>
                <div class="col-md-9">
                    <select id="idStatus" name="status" class="form-select" data-control="i18n-select2" data-hide-search="true">
                        <option data-i18n="general.active" value="1" {{- if eq .Rule.Status 1 }} selected{{- end}}>Active</option>
                        <option data-i18n="general.inactive" value="0" {{- if eq .Rule.Status 0 }} selected{{- end}}>Inactive</option>
                    </select>
                </div>
            </div>

            <div class="form-group row mt-10">
                <label for="idDescription" data-i18n="general.description" class="col-md-3 col-form-label">Description</label>
                <div class="col-md-9">
                    <input id="idDescription" type="text" class="form-control" name="description" value="{{.Rule.Description}}" maxlength="255">
                </div>
            </div>

            <div class="form-group row mt-10">
                <label for="idTrigger" data-i18n="rules.trigger" class="col-md-3 col-form-label">Trigger</label>
                <div class="col-md-9">
                    <select id="idTrigger" name="trigger" class="form-select" data-control="i18n-select2" data-hide-search="true">
                        {{- range .TriggerTypes}}
                        <option value="{{.Value}}" {{if eq $.Rule.Trigger .Value }}selected{{end}} data-i18n="{{.Name}}"></option>
                        {{- end}}
                    </select>
                </div>
            </div>

            <div class="form-group row trigger trigger-fs mt-10">
                <label for="idFsEvents" data-i18n="rules.triggers.fs_events" class="col-md-3 col-form-label">Fs events</label>
                <div class="col-md-9">
                    <select id="idFsEvents" name="fs_events" class="form-select" data-control="i18n-select2" data-hide-search="true" data-close-on-select="false" multiple>
                        {{- range $event := .FsEvents}}
                        <option value="{{$event}}" {{- range $.Rule.Conditions.FsEvents }}{{- if eq . $event}}selected{{- end}}{{- end}}>{{$event}}</option>
                        {{- end}}
                    </select>
                </div>
            </div>

            <div class="form-group row trigger trigger-provider mt-10">
                <label for="idProviderEvents" data-i18n="rules.triggers.provider_events" class="col-md-3 col-form-label">Provider events</label>
                <div class="col-md-9">
                    <select id="idProviderEvents" name="provider_events" class="form-select" data-control="i18n-select2" data-hide-search="true" data-close-on-select="false" multiple>
                        {{- range $event := .ProviderEvents}}
                        <option value="{{$event}}" {{- range $.Rule.Conditions.ProviderEvents }}{{- if eq . $event}}selected{{- end}}{{- end}}>{{$event}}</option>
                        {{- end}}
                    </select>
                </div>
            </div>

            <div class="form-group row trigger trigger-idp mt-10">
                <label for="idIDPEvent" data-i18n="general.type" class="col-md-3 col-form-label">IDP Login event</label>
                <div class="col-md-9">
                    <select id="idIDPEvent" name="idp_login_event" class="form-select" data-control="i18n-select2" data-hide-search="true">
                        <option value="0" data-i18n="ip_list.any" {{if eq .Rule.Conditions.IDPLoginEvent 0}}selected{{end}}>Any</option>
                        <option value="1" data-i18n="rules.idp_logins.user" {{if eq .Rule.Conditions.IDPLoginEvent 1}}selected{{end}}>User login</option>
                        <option value="2" data-i18n="rules.idp_logins.admin" {{if eq .Rule.Conditions.IDPLoginEvent 2}}selected{{end}}>Admin login</option>
                    </select>
                </div>
            </div>

            <div class="card trigger trigger-schedule mt-10">
                <div class="card-header bg-light">
                    <h3 data-i18n="rules.triggers.schedule" class="card-title section-title-inner">Schedules</h3>
                </div>
                <div class="card-body">
                    <div id="schedules">
                        {{- template "infomsg-no-mb" "rules.scheduler_help"}}
                        <div class="form-group">
                            <div data-repeater-list="schedules">
                                {{- range $idx, $val := .Rule.Conditions.Schedules}}
                                <div data-repeater-item>
                                    <div data-repeater-item>
                                        <div class="form-group row">
                                            <div class="col-md-3 mt-3 mt-md-8">
                                                <input data-i18n="[placeholder]general.hour" type="text" class="form-control" name="schedule_hour" value="{{$val.Hours}}" />
                                            </div>
                                            <div class="col-md-3 mt-3 mt-md-8">
                                                <input data-i18n="[placeholder]general.day_of_week" type="text" class="form-control" name="schedule_day_of_week" value="{{$val.DayOfWeek}}" />
                                            </div>
                                            <div class="col-md-3 mt-3 mt-md-8">
                                                <input data-i18n="[placeholder]general.day_of_month" type="text" class="form-control" name="schedule_day_of_month" value="{{$val.DayOfMonth}}" />
                                            </div>
                                            <div class="col-md-2 mt-3 mt-md-8">
                                                <input data-i18n="[placeholder]general.month" type="text" class="form-control" name="schedule_month" value="{{$val.Month}}" />
                                            </div>
                                            <div class="col-md-1 mt-3 mt-md-8">
                                                <a href="#" data-repeater-delete
                                                    class="btn btn-light-danger ps-5 pe-4">
                                                    <i class="ki-duotone ki-trash fs-2">
                                                        <span class="path1"></span>
                                                        <span class="path2"></span>
                                                        <span class="path3"></span>
                                                        <span class="path4"></span>
                                                        <span class="path5"></span>
                                                    </i>
                                                </a>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                {{- else}}
                                <div data-repeater-item>
                                    <div class="form-group row">
                                        <div class="col-md-3 mt-3 mt-md-8">
                                            <input data-i18n="[placeholder]general.hour" type="text" class="form-control" name="schedule_hour" value="" />
                                        </div>
                                        <div class="col-md-3 mt-3 mt-md-8">
                                            <input data-i18n="[placeholder]general.day_of_week" type="text" class="form-control" name="schedule_day_of_week" value="" />
                                        </div>
                                        <div class="col-md-3 mt-3 mt-md-8">
                                            <input data-i18n="[placeholder]general.day_of_month" type="text" class="form-control" name="schedule_day_of_month" value="" />
                                        </div>
                                        <div class="col-md-2 mt-3 mt-md-8">
                                            <input data-i18n="[placeholder]general.month" type="text" class="form-control" name="schedule_month" value="" />
                                        </div>
                                        <div class="col-md-1 mt-3 mt-md-8">
                                            <a href="#" data-repeater-delete
                                                class="btn btn-light-danger ps-5 pe-4">
                                                <i class="ki-duotone ki-trash fs-2">
                                                    <span class="path1"></span>
                                                    <span class="path2"></span>
                                                    <span class="path3"></span>
                                                    <span class="path4"></span>
                                                    <span class="path5"></span>
                                                </i>
                                            </a>
                                        </div>
                                    </div>
                                </div>
                                {{- end}}
                            </div>
                        </div>

                        <div class="form-group mt-5">
                            <a href="#" data-repeater-create class="btn btn-light-primary">
                                <i class="ki-duotone ki-plus fs-3"></i>
                                <span data-i18n="general.add">Add</span>
                            </a>
                        </div>
                    </div>
                </div>
            </div>

            {{- if .IsShared}}
            <div class="form-group row align-items-center trigger trigger-schedule mt-10">
                <div class="col-md-12">
                    <div class="form-check form-switch form-check-custom form-check-solid">
                        <input class="form-check-input" type="checkbox" id="idConcurrentExecution" name="concurrent_execution" {{if .Rule.Conditions.Options.ConcurrentExecution}}checked{{end}}/>
                        <label data-i18n="rules.concurrent_run" class="form-check-label fw-semibold text-gray-800" for="idConcurrentExecution">
                            Concurrent execution
                        </label>
                    </div>
                </div>
            </div>
            {{- end}}

            <div class="form-group row trigger trigger-fs mt-10">
                <label for="idFsProtocols" data-i18n="rules.protocol_filters" class="col-md-3 col-form-label">Protocol filters</label>
                <div class="col-md-9">
                    <select id="idFsProtocols" name="fs_protocols" class="form-select" data-control="i18n-select2" data-close-on-select="false" multiple aria-describedby="idFsProtocolsHelp">
                        {{- range $p := .Protocols}}
                        <option value="{{$p}}" {{- range $.Rule.Conditions.Options.Protocols }}{{- if eq . $p}}selected{{- end}}{{- end}}>{{$p}}</option>
                        {{- end}}
                    </select>
                    <div id="idFsProtocolsHelp" data-i18n="rules.no_filter" class="form-text"></div>
                </div>
            </div>

            <div class="form-group row trigger trigger-provider mt-10">
                <label for="idProviderObjects" data-i18n="rules.object_filters" class="col-md-3 col-form-label">Object filters</label>
                <div class="col-md-9">
                    <select id="idProviderObjects" name="provider_objects" class="form-select" data-control="i18n-select2" data-close-on-select="false" multiple aria-describedby="idProviderObjectsHelp">
                        {{- range $p := .ProviderObjects}}
                        <option value="{{$p}}" {{- range $.Rule.Conditions.Options.ProviderObjects }}{{- if eq . $p}}selected{{- end}}{{- end}}>{{$p}}</option>
                        {{- end}}
                    </select>
                    <div id="idProviderObjectsHelp" data-i18n="rules.no_filter" class="form-text"></div>
                </div>
            </div>

            <div class="card trigger trigger-fs trigger-provider trigger-schedule trigger-on-demand trigger-idp mt-10">
                <div class="card-header bg-light">
                    <h3 data-i18n="rules.name_filters" class="card-title section-title-inner">Name filters</h3>
                </div>
                <div class="card-body">
                    <div id="name_filters">
                        {{- template "infomsg-no-mb" "rules.name_filters_help"}}
                        <div class="form-group">
                            <div data-repeater-list="name_filters">
                                {{- range $idx, $val := .Rule.Conditions.Options.Names}}
                                <div data-repeater-item>
                                    <div data-repeater-item>
                                        <div class="form-group row">
                                            <div class="col-md-7 mt-3 mt-md-8">
                                                <input type="text" class="form-control" name="name_pattern" value="{{$val.Pattern}}" />
                                            </div>
                                            <div class="col-md-4 mt-3 mt-md-8">
                                                <select name="type_name_pattern" data-i18n="[data-placeholder]general.mode" class="form-select select-repetear" data-hide-search="true" data-allow-clear="true">
                                                    <option value=""></option>
                                                    <option value="inverse" data-i18n="rules.inverse_match" {{if $val.InverseMatch}}selected{{end}}>Inverse match</option>
                                                </select>
                                            </div>
                                            <div class="col-md-1 mt-3 mt-md-8">
                                                <a href="#" data-repeater-delete
                                                    class="btn btn-light-danger ps-5 pe-4">
                                                    <i class="ki-duotone ki-trash fs-2">
                                                        <span class="path1"></span>
                                                        <span class="path2"></span>
                                                        <span class="path3"></span>
                                                        <span class="path4"></span>
                                                        <span class="path5"></span>
                                                    </i>
                                                </a>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                {{- else}}
                                <div data-repeater-item>
                                    <div class="form-group row">
                                        <div class="col-md-7 mt-3 mt-md-8">
                                            <input type="text" class="form-control" name="name_pattern" value="" />
                                        </div>
                                        <div class="col-md-4 mt-3 mt-md-8">
                                            <select name="type_name_pattern" data-i18n="[data-placeholder]general.mode" class="form-select select-repetear" data-hide-search="true" data-allow-clear="true">
                                                <option value=""></option>
                                                <option value="inverse" data-i18n="rules.inverse_match">Inverse match</option>
                                            </select>
                                        </div>
                                        <div class="col-md-1 mt-3 mt-md-8">
                                            <a href="#" data-repeater-delete
                                                class="btn btn-light-danger ps-5 pe-4">
                                                <i class="ki-duotone ki-trash fs-2">
                                                    <span class="path1"></span>
                                                    <span class="path2"></span>
                                                    <span class="path3"></span>
                                                    <span class="path4"></span>
                                                    <span class="path5"></span>
                                                </i>
                                            </a>
                                        </div>
                                    </div>
                                </div>
                                {{- end}}
                            </div>
                        </div>

                        <div class="form-group mt-5">
                            <a href="#" data-repeater-create class="btn btn-light-primary">
                                <i class="ki-duotone ki-plus fs-3"></i>
                                <span data-i18n="general.add">Add</span>
                            </a>
                        </div>
                    </div>
                </div>
            </div>

            <div class="card trigger trigger-fs trigger-schedule trigger-on-demand mt-10">
                <div class="card-header bg-light">
                    <h3 data-i18n="rules.group_name_filters" class="card-title section-title-inner">Group name filters</h3>
                </div>
                <div class="card-body">
                    <div id="group_name_filters">
                        {{- template "infomsg-no-mb" "rules.group_name_filters_help"}}
                        <div class="form-group">
                            <div data-repeater-list="group_name_filters">
                                {{- range $idx, $val := .Rule.Conditions.Options.GroupNames}}
                                <div data-repeater-item>
                                    <div data-repeater-item>
                                        <div class="form-group row">
                                            <div class="col-md-7 mt-3 mt-md-8">
                                                <input type="text" class="form-control" name="group_name_pattern" value="{{$val.Pattern}}" />
                                            </div>
                                            <div class="col-md-4 mt-3 mt-md-8">
                                                <select name="type_group_name_pattern" data-i18n="[data-placeholder]general.mode" class="form-select select-repetear" data-hide-search="true" data-allow-clear="true">
                                                    <option value=""></option>
                                                    <option value="inverse" data-i18n="rules.inverse_match" {{if $val.InverseMatch}}selected{{end}}>Inverse match</option>
                                                </select>
                                            </div>
                                            <div class="col-md-1 mt-3 mt-md-8">
                                                <a href="#" data-repeater-delete
                                                    class="btn btn-light-danger ps-5 pe-4">
                                                    <i class="ki-duotone ki-trash fs-2">
                                                        <span class="path1"></span>
                                                        <span class="path2"></span>
                                                        <span class="path3"></span>
                                                        <span class="path4"></span>
                                                        <span class="path5"></span>
                                                    </i>
                                                </a>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                {{- else}}
                                <div data-repeater-item>
                                    <div class="form-group row">
                                        <div class="col-md-7 mt-3 mt-md-8">
                                            <input type="text" class="form-control" name="group_name_pattern" value="" />
                                        </div>
                                        <div class="col-md-4 mt-3 mt-md-8">
                                            <select name="type_group_name_pattern" data-i18n="[data-placeholder]general.mode" class="form-select select-repetear" data-hide-search="true" data-allow-clear="true">
                                                <option value=""></option>
                                                <option value="inverse" data-i18n="rules.inverse_match">Inverse match</option>
                                            </select>
                                        </div>
                                        <div class="col-md-1 mt-3 mt-md-8">
                                            <a href="#" data-repeater-delete
                                                class="btn btn-light-danger ps-5 pe-4">
                                                <i class="ki-duotone ki-trash fs-2">
                                                    <span class="path1"></span>
                                                    <span class="path2"></span>
                                                    <span class="path3"></span>
                                                    <span class="path4"></span>
                                                    <span class="path5"></span>
                                                </i>
                                            </a>
                                        </div>
                                    </div>
                                </div>
                                {{- end}}
                            </div>
                        </div>

                        <div class="form-group mt-5">
                            <a href="#" data-repeater-create class="btn btn-light-primary">
                                <i class="ki-duotone ki-plus fs-3"></i>
                                <span data-i18n="general.add">Add</span>
                            </a>
                        </div>
                    </div>
                </div>
            </div>

            <div class="card trigger trigger-fs trigger-schedule trigger-provider trigger-on-demand mt-10">
                <div class="card-header bg-light">
                    <h3 data-i18n="rules.role_name_filters" class="card-title section-title-inner">Role name filters</h3>
                </div>
                <div class="card-body">
                    <div id="role_name_filters">
                        {{- template "infomsg-no-mb" "rules.role_name_filters_help"}}
                        <div class="form-group">
                            <div data-repeater-list="role_name_filters">
                                {{- range $idx, $val := .Rule.Conditions.Options.RoleNames}}
                                <div data-repeater-item>
                                    <div data-repeater-item>
                                        <div class="form-group row">
                                            <div class="col-md-7 mt-3 mt-md-8">
                                                <input type="text" class="form-control" name="role_name_pattern" value="{{$val.Pattern}}" />
                                            </div>
                                            <div class="col-md-4 mt-3 mt-md-8">
                                                <select name="type_role_name_pattern" data-i18n="[data-placeholder]general.mode" class="form-select select-repetear" data-hide-search="true" data-allow-clear="true">
                                                    <option value=""></option>
                                                    <option value="inverse" data-i18n="rules.inverse_match" {{if $val.InverseMatch}}selected{{end}}>Inverse match</option>
                                                </select>
                                            </div>
                                            <div class="col-md-1 mt-3 mt-md-8">
                                                <a href="#" data-repeater-delete
                                                    class="btn btn-light-danger ps-5 pe-4">
                                                    <i class="ki-duotone ki-trash fs-2">
                                                        <span class="path1"></span>
                                                        <span class="path2"></span>
                                                        <span class="path3"></span>
                                                        <span class="path4"></span>
                                                        <span class="path5"></span>
                                                    </i>
                                                </a>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                {{- else}}
                                <div data-repeater-item>
                                    <div class="form-group row">
                                        <div class="col-md-7 mt-3 mt-md-8">
                                            <input type="text" class="form-control" name="role_name_pattern" value="" />
                                        </div>
                                        <div class="col-md-4 mt-3 mt-md-8">
                                            <select name="type_role_name_pattern" data-i18n="[data-placeholder]general.mode" class="form-select select-repetear" data-hide-search="true" data-allow-clear="true">
                                                <option value=""></option>
                                                <option value="inverse" data-i18n="rules.inverse_match">Inverse match</option>
                                            </select>
                                        </div>
                                        <div class="col-md-1 mt-3 mt-md-8">
                                            <a href="#" data-repeater-delete
                                                class="btn btn-light-danger ps-5 pe-4">
                                                <i class="ki-duotone ki-trash fs-2">
                                                    <span class="path1"></span>
                                                    <span class="path2"></span>
                                                    <span class="path3"></span>
                                                    <span class="path4"></span>
                                                    <span class="path5"></span>
                                                </i>
                                            </a>
                                        </div>
                                    </div>
                                </div>
                                {{- end}}
                            </div>
                        </div>

                        <div class="form-group mt-5">
                            <a href="#" data-repeater-create class="btn btn-light-primary">
                                <i class="ki-duotone ki-plus fs-3"></i>
                                <span data-i18n="general.add">Add</span>
                            </a>
                        </div>
                    </div>
                </div>
            </div>

            <div class="card trigger trigger-fs mt-10">
                <div class="card-header bg-light">
                    <h3 data-i18n="rules.path_filters" class="card-title section-title-inner">Path filters</h3>
                </div>
                <div class="card-body">
                    <div id="path_filters">
                        {{- template "infomsg-no-mb" "rules.path_filters_help"}}
                        <div class="form-group">
                            <div data-repeater-list="path_filters">
                                {{- range $idx, $val := .Rule.Conditions.Options.FsPaths}}
                                <div data-repeater-item>
                                    <div data-repeater-item>
                                        <div class="form-group row">
                                            <div class="col-md-7 mt-3 mt-md-8">
                                                <input type="text" class="form-control" name="fs_path_pattern" value="{{$val.Pattern}}" />
                                            </div>
                                            <div class="col-md-4 mt-3 mt-md-8">
                                                <select name="type_fs_path_pattern" data-i18n="[data-placeholder]general.mode" class="form-select select-repetear" data-hide-search="true" data-allow-clear="true">
                                                    <option value=""></option>
                                                    <option value="inverse" data-i18n="rules.inverse_match" {{if $val.InverseMatch}}selected{{end}}>Inverse match</option>
                                                </select>
                                            </div>
                                            <div class="col-md-1 mt-3 mt-md-8">
                                                <a href="#" data-repeater-delete
                                                    class="btn btn-light-danger ps-5 pe-4">
                                                    <i class="ki-duotone ki-trash fs-2">
                                                        <span class="path1"></span>
                                                        <span class="path2"></span>
                                                        <span class="path3"></span>
                                                        <span class="path4"></span>
                                                        <span class="path5"></span>
                                                    </i>
                                                </a>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                {{- else}}
                                <div data-repeater-item>
                                    <div class="form-group row">
                                        <div class="col-md-7 mt-3 mt-md-8">
                                            <input type="text" class="form-control" name="fs_path_pattern" value="" />
                                        </div>
                                        <div class="col-md-4 mt-3 mt-md-8">
                                            <select name="type_fs_path_pattern" data-i18n="[data-placeholder]general.mode" class="form-select select-repetear" data-hide-search="true" data-allow-clear="true">
                                                <option value=""></option>
                                                <option value="inverse" data-i18n="rules.inverse_match">Inverse match</option>
                                            </select>
                                        </div>
                                        <div class="col-md-1 mt-3 mt-md-8">
                                            <a href="#" data-repeater-delete
                                                class="btn btn-light-danger ps-5 pe-4">
                                                <i class="ki-duotone ki-trash fs-2">
                                                    <span class="path1"></span>
                                                    <span class="path2"></span>
                                                    <span class="path3"></span>
                                                    <span class="path4"></span>
                                                    <span class="path5"></span>
                                                </i>
                                            </a>
                                        </div>
                                    </div>
                                </div>
                                {{- end}}
                            </div>
                        </div>

                        <div class="form-group mt-5">
                            <a href="#" data-repeater-create class="btn btn-light-primary">
                                <i class="ki-duotone ki-plus fs-3"></i>
                                <span data-i18n="general.add">Add</span>
                            </a>
                        </div>
                    </div>
                </div>
            </div>

            <div class="card trigger trigger-fs mt-10">
                <div class="card-header bg-light">
                    <h3 data-i18n="rules.file_size_limits" class="card-title section-title-inner">
                        File size limits
                    </h3>
                </div>
                <div class="card-body">
                    {{- template "infomsg" "rules.file_size_limits_help"}}
                    <div class="form-group row">
                        <label for="idFsMinSize" data-i18n="rules.min_size" class="col-md-3 col-form-label">Min size</label>
                        <div class="col-md-3">
                            <input id="idFsMinSize" type="text" class="form-control" name="fs_min_size" value="{{HumanizeBytes .Rule.Conditions.Options.MinFileSize}}" />
                        </div>
                        <div class="col-md-1"></div>
                        <label for="idFsMaxSize" data-i18n="rules.max_size" class="col-md-2 col-form-label">Max size</label>
                        <div class="col-md-3">
                            <input id="idFsMaxSize" type="text" class="form-control" name="fs_max_size" value="{{HumanizeBytes .Rule.Conditions.Options.MaxFileSize}}" />
                        </div>
                    </div>
                </div>
            </div>

            <div class="card mt-10">
                <div class="card-header bg-light">
                    <h3 data-i18n="title.event_actions" class="card-title section-title-inner">Actions</h3>
                </div>
                <div class="card-body">
                    <div id="actions">
                        {{- template "infomsg-no-mb" "rules.actions_help"}}
                        <div class="form-group">
                            <div data-repeater-list="actions">
                                {{- range $idx, $val := .Rule.Actions}}
                                <div data-repeater-item>
                                    <div data-repeater-item>
                                        <div class="form-group row">
                                            <div class="col-md-6 mt-3 mt-md-8">
                                                <select name="action_name" data-i18n="[data-placeholder]rules.action_placeholder" class="form-select select-repetear" data-allow-clear="true">
                                                    <option value=""></option>
                                                    {{- range $.Actions}}
                                                    <option value="{{.Name}}" {{if eq $val.Name .Name}}selected{{end}}>{{.Name}}</option>
                                                    {{- end}}
                                                </select>
                                            </div>
                                            <div class="col-md-5 mt-3 mt-md-8">
                                                <select name="action_options" class="form-select select-repetear" data-i18n="[data-placeholder]general.options" data-close-on-select="false" data-allow-clear="true" data-hide-search="true" multiple>
                                                    <option value=""></option>
                                                    <option value="2" data-i18n="rules.option_stop_on_failure" {{if $val.Options.StopOnFailure}}selected{{end}}>Stop on failure</option>
                                                    <option value="3" data-i18n="rules.option_execute_sync" {{if $val.Options.ExecuteSync}}selected{{end}}>Execute sync</option>
                                                    <option value="1" data-i18n="rules.option_failure_action" {{if $val.Options.IsFailureAction}}selected{{end}}>Is failure action</option>
                                                </select>
                                            </div>
                                            <div class="col-md-1 mt-3 mt-md-8">
                                                <a href="#" data-repeater-delete
                                                    class="btn btn-light-danger ps-5 pe-4">
                                                    <i class="ki-duotone ki-trash fs-2">
                                                        <span class="path1"></span>
                                                        <span class="path2"></span>
                                                        <span class="path3"></span>
                                                        <span class="path4"></span>
                                                        <span class="path5"></span>
                                                    </i>
                                                </a>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                {{- else}}
                                <div data-repeater-item>
                                    <div class="form-group row">
                                        <div class="col-md-6 mt-3 mt-md-8">
                                            <select name="action_name" data-i18n="[data-placeholder]rules.action_placeholder" class="form-select select-repetear" data-allow-clear="true">
                                                <option value=""></option>
                                                {{- range $.Actions}}
                                                <option value="{{.Name}}">{{.Name}}</option>
                                                {{- end}}
                                            </select>
                                        </div>
                                        <div class="col-md-5 mt-3 mt-md-8">
                                            <select name="action_options" class="form-select select-repetear" data-i18n="[data-placeholder]general.options" data-close-on-select="false" data-allow-clear="true" data-hide-search="true" multiple>
                                                <option value=""></option>
                                                <option value="2" data-i18n="rules.option_stop_on_failure">Stop on failure</option>
                                                <option value="3" data-i18n="rules.option_execute_sync">Execute sync</option>
                                                <option value="1" data-i18n="rules.option_failure_action">Is failure action</option>
                                            </select>
                                        </div>
                                        <div class="col-md-1 mt-3 mt-md-8">
                                            <a href="#" data-repeater-delete
                                                class="btn btn-light-danger ps-5 pe-4">
                                                <i class="ki-duotone ki-trash fs-2">
                                                    <span class="path1"></span>
                                                    <span class="path2"></span>
                                                    <span class="path3"></span>
                                                    <span class="path4"></span>
                                                    <span class="path5"></span>
                                                </i>
                                            </a>
                                        </div>
                                    </div>
                                </div>
                                {{- end}}
                            </div>
                        </div>

                        <div class="form-group mt-5">
                            <a href="#" data-repeater-create class="btn btn-light-primary">
                                <i class="ki-duotone ki-plus fs-3"></i>
                                <span data-i18n="general.add">Add</span>
                            </a>
                        </div>
                    </div>
                </div>
            </div>

            <div class="d-flex justify-content-end mt-12">
                <input type="hidden" name="_form_token" value="{{.CSRFToken}}">
                <button type="submit" id="form_submit" class="btn btn-primary px-10" name="form_action" value="submit">
                    <span data-i18n="general.submit" class="indicator-label">
                        Submit
                    </span>
                    <span data-i18n="general.wait" class="indicator-progress">
                        Please wait...
                        <span class="spinner-border spinner-border-sm align-middle ms-2"></span>
                    </span>
                </button>
            </div>

        </form>
    </div>
</div>
{{- end}}

{{- define "extra_js"}}
<script {{- if .CSPNonce}} nonce="{{.CSPNonce}}"{{- end}} src="{{.StaticURL}}/assets/plugins/custom/formrepeater/formrepeater.bundle.js"></script>
<script type="text/javascript" {{- if .CSPNonce}} nonce="{{.CSPNonce}}"{{- end}}>
    function onTriggerChanged(val){
        $('.trigger').hide();
        switch (val) {
            case '1':
                $('.trigger-fs').show();
                break;
            case '2':
                $('.trigger-provider').show();
                break;
            case '3':
                $('.trigger-schedule').show();
                break;
            case '4':
            case '5':
                break;
            case '6':
                $('.trigger-on-demand').show();
                break;
            case '7':
                $('.trigger-idp').show();
                break;
            default:
                console.log(`unsupported event trigger type: ${val}`);
        }
    }

    $(document).on("i18nload", function(){
        onTriggerChanged('{{.Rule.Trigger}}');
    });

    $(document).on("i18nshow", function(){
        initRepeater('#schedules');
        initRepeater('#name_filters');
        initRepeater('#group_name_filters');
        initRepeater('#role_name_filters');
        initRepeater('#path_filters');
        initRepeater('#actions');
        initRepeaterItems();

        $('#idTrigger').on("change", function(){
            onTriggerChanged(this.value);
        });

        $('#eventrule_form').submit(function (event) {
			let submitButton = document.querySelector('#form_submit');
			submitButton.setAttribute('data-kt-indicator', 'on');
			submitButton.disabled = true;
        });
    });
</script>
{{- end}}