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

<div class="d-flex justify-content-between align-items-center mb-4">
    <h1 class="page-title"><?= e(trans('registration_form_builder')) ?></h1>
    <a href="<?= e(base_path('admin')) ?>" class="btn ec-btn btn-outline-secondary rounded-3"><?= e(trans('back')) ?></a>
</div>

<div class="ec-card   mb-4">
    <div class="ec-card-body">
        <form method="get" action="<?= e(base_path('admin/registration-form')) ?>" class="row g-3">
            <div class="col-md-6">
                <label class="form-label"><?= e(trans('conference')) ?></label>
                <select name="conference_id" class="form-select rounded-3">
                    <option value="0">--</option>
                    <?php foreach ($conferences as $c): ?>
                        <option value="<?= e((string) $c['id']) ?>" <?= (int) $conference_id === (int) $c['id'] ? 'selected' : '' ?>>
                            <?= e(current_lang() === 'ar' ? (string) ($c['title_ar'] ?? '') : (string) ($c['title_en'] ?? '')) ?>
                        </option>
                    <?php endforeach; ?>
                </select>
            </div>
            <div class="col-md-2 d-flex align-items-end">
                <button class="btn ec-btn btn-primary rounded-3 w-100"><?= e(trans('search')) ?></button>
            </div>
        </form>
    </div>
</div>

<?php if ($conference_id > 0): ?>
<div class="ec-card  ">
    <div class="ec-card-body p-4">
        <form method="post" action="<?= e(base_path('admin/registration-form?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"><?= e(trans('title_en')) ?></label><input type="text" name="title_en" class="form-control rounded-3" value="<?= e((string) ($row['title_en'] ?? '')) ?>"></div>
                <div class="col-md-6"><label class="form-label"><?= e(trans('title_ar')) ?></label><input type="text" name="title_ar" class="form-control rounded-3" value="<?= e((string) ($row['title_ar'] ?? '')) ?>"></div>
                <div class="col-md-6"><label class="form-label"><?= e(trans('intro_en')) ?></label><textarea name="intro_en" class="form-control rounded-3 richtext" rows="6"><?= e((string) ($row['intro_en'] ?? '')) ?></textarea></div>
                <div class="col-md-6"><label class="form-label"><?= e(trans('intro_ar')) ?></label><textarea name="intro_ar" class="form-control rounded-3 richtext" rows="6"><?= e((string) ($row['intro_ar'] ?? '')) ?></textarea></div>
                <div class="col-md-12"><div class="form-check"><input class="form-check-input" type="checkbox" name="is_enabled" <?= !isset($row) || !empty($row['is_enabled']) ? 'checked' : '' ?>><label class="form-check-label"><?= e(trans('enabled')) ?></label></div></div>
            </div>

            <div class="mt-4 d-flex gap-2">
                <button class="btn ec-btn btn-success rounded-3"><?= e(trans('save')) ?></button>
                <a href="<?= e(base_path('register/conference?conference_id=' . (int) $conference_id)) ?>" class="btn ec-btn btn-outline-primary rounded-3"><?= e(trans('registration_form')) ?></a>
                <a href="<?= e(base_path('admin/registration-submissions?conference_id=' . (int) $conference_id)) ?>" class="btn ec-btn btn-outline-dark rounded-3"><?= e(trans('registration_submissions')) ?></a>
            </div>
        </form>
    </div>
</div>
<?php endif; ?>

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