package corporate_patient

import "cpone/models"
import "strconv"

templ ListingData(
    data []models.DashboardPatient,
    listID string,
    hxGet string,
    hxTarget string,
    hxInclude string,
    hxSwap string,
) {
    <div id={listID} class="align-items-center py-8 flex-column">
        <div class="bg-field rounded">
            <div class="p-8">
                for i, d := range data {
                    if i == (len(data) - 1) {
                        <div id={ strconv.Itoa(d.T_OrderHeaderID) } class="card shadow p-8">
                            @ItemCard(d,
                                hxGet,
                                hxTarget,
                                hxInclude,
                                hxSwap,
                            )
                        </div>
                    } else {
                        <div id={ strconv.Itoa(d.T_OrderHeaderID) } class="card shadow p-8 mb-8">
                            @ItemCard(d,
                                hxGet,
                                hxTarget,
                                hxInclude,
                                hxSwap,
                            )
                        </div>                    
                    }
                }
            </div>
        </div>
    </div>
}

templ ItemCard(
    data models.DashboardPatient,
    hxGet string,
    hxTarget string,
    hxInclude string,
    hxSwap string,
) {
    <div class="row d-flex align-items-center">
        <div class="col-8">
            <h4 class="text-black">{ data.T_OrderHeaderLabNumber }</h4>
        </div>
        <div class="col-3" style="text-align: right;">
            <h4 class="text-black">{ data.T_OrderHeaderDate }</h4>
        </div>
        <div class="col-1">
            <a 
                type="button"
                class="btncetak"
                hx-get={ hxGet +"?id=" + strconv.Itoa(data.T_OrderHeaderID) }
                hx-target={ hxTarget }
                hx-swap={ hxSwap }
                hx-include={ hxInclude }			    
            >
                <i class="flaticon-doc"></i>
            </a>
        </div>
    </div>
}

script HandleBeforeRequestRow(id string) {
	var cusid_ele = document.getElementsByClassName('btncetak');
	for (var i = 0; i < cusid_ele.length; ++i) {
		var item = cusid_ele[i];  
		item.classList.add('disabled');
	}
	console.log(id)
}

script HandleAfterRequestRow(id string) {
	var cusid_ele = document.getElementsByClassName('btncetak');
	for (var i = 0; i < cusid_ele.length; ++i) {
		var item = cusid_ele[i];  
		item.classList.remove('disabled');
	}
	console.log(id)    
}