package site

import (
	"fmt"
	datastar "github.com/starfederation/datastar/sdk/go"
)

templ deleteRowContact(cs *ContactActive) {
	<tr id={ fmt.Sprintf("contact_%d", cs.ID) }>
		<td class="text-center">{ cs.Name }</td>
		<td class="text-center">{ cs.Email }</td>
		<td class="text-center">
			if cs.IsActive {
				Active
			} else {
				Inactive
			}
		</td>
		<td class="flex justify-end">
			<button
				class="btn btn-error"
				data-on-click={ fmt.Sprintf(`confirm('Are you sure?') && sse("/examples/delete_row/data/%d", {method:'delete'})`, cs.ID) }
			>
				@icon("material-symbols:delete")
				Delete
			</button>
		</td>
	</tr>
}

templ deleteRowContacts(contacts []*ContactActive) {
	<div id="delete_row" class="flex flex-col gap-8">
		<table class="table w-full table-zebra">
			<caption>Contacts</caption>
			<thead>
				<tr>
					<th>Name</th>
					<th>Email</th>
					<th>Status</th>
					<th class="text-right">Actions</th>
				</tr>
			</thead>
			<tbody>
				for _, cs := range contacts {
					@deleteRowContact(cs)
				}
			</tbody>
		</table>
		<div>
			<button
				class="btn btn-primary"
				data-on-click={ datastar.GetSSE("/examples/delete_row/data/reset") }
			>
				@icon("material-symbols:refresh")
				Reset
			</button>
		</div>
	</div>
}
