<div class="row justify-content-center">
    <div class="col-lg-8">
        <div class="card">
            <div class="card-header"><h5 class="mb-0"><?= e($title) ?></h5></div>
            <div class="card-body">
                <form method="POST" action="<?= e($formAction) ?>" data-ajax="true">
                    <?= csrf_field() ?>
                    <div class="row g-3">
                        <div class="col-md-6">
                            <label class="form-label"><?= lang('board.term') ?> <span class="text-danger">*</span></label>
                            <select name="term_id" class="form-select" required>
                                <option value="">-- Select --</option>
                                <?php foreach ($terms as $t): ?>
                                <option value="<?= $t['id'] ?>" <?= selected($t['id'], $boardMember['term_id'] ?? '') ?>><?= e($t['term_name_en']) ?></option>
                                <?php endforeach; ?>
                            </select>
                            <div class="invalid-feedback" data-field="term_id"></div>
                        </div>
                        <div class="col-md-6">
                            <label class="form-label"><?= lang('board.position') ?> <span class="text-danger">*</span></label>
                            <select name="position_id" class="form-select" required>
                                <option value="">-- Select --</option>
                                <?php foreach ($positions as $p): ?>
                                <option value="<?= $p['id'] ?>" <?= selected($p['id'], $boardMember['position_id'] ?? '') ?>><?= e($p['title_en']) ?></option>
                                <?php endforeach; ?>
                            </select>
                            <div class="invalid-feedback" data-field="position_id"></div>
                        </div>
                        <div class="col-md-6">
                            <label class="form-label"><?= lang('board.name') ?> (EN) <span class="text-danger">*</span></label>
                            <input type="text" name="full_name_en" class="form-control" value="<?= e($boardMember['full_name_en'] ?? '') ?>" required>
                            <div class="invalid-feedback" data-field="full_name_en"></div>
                        </div>
                        <div class="col-md-6">
                            <label class="form-label"><?= lang('board.name') ?> (AR)</label>
                            <input type="text" name="full_name_ar" class="form-control" value="<?= e($boardMember['full_name_ar'] ?? '') ?>" dir="rtl">
                        </div>
                        <div class="col-md-4">
                            <label class="form-label"><?= lang('board.start_date') ?> <span class="text-danger">*</span></label>
                            <input type="date" name="start_date" class="form-control" value="<?= e($boardMember['start_date'] ?? date('Y-m-d')) ?>" required>
                            <div class="invalid-feedback" data-field="start_date"></div>
                        </div>
                        <div class="col-md-4">
                            <label class="form-label"><?= lang('board.end_date') ?></label>
                            <input type="date" name="end_date" class="form-control" value="<?= e($boardMember['end_date'] ?? '') ?>">
                        </div>
                        <?php if ($boardMember): ?>
                        <div class="col-md-4">
                            <label class="form-label"><?= lang('common.status') ?></label>
                            <select name="status" class="form-select">
                                <option value="active" <?= selected('active', $boardMember['status']) ?>>Active</option>
                                <option value="resigned" <?= selected('resigned', $boardMember['status']) ?>>Resigned</option>
                                <option value="removed" <?= selected('removed', $boardMember['status']) ?>>Removed</option>
                                <option value="term_ended" <?= selected('term_ended', $boardMember['status']) ?>>Term Ended</option>
                            </select>
                        </div>
                        <?php endif; ?>
                        <div class="col-md-6">
                            <label class="form-label">Club Member ID</label>
                            <input type="number" name="member_id" class="form-control" value="<?= e($boardMember['member_id'] ?? '') ?>" placeholder="Link to club member (optional)">
                        </div>
                        <div class="col-md-6">
                            <label class="form-label">System User ID</label>
                            <input type="number" name="user_id" class="form-control" value="<?= e($boardMember['user_id'] ?? '') ?>" placeholder="Link to system user (optional)">
                        </div>
                        <div class="col-12">
                            <label class="form-label"><?= lang('board.notes') ?></label>
                            <textarea name="notes" class="form-control" rows="3"><?= e($boardMember['notes'] ?? '') ?></textarea>
                        </div>
                    </div>
                    <div class="mt-4 d-flex gap-2">
                        <button type="submit" class="btn btn-primary"><i class="fas fa-save me-1"></i><?= lang('common.save') ?></button>
                        <a href="/board/members" class="btn btn-secondary"><?= lang('common.cancel') ?></a>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>