{{ define "title" }}Channels - Intake{{ end }}

{{ define "content" -}}
<nav class="center">
    <span class="feed-controls">
    <a href="/">Home</a>
    </span>
</nav>

<nav>
<span class="feed-controls">Edit channels</span>

<p>
<form>
    <label for="source">Add</label>
    <select name="source">{{ range .Sources }}
        <option value="{{ . }}">{{ . }}</option>{{ end }}
    </select>
    <label for="channel">to</label>
    <input type="text" name="channel" list="channel-options">
    <button
        hx-post="/channel/"
    >Submit</button>
</form>
</p>

<datalist id="channel-options">{{ range $channel, $_ := .ChannelSources }}
    <option value="{{ $channel }}"></option>{{ end }}
</datalist>

{{ range $channel, $sources := .ChannelSources }}
{{ if $channel }}
<p><b><a href="/channel/{{ $channel }}">{{ $channel }}</a></b></p>
<table>
{{- range $sources }}
<tr>
<td>
    <button
        hx-delete="/channel/?channel={{ $channel }}&source={{ . }}"
    >&#10005;</button>
</td>
    </form>
<td><a href="/source/{{ . }}">{{ . }}</a></td>
</tr>
{{ end }}
</table>
{{ end }}
{{ end }}

{{ if index .ChannelSources "" }}
<p><b>not in a channel</b></p>
<ul>
{{ range index .ChannelSources "" }}
<li><a href="/source/{{ . }}">{{ . }}</a></li>
{{ end }}
</ul>
{{ end }}
</nav>
{{- end }}