<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>

<?php
$module = isset($module) ? $module : '';
$module_id = isset($module_id) ? $module_id : null;
$reminder_id = isset($reminder_id) ? $reminder_id : null;

if (empty($module) || empty($module_id)) {
	echo '<div class="text-sm text-muted-foreground">' . lang('there_in_no_value') . '</div>';
	return;
}

$reminder_info = null;
if (!empty($reminder_id)) {
	$reminder_info = get_row('tbl_reminders', array('reminder_id' => $reminder_id));
}

$reminder_date = !empty($reminder_info->date) ? $reminder_info->date : date('Y-m-d H:i');
$reminder_description = !empty($reminder_info->description) ? $reminder_info->description : '';
$notify_checked = !empty($reminder_info->notify_by_email) && $reminder_info->notify_by_email === 'Yes';

$form_action = base_url('admin/invoice/reminder/' . $module . '/' . $module_id . '/' . (!empty($reminder_info->reminder_id) ? $reminder_info->reminder_id : ''));
$form_label = !empty($reminder_info) ? lang('updates') : lang('save');
?>

<?php echo form_open($form_action, array('class' => 'modal-form', 'data-parsley-validate' => '')); ?>
<div class="grid gap-4">
	<div class="grid gap-4 md:grid-cols-2">
		<?= form_datepicker('date', lang('date_to_notified'), $reminder_date, true, array('data-type' => 'datetime', 'data-format' => 'Y-m-d H:i', 'data-min-date' => date('Y-m-d'))); ?>
		<?= form_textarea_group('description', lang('description'), $reminder_description, 3, false, array('class' => 'textarea')); ?>
	</div>
	<label class="inline-flex items-center gap-2 text-sm text-muted-foreground">
		<input type="checkbox" value="Yes" name="notify_by_email" class="rounded border-border" <?= $notify_checked ? 'checked' : ''; ?>>
		<?= lang('send_also_email_this_reminder') ?>
	</label>
</div>

<div class="mt-6 flex items-center justify-end gap-2">
	<button type="button" class="cancel-upload inline-flex items-center gap-2 rounded-lg border border-slate-200 bg-white px-4 py-2 text-xs font-semibold text-slate-600 hover:bg-slate-50" data-dismiss="modal">
		<i data-lucide="x" class="h-4 w-4"></i>
		<?= lang('close'); ?>
	</button>
	<button type="submit" class="start-upload inline-flex items-center gap-2 rounded-lg bg-slate-900 px-4 py-2.5 text-xs font-semibold text-white hover:bg-slate-800 dark:bg-slate-700 dark:hover:bg-slate-600">
		<i data-lucide="check-circle" class="h-4 w-4"></i>
		<?= $form_label; ?>
	</button>
</div>
<?php echo form_close(); ?>
