<?php if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly ?>

<?php
	$ehx_form = get_post_meta($post->ID, 'ehx_form', true);
?>

<div class="ehx-admin-metabox">
    <table class="form-table ehxme-form-table ehxme-form-login-settings ehx-top-label">
        <tbody>
            <?php foreach($fields->options as $key => $field): ?>
				<tr 
					class="ehxme-forms-line<?php echo $key != 0 && $field->id != 'enable_recaptcha' ? ' ehxme-forms-line-conditioned':''; ?>"
					style="display: <?php echo $key != 0 && (isset($ehx_form['login_after_login']) && $ehx_form['login_after_login'] != 'redirect_url') && $field->id != 'enable_recaptcha' || ($field->id == 'login_redirect_url' && !isset($ehx_form['login_after_login'])) ? 'none':'block'; ?>;"
				>
					<td>
						<label for="<?php echo esc_attr($field->id); ?>">
							<?php echo esc_html($field->label); ?>
							<?php if(isset($field->tooltip)): ?>
								<span class="ehx_tooltip dashicons dashicons-editor-help" title="<?php echo esc_html($field->tooltip); ?>"></span>
							<?php endif ?>
						</label>
						
						<?php if($field->type === 'select'): ?>
							<select id="<?php echo esc_attr($field->id); ?>" name="ehx_form[<?php echo esc_attr($field->id); ?>]" class="ehxme-forms-field ehx-long-field">
								<?php foreach($field->options as $key => $value): ?>
									<option value="<?php echo esc_html($key); ?>" <?php echo selected($key, $ehx_form[$field->id] ?? null) ?>><?php echo esc_html($value); ?></option>
								<?php endforeach ?>
							</select>
						<?php else: ?>
							<input type="text" id="<?php echo esc_attr($field->id); ?>" name="ehx_form[<?php echo esc_attr($field->id); ?>]" class="ehxme-forms-field ehx-long-field" placeholder="<?php echo esc_attr($field->placeholder ?? ''); ?>" value="<?php echo esc_html($ehx_form[$field->id] ?? null) ?>">
						<?php endif ?>
					</td>
				</tr>
			<?php endforeach ?>
        </tbody>
    </table>

    <div class="clear"></div>
</div>