<div class="invoice-modern">
	<?php
	$reminder_active_tab = (!empty($active) && (int) $active === 1) ? 'manage' : 'create';
	$manage_tab_classes = 'reminder-tab-btn inline-flex items-center rounded-lg border px-3 py-2 text-xs font-semibold transition';
	$create_tab_classes = $manage_tab_classes;
	if ($reminder_active_tab === 'manage') {
		$manage_tab_classes .= ' border-slate-900 bg-slate-900 text-white dark:border-slate-100 dark:bg-slate-100 dark:text-slate-900';
		$create_tab_classes .= ' border-slate-200 bg-white text-slate-600 hover:bg-slate-50 dark:border-slate-700 dark:bg-slate-900 dark:text-slate-300 dark:hover:bg-slate-800';
	} else {
		$manage_tab_classes .= ' border-slate-200 bg-white text-slate-600 hover:bg-slate-50 dark:border-slate-700 dark:bg-slate-900 dark:text-slate-300 dark:hover:bg-slate-800';
		$create_tab_classes .= ' border-slate-900 bg-slate-900 text-white dark:border-slate-100 dark:bg-slate-100 dark:text-slate-900';
	}

	$selected_reminder_user_label = '';
	if (!empty($reminder_info->user_id)) {
		$selected_reminder_user = $this->db->select('fullname')->where('user_id', $reminder_info->user_id)->get('tbl_account_details')->row();
		if (!empty($selected_reminder_user->fullname)) {
			$selected_reminder_user_label = $selected_reminder_user->fullname;
		}
	}
	?>
	<div class="rounded-2xl border border-slate-200 bg-white shadow-sm dark:border-slate-700 dark:bg-slate-900">

		<div class="border-b border-slate-200 px-5 py-4 dark:border-slate-700">
			<div class="flex flex-wrap gap-2">
				<button type="button" data-reminder-tab-btn="manage"
					class="<?= $manage_tab_classes ?>">
					<?= lang('reminder') . ' ' . lang('list') ?>
				</button>

				<button type="button" data-reminder-tab-btn="create"
					class="<?= $create_tab_classes ?>">
					<?= lang('set') . ' ' . lang('reminder') ?>
				</button>
			</div>
		</div>

		<div class="p-5">
			<div id="tab-manage" data-reminder-tab-panel="manage" class="<?= $reminder_active_tab === 'manage' ? '' : 'hidden' ?>">
				<div class="overflow-x-auto rounded-xl border border-slate-200 dark:border-slate-700">
					<table class="min-w-full divide-y divide-slate-200 text-sm dark:divide-slate-700" width="100%">
						<thead class="bg-slate-50 text-slate-600 dark:bg-slate-800 dark:text-slate-300">
							<tr>
								<th class="px-4 py-3 text-left font-semibold"><?= lang('description') ?></th>
								<th class="px-4 py-3 text-left font-semibold"><?= lang('date') ?></th>
								<th class="px-4 py-3 text-left font-semibold"><?= lang('remind') ?></th>
								<th class="px-4 py-3 text-left font-semibold"><?= lang('notified') ?></th>
								<th class="col-options no-sort px-4 py-3 text-right font-semibold"><?= lang('action') ?></th>
							</tr>
						</thead>
						<tbody class="divide-y divide-slate-100 dark:divide-slate-800">
							<?php
							if (!empty($all_reminder)) {
								foreach ($all_reminder as $v_reminder):
									$remind_user_info = $this->db->where('user_id', $v_reminder->user_id)->get('tbl_account_details')->row();
									$remind_name = !empty($remind_user_info->fullname) ? $remind_user_info->fullname : lang('unknown');
							?>
									<tr id="table_reminder_<?= $v_reminder->reminder_id ?>">
										<td class="px-4 py-3 text-slate-700 dark:text-slate-200"><?= html_escape($v_reminder->description) ?></td>
										<td class="px-4 py-3 text-slate-700 dark:text-slate-200"><?= display_date($v_reminder->date) . ' ' . display_time($v_reminder->date) ?></td>
										<td class="px-4 py-3">
											<a href="<?= base_url() ?>admin/user/user_details/<?= $v_reminder->user_id ?>" class="text-primary hover:underline">
												<?= html_escape($remind_name) ?>
											</a>
										</td>
										<td class="px-4 py-3 text-slate-700 dark:text-slate-200"><?= html_escape($v_reminder->notified) ?></td>
										<td class="px-4 py-3">
											<?=
											ajax_anchor(
												base_url("admin/invoice/delete_reminder/" . $v_reminder->module . '/' . $v_reminder->module_id . '/' . $v_reminder->reminder_id),
												lang('delete'),
												array(
													"class" => "inline-flex items-center rounded-lg border border-rose-200 bg-rose-50 px-2.5 py-1 text-xs font-semibold text-rose-600 transition hover:bg-rose-100 dark:border-rose-900/60 dark:bg-rose-950/30 dark:text-rose-300 dark:hover:bg-rose-900/40",
													"title" => lang('delete'),
													"data-fade-out-on-success" => "#table_reminder_" . $v_reminder->reminder_id
												)
											);
											?>
										</td>
									</tr>
								<?php
								endforeach;
							} else {
								?>
								<tr>
									<td colspan="5" class="px-4 py-6 text-center text-sm text-slate-500 dark:text-slate-400"><?= lang('nothing_to_display') ?></td>
								</tr>
							<?php } ?>
						</tbody>
					</table>
				</div>
			</div>

			<div id="tab-create" data-reminder-tab-panel="create" class="<?= $reminder_active_tab === 'create' ? '' : 'hidden' ?>">
				<form role="form" data-parsley-validate="" novalidate="" enctype="multipart/form-data" id="form"
					action="<?php echo base_url(); ?>admin/invoice/reminder/<?= $module ?>/<?= $module_id ?>/<?php
																												if (!empty($reminder_info)) {
																													echo $reminder_info->reminder_id;
																												}
																												?>"
					method="post">

					<div class="grid gap-2 md:grid-cols-12 md:gap-3">
						<label class="md:col-span-3 pt-2 text-sm font-semibold text-slate-700 dark:text-slate-200 text-right">
							<?= lang('date_to_notified') ?> <span class="text-rose-500">*</span>
						</label>
						<div class="md:col-span-8">
							<input type="text" name="date"
								class="ts-datepicker w-full rounded-lg border border-slate-200 bg-white px-3 py-2 text-sm text-slate-700 outline-none transition focus:border-slate-400 focus:ring-2 focus:ring-slate-200 dark:border-slate-700 dark:bg-slate-800 dark:text-slate-100 dark:focus:border-slate-500 dark:focus:ring-slate-700"
								value="<?php
										if (!empty($reminder_info->date)) {
											echo $reminder_info->date;
										} else {
											echo date('Y-m-d H:i');
										}
										?>"
								data-type="datetime"
								data-format="Y-m-d H:i"
								data-min-date="<?= date('Y-m-d'); ?>">
						</div>
					</div>


					<div class="grid gap-2 md:grid-cols-12 md:gap-4">
						<div class="md:col-span-8">

							<?= form_textarea('description', lang('description'), !empty($reminder_info) ? $reminder_info->description : '', 3, false, array(), 'horizontal'); ?>
						</div>
					</div>

					<?= form_lookup_group(
						'user_id',
						lang('set_reminder_to'),
						!empty($reminder_info->user_id) ? $reminder_info->user_id : '',
						$selected_reminder_user_label,
						true,
						array(),
						'md:col-span-8',
						array(
							'type' => 'staff',
							'min_length' => 0,
							'placeholder' => lang('search') . ' ' . lang('staff'),
						),
						'horizontal'
					); ?>

					<div class="grid gap-2 md:grid-cols-12 md:gap-4 mb-3">
						<div class="md:col-span-3"></div>
						
						<div class="md:col-span-8">
							<?= form_checkbox(
								'notify_by_email',
								lang('send_also_email_this_reminder'),
								(!empty($reminder_info) && $reminder_info->notify_by_email == 'Yes'),
								false,
								array(
									'value' => 'Yes',
									'id' => 'notify_by_email'
								)
							); ?>
						</div>
					</div>

					<div class="grid gap-2 md:grid-cols-12 md:gap-4">
						<label class="md:col-span-3"></label>
						<div class="md:col-span-8">
							<button type="submit"
								class="inline-flex items-center rounded-lg bg-slate-900 px-4 py-2 text-sm font-semibold text-white transition hover:bg-slate-800 dark:bg-slate-100 dark:text-slate-900 dark:hover:bg-white">
								<?= lang('update') ?>
							</button>
						</div>
					</div>
				</form>
			</div>
		</div>
	</div>
</div>
