package groupresult

import (
	"cpone/models"
	"cpone/component/customtextfield"
	"cpone/component/customcheckbox"
	"cpone/component/customdropdown"
)

templ DialogNewBodyV1(inputId models.CustomTextFieldv2Prm,
	inputGrName models.CustomTextFieldv2Prm,
	checkboxGrFlagPerTest models.CustomCheckboxv1Prm,
	checkboxGrFlagNonLab models.CustomCheckboxv1Prm,
	dropdownGrResumeMcu models.CustomDropdownv1Prm,
	listItem templ.Component,
	componentID string,
	hxOnLoad templ.ComponentScript) {
	<div id={ componentID } hx-on::load={ hxOnLoad }>
		@customtextfield.CustomTextFieldv2(
			inputId)
		@customtextfield.CustomTextFieldv2(
			inputGrName)
		@customcheckbox.MainCustomCheckboxInput(
			checkboxGrFlagPerTest)
		@customcheckbox.MainCustomCheckboxInput(
			checkboxGrFlagNonLab)
		@customdropdown.MainCustomDropdownInput(
			dropdownGrResumeMcu,
			listItem)
	</div>
	<script>
    document.addEventListener('htmx:afterSwap', function(event) {
        // Reinitialize selectpicker after HTMX content swap
        $('.selectpicker').selectpicker('refresh');
    });
    </script>
}

script HandleJSModalAddGR(modalID string) {
	$(modalID).modal('hide');
}

script HandleJSModalAddGRShow(modalID string) {
	$(modalID).modal('show')
}

templ DialogNewActionV1(LinkClose string, targetClose string, hxSwapClose string, modalID string) {
	<div>
		<button
			hx-on::after-request={ HandleJSModalAddGR(modalID) }
			hx-post={ LinkClose }
			hx-target={ targetClose }
			hx-swap={ hxSwapClose }
			type="button"
			class="btn btn-outline-secondary font-weight-bolder rounded-lg mr-4 btnaddact"
			data-dismiss="modal"
		>
			Batal
		</button>
		<button
			type="submit"
			class="btn btn-primary btn-shadow font-weight-bold rounded-lg btnaddact"
		>
			Save
		</button>
	</div>
}

templ DialogNewAction() {
	<div>
		<button
			type="button"
			class="btn btn-outline-secondary font-weight-bolder rounded-lg mr-4"
			data-dismiss="modal"
		>
			Batal
		</button>
		<button
			type="submit"
			class="btn btn-primary btn-shadow font-weight-bold rounded-lg"
		>
			Save changes
		</button>
	</div>
}

templ BtnCloseNew() {
	<button
		type="button"
		class="close"
		data-dismiss="modal"
		aria-label="Close"
	>
		<i aria-hidden="true" class="ki ki-close"></i>
	</button>
}

templ BtnCloseNewV1(LinkClose string, targetClose string, hxSwapClose string, modalID string) {
	<button
		hx-post={ LinkClose }
		hx-target={ targetClose }
		hx-swap={ hxSwapClose }
		type="button"
		hx-on::after-request={ HandleJSModalAddGR(modalID) }
		class="close btnaddact"
		data-dismiss="modal"
		aria-label="Close"
	>
		<i aria-hidden="true" class="ki ki-close"></i>
	</button>
}
