<?php
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals

if ( ! defined( 'ABSPATH' ) ) {
	 exit;
}

$form_row          = is_object( $row ) ? $row : (object) array();
$current_form_id   = isset( $form_row->id ) ? absint( $form_row->id ) : 0;
$current_form_name = isset( $form_row->name ) ? $form_row->name : '';
$preview_page_id   = (int) get_option( 'wpefb_preview_page_id', 0 );
$preview_url       = $preview_page_id ? get_permalink( $preview_page_id ) : home_url( '/' );
if ( ! is_string( $preview_url ) || '' === $preview_url ) {
	$preview_url = home_url( '/' );
}
$preview_url = add_query_arg( 'id', $current_form_id, $preview_url );

$available_roles = array();
if ( function_exists( 'get_editable_roles' ) ) {
	$available_roles = get_editable_roles();
}
if ( empty( $available_roles ) ) {
	$wefb_wp_roles = wp_roles();
	if ( $wefb_wp_roles && ! empty( $wefb_wp_roles->roles ) ) {
		$available_roles = $wefb_wp_roles->roles;
	}
}
$selected_user_role = isset( $meta['user_role'] ) ? sanitize_key( $meta['user_role'] ) : 'subscriber';
?>
<div class="advrf-wrapper wrap wef-forms-modern wef-dashboard-modern wef-configure-modern">
    <div class="advrf-page-title">		 
        <h1 class="wpefb-page-heading">
            <?php echo esc_html( $current_form_name ); ?></h1>
        <ul class="advrf-nav">
            <li class="advrf-nav-item">
                <a href="<?php echo esc_url( admin_url( 'admin.php?page=wpefb_manage_forms' ) ); ?>">
                    <span class="dashicons dashicons-feedback"></span>
                    <?php esc_html_e( 'All Forms', 'vedrixa-forms-registration-builder' ); ?></a>
            </li>
            <li class="advrf-nav-item">
                <a href="<?php echo esc_url( admin_url( 'admin.php?page=wpefb_form_dashboard&id=' . $current_form_id ) ); ?>">
                    <span class="dashicons dashicons-admin-generic"></span>
                    	<?php esc_html_e( 'Dashboard', 'vedrixa-forms-registration-builder' ); ?>					</a>
            </li>
            <li class="advrf-nav-item">
                <a target="_blank" href="<?php echo esc_url( $preview_url ); ?>">
                    <span class="dashicons dashicons-visibility"></span>
                     <?php esc_html_e( 'Preview', 'vedrixa-forms-registration-builder' ); ?>	</a>
            </li>    
        </ul>
        
         </div>
    <div class="clearfix">
        <div class="advrf-form-conf-wrapper">
            <form action="" method="post" id="advrf_configuration_form">
                <fieldset class="advrf-config-wrap">
                    <div>
                        <div class="group-title">
                            <?php esc_html_e( 'Accounts', 'vedrixa-forms-registration-builder' ); ?>				</div>
                        <div class="group-wrap">

                            <div class="advrf-row">
						<div class="advrf-control-label">
							<label><?php esc_html_e( 'Also create WP User account? (This will add Username and Password fields to this form)', 'vedrixa-forms-registration-builder' ); ?></label>
						</div>
						<div class="advrf-control advrf-has-child">
                                                    <input class="advrf_toggle"  type="checkbox" value="1" id="wpefb_create_user" name="meta[wpefb_create_user]" data-has-child="1" data-toggle-target="wpefb_create_user_html"
                                                    <?php
                                                    if ( isset( $meta['wpefb_create_user'] ) ) {
														checked( $meta['wpefb_create_user'], 1 );}
													?>
                                                      />
							<label></label>
							<p class="description"><?php esc_html_e( 'Selecting this will register the user in WP Users area.', 'vedrixa-forms-registration-builder' ); ?></p>
						</div>  
					</div>
                            
                            <div class="advrf-child-rows advrf-child-options" id="wpefb_create_user_html" style="<?php echo ! empty( $meta['wpefb_create_user'] ) ? '' : 'display:none'; ?>">

								<div class="advrf-row">
									<div class="advrf-control-label">
										<label for="wpefb_user_role"><?php esc_html_e( 'New User Role', 'vedrixa-forms-registration-builder' ); ?></label>
									</div>
									<div class="advrf-control">
										<select id="wpefb_user_role" name="meta[user_role]" class="advrf-input-field">
											<?php foreach ( $available_roles as $role_key => $role_data ) : ?>
												<option value="<?php echo esc_attr( $role_key ); ?>" <?php selected( $selected_user_role, $role_key ); ?>><?php echo esc_html( isset( $role_data['name'] ) ? $role_data['name'] : $role_key ); ?></option>
											<?php endforeach; ?>
										</select>
										<p class="description"><?php esc_html_e( 'Newly registered users will be assigned to this WordPress role.', 'vedrixa-forms-registration-builder' ); ?></p>
									</div>
								</div>
                                

                                
                                
                                </div>
                    </div>


                  


                </fieldset>

                <p class="submit">
                    <input type="hidden" name="form_id" id="form_id" value="<?php echo esc_attr( $current_form_id ); ?>" />
                    <?php wp_nonce_field( 'save_wpefb_add_form' ); ?>
                    <input type="submit" value="<?php esc_attr_e( 'Save', 'vedrixa-forms-registration-builder' ); ?>" class="button button-primary" name="submit_form" id="submit_form" onClick="return add_form_validation()"/>
                    <a class="button button-secondary" href="<?php echo esc_url( admin_url( 'admin.php?page=wpefb_form_dashboard&id=' . $current_form_id ) ); ?>"><?php esc_html_e( 'Cancel', 'vedrixa-forms-registration-builder' ); ?></a>
                    <div class="all_error_text" style="display:none;"></div>
                </p>
            </form>  
        </div> 
    </div>
    </div>
