<?= $this->extend('layouts/main') ?>
<?= $this->section('content') ?>

<div class="d-flex align-items-center justify-content-between mb-4">
    <h4 class="page-title mb-0"><i class="bi bi-gear me-2 text-primary"></i><?= lang('Admin.settings') ?></h4>
</div>

<form action="<?= site_url('admin/settings') ?>" method="post" enctype="multipart/form-data">
    <?= csrf_field() ?>
    <div class="row g-4">
        <div class="col-lg-7">
            <div class="card border-0 shadow-sm mb-4">
                <div class="card-header bg-white py-3">
                    <h6 class="mb-0 fw-semibold">General Settings</h6>
                </div>
                <div class="card-body">
                    <div class="mb-3">
                        <label class="form-label fw-medium"><?= lang('Admin.app_name') ?></label>
                        <input type="text" name="app_name" class="form-control"
                               value="<?= esc($settings['app_name'] ?? '') ?>">
                    </div>
                    <div class="mb-3">
                        <label class="form-label fw-medium"><?= lang('Admin.qr_base_url') ?></label>
                        <input type="url" name="qr_base_url" class="form-control"
                               value="<?= esc($settings['qr_base_url'] ?? '') ?>"
                               placeholder="http://yourdomain.com/profile/">
                        <div class="form-text">This URL is used as prefix when generating QR codes.</div>
                    </div>
                    <div class="mb-3">
                        <label class="form-label fw-medium"><?= lang('Admin.default_language') ?></label>
                        <select name="default_language" class="form-select">
                            <option value="en" <?= ($settings['default_language']??'')=='en' ? 'selected':'' ?>>English</option>
                            <option value="hi" <?= ($settings['default_language']??'')=='hi' ? 'selected':'' ?>>हिंदी (Hindi)</option>
                            <option value="mr" <?= ($settings['default_language']??'')=='mr' ? 'selected':'' ?>>मराठी (Marathi)</option>
                        </select>
                    </div>
                    <div class="mb-3">
                        <label class="form-label fw-medium"><?= lang('Admin.items_per_page') ?></label>
                        <input type="number" name="items_per_page" class="form-control"
                               value="<?= esc($settings['items_per_page'] ?? 15) ?>"
                               min="5" max="100">
                    </div>
                    <div class="mb-3">
                        <label class="form-label fw-medium"><?= lang('Admin.qr_logo') ?></label>
                        <?php if (!empty($settings['qr_logo_path'])): ?>
                        <div class="mb-2">
                            <img src="<?= upload_url($settings['qr_logo_path']) ?>"
                                 height="50" class="border rounded" alt="Current QR logo">
                            <div class="form-text">Current logo. Upload new to replace.</div>
                        </div>
                        <?php endif; ?>
                        <input type="file" name="qr_logo" class="form-control" accept="image/png,image/jpeg">
                        <div class="form-text">Transparent PNG recommended. Used in QR code centre.</div>
                    </div>
                </div>
            </div>

            <div class="d-flex gap-2">
                <button type="submit" class="btn btn-primary">
                    <i class="bi bi-check-circle me-2"></i><?= lang('Admin.save') ?>
                </button>
            </div>
        </div>
    </div>
</form>

<?= $this->endSection() ?>
