<?php
$items = isset($items) ? $items : array();
if (is_string($items)) {
	$decoded_items = json_decode($items);
	if (json_last_error() === JSON_ERROR_NONE && is_array($decoded_items)) {
		$items = $decoded_items;
	} else {
		$items = array();
	}
}
$tax_rates = isset($tax_rates) ? $tax_rates : $this->db->order_by('tax_rate_name', 'ASC')->get('tbl_tax_rates')->result();
$show_quantity_as = isset($show_quantity_as) ? strtolower((string) $show_quantity_as) : 'qty';
if (!in_array($show_quantity_as, array('qty', 'hours', 'qty_hours'), true)) {
	$show_quantity_as = 'qty';
}
$discount_percent = isset($discount_percent) ? $discount_percent : 0;
$discount_type = isset($discount_type) ? $discount_type : 'percent';
$adjustment = isset($adjustment) ? $adjustment : 0;
$currency_symbol = isset($currency_symbol) ? $currency_symbol : '';
$invoice_view = config_item('invoice_view');
$itemType = isset($itemType) ? $itemType : 'invoice';
$editor_variant = isset($editor_variant) ? $editor_variant : '';
$hide_header = $editor_variant === 'pos';
$is_pos_variant = $editor_variant === 'pos';

if (in_array($discount_type, array('', 'before_tax', 'after_tax', 'percent', 'percentage'), true)) {
	$discount_type = 'percent';
} elseif ($discount_type !== 'fixed') {
	$discount_type = 'percent';
}

$tax_rate_lookup_map = array();
$tax_rate_value_map = array();
if (!empty($tax_rates)) {
	foreach ($tax_rates as $tax_rate) {
		$tax_value = $tax_rate->tax_rate_name . '|' . $tax_rate->tax_rate_percent;
		$tax_rate_lookup_map[$tax_value] = $tax_rate->tax_rate_name . ' (' . $tax_rate->tax_rate_percent . '%)';
		$tax_rate_value_map[(string) $tax_rate->tax_rates_id] = $tax_value;
	}
}

$render_tax_lookup = function ($selected_values = array(), $lookup_seed = 'tax_lookup') use ($tax_rate_lookup_map, $tax_rate_value_map) {
	if (!is_array($selected_values)) {
		$selected_values = empty($selected_values) ? array() : array($selected_values);
	}
	$hidden_html = '';
	$chips_html = '';
	foreach ($selected_values as $selected_value) {
		$selected_value = (string) $selected_value;
		if ($selected_value === '') {
			continue;
		}
		$selected_label = isset($tax_rate_lookup_map[$selected_value]) ? $tax_rate_lookup_map[$selected_value] : $selected_value;
		$hidden_html .= '<input type="hidden" name="tax_lookup[]" value="' . html_escape($selected_value) . '" data-lookup-hidden-item>';
		$chips_html .= '<span class="inline-flex items-center gap-1 rounded-full border border-slate-200 bg-slate-100 px-2.5 py-1 text-[11px] font-medium text-slate-700 dark:border-slate-700 dark:bg-slate-800 dark:text-slate-200" data-lookup-chip data-lookup-chip-id="' . html_escape($selected_value) . '">'
			. '<span>' . html_escape($selected_label) . '</span>'
			. '<button type="button" class="rounded-full p-0.5 text-slate-400 hover:bg-slate-200 hover:text-slate-700 dark:text-slate-400 dark:hover:bg-slate-700 dark:hover:text-slate-100" data-lookup-chip-remove="' . html_escape($selected_value) . '">'
			. '<i data-lucide="x" class="h-3 w-3"></i>'
			. '</button>'
			. '</span>';
	}

	return '<div class="sales-items-modern__taxlookup" data-tax-lookup data-lookup="1" data-lookup-type="tax_rate" data-lookup-multiple="1" data-lookup-name="tax_lookup[]" data-lookup-limit="6" data-lookup-min-length="0" data-lookup-value-map="' . html_escape(json_encode($tax_rate_value_map)) . '">'
		. '<div data-lookup-hidden-list>' . $hidden_html . '</div>'
		. '<div class="mb-2 flex flex-wrap gap-1.5" data-lookup-chips>' . $chips_html . '</div>'
		. '<div class="relative">'
		. '<input type="text" class="w-full rounded-xl border border-slate-300 bg-white px-3 py-2.5 text-sm text-slate-900 placeholder:text-slate-400 focus:border-slate-400 focus:outline-none focus:ring-2 focus:ring-slate-200 dark:border-slate-700 dark:bg-slate-950/70 dark:text-slate-100 dark:placeholder:text-slate-500 dark:focus:border-slate-500 dark:focus:ring-slate-800" autocomplete="off" data-lookup-input placeholder="' . html_escape(lang('search') . ' ' . lang('tax')) . '">'
		. '<div class="absolute z-30 mt-1 hidden max-h-56 w-full overflow-y-auto rounded-xl border border-slate-200 bg-white shadow-lg dark:border-slate-700 dark:bg-slate-900" data-lookup-results></div>'
		. '</div>'
		. '<p class="mt-1 hidden text-xs text-rose-500" data-lookup-status>' . html_escape(lang('search') . ' ' . lang('tax')) . '</p>'
		. '</div>';
};
?>

