<div class="invoice-modern">
<?php if (!empty($invoices_to_merge) && count(array($invoices_to_merge)) > 0) { ?>
    <div class="rounded-2xl border border-border bg-card shadow-sm">
        <div class="border-b border-border px-5 py-4">
            <h4 class="text-base font-semibold text-foreground"><?php echo lang('invoices_available_for_merging'); ?></h4>
            <p class="mt-1 text-sm text-muted-foreground"><?= lang('invoice') . ' ' . lang('list') ?></p>
        </div>

        <div class="space-y-4 px-5 py-5">
            <?php foreach ($invoices_to_merge as $_inv) { ?>
                <?php
                $currency = $this->invoice_model->client_currency_symbol($_inv->client_id);
                if (empty($currency)) {
                    $currency = $this->invoice_model->check_by(array('code' => config_item('default_currency')), 'tbl_currencies');
                }

                $invoice_label = '<span class="inline-flex items-center gap-2">'
                    . '<i class="text-red-500" data-lucide="hand" aria-hidden="true"></i>'
                    . '<a href="' . base_url() . 'admin/invoice/manage_invoice/invoice_details/' . $_inv->invoices_id . '"
                            data-toggle="tooltip"
                            data-title="' . html_escape($this->invoice_model->get_payment_status($_inv->invoices_id)) . '"
                            target="_blank"
                            class="font-semibold text-primary hover:underline">'
                    . $_inv->reference_no . '</a>'
                    . '<span class="text-muted-foreground">-</span>'
                    . '<strong>' . display_money($this->invoice_model->calculate_to('invoice_due', $_inv->invoices_id), $currency->symbol) . '</strong>'
                    . '</span>';
                ?>
                <div class="rounded-xl border border-border bg-background/40 p-4">
                    <?= form_checkbox('invoices_to_merge[]', $invoice_label, false, false, array('value' => $_inv->invoices_id, 'id' => 'merge_invoice_' . $_inv->invoices_id)); ?>
                    <?php if ($_inv->discount_total > 0) { ?>
                        <p class="mt-2 pl-8 text-sm text-amber-600 dark:text-amber-400">
                            <?= lang('invoices_merge_discount', display_money($_inv->discount_total, $currency->symbol)); ?>
                        </p>
                    <?php } ?>
                </div>
            <?php } ?>

            <div class="rounded-xl border border-emerald-200 bg-emerald-50/70 p-4 dark:border-emerald-900/50 dark:bg-emerald-950/20">
                <?= form_checkbox('cancel_merged_invoices', '<strong>' . lang('invoices_merge_cancel') . '</strong>', true, false, array('id' => 'cancel_merged_invoices')); ?>
            </div>
        </div>
    </div>
<?php } ?>
</div>
