<?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 );
?>
<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( 'Submission Limits', 'vedrixa-forms-registration-builder' ); ?>				</div>
                        <div class="group-wrap">

                            <div class="advrf-row">
						<div class="advrf-control-label">
							<label><?php esc_html_e( 'Limit Submissions', 'vedrixa-forms-registration-builder' ); ?></label>
						</div>
						<div class="advrf-control advrf-has-child">
                                                    <input class="advrf_toggle"  type="checkbox" value="1" id="wpefb_limit_submissions" name="meta[wpefb_limit_submissions]" data-has-child="1" data-toggle-target="wpefb_limit_submissions_html" 
                                                    <?php
                                                    if ( isset( $meta['wpefb_limit_submissions'] ) ) {
														checked( $meta['wpefb_limit_submissions'], 1 );}
													?>
                                                      />
							<label></label>
							<p class="description"><?php esc_html_e( 'Select this if you want to auto unpublish the form after reaching the submission limit.', 'vedrixa-forms-registration-builder' ); ?></p>
						</div>  
					</div>
                            
                            <div class="advrf-child-rows advrf-child-options" id="wpefb_limit_submissions_html" style="<?php echo ! empty( $meta['wpefb_limit_submissions'] ) ? '' : 'display:none'; ?>">
                                <div class="advrf-row">
                                    <div class="advrf-control-label">
                                        <label><?php esc_html_e( 'Max Submissions', 'vedrixa-forms-registration-builder' ); ?></label>
                                    </div>
                                    <div class="advrf-control">
                                        <input type="number" min="0" class="advrf-input-field" name="meta[submission_limit]" value="<?php echo isset( $meta['submission_limit'] ) ? esc_attr( $meta['submission_limit'] ) : ''; ?>">
                                        <p class="description"><?php esc_html_e( 'Define the maximum number of submissions allowed for this form.', 'vedrixa-forms-registration-builder' ); ?></p>
                                    </div>
                                </div>

                                <div class="advrf-row">
                                    <div class="advrf-control-label">
                                        <label><?php esc_html_e( 'Limit Reached Message', 'vedrixa-forms-registration-builder' ); ?></label>
                                    </div>
                                    <div class="advrf-control">
                                        <?php
										$submission_limit_message = isset( $meta['submission_limit_message'] ) ? $meta['submission_limit_message'] : '';
										$editor_id                = 'wpefb_submission_limit_message';
										$settings                 = array(
											'wpautop'      => false,
											'media_buttons' => true,
											'textarea_name' => 'meta[submission_limit_message]',
											'textarea_rows' => 12,
											'tabindex'     => '',
											'tabfocus_elements' => ':prev,:next',
											'editor_css'   => '',
											'editor_class' => 'advrf-editor',
											'teeny'        => false,
											'dfw'          => false,
											'tinymce'      => true,
											'quicktags'    => true,
										);
										wp_editor( $submission_limit_message, $editor_id, $settings );
										?>
                                        <p class="description"><?php esc_html_e( 'Shown when the submission limit is reached.', 'vedrixa-forms-registration-builder' ); ?></p>
                                    </div>
                                </div>

                                <div class="advrf-row">
                                    <div class="advrf-control-label">
                                        <label><?php esc_html_e( 'Limit Submissions Per Email/User', 'vedrixa-forms-registration-builder' ); ?></label>
                                    </div>
                                    <div class="advrf-control">
                                        <input type="number" min="0" class="advrf-input-field" name="meta[wpefb_limit_submission]" value="<?php echo isset( $meta['wpefb_limit_submission'] ) ? esc_attr( $meta['wpefb_limit_submission'] ) : ''; ?>">
                                        <p class="description"><?php esc_html_e( 'Limits how many times the same email can submit this form. Set 0 to disable.', 'vedrixa-forms-registration-builder' ); ?></p>
                                    </div>
                                </div>

                                <div class="advrf-row">
                                    <div class="advrf-control-label">
                                        <label><?php esc_html_e( 'Show Submission Status on Frontend', 'vedrixa-forms-registration-builder' ); ?></label>
                                    </div>
                                    <div class="advrf-control">
                                        <input class="advrf_toggle" type="checkbox" value="1" id="wpefb_show_submission_status" name="meta[wpefb_show_submission_status]" <?php checked( isset( $meta['wpefb_show_submission_status'] ) ? (int) $meta['wpefb_show_submission_status'] : 0, 1 ); ?> />
                                        <label></label>
                                        <p class="description"><?php esc_html_e( 'Display current submissions count and limit above the form on frontend.', '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>
