<?= message_box('success'); ?>

<?php
$all_currencies = $this->db->get('tbl_currencies')->result();
$id = $this->uri->segment(4);
$edit_code = '';
$edit_name = '';
$edit_symbol = '';
$action_url = base_url() . 'admin/settings/new_currency/save';
$submit_label = lang('add');
if (!empty($id) && !empty($currency)) {
    $edit_code = $currency->code;
    $edit_name = $currency->name;
    $edit_symbol = $currency->symbol;
    $action_url = base_url() . 'admin/settings/new_currency/save/' . $currency->code;
    $submit_label = lang('update');
}
?>

<div 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('all_currency') ?></h3>
                <p class="text-sm text-muted-foreground"><?= lang('manage') . ' ' . lang('all_currency') ?></p>
            </div>
            <!-- <div class="flex items-center gap-2">
                <?php do_action('currency_sync_provider'); ?>
                <?php if ($this->session->userdata('user_type') == '1') { ?>
                    <a data-toggle="modal" data-target="#myModal" href="<?= base_url() ?>admin/settings/new_currency" class="btn_modal btn btn-sm btn-success" title="<?= lang('new_currency'); ?>">
                        <i class="text-white" data-lucide="plus"></i>
                    </a>
                <?php } ?>
            </div> -->
        </div>
        <div class="p-6">
            <div class="grid grid-cols-1 lg:grid-cols-12 gap-6">
                <div class="lg:col-span-4">
                    <div class="rounded-2xl border border-dashed border-border bg-card p-4 space-y-4">
                        <form method="post" action="<?= $action_url ?>" class="space-y-4">
                            <?= form_input_group('code', lang('code'), $edit_code, 'text', true, array('placeholder' => lang('code'))); ?>
                            <?= form_input_group('name', lang('code_name'), $edit_name, 'text', true, array('placeholder' => lang('code_name'))); ?>
                            <?= form_input_group('symbol', lang('symbol'), $edit_symbol, 'text', true, array('placeholder' => lang('symbol'))); ?>
                            <div class="flex items-center gap-2">
                                <button type="submit" class="btn btn-sm btn-primary inline-flex items-center gap-2">
                                    <i data-lucide="check" class="h-4 w-4"></i>
                                    <?= $submit_label ?>
                                </button>
                                <?php if (!empty($id)) { ?>
                                    <a href="<?= base_url('admin/settings/all_currency/') ?>" class="btn btn-danger btn-sm"><?= lang('cancel') ?></a>
                                <?php } ?>
                            </div>
                        </form>
                    </div>
                </div>
                <div class="lg:col-span-8">
                    <div class="grid grid-cols-1 xl:grid-cols-2 2xl:grid-cols-3 gap-4">
                        <?php
                        if (!empty($all_currencies)) {
                            foreach ($all_currencies as $v_currencies) {
                                ?>
                                <div class="rounded-xl border border-border bg-muted/30 p-4">
                                    <div class="flex items-start justify-between gap-2">
                                        <div>
                                            <h4 class="text-sm font-semibold text-foreground"><?= $v_currencies->code ?></h4>
                                            <p class="text-xs text-muted-foreground"><?= $v_currencies->name ?></p>
                                            <p class="text-xs text-muted-foreground"><?= $v_currencies->symbol ?></p>
                                        </div>
                                        <div class="flex items-center gap-2">
                                            <?= btn_edit('admin/settings/all_currency/' . $v_currencies->code) ?>
                                        </div>
                                    </div>
                                </div>
                            <?php }
                        }
                        ?>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

