<section class="report-toolbar">
    <div>
        <p class="eyebrow"><?= e(trans('common.administrator')) ?></p>
        <h1><?= e($question['id'] ? trans('page_titles.edit_question') : trans('page_titles.add_question')) ?></h1>
        <p class="support-copy"><?= e(trans('admin.question_form_copy')) ?></p>
    </div>
    <div class="toolbar-actions">
        <a class="ghost-button" href="<?= e(base_url('/admin/questions')) ?>"><?= e(trans('common.back')) ?></a>
    </div>
</section>

<section class="card table-card">
    <form method="post" action="<?= e(base_url('/admin/questions/save')) ?>" class="stack-form">
        <input type="hidden" name="_csrf" value="<?= e(csrf_token()) ?>">
        <input type="hidden" name="id" value="<?= e((string) ($question['id'] ?? '')) ?>">
        <input type="hidden" name="source_key" value="<?= e((string) ($question['source_key'] ?? '')) ?>">

        <div class="inline-form-grid">
            <label>
                <span><?= e(trans('common.area')) ?></span>
                <select name="area_code" required>
                    <?php foreach ($areas as $areaCode => $area): ?>
                        <option value="<?= e($areaCode) ?>" <?= ($question['area_code'] ?? '') === $areaCode ? 'selected' : '' ?>><?= e($areaCode . ' - ' . area_name($areaCode)) ?></option>
                    <?php endforeach; ?>
                </select>
            </label>
            <label>
                <span><?= e(trans('common.order')) ?></span>
                <input type="number" min="1" name="sort_order" value="<?= e((string) ($question['sort_order'] ?? 1)) ?>" required>
            </label>
            <label class="checkbox-field">
                <input type="checkbox" name="is_active" value="1" <?= !empty($question['is_active']) ? 'checked' : '' ?>>
                <span><?= e(trans('common.active')) ?></span>
            </label>
        </div>

        <label>
            <span><?= e(trans('admin.question_text')) ?> <?= e('(' . trans('common.required') . ')') ?></span>
            <textarea name="statement" rows="3" required><?= e((string) ($question['statement'] ?? '')) ?></textarea>
        </label>

        <div class="toolbar-actions">
            <button class="primary-button" type="submit"><?= e(trans('admin.save_question')) ?></button>
        </div>
    </form>
</section>