<?php $item = $row ?? null; ?>
<div class="row g-3">
    <div class="col-md-4">
        <label class="form-label ec-required"><?= e(trans('module_name')) ?></label>
        <select name="module_name" class="form-select rounded-3" required>
            <option value="registration" <?= (($item['module_name'] ?? '') === 'registration') ? 'selected' : '' ?>><?= e(trans('custom_fields_module_registration')) ?></option>
            <option value="submission" <?= (($item['module_name'] ?? '') === 'submission') ? 'selected' : '' ?>><?= e(trans('custom_fields_module_submission')) ?></option>
            <option value="review" <?= (($item['module_name'] ?? '') === 'review') ? 'selected' : '' ?>><?= e(trans('custom_fields_module_review')) ?></option>
        </select>
    </div>

    <div class="col-md-4">
        <label class="form-label ec-required"><?= e(trans('field_key')) ?></label>
        <input type="text" name="field_key" class="form-control rounded-3" value="<?= e((string) ($item['field_key'] ?? '')) ?>" required>
    </div>

    <div class="col-md-4">
        <label class="form-label ec-required"><?= e(trans('field_type')) ?></label>
        <select name="field_type" class="form-select rounded-3" required>
            <?php foreach (['text','textarea','select','checkbox','radio','date','number','email'] as $type): ?>
                <option value="<?= e($type) ?>" <?= (($item['field_type'] ?? 'text') === $type) ? 'selected' : '' ?>>
                    <?= e($type === 'email' ? trans('email_field') : trans($type)) ?>
                </option>
            <?php endforeach; ?>
        </select>
    </div>

    <div class="col-md-6">
        <label class="form-label"><?= e(trans('label_en')) ?></label>
        <input type="text" name="label_en" class="form-control rounded-3" value="<?= e((string) ($item['label_en'] ?? '')) ?>" required>
    </div>

    <div class="col-md-6">
        <label class="form-label"><?= e(trans('label_ar')) ?></label>
        <input type="text" name="label_ar" class="form-control rounded-3" value="<?= e((string) ($item['label_ar'] ?? '')) ?>" required>
    </div>

    <div class="col-md-6">
        <label class="form-label"><?= e(trans('placeholder_en')) ?></label>
        <input type="text" name="placeholder_en" class="form-control rounded-3" value="<?= e((string) ($item['placeholder_en'] ?? '')) ?>">
    </div>

    <div class="col-md-6">
        <label class="form-label"><?= e(trans('placeholder_ar')) ?></label>
        <input type="text" name="placeholder_ar" class="form-control rounded-3" value="<?= e((string) ($item['placeholder_ar'] ?? '')) ?>">
    </div>

    <div class="col-md-6">
        <label class="form-label"><?= e(trans('help_text_en')) ?></label>
        <textarea name="help_text_en" class="form-control rounded-3" rows="4"><?= e((string) ($item['help_text_en'] ?? '')) ?></textarea>
    </div>

    <div class="col-md-6">
        <label class="form-label"><?= e(trans('help_text_ar')) ?></label>
        <textarea name="help_text_ar" class="form-control rounded-3" rows="4"><?= e((string) ($item['help_text_ar'] ?? '')) ?></textarea>
    </div>

    <div class="col-md-6">
        <label class="form-label"><?= e(trans('field_options')) ?></label>
        <textarea name="field_options" class="form-control rounded-3" rows="5"><?= e((string) ($item['field_options'] ?? '')) ?></textarea>
        <div class="form-text"><?= e(trans('one_option_per_line')) ?></div>
    </div>

    <div class="col-md-3">
        <label class="form-label"><?= e(trans('sort_order')) ?></label>
        <input type="number" name="sort_order" class="form-control rounded-3" value="<?= e((string) ($item['sort_order'] ?? 0)) ?>">
    </div>

    <div class="col-md-3 d-flex flex-column justify-content-end gap-2">
        <div class="form-check">
            <input class="form-check-input" type="checkbox" name="is_required" <?= !empty($item['is_required']) ? 'checked' : '' ?>>
            <label class="form-check-label"><?= e(trans('is_required')) ?></label>
        </div>
        <div class="form-check">
            <input class="form-check-input" type="checkbox" name="is_active" <?= !isset($item) || !empty($item['is_active']) ? 'checked' : '' ?>>
            <label class="form-check-label"><?= e(trans('is_active')) ?></label>
        </div>
    </div>
</div>
