<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>

<?php
$selected_client_id = !empty($project_info->client_id) ? $project_info->client_id : '';
$selected_client_label = '';
$new_client_html = form_lookup_add_link(
    'client_id',
    base_url('admin/client/manage_client'),
    lang('create') . ' ' . lang('client'),
    '2xl'
);

if (!empty($all_client)) {
    foreach ($all_client as $v_client) {
        if ((string) $selected_client_id === (string) $v_client->client_id) {
            $selected_client_label = $v_client->name;
            break;
        }
    }
}

$start_date = !empty($project_info->start_date) ? date('Y-m-d', safe_strtotime($project_info->start_date)) : '';
$end_date = !empty($project_info->end_date) ? date('Y-m-d', safe_strtotime($project_info->end_date)) : '';
?>

<div class="panel panel-custom">
    <div class="modal-body wrap-modal wrap">
        <?php echo form_open(base_url('admin/projects/cloned_project/' . $project_info->project_id), array('role' => 'form', 'id' => 'from_items', 'class' => '', 'data-parsley-validate' => 'true')); ?>

        <div class="grid gap-8">
            <div class="space-y-4">
                <div class="rounded-xl border border-slate-200 bg-slate-50 p-4 dark:border-slate-700 dark:bg-slate-800">
                    <div class="grid grid-cols-1 gap-4 md:grid-cols-2">
                        <?= form_lookup_group(
                            'client_id',
                            lang('select') . ' ' . lang('client'),
                            $selected_client_id,
                            $selected_client_label,
                            true,
                            array(),
                            '',
                            array(
                                'type' => 'client',
                                'append' => $new_client_html,
                                'placeholder' => lang('search') . ' ' . lang('client'),
                            )
                        ); ?>

                        <?= form_datepicker('start_date', lang('start_date'), $start_date, true); ?>

                        <?= form_datepicker(
                            'end_date',
                            lang('end_date'),
                            $end_date,
                            true,
                            array(
                                'data-rule-required' => 'true',
                                'data-msg-greaterThanOrEqual' => 'end_date_must_be_equal_or_greater_than_start_date',
                                'data-rule-greaterThanOrEqual' => '#start_date',
                            )
                        ); ?>

                        <div class="md:col-span-2">
                            <label class="mb-2 block text-sm font-semibold text-slate-700 dark:text-slate-200">
                                <?= lang('also_added') ?>
                            </label>
                            <div class="space-y-3">
                                <label class="flex items-center justify-between rounded-2xl border border-slate-200 bg-white px-4 py-3 text-sm text-slate-700 shadow-sm dark:border-slate-700 dark:bg-slate-900 dark:text-slate-200">
                                    <span><?= lang('milestones') ?></span>
                                    <input
                                        type="checkbox"
                                        name="milestones"
                                        value="1"
                                        class="h-4 w-4 rounded border-slate-300 text-indigo-600 focus:ring-indigo-500"
                                        <?= !empty($milestone_info) ? 'checked' : '' ?>>
                                </label>
                                <label class="flex items-center justify-between rounded-2xl border border-slate-200 bg-white px-4 py-3 text-sm text-slate-700 shadow-sm dark:border-slate-700 dark:bg-slate-900 dark:text-slate-200">
                                    <span><?= lang('tasks') ?></span>
                                    <input
                                        type="checkbox"
                                        name="tasks"
                                        value="1"
                                        class="h-4 w-4 rounded border-slate-300 text-indigo-600 focus:ring-indigo-500"
                                        <?= !empty($task_info) ? 'checked' : '' ?>>
                                </label>
                            </div>
                        </div>
                    </div>

                    <div class="mt-6 flex items-center gap-2">
                        <button type="button" class="inline-flex items-center rounded-xl border border-slate-300 bg-white px-4 py-2 text-sm font-semibold text-slate-700 transition hover:border-slate-400 hover:bg-slate-50 dark:border-slate-600 dark:bg-slate-900 dark:text-slate-200 dark:hover:bg-slate-800" data-dismiss="modal">
                            <?= lang('close') ?>
                        </button>
                        <?= btn_update(lang('clone'), 'md') ?>
                    </div>
                </div>
            </div>
        </div>

        <?php echo form_close(); ?>
    </div>
</div>
