<?php require __DIR__ . '/../layouts/header.php'; ?>

<div class="auth-wrapper">
    <div class="auth-card" style="max-width:900px;">
        <div class="auth-header">
            <h2><?= e(current_lang() === 'ar' ? (string) (($settings['title_ar'] ?? '') ?: ($conference['title_ar'] ?? '')) : (string) (($settings['title_en'] ?? '') ?: ($conference['title_en'] ?? ''))) ?></h2>
        </div>

        <div class="p-4 p-md-5">
            <div class="mb-4">
                <?= current_lang() === 'ar'
                    ? (string) ($settings['intro_ar'] ?? '')
                    : (string) ($settings['intro_en'] ?? '') ?>
            </div>

            <form method="post" action="<?= e(base_path('register/conference?conference_id=' . (int) $conference['id'])) ?>">
                <input type="hidden" name="_csrf" value="<?= e(csrf_token()) ?>">
                <input type="hidden" name="conference_id" value="<?= e((string) $conference['id']) ?>">

                <div class="row g-3">
                    <div class="col-md-6"><label class="form-label ec-required"><?= e(trans('full_name_en')) ?></label><input type="text" name="full_name_en" class="form-control rounded-3" required></div>
                    <div class="col-md-6"><label class="form-label"><?= e(trans('full_name_ar')) ?></label><input type="text" name="full_name_ar" class="form-control rounded-3"></div>
                    <div class="col-md-6"><label class="form-label"><?= e(trans('email')) ?></label><input type="email" name="email" class="form-control rounded-3"></div>
                    <div class="col-md-6"><label class="form-label"><?= e(trans('mobile')) ?></label><input type="text" name="mobile" class="form-control rounded-3"></div>

                    <?php foreach ($fields as $field): ?>
                        <?php
                            $key = (string) $field['field_key'];
                            $type = (string) ($field['field_type'] ?? 'text');
                            $label = current_lang() === 'ar' ? (string) ($field['label_ar'] ?: $field['label_en']) : (string) ($field['label_en'] ?: $field['label_ar']);
                            $placeholder = current_lang() === 'ar' ? (string) ($field['placeholder_ar'] ?: $field['placeholder_en']) : (string) ($field['placeholder_en'] ?: $field['placeholder_ar']);
                            $required = !empty($field['is_required']) ? 'required' : '';
                            $options = preg_split('/\r\n|\r|\n/', (string) ($field['field_options'] ?? '')) ?: [];
                        ?>
                        <div class="col-md-6">
                            <label class="form-label"><?= e($label) ?></label>
                            <?php if ($type === 'textarea'): ?>
                                <textarea name="cf[<?= e($key) ?>]" class="form-control rounded-3" rows="4" <?= $required ?>><?= e((string) ($_POST['cf'][$key] ?? '')) ?></textarea>
                            <?php elseif ($type === 'select'): ?>
                                <select name="cf[<?= e($key) ?>]" class="form-select rounded-3" <?= $required ?>>
                                    <option value=""><?= e(trans('select_option')) ?></option>
                                    <?php foreach ($options as $opt): if (trim($opt)==='') continue; ?>
                                        <option value="<?= e(trim($opt)) ?>"><?= e(trim($opt)) ?></option>
                                    <?php endforeach; ?>
                                </select>
                            <?php else: ?>
                                <input type="<?= e($type === 'email' ? 'email' : ($type === 'number' ? 'number' : ($type === 'date' ? 'date' : 'text'))) ?>" name="cf[<?= e($key) ?>]" class="form-control rounded-3" placeholder="<?= e($placeholder) ?>" <?= $required ?>>
                            <?php endif; ?>
                        </div>
                    <?php endforeach; ?>
                </div>

                <div class="mt-4">
                    <button class="btn btn-success btn-lg rounded-3"><?= e(trans('save')) ?></button>
                </div>
            </form>
        </div>
    </div>
</div>

<?php require __DIR__ . '/../layouts/footer.php'; ?>
