<?php

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

// phpcs:ignoreFile WordPress.Files.FileName.NotHyphenatedLowercase
$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 );
$form_redirect = isset( $meta['wpefb_form_redirect'] ) ? sanitize_key( $meta['wpefb_form_redirect'] ) : 'none';
?>
<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( 'Post Submission', 'vedrixa-forms-registration-builder' ); ?>				</div>
                        <div class="group-wrap">
                            
                            <div class="advrf-row">
						<div class="advrf-control-label">
							<label><?php esc_html_e( 'Success Message', 'vedrixa-forms-registration-builder' ); ?></label>
						</div>
						<div class="advrf-control">
							<?php
							$editor_id                               = 'wpefb_success_msg_content';
							$settings                                = array(
								'wpautop'           => false,
								'media_buttons'     => true,
								'textarea_name'     => 'meta[wpefb_success_msg_content]',
								'textarea_rows'     => 20,
								'tabindex'          => '',
								'tabfocus_elements' => ':prev,:next',
								'editor_css'        => '',
								'editor_class'      => 'advrf-editor',
								'teeny'             => false,
								'dfw'               => false,
								'tinymce'           => true, // <-----
								'quicktags'         => true,
							);
                                                        $before_form = isset( $meta['wpefb_success_msg_content'] )?$meta['wpefb_success_msg_content']:'';
							wp_editor( $before_form, $editor_id, $settings );
							?>
							<p class="description">
								<?php esc_html_e( 'Display a message after the form has been successfully submitted.', 'vedrixa-forms-registration-builder' ); ?><br/>
			
							</p>
						</div>  
					</div>
                            
                            <div class="advrf-row">
							<div class="advrf-control-label">
								<label><?php esc_html_e( 'Redirection', 'vedrixa-forms-registration-builder' ); ?></label>
							</div>
							<div class="advrf-control advrf-has-child">
								<div class="wef-radio-group">
									<label class="wef-radio-option" for="wpefb_redirect_none">
										<input type="radio" id="wpefb_redirect_none" value="none" name="meta[wpefb_form_redirect]" data-child-index="-1" <?php checked( $form_redirect, 'none' ); ?> onclick="wef_show_hide(this,'','wpefb_form_redirect_page_html','wpefb_form_redirect_url_html')" />
										<span><?php esc_html_e( 'None', 'vedrixa-forms-registration-builder' ); ?></span>
									</label>
									<label class="wef-radio-option" for="wpefb_redirect_page">
										<input type="radio" id="wpefb_redirect_page" value="page" name="meta[wpefb_form_redirect]" data-child-index="1" <?php checked( $form_redirect, 'page' ); ?> onclick="wef_show_hide(this,'wpefb_form_redirect_page_html','wpefb_form_redirect_url_html')"/>
										<span><?php esc_html_e( 'Page', 'vedrixa-forms-registration-builder' ); ?></span>
									</label>
									<label class="wef-radio-option" for="wpefb_redirect_url">
										<input type="radio" id="wpefb_redirect_url" value="url" name="meta[wpefb_form_redirect]" data-child-index="1" <?php checked( $form_redirect, 'url' ); ?> onclick="wef_show_hide(this,'wpefb_form_redirect_url_html','wpefb_form_redirect_page_html')"/>
										<span><?php esc_html_e( 'URL', 'vedrixa-forms-registration-builder' ); ?></span>
									</label>
								</div>
								<p class="description"><?php esc_html_e( 'Choose where visitors should be redirected after a successful submission.', 'vedrixa-forms-registration-builder' ); ?></p>
							</div>  
						</div>

						

                            <?php $redirect_type = $form_redirect; ?>
                            <div class="advrf-child-rows" id="wpefb_form_redirect_url_html" style="<?php echo ( $redirect_type === 'url' ) ? '' : 'display:none'; ?>">
                                
                                                    <div class="advrf-row">
                                                    <div class="advrf-control-label">
                                                        <label><?php esc_html_e( 'URL', 'vedrixa-forms-registration-builder' ); ?></label>
                                                    </div>
                                                    <div class="advrf-control">
                                                        <input type="url" class="advrf-input-field" name="meta[wpefb_redirect_url]" value="<?php echo esc_url( isset( $meta['wpefb_redirect_url'] ) ? $meta['wpefb_redirect_url'] : '' ); ?>">
                                                        <p class="description"><?php esc_html_e( 'Enter a full URL to redirect after form submission.', 'vedrixa-forms-registration-builder' ); ?></p>
                                                    </div>

                                                </div>
                            
                           
                            </div>
                            
                            
                            <div class="advrf-child-rows" id="wpefb_form_redirect_page_html" style="<?php echo ( $redirect_type === 'page' ) ? '' : 'display:none'; ?>">
                                
                                                    <div class="advrf-row">
                                                    <div class="advrf-control-label">
                                                        <label><?php esc_html_e( 'Page', 'vedrixa-forms-registration-builder' ); ?></label>
                                                    </div>
                                                    <div class="advrf-control">
                                                        <?php
												if ( ! empty( $meta['wpefb_redirect_page'] ) ) {
													$selected = absint( $meta['wpefb_redirect_page'] );
												} else {
													$selected = 0;
												}

												$all_pages = get_pages();
												if ( empty( $all_pages ) ) {
													echo '<p class="description">' . esc_html__( 'No pages found. Create a page first to use page redirection.', 'vedrixa-forms-registration-builder' ) . '</p>';
													echo '<a class="button" href="' . esc_url( admin_url( 'post-new.php?post_type=page' ) ) . '">' . esc_html__( 'Create Page', 'vedrixa-forms-registration-builder' ) . '</a>';
												} else {
													// wp_dropdown_pages() returns safe <select> markup for this admin form control.
													echo wp_dropdown_pages(
														array(
															'depth'            => 0,
															'child_of'         => 0,
															'selected'         => $selected,
															'echo'             => 0,
															'name'             => 'meta[wpefb_redirect_page]',
															'show_option_none' => esc_html__( 'Select a page', 'vedrixa-forms-registration-builder' ),
														)
													); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
													echo '<p class="description">' . esc_html__( 'Select a page to redirect after form submission.', '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>

