{{/*

  This template is used to render tables of MSC proposals.

  It expects there to be a "proposals.json" under /data/msc.
  It expects "proposals.json" to contain an array of objects,
  one for each MSC state. Each object contains:
  * `title`: human-readable title for the state, like "Proposal In Review"
  * `label`: the GitHub label used for the state, like "proposal-in-review"
  * `proposals`: an array of objects, each of which represents an MSC and contains:
      * `number`: GitHub issue number
      * `url`: GitHub URL for this issue
      * `title`: Issue title
      * `created_at`: issue creation date
      * `updated_at`: issue last-updated date
      * `authors`: array of GitHub user names representing authors of this MSC
      * `shepherd`: GitHub user name representing the shepherd of this MSC, or null
      * `documentation`: Links to further documentation referenced in the GitHub issue

  This data is scraped from GitHub using the /scripts/proposals.js Node script.
  The script is run in CI: so typically if you run a local server the data will
  be missing and no tables will be generated. If you do want to see the tables locally,
  you can run the script locally:

    npm install
    npm run get-proposals

  If this template does find the data, it renders one table for each MSC state,
  containing a row for each MSC in that state.

*/}}

{{ $states := .Site.Data.msc.proposals }}

{{ range $states }}
### {{ .title }} {.proposal-table-title}
    {{ if .proposals }}
<table class="msc-table table">
  <thead>
    <tr>
      <th>MSC</th>
      <th>Title</th>
      <th>Created at</th>
      <th>Updated at</th>
      <th>Docs</th>
      <th>Author</th>
      <th>Shepherd</th>
    </tr>
  </thead>

  <tbody>
        {{ range .proposals }}

            {{ $index := 0 }}
            {{ $docs_links_list := slice }}
            {{ range .documentation }}
                {{ $index = add $index 1 }}
                {{ $docs_link := printf "<a href=\"%s\">%d</a>" . $index }}
                {{ $docs_links_list = $docs_links_list | append $docs_link }}
            {{ end }}
            {{ $docs_links := delimit $docs_links_list ", " }}

            {{ $authors_list := apply .authors "printf" "<a href=\"https://github.com/%s\">@%s</a>" "." "." }}
            {{ $authors := delimit $authors_list ", " }}

  <tr>
      <td><a href="{{ .url }}">{{ .number }}</a></td>
      <td>{{ .title }}</td>
      <td>{{ .created_at }}</td>
      <td>{{ .updated_at }}</td>
      <td>{{ with $docs_links }}{{ $docs_links | safeHTML }}{{ end }}</td>
      <td>{{ $authors | safeHTML }}</td>
      <td>{{ with .shepherd }}<a href="https://github.com/{{ . }}">@{{ . }}</a>{{ end }}</td>
  </tr>
        {{ end }}
  </tbody>
</table>
    {{ else }}
<p>No MSCs are currently in this state.</p>
    {{ end }}
{{ end }}
