package corporate_mcudetail

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


templ ContentLayout(
    tablecomponent templ.Component,
    paginationtable templ.Component,
) {
    <div id="contentlayout" hx-on::load={ AfterRequestContent() }>
        @tablecomponent
        @paginationtable
    </div>
}

templ TableDaftarPeserta(
    data []models.ModelMcuDaftarPeserta,
    tableID string,
    hxGetRpt string,
    hxTargetRpt string,
    hxIncludeRpt string,
    hxSwapRpt string,
    hxGetAcc string,
    hxTargetAcc string,
    hxIncludeAcc string,
    hxSwapAcc string,
    hxGetDetail string,
    hxTargetDetail string,
    hxIncludeDetail string,
    hxSwapDetail string,
) {
    <div id={ tableID }>
        @tablecomponent.TableV3([]string{"NOMOR LAB", "NAMA", "JENIS KELAMIN", "UMUR", "NAMA PAKET", "AKSI"},
            []string{"15%","20%","10%","10%","30%","15%"},
            ItemRow(data,
                hxGetRpt,
                hxTargetRpt,
                hxIncludeRpt,
                hxSwapRpt,
                hxGetAcc,
                hxTargetAcc,
                hxIncludeAcc,
                hxSwapAcc,
                hxGetDetail,
                hxTargetDetail,
                hxIncludeDetail,
                hxSwapDetail,
            ))
    </div>
}

templ ItemRow(
    data []models.ModelMcuDaftarPeserta,
    hxGetRpt string,
    hxTargetRpt string,
    hxIncludeRpt string,
    hxSwapRpt string,
    hxGetAcc string,
    hxTargetAcc string,
    hxIncludeAcc string,
    hxSwapAcc string,
    hxGetDetail string,
    hxTargetDetail string,
    hxIncludeDetail string,
    hxSwapDetail string,
) {
    if len(data) == 0 {
        <tr>
            <td colspan="6" class="text-center">Data Tidak Ditemukan</td>
        </tr>
    }
    for _, v := range data {
        <tr>
            <td>{ v.T_OrderHeaderLabNumber }</td>
            <td>{ v.M_PatientName }</td>
            <td>{ v.JenisKelamin }</td>
            <td>{ v.Age }</td>
            <td>{ v.List_Paket }</td>
            <td>
                @ItemAction(v,
                    hxGetRpt,
                    hxTargetRpt,
                    hxIncludeRpt,
                    hxSwapRpt,
                    hxGetAcc,
                    hxTargetAcc,
                    hxIncludeAcc,
                    hxSwapAcc,
                    hxGetDetail,
                    hxTargetDetail,
                    hxIncludeDetail,
                    hxSwapDetail,
                )
            </td>
        </tr>
    }
}

templ ItemAction(
    data models.ModelMcuDaftarPeserta,
    hxGetRpt string,
    hxTargetRpt string,
    hxIncludeRpt string,
    hxSwapRpt string,
    hxGetAcc string,
    hxTargetAcc string,
    hxIncludeAcc string,
    hxSwapAcc string,
    hxGetDetail string,
    hxTargetDetail string,
    hxIncludeDetail string,
    hxSwapDetail string,
) {
    <div class="row px-5 d-flex justify-content-around">
        <a
            type="button"
            class="btn btn-icon"
            title="Detail test dan paket"
            hx-get={ hxGetDetail +"?idx=" + data.T_OrderHeaderID }
            hx-target={ hxTargetDetail }
            hx-swap={ hxSwapDetail }
            hx-include={ hxIncludeDetail }
        >
            <i class="flaticon2-list-1"></i>
        </a>
        <a
            type="button"
            class="btn btn-icon"
            hx-get={ hxGetRpt +"?idx=" + data.T_OrderHeaderID }
            hx-target={ hxTargetRpt }
            hx-swap={ hxSwapRpt }
            hx-include={ hxIncludeRpt }
            title="Laporan MCU"
        >
            <i class="flaticon2-file"></i>
        </a>
        if data.AuthPatientEmail != "none" {
            <a 
                type="button"
                class="btn btn-icon"
                hx-get={ hxGetAcc + "?patid=" + data.M_PatientID }
                hx-target={ hxTargetAcc }
                hx-swap={ hxSwapAcc }
                hx-include={ hxIncludeAcc }
                title="Ganti password peserta"
            >
                <i class="flaticon2-edit"></i>
            </a>
        } else {
            <a 
                type="button"
                class="btn btn-icon d-none"
                hx-get={ hxGetAcc + "?patid=" + data.M_PatientID }
                hx-target={ hxTargetAcc }
                hx-swap={ hxSwapAcc }
                hx-include={ hxIncludeAcc }
            >
                <i class="flaticon2-edit"></i>
            </a>
        }
    </div>
}


templ TableDetailMCU(
    data []models.TableTestPaket,
) {
    <div id="table-detail-mcu" style="max-height: 700px; overflow-y: auto;">
        @tablecomponent.TableV3([]string{"NOMOR", "NAMA TEST", "NAMA PAKET"},
            []string{"20%","40%","40%"},
            DetailRow(data),
        )
    </div>
}

templ DetailRow(
    data []models.TableTestPaket,
) {
    if len(data) == 0 {
        <tr>
            <td colspan="3" class="text-center">Data Tidak Ditemukan</td>
        </tr>
    }
    for _, v := range data {
        <tr>
            <td>{ strconv.Itoa(v.Nomor) }</td>
            <td>{ v.NamaTest }</td>
            <td>{ v.NamaPaket }</td>
        </tr>
    }
}