<?php
$new_user_html = form_lookup_add_link(
	'user_id',
	base_url('admin/users/new_user'),
	lang('create') . ' ' . lang('user'),
);

$selected_user_id = !empty($milestone_info->user_id) ? $milestone_info->user_id : '';
$selected_user_label = '';
if (!empty($selected_user_id)) {
	$user_row = $this->db->where('user_id', $selected_user_id)->get('tbl_account_details')->row();
	if (!empty($user_row)) {
		$selected_user_label = $user_row->fullname;
	}
}
?>
<?php echo form_open(base_url("admin/projects/save_milestones/$project_id" . '/' . (!empty($milestone_info) ? $milestone_info->milestones_id : '')), array("id" => "form", "class" => "modal-form")); ?>

<div class="grid gap-4">
	<div class="grid gap-4 md:grid-cols-1">
		<input type="hidden" name="project_id" value="<?= $project_id ?>">

		<?= form_input_group('milestone_name', lang('milestone_name'), (!empty($milestone_info) ? $milestone_info->milestone_name : ''), 'text', true) ?>
		<?= form_textarea_group('description', lang('description'), (!empty($milestone_info) ? $milestone_info->description : '')) ?>
		<div class="grid gap-4  md:grid-cols-2">
			<?= form_datepicker('start_date', lang('start_date'), !empty($milestone_info->start_date) ? date('Y-m-d', safe_strtotime($milestone_info->start_date)) : '', true, ['id' => 'start-date', 'data-max' => '#end-date', 'data-auto-close' => 'true']); ?>
			<?= form_datepicker('end_date', lang('end_date'), !empty($milestone_info->end_date) ? date('Y-m-d', safe_strtotime($milestone_info->end_date)) : '', true, ['id' => 'end-date', 'data-min' => '#start-date', 'data-auto-close' => 'true']); ?>

			<!-- <?= form_select_group('responsible', lang('responsible'), [], (!empty($milestone_info) ? $milestone_info->responsible : ''), false, array('data-live-search' => 'true')) ?> -->
			<?= form_lookup_group('user_id', lang('responsible'), $selected_user_id, $selected_user_label, true, array('data-live-search' => 'true'), '', array('type' => 'user', 'append' => $new_user_html)); ?>

			<?= form_switch_radio(
				'client_visible',
				lang('visible_to_client'),
				(!empty($milestone_info) ? $milestone_info->client_visible : 'no'),
				false,
				[],
				'stacked',
				['yes' => lang('yes'), 'no' => lang('no')]
			) ?>
		</div>
	</div>
</div>
<div class="mt-6 flex items-center justify-end gap-2">
	<button type="button" class="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 h-7" data-dismiss="modal">
		<i data-lucide="x" class="h-4 w-4"></i>
		<?= lang('close') ?>
	</button>
	<button type="submit" class="inline-flex items-center gap-2 rounded-lg bg-slate-900 px-4 py-2 text-xs font-semibold text-white hover:bg-slate-800 dark:bg-slate-700 dark:hover:bg-slate-600 h-7">
		<i data-lucide="check-circle" class="h-4 w-4"></i>
		<?= lang('save') ?>
	</button>
</div>
<?php echo form_close(); ?>