<div class="prodcutTable sales-items-modern  bg-white shadow-sm dark:border-slate-800 dark:bg-slate-950/70 <?= $is_pos_variant ? 'rounded-[18px] border-slate-300 bg-slate-50 dark:border-slate-700 dark:bg-slate-900' : 'rounded-[22px] border border-slate-200' ?>"
	data-sales-items
	data-terget="<?= html_escape($itemType) ?>"
	data-currency-symbol="<?= html_escape($currency_symbol) ?>">
	<div class="sales-items-modern__header border-b border-slate-200 px-5 py-5 dark:border-slate-800 <?= $hide_header ? 'hidden' : '' ?>">
		<div class="flex flex-col gap-4">
			<div class="sales-items-modern__headline flex flex-col gap-4 lg:flex-row lg:items-center lg:justify-between">
				<div class="min-w-0">
					<p class="text-[11px] font-semibold uppercase tracking-[0.24em] text-slate-400 dark:text-slate-500">Line Items</p>
					<h3 class="mt-1 text-[1.05rem] font-semibold tracking-tight text-slate-900 dark:text-slate-100">Invoice Items</h3>
				</div>

				<div class="sales-items-modern__header-actions flex flex-wrap items-center gap-2">
					<?= btn_modal(
						'admin/items/manuallyItems',
						'',
						'',
						'lg',
						'plus',
						array(
							'class' => 'inline-flex h-10 items-center justify-center gap-2 rounded-xl border border-slate-300 bg-white px-3.5 text-sm font-medium text-slate-700 transition hover:bg-slate-50 dark:border-slate-700 dark:bg-slate-900 dark:text-slate-100 dark:hover:bg-slate-800',
							'title' => lang('add') . ' ' . lang('manual'),
						)
					) ?>
					<button type="button" data-add-item class="inline-flex h-10 items-center gap-2 rounded-xl bg-slate-900 px-4 text-sm font-semibold text-white shadow-sm transition hover:bg-slate-800 dark:bg-slate-100 dark:text-slate-900 dark:hover:bg-white">
						<i data-lucide="plus" class="h-4 w-4"></i>
						<?= lang('add') ?> Row
					</button>
				</div>
			</div>

			<div class="sales-items-modern__controlbar flex flex-col gap-3 xl:flex-row xl:items-center xl:justify-between">
				<div class="sales-items-modern__search relative min-w-0 xl:w-[36rem]">
					<i data-lucide="search" class="pointer-events-none absolute left-4 top-1/2 h-4.5 w-4.5 -translate-y-1/2 text-slate-400"></i>
					<input
						type="text"
						id="<?= html_escape($itemType) ?>_item"
						placeholder="<?= lang('search_item_by_code_or_name') ?>"
						class="h-10 w-full rounded-xl border border-slate-300 bg-white pl-11 pr-4 text-sm text-slate-900 placeholder:text-slate-400 focus:border-slate-400 focus:outline-none focus:ring-2 focus:ring-slate-200 dark:border-slate-700 dark:bg-slate-950 dark:text-slate-100 dark:placeholder:text-slate-500 dark:focus:border-slate-500 dark:focus:ring-slate-800">
					<div class="sales-items-modern__search-results absolute left-0 right-0 top-[calc(100%+0.45rem)] z-30 hidden max-h-72 overflow-y-auto rounded-2xl border border-slate-200 bg-white shadow-lg dark:border-slate-700 dark:bg-slate-900" data-item-search-results></div>
				</div>

				<div class="sales-items-modern__modebar shrink-0">
					<div class="sales-items-modern__toggle inline-flex items-center rounded-xl border border-slate-200 bg-slate-50 p-1 dark:border-slate-800 dark:bg-slate-900">
						<label class="inline-flex cursor-pointer items-center">
							<input type="radio" name="show_quantity_as" value="qty" class="peer sr-only" <?= $show_quantity_as === 'qty' ? 'checked' : '' ?>>
							<span class="rounded-lg px-3.5 py-2 text-xs font-semibold text-slate-600 transition peer-checked:text-white dark:text-slate-300"><?= lang('qty') ?></span>
						</label>
						<label class="inline-flex cursor-pointer items-center">
							<input type="radio" name="show_quantity_as" value="hours" class="peer sr-only" <?= $show_quantity_as === 'hours' ? 'checked' : '' ?>>
							<span class="rounded-lg px-3.5 py-2 text-xs font-semibold text-slate-600 transition dark:text-slate-300"><?= lang('hours') ?></span>
						</label>
						<label class="inline-flex cursor-pointer items-center">
							<input type="radio" name="show_quantity_as" value="qty_hours" class="peer sr-only" <?= $show_quantity_as === 'qty_hours' ? 'checked' : '' ?>>
							<span class="rounded-lg px-3.5 py-2 text-xs font-semibold text-slate-600 transition dark:text-slate-300"><?= lang('qty') . '/' . lang('hours') ?></span>
						</label>
					</div>
				</div>
			</div>
		</div>
	</div>

	<div class="sales-items-modern__table-wrap overflow-x-auto overflow-y-visible">
		<table class="sales-items-modern__table <?= $is_pos_variant ? 'min-w-[680px]' : 'min-w-[1040px]' ?> w-full table-fixed border-collapse text-sm">
			<thead class="<?= $is_pos_variant ? 'bg-slate-100 text-[11px] font-semibold uppercase tracking-[0.14em] text-slate-500 dark:bg-slate-800 dark:text-slate-300' : 'bg-slate-50 text-xs font-semibold uppercase tracking-[0.14em] text-slate-500 dark:bg-slate-900/80 dark:text-slate-400' ?>">
				<tr>
					<th class="w-12 px-4 py-3 text-left <?= $is_pos_variant ? 'hidden' : '' ?>">#</th>
					<th class="<?= $is_pos_variant ? 'w-1/1 px-4 py-3 text-left' : 'w-[34%] px-4 py-3 text-left' ?>"><?= strtoupper(lang('item_details')) ?></th>
					<th class="w-[9%] px-3 py-3 text-left <?= $is_pos_variant ? 'hidden' : '' ?>"><?= lang('unit') ?></th>
					<th class="<?= $is_pos_variant ? 'w-1/6 px-3 py-3 text-right' : 'w-[9%] px-3 py-3 text-left' ?>">
						<span data-qty-label data-qty-label-qty="<?= html_escape(lang('qty')) ?>" data-qty-label-hours="<?= html_escape(lang('hours')) ?>" data-qty-label-qty-hours="<?= html_escape(lang('qty') . '/' . lang('hours')) ?>">
							<?= $is_pos_variant ? 'QTY' : lang('qty') ?>
						</span>
					</th>
					<th class="<?= $is_pos_variant ? 'w-1/6 px-3 py-3 text-right' : 'w-[10%] px-3 py-3 text-left' ?>"><?= $is_pos_variant ? 'PRICE' : lang('price') ?></th>
					<th class="w-[20%] px-3 py-3 text-left <?= $is_pos_variant ? 'hidden' : '' ?>"><?= lang('tax_rate') ?></th>
					<th class="<?= $is_pos_variant ? 'w-1/5 px-3 py-3 text-right' : 'w-[9%] px-3 py-3 text-right' ?>"><?= $is_pos_variant ? 'TOTAL' : lang('total') ?></th>
					<?php if (!$is_pos_variant) : ?>
						<th class="w-[72px] px-3 py-3 text-right"><?= lang('action') ?></th>
					<?php endif; ?>
				</tr>
			</thead>
			<tbody class="divide-y divide-slate-200 dark:divide-slate-800" data-items-body>
				<?php if (!empty($items)) : ?>
					<?php foreach ($items as $index => $item) : ?>
						<?php
						$item_taxes = array();
						if (!empty($item->taxname) && is_array($item->taxname)) {
							$item_taxes = $item->taxname;
						} elseif (!empty($item->item_tax_name)) {
							$item_taxes = json_decode($item->item_tax_name, true);
							if (json_last_error() !== JSON_ERROR_NONE || !is_array($item_taxes)) {
								$item_taxes = array();
								$legacy_tax_name = trim((string) $item->item_tax_name);
								if ($legacy_tax_name !== '') {
									$legacy_tax_total = isset($item->item_tax_total) ? (float) $item->item_tax_total : 0;
									$legacy_line_total = isset($item->total_cost) ? (float) $item->total_cost : 0;
									if ($legacy_tax_total > 0 && $legacy_line_total > 0) {
										$legacy_tax_rate = round(($legacy_tax_total / $legacy_line_total) * 100, 2);
										$item_taxes[] = $legacy_tax_name . '|' . rtrim(rtrim(number_format($legacy_tax_rate, 2, '.', ''), '0'), '.');
									} else {
										$item_taxes[] = $legacy_tax_name;
									}
								}
							}
						}
						?>
						<tr data-item-row class="align-top">
							<td class="px-4 py-3.5 text-sm font-semibold text-slate-400 dark:text-slate-500 <?= $is_pos_variant ? 'hidden' : '' ?>" data-item-index><?= $index + 1 ?></td>
							<td class="px-4 py-3.5">
								<div class="space-y-2.5">
									<input type="hidden" data-field="items_id" value="<?= html_escape($item->items_id) ?>">
									<input type="hidden" data-field="saved_items_id" value="<?= html_escape($item->saved_items_id) ?>">
									<input type="text" data-field="item_name" value="<?= html_escape($item->item_name) ?>" class="<?= $is_pos_variant ? 'mb-1 h-auto w-full border-0 bg-transparent p-0 text-[12px] font-semibold leading-tight text-slate-800 shadow-none focus:border-transparent focus:outline-none focus:ring-0 dark:text-slate-100' : 'mb-2 h-9 w-full rounded-xl border border-slate-300 bg-white px-3 text-sm font-semibold text-slate-900 focus:border-slate-400 focus:outline-none focus:ring-2 focus:ring-slate-200 dark:border-slate-700 dark:bg-slate-950/70 dark:text-slate-100 dark:focus:border-slate-500 dark:focus:ring-slate-800' ?>">
									<textarea data-field="item_desc" rows="2" class="<?= $is_pos_variant ? 'w-full min-h-0 resize-none border-0 bg-transparent p-0 text-[9px] font-semibold uppercase tracking-[0.12em] leading-tight text-slate-500 shadow-none focus:border-transparent focus:outline-none focus:ring-0 dark:text-slate-400' : 'w-full rounded-xl border border-slate-300 bg-white px-3 py-2 text-sm text-slate-600 focus:border-slate-400 focus:outline-none focus:ring-2 focus:ring-slate-200 dark:border-slate-700 dark:bg-slate-950/70 dark:text-slate-300 dark:focus:border-slate-500 dark:focus:ring-slate-800' ?>"><?= html_escape($item->item_desc) ?></textarea>
									<?php if (!empty($invoice_view) && $invoice_view == '2') { ?>
										<input type="text" data-field="hsn_code" value="<?= html_escape($item->hsn_code) ?>" placeholder="<?= lang('hsn_code') ?>" class="h-[34px] w-full rounded-xl border border-slate-300 bg-white px-3 text-xs text-slate-700 focus:border-slate-400 focus:outline-none focus:ring-2 focus:ring-slate-200 dark:border-slate-700 dark:bg-slate-950/70 dark:text-slate-200 dark:focus:border-slate-500 dark:focus:ring-slate-800">
									<?php } ?>
								</div>
							</td>
							<td class="px-3 py-3.5 <?= $is_pos_variant ? 'hidden' : '' ?>">
								<input type="text" data-field="unit" value="<?= html_escape($item->unit) ?>" class="h-[34px] min-w-12 w-full rounded-xl border border-slate-300 bg-white px-3 text-center text-sm text-slate-900 focus:border-slate-400 focus:outline-none focus:ring-2 focus:ring-slate-200 dark:border-slate-700 dark:bg-slate-950/70 dark:text-slate-100 dark:focus:border-slate-500 dark:focus:ring-slate-800">
							</td>
							<td class="px-3 py-3.5">
								<input type="number" step="0.01" data-field="quantity" value="<?= html_escape($item->quantity) ?>" class="<?= $is_pos_variant ? 'h-[34px] w-full min-w-12 rounded-xl border border-slate-300 bg-slate-50 px-3 text-right text-[11px] font-medium text-slate-800 focus:border-slate-400 focus:outline-none focus:ring-2 focus:ring-slate-200 dark:border-slate-600 dark:bg-slate-800 dark:text-slate-100 dark:focus:border-slate-500 dark:focus:ring-slate-700' : 'h-[34px] w-full min-w-12 rounded-xl border border-slate-300 bg-white px-3 text-center text-sm text-slate-900 focus:border-slate-400 focus:outline-none focus:ring-2 focus:ring-slate-200 dark:border-slate-700 dark:bg-slate-950/70 dark:text-slate-100 dark:focus:border-slate-500 dark:focus:ring-slate-800' ?>">
							</td>
							<td class="px-3 py-3.5">
								<input type="number" step="0.01" data-field="unit_cost" value="<?= html_escape($item->unit_cost) ?>" class="<?= $is_pos_variant ? 'h-[34px] w-full min-w-12 rounded-xl border border-slate-300 bg-slate-50 px-3 text-right text-[11px] font-medium text-slate-800 focus:border-slate-400 focus:outline-none focus:ring-2 focus:ring-slate-200 dark:border-slate-600 dark:bg-slate-800 dark:text-slate-100 dark:focus:border-slate-500 dark:focus:ring-slate-700' : 'h-[34px] w-full min-w-12 rounded-xl border border-slate-300 bg-white px-3 text-sm text-slate-900 focus:border-slate-400 focus:outline-none focus:ring-2 focus:ring-slate-200 dark:border-slate-700 dark:bg-slate-950/70 dark:text-slate-100 dark:focus:border-slate-500 dark:focus:ring-slate-800' ?>">
							</td>
							<td class="px-3 py-3.5 <?= $is_pos_variant ? 'hidden' : '' ?>">
								<?= $render_tax_lookup($item_taxes, 'tax_existing_' . $index) ?>
							</td>
							<td class="px-3 py-3.5 text-right <?= $is_pos_variant ? 'text-[15px] font-bold text-slate-800 dark:text-slate-100' : 'text-[15px] font-semibold text-slate-900 dark:text-slate-100' ?>">
								<?php if ($is_pos_variant) : ?>
									<div class="inline-flex w-full items-center justify-end gap-2 align-middle">
										<span data-line-total><?= display_money($item->total_cost, $currency_symbol) ?></span>
										<button type="button" data-remove-item class="inline-flex h-7 w-7 items-center justify-center rounded-lg border border-rose-200 bg-rose-50 text-rose-600 hover:bg-rose-100 dark:border-rose-900/50 dark:bg-rose-900/20 dark:text-rose-300 dark:hover:bg-rose-900/35">
											<i data-lucide="trash-2" class="h-4 w-4"></i>
										</button>
									</div>
								<?php else : ?>
									<span data-line-total><?= display_money($item->total_cost, $currency_symbol) ?></span>
								<?php endif; ?>
							</td>
							<?php if (!$is_pos_variant) : ?>
								<td class="px-3 py-3.5 text-right">
									<button type="button" data-remove-item class="inline-flex h-9 w-9 items-center justify-center rounded-xl border border-rose-200 bg-rose-50 text-rose-600 hover:bg-rose-100 dark:border-rose-900/50 dark:bg-rose-900/20 dark:text-rose-300 dark:hover:bg-rose-900/35">
										<i data-lucide="trash-2" class="h-4 w-4"></i>
									</button>
								</td>
							<?php endif; ?>
						</tr>
					<?php endforeach; ?>
				<?php endif; ?>
			</tbody>
		</table>
	</div>

	<template data-item-template>
		<tr data-item-row class="align-top">
			<td class="px-4 py-3.5 text-sm font-semibold text-slate-400 dark:text-slate-500 <?= $is_pos_variant ? 'hidden' : '' ?>" data-item-index>1</td>
			<td class="px-4 py-3.5">
				<div class="">
					<input type="hidden" data-field="items_id" value="">
					<input type="hidden" data-field="saved_items_id" value="0">
					<input type="text" data-field="item_name" value="" placeholder="<?= lang('item_name') ?>" class="<?= $is_pos_variant ? 'mb-1 h-auto w-full border-0 bg-transparent p-0 text-[12px] font-semibold leading-tight text-slate-800 shadow-none focus:border-transparent focus:outline-none focus:ring-0 dark:text-slate-100' : 'mb-2 h-9 w-full rounded-xl border border-slate-300 bg-white px-3 text-sm font-semibold text-slate-900 focus:border-slate-400 focus:outline-none focus:ring-2 focus:ring-slate-200 dark:border-slate-700 dark:bg-slate-950/70 dark:text-slate-100 dark:focus:border-slate-500 dark:focus:ring-slate-800' ?>">
					<textarea data-field="item_desc" rows="2" placeholder="<?= lang('description') ?>" class="<?= $is_pos_variant ? 'w-full min-h-0 resize-none border-0 bg-transparent p-0 text-[9px] font-semibold uppercase tracking-[0.12em] leading-tight text-slate-500 shadow-none focus:border-transparent focus:outline-none focus:ring-0 dark:text-slate-400' : 'w-full rounded-xl border border-slate-300 bg-white px-3 py-2 text-sm text-slate-600 focus:border-slate-400 focus:outline-none focus:ring-2 focus:ring-slate-200 dark:border-slate-700 dark:bg-slate-950/70 dark:text-slate-300 dark:focus:border-slate-500 dark:focus:ring-slate-800' ?>"></textarea>
					<?php if (!empty($invoice_view) && $invoice_view == '2') { ?>
						<input type="text" data-field="hsn_code" value="" placeholder="<?= lang('hsn_code') ?>" class="h-[34px] w-full rounded-xl border border-slate-300 bg-white px-3 text-xs text-slate-700 focus:border-slate-400 focus:outline-none focus:ring-2 focus:ring-slate-200 dark:border-slate-700 dark:bg-slate-950/70 dark:text-slate-200 dark:focus:border-slate-500 dark:focus:ring-slate-800">
					<?php } ?>
				</div>
			</td>
			<td class="px-3 py-3.5 <?= $is_pos_variant ? 'hidden' : '' ?>">
				<input type="text" data-field="unit" value="1" class="h-[34px] min-w-12 w-full rounded-xl border border-slate-300 bg-white px-3 text-center text-sm text-slate-900 focus:border-slate-400 focus:outline-none focus:ring-2 focus:ring-slate-200 dark:border-slate-700 dark:bg-slate-950/70 dark:text-slate-100 dark:focus:border-slate-500 dark:focus:ring-slate-800">
			</td>
			<td class="px-3 py-3.5">
				<input type="number" step="0.01" data-field="quantity" value="1" class="<?= $is_pos_variant ? 'h-[34px] w-full min-w-12 rounded-xl border border-slate-300 bg-slate-50 px-3 text-right text-[11px] font-medium text-slate-800 focus:border-slate-400 focus:outline-none focus:ring-2 focus:ring-slate-200 dark:border-slate-600 dark:bg-slate-800 dark:text-slate-100 dark:focus:border-slate-500 dark:focus:ring-slate-700' : 'h-[34px] w-full min-w-12 rounded-xl border border-slate-300 bg-white px-3 text-center text-sm text-slate-900 focus:border-slate-400 focus:outline-none focus:ring-2 focus:ring-slate-200 dark:border-slate-700 dark:bg-slate-950/70 dark:text-slate-100 dark:focus:border-slate-500 dark:focus:ring-slate-800' ?>">
			</td>
			<td class="px-3 py-3.5">
				<input type="number" step="0.01" data-field="unit_cost" value="0" class="<?= $is_pos_variant ? 'h-[34px] w-full min-w-12 rounded-xl border border-slate-300 bg-slate-50 px-3 text-right text-[11px] font-medium text-slate-800 focus:border-slate-400 focus:outline-none focus:ring-2 focus:ring-slate-200 dark:border-slate-600 dark:bg-slate-800 dark:text-slate-100 dark:focus:border-slate-500 dark:focus:ring-slate-700' : 'h-[34px] w-full min-w-12 rounded-xl border border-slate-300 bg-white px-3 text-sm text-slate-900 focus:border-slate-400 focus:outline-none focus:ring-2 focus:ring-slate-200 dark:border-slate-700 dark:bg-slate-950/70 dark:text-slate-100 dark:focus:border-slate-500 dark:focus:ring-slate-800' ?>">
			</td>
			<td class="px-3 py-3.5 <?= $is_pos_variant ? 'hidden' : '' ?>">
				<?= $render_tax_lookup(array(), 'tax_template') ?>
			</td>
			<td class="px-3 py-3.5 text-right <?= $is_pos_variant ? 'text-[15px] font-bold text-slate-800 dark:text-slate-100' : 'text-[15px] font-semibold text-slate-900 dark:text-slate-100' ?>">
				<?php if ($is_pos_variant) : ?>
					<div class="inline-flex w-full items-center justify-end gap-2 align-middle">
						<span data-line-total><?= display_money(0, $currency_symbol) ?></span>
						<button type="button" data-remove-item class="inline-flex h-7 w-7 items-center justify-center rounded-lg border border-rose-200 bg-rose-50 text-rose-600 hover:bg-rose-100 dark:border-rose-900/50 dark:bg-rose-900/20 dark:text-rose-300 dark:hover:bg-rose-900/35">
							<i data-lucide="trash-2" class="h-4 w-4"></i>
						</button>
					</div>
				<?php else : ?>
					<span data-line-total><?= display_money(0, $currency_symbol) ?></span>
				<?php endif; ?>
			</td>
			<?php if (!$is_pos_variant) : ?>
				<td class="px-3 py-3.5 text-right">
					<button type="button" data-remove-item class="inline-flex h-9 w-9 items-center justify-center rounded-xl border border-rose-200 bg-rose-50 text-rose-600 hover:bg-rose-100 dark:border-rose-900/50 dark:bg-rose-900/20 dark:text-rose-300 dark:hover:bg-rose-900/35">
						<i data-lucide="trash-2" class="h-4 w-4"></i>
					</button>
				</td>
			<?php endif; ?>
		</tr>
	</template>

	<div class="border-t border-slate-200 px-5 py-5 dark:border-slate-800">
		<div class="flex flex-col gap-5 2xl:flex-row">
			<div class="sales-items-modern__footer-fields <?= $is_pos_variant ? 'hidden' : 'flex-col 2xl:flex-1' ?>">
				<label class="block mb-2 rounded-[18px] border border-slate-200 bg-slate-50 p-4 dark:border-slate-800 dark:bg-slate-900/60">
					<span class="mb-2 block text-[11px] font-semibold uppercase tracking-[0.18em] text-slate-500 dark:text-slate-400" data-discount-label><?= lang('discount') ?> (%)</span>
					<div class="sales-items-modern__discount-row">
						<select name="discount_type" data-discount-type class="sales-items-modern__discount-select h-9 border-0 bg-transparent px-3 text-sm text-slate-900 focus:outline-none dark:text-slate-100">
							<option value="percent" <?= $discount_type === 'percent' ? 'selected' : '' ?>>Percent</option>
							<option value="fixed" <?= $discount_type === 'fixed' ? 'selected' : '' ?>><?= lang('fixed') ?></option>
						</select>
						<input type="number" step="0.01" min="0" max="<?= $discount_type === 'percent' ? '100' : '' ?>" name="discount_percent" value="<?= html_escape($discount_percent) ?>" data-discount-percent class="sales-items-modern__discount-input h-9 min-w-0 border-0 bg-transparent px-3.5 text-right text-sm text-slate-900 focus:outline-none dark:text-slate-100">
						<span class="sales-items-modern__discount-addon" data-discount-addon><?= $discount_type === 'fixed' ? html_escape($currency_symbol) : '%' ?></span>
					</div>
				</label>
				<label class="block rounded-[18px] border border-slate-200 bg-slate-50 p-4 dark:border-slate-800 dark:bg-slate-900/60">
					<span class="mb-2 block text-[11px] font-semibold uppercase tracking-[0.18em] text-slate-500 dark:text-slate-400"><?= lang('adjustment') ?></span>
					<input type="number" step="0.01" name="adjustment" value="<?= html_escape($adjustment) ?>" data-adjustment class="h-9 w-full rounded-xl border border-slate-300 bg-white px-3.5 text-sm text-slate-900 focus:border-slate-400 focus:outline-none focus:ring-2 focus:ring-slate-200 dark:border-slate-700 dark:bg-slate-950/70 dark:text-slate-100 dark:focus:border-slate-500 dark:focus:ring-slate-800">
				</label>
			</div>

			<div class="sales-items-modern__summary 2xl:flex-1  <?= $is_pos_variant ? '' : ' rounded-[22px] border border-slate-200 bg-slate-50 p-5 dark:border-slate-800 dark:bg-slate-900/70' ?>">
				<div class="space-y-3.5 text-[15px]">
					<div class="flex items-center justify-between gap-4 text-slate-500 dark:text-slate-400 <?= $is_pos_variant ? 'hidden' : '' ?>">
						<span><?= lang('sub_total') ?></span>
						<span class="font-semibold text-slate-900 dark:text-slate-100" data-subtotal>0.00</span>
					</div>
					<div class="space-y-2 <?= $is_pos_variant ? 'hidden' : '' ?>" data-tax-breakdown></div>
					<div class="flex items-center justify-between gap-4 text-slate-500 dark:text-slate-400 <?= $is_pos_variant ? 'hidden' : '' ?>">
						<span><?= lang('tax') ?></span>
						<span class="font-semibold text-slate-900 dark:text-slate-100" data-tax-total>0.00</span>
					</div>
					<div class="flex items-center justify-between gap-4 text-slate-500 dark:text-slate-400 <?= $is_pos_variant ? 'hidden' : '' ?>">
						<span><?= lang('discount') ?></span>
						<span class="font-semibold text-rose-500 dark:text-rose-400" data-discount-total-display>0.00</span>
					</div>
					<div class="hidden items-center justify-between gap-4 text-slate-500 dark:text-slate-400 <?= $is_pos_variant ? 'hidden' : '' ?>" data-adjustment-row>
						<span><?= lang('adjustment') ?></span>
						<span class="font-semibold text-slate-900 dark:text-slate-100" data-adjustment-total>0.00</span>
					</div>
					<div class="border-t border-slate-200 pt-4 dark:border-slate-800 <?= $is_pos_variant ? 'border-slate-300 pt-3 dark:border-slate-700' : '' ?>">
						<div class="flex items-center justify-between gap-4">
							<div >
								<p class="text-[11px] font-semibold uppercase tracking-[0.14em] text-slate-500 dark:text-slate-400 ">Total Amount</p>
								<p class="mt-1 text-xs text-slate-400 dark:text-slate-500 <?= $is_pos_variant ? 'hidden' : '' ?>">Ready to save</p>
							</div>
							<span class="<?= $is_pos_variant ? 'text-[2.625rem]' : 'text-[2rem]' ?> font-semibold leading-none text-slate-900 dark:text-slate-100" data-total>0.00</span>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>

	<div data-tax-hidden></div>
	<div data-removed-items></div>
	<input type="hidden" name="discount_total" data-discount-total value="0">
</div>
