package masterkelainan

import "cpone/models"
import "cpone/component/table"
import "strconv"

templ TableKelainanDetail(data []models.KelainanDetail,
	tableDetailID string,
	hxGetDelete string,
	hxTargetDelete string,
	hxSwapDelete string,
	hxIncludeDelete string,
) {
	<div id={ tableDetailID } hx-swap-oob="true">
		@tablecomponent.TableV3([]string{"NO", "KELAINAN", "AKSI"},
			[]string{"10%", "60%", "30%"},
			TableDetailRow(data,
				hxGetDelete,
				hxTargetDelete,
				hxSwapDelete,
				hxIncludeDelete,
			))
	</div>
}

templ TableDetailRow(data []models.KelainanDetail,
	hxGetDelete string,
	hxTargetDelete string,
	hxSwapDelete string,
	hxIncludeDelete string,
) {
	if len(data) == 0 {
		<tr>
			<td colspan="3" class="text-center">Data Tidak Ditemukan</td>
		</tr>
	}
	for _, v := range data {
		<tr>
			<td>{ v.Nomor }</td>
			<td>
				{ v.Mcu_KelainanName }
				if v.Mcu_KelainanClasification != "" {
					<p class="dot-text">{ v.Mcu_KelainanClasification }</p>
				}
			</td>
			<td>
				@TableDetailAction(v.Mcu_KelainanID,
					hxGetDelete,
					hxTargetDelete,
					hxSwapDelete,
					hxIncludeDelete,
				)
			</td>
		</tr>
	}
}

templ TableDetailAction(
	id int,
	hxGetDelete string,
	hxTargetDelete string,
	hxSwapDelete string,
	hxIncludeDelete string,
) {
	<div class="row px-5 d-flex justify-content-around">
		<label class="checkbox">
			<input type="checkbox" name="Checkboxes1"/>
			<span></span>
		</label>
		<a
			id="btndeleteug"
			type="button"
			class=" btndeleteug col-12 col-sm-12 col-md-12 col-lg-5 col-xl-5 col-xxl-5 btn btn-light-danger mb-2"
			hx-get={ hxGetDelete + "?id=" + strconv.Itoa(id) }
			hx-target={ hxTargetDelete }
			hx-swap={ hxSwapDelete }
			hx-include={ hxIncludeDelete }
		>
			Hapus
		</a>
	</div>
}
