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

<?php
$all_customer_group = $this->db->where('type', 'client')->get('tbl_customer_group')->result();

$customer_group_options = array('' => lang('nothing_selected'));
if (!empty($all_customer_group)) {
	foreach ($all_customer_group as $customer_group) {
		$customer_group_options[$customer_group->customer_group_id] = $customer_group->customer_group;
	}
}
$selected_customer_group = !empty($client_info->customer_group_id) ? $client_info->customer_group_id : '';

$language_options = array();
if (!empty($languages)) {
	foreach ($languages as $lang) {
		$language_options[$lang->name] = ucfirst($lang->name);
	}
}
$selected_language = !empty($client_info->language) ? $client_info->language : $this->config->item('language');

$currency_options = array();
if (!empty($currencies)) {
	foreach ($currencies as $currency) {
		$currency_options[$currency->code] = $currency->name;
	}
}
$selected_currency = !empty($client_info->currency) ? $client_info->currency : $this->config->item('default_currency');

$country_options = array(
	$this->config->item('company_country') => $this->config->item('company_country'),
);
if (!empty($countries)) {
	foreach ($countries as $country) {
		$country_options[$country->value] = $country->value;
	}
}
$selected_country = !empty($client_info->country) ? $client_info->country : $this->config->item('company_country');

$permissionL = !empty($client_info->permission) ? $client_info->permission : null;
?>

<div class="rounded-2xl border border-border bg-card shadow-sm">
	<div class="px-6 py-5 flex justify-between items-start border-b border-border">
		<div class="flex items-center">
			<div>
				<h3 class="text-xl font-bold text-foreground"><?= lang('import') . ' ' . lang('client') ?></h3>
				<p class="text-sm mt-1 text-muted-foreground"><?= lang('fill_form_fields'); ?></p>
			</div>
		</div>
		<div class="flex gap-2">
			<?= btn_back(lang('back')); ?>
			<a href="<?= base_url('assets/sample/client_sample.csv') ?>"
			   class="inline-flex items-center gap-2 rounded-lg bg-slate-900 px-4 py-2 text-sm font-medium text-white shadow hover:bg-slate-800 transition dark:bg-slate-100 dark:text-slate-900 dark:hover:bg-white">
				<i data-lucide="download" class="h-4 w-4"></i>
				<?= lang('download_sample') ?>
			</a>
		</div>
	</div>

	<?= form_open_multipart(base_url('admin/client/save_imported'), array('id' => 'form', 'class' => 'p-6 space-y-6')); ?>
		<div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
			<div class="lg:col-span-2 space-y-5">
				<div class="bg-slate-50 p-4 rounded-xl border border-slate-200 dark:bg-slate-800 dark:border-slate-700">
					<h4 class="text-sm font-semibold text-foreground flex items-center gap-2 mb-3 border-b border-slate-200 pb-2 dark:text-slate-100 dark:border-slate-700">
						<i data-lucide="upload" class="h-5 w-5"></i>
						<?= lang('general'); ?>
					</h4>

					<div class="space-y-4">
						<?= form_attachment('upload_file', lang('choose_file') . ' *', 'file', array('accept' => '.xlsx,.csv')) ?>

						<div class="grid grid-cols-1 md:grid-cols-2 gap-5">
							<?= form_select_group(
								'customer_group_id',
								lang('customer_group'),
								$customer_group_options,
								$selected_customer_group,
								false,
								array('class' => 'select_box', 'data-search' => 'true')
							) ?>

							<?= form_select_group(
								'language',
								lang('language'),
								$language_options,
								$selected_language,
								false,
								array('class' => 'select_box', 'data-search' => 'true')
							) ?>

							<?= form_select_group(
								'currency',
								lang('currency'),
								$currency_options,
								$selected_currency,
								false,
								array('class' => 'select_box', 'data-search' => 'true')
							) ?>

							<?= form_select_group(
								'country',
								lang('country'),
								$country_options,
								$selected_country,
								false,
								array('class' => 'select_box', 'data-search' => 'true')
							) ?>
						</div>

						<div class="flex items-center gap-2 pt-2">
							<?= btn_update(lang('upload'), 'md') ?>
							<?= btn_cancel('admin/client/manage_client', 'cancel', 'md', 'x', array('class' => 'mb-0 !h-9')); ?>
						</div>
					</div>
				</div>
			</div>

			<div class="space-y-5">
				<?= form_permission_modern($assign_user, $permissionL, lang('assined_to')); ?>
			</div>
		</div>
	<?= form_close(); ?>
</div>
