<div class="invoice-modern">
<?php
$status_options = array('all' => lang('all'));
if ($module == 'invoice') {
    $invoiceFilter = $this->invoice_model->get_invoice_filter();
}
if ($module == 'estimate') {
    $invoiceFilter = $this->estimates_model->get_invoice_filter();
}
if ($module == 'credit_note') {
    $invoiceFilter = $this->credit_note_model->get_credit_note_filter();
}
if ($module == 'proposal') {
    $invoiceFilter = $this->proposal_model->get_invoice_filter();
}
if ($module == 'payment') {
    $invoiceFilter = $this->invoice_model->get_invoice_payment();
}
if (!empty($invoiceFilter)) {
    foreach ($invoiceFilter as $v_Filter) {
        $status_options[$v_Filter['value']] = $v_Filter['name'];
    }
}
?>


        <?php
        $zip_action = 'admin/invoice/zipped/' . $module;
        if (!empty($client_id)) {
            $zip_action .= '/' . (int) $client_id;
        }
        ?>
        <form id="from_items" action="<?= base_url($zip_action) ?>" method="post" class="space-y-5" data-modal-native-submit="true">
            <div class="rounded-xl border border-border bg-background/40 p-4">
                <?= form_radio_group('invoice_status', lang('status'), $status_options, 'all', false, array('group_class' => 'grid grid-cols-1 sm:grid-cols-2 gap-3 lg:grid-cols-3'), 'stacked'); ?>
            </div>

            <div id="zip_period_fields" class="grid grid-cols-1 gap-4 md:grid-cols-2">
                <?= form_datepicker('from_date', lang('from_date'), '', false, array('data-max' => '#to_date', 'data-auto-close' => 'true')); ?>
                <?= form_datepicker('to_date', lang('to_date'), '', false, array('data-min' => '#from_date', 'data-auto-close' => 'true')); ?>
            </div>

            <?php if (!empty($client_id)) { ?>
                <input type="hidden" name="client_id" value="<?= (int) $client_id ?>">
            <?php } ?>

            <div class="flex items-center justify-end border-t border-border pt-4">
                <?= btn_modal_close() ?>
                <button type="submit" class="inline-flex items-center mb-1 ml-1 gap-2 rounded-lg bg-primary px-4 py-2.5 text-xs font-semibold text-primary-foreground shadow-sm hover:bg-primary/90">
                    <i data-lucide="archive" class="h-4 w-4"></i>
                    <?= lang('zipped') ?>
                </button>
            </div>
        </form>
</div>

<script type="text/javascript">
    $(document).ready(function () {
        function toggleZipPeriodFields() {
            var val = $('[name="invoice_status"]:checked').val() || 'all';
            var year = val.split('_');
            if (val === 'last_month' || val === 'this_months' || $.isNumeric(year[1])) {
                $('#zip_period_fields').addClass('hidden');
                $('#zip_period_fields').find('input').prop('disabled', true);
            } else {
                $('#zip_period_fields').removeClass('hidden');
                $('#zip_period_fields').find('input').prop('disabled', false);
            }
        }

        $('[name="invoice_status"]').on('change', toggleZipPeriodFields);
        toggleZipPeriodFields();
    });
</script>
</div>
