<?php echo message_box('success') ?>
<?php echo message_box('error') ?>

<div class="space-y-6">
    <form action="<?php echo base_url() ?>admin/settings/save_purchase" enctype="multipart/form-data" method="post" class="space-y-6">
        <div class="rounded-2xl border border-border bg-card shadow-sm">
            <div class="flex items-center justify-between border-b border-border px-6 py-4">
                <div>
                    <h3 class="text-lg font-semibold text-foreground"><?= lang('purchase') . ' ' . lang('settings') ?></h3>
                    <p class="text-sm text-muted-foreground"><?= lang('manage') . ' ' . lang('purchase') ?></p>
                </div>
                <button type="submit" class="inline-flex items-center justify-center gap-2 rounded-lg bg-primary px-6 py-2.5 text-sm font-medium text-primary-foreground shadow-sm hover:bg-primary/90 transition-colors">
                    <i data-lucide="save" class="h-4 w-4"></i>
                    <?= lang('save_changes') ?>
                </button>
            </div>
            <div class="p-6 space-y-6">
                <input type="hidden" name="settings" value="<?= $load_setting ?>">

                <div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
                    <div class="rounded-xl border border-border bg-card p-5 space-y-4">
                        <div class="flex items-center gap-2 border-b border-border pb-3">
                            <i data-lucide="shopping-cart" class="h-5 w-5"></i>
                            <h4 class="text-base font-semibold text-foreground"><?= lang('purchase') ?></h4>
                        </div>
                        <?= form_input_group('purchase_prefix', lang('purchase') . ' ' . lang('prefix'), config_item('purchase_prefix'), 'text', true, ) ?>
                        <?= form_input_group('purchase_start_no', lang('purchase') . ' ' . lang('start_no'), config_item('purchase_start_no'), 'text', true, ) ?>
                        <div class="space-y-2">
                            <?=
                            form_input_group(
                                'purchase_number_format',
                                lang('purchase') . ' ' . lang('number_format'),
                                empty(config_item('purchase_number_format'))
                                    ? '[' . config_item('purchase_prefix') . ']' . '[yyyy][mm][dd][number]'
                                    : config_item('purchase_number_format'),
                                'text',
                                false,
                            )
                            ?>
                            <p class="text-xs text-muted-foreground">ex [<?= config_item('purchase_prefix') ?>] = <?= lang('purchase_prefix') ?>,[yyyy] = 'Current Year (<?= date('Y') ?>)'[yy] ='Current Year (<?= date('y') ?>)',[mm] = 'Current Month(<?= date('M') ?>)',[m] = 'Current Month(<?= date('m') ?>)',[dd] = 'Current Date (<?= date('d') ?>)',[number] = 'Invoice Number (<?= sprintf('%04d', config_item('purchase_start_no')) ?>)'</p>
                        </div>
                        <?= form_checkbox('update_stock_when_make_payment', lang('update_stock_when_make_payment'), config_item('update_stock_when_make_payment') == 'Yes', false, array('value' => 'Yes')) ?>
                    </div>

                    <div class="rounded-xl border border-border bg-card p-5 space-y-4">
                        <div class="flex items-center gap-2 border-b border-border pb-3">
                            <i data-lucide="undo" class="h-5 w-5"></i>
                            <h4 class="text-base font-semibold text-foreground"><?= lang('return_stock') ?></h4>
                        </div>
                        <?= form_input_group('return_stock_prefix', lang('return_stock') . ' ' . lang('prefix'), config_item('return_stock_prefix'), 'text', true) ?>
                        <?= form_input_group('return_stock_start_no', lang('return_stock') . ' ' . lang('start_no'), config_item('return_stock_start_no'), 'text', true) ?>
                        <div class="space-y-2">
                            <?=
                            form_input_group(
                                'return_stock_number_format',
                                lang('return_stock') . ' ' . lang('number_format'),
                                empty(config_item('return_stock_number_format'))
                                    ? '[' . config_item('return_stock_prefix') . ']' . '[yyyy][mm][dd][number]'
                                    : config_item('return_stock_number_format'),
                                'text',
                                false,
                            )
                            ?>
                            <p class="text-xs text-muted-foreground">ex [<?= config_item('return_stock_prefix') ?>] = <?= lang('return_stock_prefix') ?>,[yyyy] = 'Current Year (<?= date('Y') ?>)'[yy] ='Current Year (<?= date('y') ?>)',[mm] = 'Current Month(<?= date('M') ?>)',[m] = 'Current Month(<?= date('m') ?>)',[dd] = 'Current Date (<?= date('d') ?>)',[number] = 'Invoice Number (<?= sprintf('%04d', config_item('return_stock_start_no')) ?>)'</p>
                        </div>
                        <?= form_editor('purchase_notes', lang('purchase_notes'), config_item('purchase_notes'), false, array('class' => 'textarea')) ?>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>
