<?= message_box('success'); ?>
<?= message_box('error'); ?>

<?php
$permissionL = !empty($leads_info->permission) ? $leads_info->permission : null;

$lead_source_selected = !empty($leads_info->lead_source_id) ? $leads_info->lead_source_id : '';
$lead_source_selected_label = '';
if (!empty($lead_source_selected)) {
	$lead_source_row = $this->db->select('lead_source')->where('lead_source_id', $lead_source_selected)->get('tbl_lead_source')->row();
	if (!empty($lead_source_row)) {
		$lead_source_selected_label = $lead_source_row->lead_source;
	}
}

$lead_status_selected = !empty($leads_info->lead_status_id) ? $leads_info->lead_status_id : '';
$lead_status_selected_label = '';
if (!empty($lead_status_selected)) {
	$lead_status_row = $this->db->select('lead_status')->where('lead_status_id', $lead_status_selected)->get('tbl_lead_status')->row();
	if (!empty($lead_status_row)) {
		$lead_status_selected_label = $lead_status_row->lead_status;
	}
}

$new_status_html = form_lookup_add_link(
	'lead_status_id',
	base_url('admin/leads/lead_status'),
	lang('create') . ' ' . lang('lead_status'),
);

$new_source_html = form_lookup_add_link(
	'lead_source_id',
	base_url('admin/leads/lead_source'),
	lang('create') . ' ' . lang('lead_source'),
);
?>

<div class="space-y-6">
	<div class="rounded-2xl border border-border bg-card p-6">
		<div class="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
			<div>
				<p class="text-xs font-semibold uppercase tracking-wide text-muted-foreground"><?= lang('leads'); ?></p>
				<h1 class="text-2xl font-semibold text-foreground"><?= lang('import_leads') ?></h1>
			</div>
			<div class="flex items-center gap-2">
				<a href="<?= base_url('assets/sample/leads_sample.xlsx') ?>"
					class="inline-flex items-center gap-2 rounded-lg border border-border bg-card px-3 py-2 text-sm font-medium text-foreground hover:bg-muted">
					<i data-lucide="download" class="h-4 w-4"></i>
					<?= lang('download_sample') ?>
				</a>
			</div>
		</div>
	</div>

	<?= form_open(base_url('admin/leads/save_imported'), [
		'id' => 'form',
		'class' => 'space-y-6',
		'enctype' => 'multipart/form-data',
		'data-parsley-validate' => '',
		'novalidate' => '',
	]); ?>
		<div class="grid grid-cols-1 xl:grid-cols-12 gap-6">
			<div class="xl:col-span-8 space-y-6">
				<div class="rounded-xl border border-border bg-card p-6 space-y-5">
					<div class="flex items-center gap-2 border-b border-slate-200 pb-3 dark:border-slate-700">
						<i data-lucide="upload" class="h-5 w-5"></i>
						<h2 class="text-base font-semibold text-foreground"><?= lang('import') . ' ' . lang('details') ?></h2>
					</div>

					<div class="grid grid-cols-1 md:grid-cols-2 gap-5">
						<div class="md:col-span-2">
							<label for="upload_file" class="text-sm font-medium text-foreground">
								<?= lang('choose_file') ?> <span class="text-rose-500">*</span>
							</label>
							<input id="upload_file" name="upload_file" type="file" required
								class="mt-2 block w-full rounded-lg border border-border bg-card px-3 py-2 text-sm text-foreground shadow-sm file:mr-4 file:rounded-md file:border-0 file:bg-muted file:px-3 file:py-2 file:text-sm file:font-semibold hover:file:bg-muted/80">
							<p class="mt-2 text-xs text-muted-foreground"><?= lang('select_file') ?></p>
						</div>

						<?= form_lookup_group('lead_source_id', lang('lead_source'), $lead_source_selected, $lead_source_selected_label, true, array(), '', array('type' => 'lead_source', 'append' => $new_source_html)); ?>

						<?= form_lookup_group('lead_status_id', lang('lead_status'), $lead_status_selected, $lead_status_selected_label, true, array(), '', array('type' => 'lead_status', 'append' => $new_status_html)); ?>
					</div>
				</div>
			</div>

			<aside class="xl:col-span-4 space-y-6">
				<?= form_permission_modern($assign_user, $permissionL, lang('assigned_to')); ?>
			</aside>
		</div>

		<div class="sticky bottom-4 z-20">
			<div class="flex flex-wrap justify-end gap-3 rounded-2xl border border-border bg-card px-4 py-3 shadow-sm">
				<button type="submit" class="inline-flex items-center gap-2 rounded-lg bg-indigo-600 px-4 py-2 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500">
					<i data-lucide="upload" class="h-4 w-4"></i>
					<?= lang('upload') ?>
				</button>
			</div>
		</div>
	<?= form_close(); ?>
</div>
