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

<?php if ($field['_type'] == 'hidden'): ?>
    <input 
        type="<?php echo esc_attr($field['_type']); ?>" 
        name="<?php echo esc_attr($metaKey); ?>" 
        id="<?php echo esc_attr($metaKey); ?>" 
        value="<?php echo esc_html($value); ?>"
    />
<?php else: ?>
    <div class="<?php echo esc_attr($column) ?>">
        <label class="ehx-details" for="<?php echo esc_attr($metaKey); ?>">
            <?php echo esc_html($field['_label']); ?>
            <?php echo $required ? '<span>*</span>' : ''; ?>
        </label>
        <?php if (in_array($field['_type'], ['select', 'multiselect'])): ?>
            <select 
                name="<?php echo esc_attr($metaKey); echo $field['_type'] == 'multiselect' ? '[]':''; ?>" 
                id="<?php echo esc_attr($metaKey); ?>" 
                class="<?php echo esc_attr($class); ?>" 
                <?php echo esc_attr($required ? 'required': ''); ?>
                <?php echo esc_attr($field['_type'] == 'multiselect' ? 'multiple': ''); ?>
            >
                <option value="">Select option</option>
                <?php foreach ($options as $option): ?>
                    <option 
                        value="<?php echo esc_html($option); ?>" 
                        <?php selected($option, $value) ?>
                    ><?php echo esc_html($option); ?></option>
                <?php endforeach ?>
            </select>
        <?php elseif (in_array($field['_type'], ['radio', 'checkbox'])): ?>
            <div class="ehx-gender-details">
                <div class="ehx-category">
                    <?php foreach ($options as $option): ?>
                        <div>
                            <input 
                                type="<?php echo esc_attr($field['_type']); echo isset($field['is_multiple']) && $field['is_multiple'] ? '[]':''; ?>" 
                                name="<?php echo esc_attr($metaKey); ?>" 
                                id="<?php echo esc_attr($option) ?>" 
                                value="<?php echo esc_html($option) ?>"
                                <?php checked($option, $value) ?>
                                <?php echo esc_attr($required ? 'required': '' ); ?>
                            >
                            
                            <label for="<?php echo esc_attr($option); ?>">
                                <span class="ehx-dot ehx-dot-<?php echo esc_attr($field['_type']) ?>"></span>
                                <span class="ehx-gender"><?php echo esc_html($option); ?></span>
                            </label>
                        </div>
                    <?php endforeach ?>
                </div>
            </div>
        <?php elseif ($field['_type'] == 'textarea'): ?>
            <textarea 
                name="<?php echo esc_attr($metaKey); ?>" 
                id="<?php echo esc_attr($metaKey); ?>" 
                class="<?php echo esc_attr($class); ?>" 
                <?php echo esc_attr($required ? 'required': ''); ?>
                <?php if(isset($field['_height']) && !empty($field['_height'])): ?>
                    height="<?php echo esc_html($field["_height"]); ?>"
                <?php endif ?>
            ><?php echo esc_html($value); ?></textarea>
        <?php else: ?>
            <input
                type="<?php echo esc_attr($field['_type']); ?>"
                name="<?php echo esc_attr($metaKey); ?>"
                id="<?php echo esc_attr($metaKey); ?>"
                class="<?php echo esc_attr($class); ?>"
                value="<?php echo $field['_type'] != 'password' ? esc_html($value) : ''; ?>"
                placeholder="<?php echo esc_attr($field['_placeholder']); ?>"
                <?php echo esc_attr($required ? 'required': ''); ?>
                <?php if(count($allowed_types)): ?>
                    accept="<?php echo esc_attr(implode(',', array_map(fn($type) => 'image/' . $type, $allowed_types))) ?>"
                <?php endif ?>
            />
        <?php endif ?>
        <div class="invalid-feedback" id="invalid_<?php echo esc_attr($metaKey); ?>"></div>
    </div>
<?php endif ?>