<?php
echo message_box('success');
echo message_box('error');

// $all_customer_group = $this->db->where('type', 'client')->order_by('customer_group_id', 'DESC')->get('tbl_customer_group')->result();
$client_id = !empty($client_info) ? $client_info->client_id : null;
$selected_category_id = !empty($client_info->customer_group_id) ? $client_info->customer_group_id : null;
$selected_category_label = null;
if (!empty($client_info->customer_group_id)) {
	$group_info = $this->db->where('customer_group_id', $client_info->customer_group_id)->get('tbl_customer_group')->row();
	if (!empty($group_info)) {
		$selected_category_label = $group_info->customer_group;
	}
}
?>


<?php echo form_open(base_url('admin/client/update_client/' . $client_id), array('id' => 'client_modal', 'class' => 'space-y-6 ', 'enctype' => 'multipart/form-data', 'data-parsley-validate' => 'true', 'role' => 'form')); ?>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
	<?= form_input_group('name', lang('company_name'), '', 'text', true); ?>
	<?= form_input_group('email', lang('company_email'), '', 'email', true); ?>
	<?= form_input_group('vat', lang('company_vat'), '', 'text'); ?>
	<?php
	// $group_options = [];
	// if (!empty($all_customer_group)) {
	// 	foreach ($all_customer_group as $group) {
	// 		$group_options[$group->customer_group_id] = $group->customer_group;
	// 	}
	// }
	$new_group_html = form_lookup_add_link(
		'customer_group_id',
		base_url('admin/client/customer_group'),
		lang('new') . ' ' . lang('customer_group'),
		'sm'
	);

	?>
	<?= form_lookup_group('customer_group_id', lang('customer_group'), $selected_category_id, $selected_category_label, false, array(), '', array('type' => 'category', 'extra' => ['type' => 'client'], 'append' => $new_group_html)); ?>
	
	<?php
	$lang_opts = [];
	if (!empty($languages)) {
		foreach ($languages as $lang) {
			$lang_opts[$lang->name] = ucfirst($lang->name);
		}
	}
	?>
	<?= form_select_group('language', lang('language'), $lang_opts, $this->config->item('language'), false); ?>
	<?php
	$curr_opts = [];
	if (!empty($currencies)) {
		foreach ($currencies as $currency) {
			$curr_opts[$currency->code] = $currency->name;
		}
	}
	?>
	<?= form_select_group('currency', lang('currency'), $curr_opts, config_item('default_currency'), false); ?>

	<?= form_textarea_group('short_note', lang('short_note'), '', 3, false); ?>


</div>

<div class="modal-footer flex items-center justify-end gap-0 mt-4">
	<?= btn_modal_close('close', 'sm') ?>
	<?= btn_update('save_changes', 'sm') ?>
</div>

<?php echo form_close(); ?>
