<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>
<?php
$edited = can_action('24', 'edited');
$deleted = can_action('24', 'deleted');
$document_info = get_row('tbl_employee_document', array('user_id' => $profile_info->user_id));
?>

<div class="rounded-2xl border border-border bg-card shadow-sm">
    <div class="flex items-center justify-between border-b border-border px-5 py-4">
        <h4 class="text-sm font-semibold text-foreground"><?= lang('user_documents') ?></h4>
        <?php if (!empty($edited)) { ?>
            <span data-placement="top" data-toggle="tooltip" title="<?= lang('update_conatct') ?>">
                <?= btn_modal(
                    'admin/user/user_documents/' . $profile_info->user_id,
                    lang('update'),
                    lang('update'),
                    'md',
                    '',
                    array('class' => 'text-xs font-semibold text-primary hover:underline')
                ) ?>
            </span>
        <?php } ?>
    </div>
    <div class="p-5 space-y-4">
        <?php if (!empty($document_info->resume)) : ?>
            <div class="flex items-center justify-between rounded-lg border border-border bg-muted/40 px-4 py-2">
                <span class="text-sm text-foreground"><?= lang('resume') ?></span>
                <div class="flex items-center gap-2">
                    <a href="<?php echo base_url() . $document_info->resume; ?>" target="_blank" class="text-xs font-semibold text-primary hover:underline"><?= lang('view') ?></a>
                    <a href="<?= base_url('admin/user/delete_documents/resume/' . $document_info->document_id) ?>"
                       class="text-rose-600 hover:text-rose-700 text-xs font-semibold" title="" data-toggle="tooltip" data-placement="top"
                       onclick="return confirm(<?= json_encode(lang('delete_alert')) ?>);"
                       data-original-title="<?= lang('delete') ?>"><i data-lucide="trash-2"></i></a>
                </div>
            </div>
        <?php endif; ?>

        <?php if (!empty($document_info->offer_letter)) : ?>
            <div class="flex items-center justify-between rounded-lg border border-border bg-muted/40 px-4 py-2">
                <span class="text-sm text-foreground"><?= lang('offer_latter') ?></span>
                <div class="flex items-center gap-2">
                    <a href="<?php echo base_url() . $document_info->offer_letter; ?>" target="_blank" class="text-xs font-semibold text-primary hover:underline"><?= lang('view') ?></a>
                    <a href="<?= base_url('admin/user/delete_documents/offer_letter/' . $document_info->document_id) ?>"
                       class="text-rose-600 hover:text-rose-700 text-xs font-semibold" title="" data-toggle="tooltip" data-placement="top"
                       onclick="return confirm(<?= json_encode(lang('delete_alert')) ?>);"
                       data-original-title="<?= lang('delete') ?>"><i data-lucide="trash-2"></i></a>
                </div>
            </div>
        <?php endif; ?>

        <?php if (!empty($document_info->joining_letter)) : ?>
            <div class="flex items-center justify-between rounded-lg border border-border bg-muted/40 px-4 py-2">
                <span class="text-sm text-foreground"><?= lang('joining_latter') ?></span>
                <div class="flex items-center gap-2">
                    <a href="<?php echo base_url() . $document_info->joining_letter; ?>" target="_blank" class="text-xs font-semibold text-primary hover:underline"><?= lang('view') ?></a>
                    <a href="<?= base_url('admin/user/delete_documents/joining_letter/' . $document_info->document_id) ?>"
                       class="text-rose-600 hover:text-rose-700 text-xs font-semibold" title="" data-toggle="tooltip" data-placement="top"
                       onclick="return confirm(<?= json_encode(lang('delete_alert')) ?>);"
                       data-original-title="<?= lang('delete') ?>"><i data-lucide="trash-2"></i></a>
                </div>
            </div>
        <?php endif; ?>

        <?php if (!empty($document_info->contract_paper)) : ?>
            <div class="flex items-center justify-between rounded-lg border border-border bg-muted/40 px-4 py-2">
                <span class="text-sm text-foreground"><?= lang('contract_paper') ?></span>
                <div class="flex items-center gap-2">
                    <a href="<?php echo base_url() . $document_info->contract_paper; ?>" target="_blank" class="text-xs font-semibold text-primary hover:underline"><?= lang('view') ?></a>
                    <a href="<?= base_url('admin/user/delete_documents/contract_paper/' . $document_info->document_id) ?>"
                       class="text-rose-600 hover:text-rose-700 text-xs font-semibold" title="" data-toggle="tooltip" data-placement="top"
                       onclick="return confirm(<?= json_encode(lang('delete_alert')) ?>);"
                       data-original-title="<?= lang('delete') ?>"><i data-lucide="trash-2"></i></a>
                </div>
            </div>
        <?php endif; ?>

        <?php if (!empty($document_info->id_proff)) : ?>
            <div class="flex items-center justify-between rounded-lg border border-border bg-muted/40 px-4 py-2">
                <span class="text-sm text-foreground"><?= lang('id_prof') ?></span>
                <div class="flex items-center gap-2">
                    <a href="<?php echo base_url() . $document_info->id_proff; ?>" target="_blank" class="text-xs font-semibold text-primary hover:underline"><?= lang('view') ?></a>
                    <a href="<?= base_url('admin/user/delete_documents/id_proff/' . $document_info->document_id) ?>"
                       class="text-rose-600 hover:text-rose-700 text-xs font-semibold" title="" data-toggle="tooltip" data-placement="top"
                       onclick="return confirm(<?= json_encode(lang('delete_alert')) ?>);"
                       data-original-title="<?= lang('delete') ?>"><i data-lucide="trash-2"></i></a>
                </div>
            </div>
        <?php endif; ?>

        <?php if (!empty($document_info->other_document)) : ?>
            <div class="space-y-2">
                <div class="text-sm font-semibold text-foreground"><?= lang('other_document') ?></div>
                <?php
                $uploaded_file = json_decode($document_info->other_document);
                if (!empty($uploaded_file)) :
                    foreach ($uploaded_file as $sl => $v_files) :
                        if (!empty($v_files)) : ?>
                            <div class="flex items-center justify-between rounded-lg border border-border bg-muted/40 px-4 py-2">
                                <span class="text-sm text-foreground"><?= ($sl + 1) . '. ' . lang('other_document'); ?></span>
                                <a href="<?php echo base_url() . 'uploads/' . $v_files->fileName; ?>" target="_blank" class="text-xs font-semibold text-primary hover:underline"><?= lang('view') ?></a>
                            </div>
                        <?php endif;
                    endforeach;
                endif; ?>
            </div>
        <?php endif; ?>

        <?php if (empty($document_info)) : ?>
            <p class="text-sm text-muted-foreground"><?= lang('no_data_found') ?></p>
        <?php endif; ?>
    </div>
</div>

<script type="text/javascript">
    $(document)
        .off('click.userDocumentsAdd', '#add_more')
        .on('click.userDocumentsAdd', '#add_more', function () {
            var $container = $('#add_new');

            if (!$container.length) {
                return;
            }

            $container.append(
                '<div class="grid grid-cols-1 md:grid-cols-2 gap-4"><?= addslashes(form_file('other_document[]', lang('other_document'))); ?></div>'
            );

            if (window.lucide && typeof lucide.createIcons === 'function') {
                lucide.createIcons();
            }
        });

    $(document)
        .off('click.userDocumentsRemove', '#add_new .RCF')
        .on('click.userDocumentsRemove', '#add_new .RCF', function () {
            $(this).closest('.flex').remove();
        });
</script>





