<?php

$selected_awardrule = !empty($awardrule_info->award_rule_id) ? $awardrule_info->award_rule_id : '';
$selected_awardrule_label = null;
if (!empty($awardrule_info->award_rule_id)) {
	$rule = $this->db->where('award_rule_id', $awardrule_info->award_rule_id)->get('tbl_award_rule')->row();
	if (!empty($rule)) {
		$selected_awardrule_label = $rule->rule_name;
	}
}

$new_client_html = form_lookup_add_link(
	'client_id',
	base_url('admin/client/create'),
	lang('create') . ' ' . lang('client'),
);

$selected_client = !empty($awardrule_info->client_id) ? $awardrule_info->client_id : '';
$selected_client_label = null;
if (!empty($awardrule_info->client_id)) {
	$client = $this->db->where('client_id', $awardrule_info->client_id)->get('tbl_client')->row();
	if (!empty($client)) {
		$selected_client_label = $client->name;
	}
}
?>
<div class="rounded-2xl ">


	<?php echo form_open(base_url('admin/settings/save_program/' . (!empty($awardrule_info->award_program_id) ? $awardrule_info->award_program_id : '')), array('class' => 'space-y-6 ', 'enctype' => 'multipart/form-data', 'data-parsley-validate' => 'true', 'role' => 'form')); ?>

	<!-- <input type="hidden" name="settings" value="<?= $load_setting ?>"> -->

	<div class="grid grid-cols-1 gap-4 md:grid-cols-2">
		<?= form_input_group('program_name', lang('program_name'), (!empty($awardrule_info->program_name) ? $awardrule_info->program_name : ''), 'text', true); ?>


		<?= form_lookup_group('award_rule_id', lang('award_rule'), $selected_awardrule, $selected_awardrule_label, true, array(), '', array('type' => 'award_rule', 'append' => '')); ?>

		<?= form_lookup_group('client_id', lang('client'), $selected_client, $selected_client_label, true, array(), '', array('type' => 'client', 'append' => $new_client_html)); ?>


		<?= form_datepicker('start_date', lang('start_date'), !empty($awardrule_info->start_date) ? date('Y-m-d', safe_strtotime($awardrule_info->start_date)) : '', true); ?>
		<?= form_datepicker('end_date', lang('end_date'), !empty($awardrule_info->end_date) ? date('Y-m-d', safe_strtotime($awardrule_info->end_date)) : '', true); ?>


		<?php
		$status_options = array(
			'1' => lang('active'),
			'0' => lang('deactive')
		);
		$selected_status = !empty($awardrule_info->status) ? $awardrule_info->status : '1';
		?>
		<?= form_select_group('status', lang('status'), $status_options, $selected_status, false); ?>

		<?= form_editor('description', lang('description'), (!empty($awardrule_info->description) ? $awardrule_info->description : ''), false); ?>

	</div>




	<div class="flex items-center justify-end gap-2">
		<button type="submit" class="btn btn-sm btn-primary"><?= lang('save_changes') ?></button>
		<button type="button" class="btn btn-sm btn-secondary" data-dismiss="modal"><?= lang('cancel') ?></button>
	</div>
	<?php echo form_close(); ?>

</div>


<script type="text/javascript">
	$(document).ready(function() {
		$('body').find('select.selectpicker').not('.ajax-search').selectpicker({
			showSubtext: true,
		});
	});
</script>
