<dialog class="modal" :open="isDialogSampleOpen">
	<div class="modal-box w-2/3 max-w-5xl">
		<div class='flex justify-between items-center mb-2'>
		
	
	<div class='flex gap-2 ml-auto'>
				<template x-if="item && item.accessnumber">
					<button class="btn btn-xs btn-outline btn-info" @click="openAuditDialog(item.accessnumber)">
						<i class="fa fa-history"></i> Audit
					</button>
				</template>
				<button class="btn btn-xs btn-neutral" @click="closeSampleDialog()">X</button>
			</div>
		</div>

		<template x-if="isSampleLoading">
			<div class="text-center py-10">
				<span class="loading loading-spinner loading-lg text-primary"></span>
				<p class="mt-2">Loading data...</p>
			</div>
		</template>

		<template x-if="!isSampleLoading && item">
			<div>
				<table class="table table-xs table-compact w-full mb-4">
					<tr>
						<td>MR# </td>
						<td x-text="': '+item.patnumber"></td>
						<td>Patient Name </td>
						<td x-text="': '+item.patname"></td>
					</tr>
					<tr>
						<td>KTP# </td>
						<td x-text="': '+item.ktp"></td>
						<td>Sex / Age </td>
						<td x-text="': '+item.placeofbirth+' '+item.gender+' / '+item.age"></td>
					</tr>
					<tr>
						<td>Note</td>
						<td colspan='3' x-text="item.comment"></td>
					</tr>
				</table>

				<table class="table table-xs table-compact w-full">
					<thead>
						<tr>
							<th>Sample Code</th>
							<th>Sample Name</th>
							<th class='text-center'>Collected</th>
							<th class='text-center'>Received</th>
						<th>
							<div class='flex items-center gap-2'>
								<span>Action</span>
								<select x-model="selectedPrinter" class="select select-bordered select-xs w-28">
									<option value="zebracs1">CS 2 Printer</option>
									<option value="zebracs2">CS 4 Printer</option>
									<option value="zebracs3">CS Lab Printer</option>
									<option value="zebralab">Lab Printer</option>
								</select>
							</div>
						</th>
						<th></th>
						</tr>
					</thead>

					<tbody>
						<tr>
							<td></td>
							<td>All</td>
							<td></td>
							<td></td>
							<td>
								<button class="btn btn-sm btn-secondary px-2 py-1" @click="printAllLabels(item.accessnumber)"><i class="fa-solid fa-print"></i></button>
							</td>
						</tr>
						<tr>
							<td></td>
							<td>Collection</td>
							<td></td>
							<td></td>
							<td>
								<button class="btn btn-sm btn-secondary px-2 py-1" @click="printCollectionLabel(item.accessnumber)"><i class="fa-solid fa-print"></i></button>
							</td>
						</tr>

						<template x-for="sample in item.samples">
							<tr>
								<td x-text="sample.sampcode"></td>
								<td x-text="sample.name"></td>
								<td class='text-center'>
									<input type="checkbox" class="checkbox" x-bind:checked="sample.colstatus == 1" disabled>
								</td>
								<td class='text-center'>
									<input type="checkbox" class="checkbox" x-bind:checked="sample.tubestatus != 0" disabled>
								</td>
								<td>
									
<button class="btn btn-sm btn-secondary px-2 py-1" @click="printSampleLabel(item.accessnumber, sample.sampcode)"><i class="fa-solid fa-print"></i></button>
									<?php if ($config['sampleDialog']['showCollectButtons'] ?? true): ?>
										<template x-if="sample.colstatus == 0">
											<button class="btn btn-sm btn-success px-2 py-1"
												@click="collect(sample.sampcode, item.accessnumber)">
												<h6 class="p-0 m-0">Coll.</h6>
											</button>
										</template>
										<?php if (in_array(session('userroleid'), [0, 1])): ?>
											<template x-if="sample.tubestatus != 0">
												<button class="btn btn-sm btn-error px-2 py-1"
													@click="unreceive(sample.sampcode, item.accessnumber)">
													<h6 class="p-0 m-0">Un-Recv.</h6>
												</button>
											</template>
										<?php endif; ?>
									<?php endif; ?>
								</td>
								<td></td>
							</tr>
						</template>
					</tbody>
				</table>
			</div>
		</template>
	</div>
</dialog>