{{ define "title" }}Choose voters{{ end }}

{{ define "main" }}
    {{ $voterIDs := .Form.VoterIDs }}
    <div class="ui info message">
        <div class="header">Edit voter list</div>
        <p>Use the lists below to add or remove voters.</p>
    </div>
    <div class="ui form segment{{ if .Form.FieldErrors }} error{{ end }}">
        <form action="/voters/" method="post">
            <input type="hidden" name="csrf_token" value="{{ .CSRFToken }}">
            <label class="hidden" aria-label="voters" for="voters">Voters</label>
            <div class="field">
                <select id="voters" name="voters" class="ui fluid search dropdown" multiple aria-multiselectable="true">
                    {{ range .Form.Users }}
                        {{ $userID := .ID }}
                        <option value="{{ .ID }}" {{ range $voterIDs }}{{ if eq $userID . }} selected{{ end }}{{ end }}>{{ .Name }}</option>
                    {{ end }}
                </select>
            </div>
            <div class="required field{{ if .Form.FieldErrors.reasoning }} error{{ end }}">
                <label for="reasoning">Reasoning for the change</label>
                <textarea id="reasoning" name="reasoning" rows="2">{{ .Form.Reasoning }}</textarea>
                {{ if .Form.FieldErrors.reasoning }}
                    <span class="ui small error text">{{ .Form.FieldErrors.reasoning }}</span>
                {{ end }}
            </div>
            <button class="ui primary labeled icon button" type="submit">
                <i class="edit icon"></i>
                Change voters
            </button>
        </form>
    </div>
{{ end }}