<?= $this->extend('layout/main') ?>

<?= $this->section('content') ?>

<h2>User Preferences</h2>

<?php if (session()->getFlashdata('success')) : ?>
    <div class="alert alert-success">
        <?= session()->getFlashdata('success') ?>
    </div>
<?php endif; ?>

<?php if (isset($validation)) : ?>
    <div class="alert alert-danger">
        <?= $validation->listErrors() ?>
    </div>
<?php endif; ?>

<form action="<?= base_url('/preferences/update/' . session()->get('id')) ?>" method="post">
    <?= csrf_field() ?>

    <div class="container-fluid">
        <div class="row">
            <main class="col-4 px-md-4">
                <div class="form-group">
                    <label for="notification_email">Receive Email Notifications:</label>
                    <input type="checkbox" name="notification_email" value="1"
                        <?= isset($preferences['notification_email']) && $preferences['notification_email'] ? 'checked' : '' ?>>
                </div>

                <div class="form-group">
                    <label for="notification_sms">Receive SMS Notifications:</label>
                    <input type="checkbox" name="notification_sms" value="1"
                        <?= isset($preferences['notification_sms']) && $preferences['notification_sms'] ? 'checked' : '' ?>>
                </div>

                <div class="form-group">
                    <label for="theme">Theme:</label>
                    <select name="theme" class="form-control">
                        <option value="light"
                            <?= isset($preferences['theme']) && $preferences['theme'] === 'light' ? 'selected' : '' ?>>
                            Light
                        </option>
                        <option value="dark"
                            <?= isset($preferences['theme']) && $preferences['theme'] === 'dark' ? 'selected' : '' ?>
                            >Dark</option>
                    </select>
                </div>

                <?php $styleOptions = $styleOptions ?? []; $menuOptions = $menuOptions ?? []; ?>
                <div class="form-group">
                    <label for="style_color">Accent color:</label>
                    <select name="style_color" class="form-control">
                        <?php foreach ($styleOptions as $opt): ?>
                            <option value="<?= esc($opt) ?>" <?= (isset($preferences['style_color']) && $preferences['style_color'] === $opt) ? 'selected' : '' ?>>
                                <?= ucfirst(esc($opt)) ?>
                            </option>
                        <?php endforeach; ?>
                    </select>
                </div>

                <div class="form-group">
                    <label for="menu_color">Menu color:</label>
                    <select name="menu_color" class="form-control">
                        <?php foreach ($menuOptions as $opt): ?>
                            <option value="<?= esc($opt) ?>" <?= (isset($preferences['menu_color']) && $preferences['menu_color'] === $opt) ? 'selected' : '' ?>>
                                <?= ucfirst(esc($opt)) ?>
                            </option>
                        <?php endforeach; ?>
                    </select>
                </div>

                <button type="submit" class="btn btn-primary" style="margin-bottom: 20px;">Save Preferences</button>
            </main>
        </div>
    </div>
</form>

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

