package components

import (
	"go.alanpearce.eu/searchix/internal/index"
	"go.alanpearce.eu/searchix/internal/nix"
)

templ Packages(result *index.Result) {
	<table>
		<thead>
			<tr>
				<th scope="col">Attribute</th>
				<th scope="col">Name</th>
				<th scope="col">Description</th>
			</tr>
		</thead>
		<tbody>
			for _, hit := range result.Hits {
				if m := convertMatch[nix.Package](hit.Data); m != nil {
					@packageRow(*m)
				}
			}
		</tbody>
	</table>
}

templ packageRow(p nix.Package) {
	<tr>
		<td>
			@openDialogLink(p.Attribute)
		</td>
		<td>
			{ p.Name }
		</td>
		<td>
			{ p.Description }
		</td>
	</tr>
}