/**
* wpv_get_limit_offset_summary
*
* Returns the limit and offset summary for a View
*
* @param $view_settings
*
* @returns (string) $summary
*
* @since 1.6.0
*/
function wpv_get_limit_offset_summary( $view_settings, $context = 'listing' ) {
	$view_settings = wpv_limit_offset_default_settings( $view_settings );
	$output = '';
	$limit = 0;
	$offset = 0;
	if ( 
		! isset( $view_settings['query_type'] ) 
		|| (
			isset($view_settings['query_type'] ) 
			&& $view_settings['query_type'][0] == 'posts' 
		) 
	) {
		$limit = intval( $view_settings['limit'] );
		$offset = intval( $view_settings['offset'] );
	}
	if ( isset( $view_settings['query_type'] ) && $view_settings['query_type'][0] == 'taxonomy' ) {
		$limit = intval( $view_settings['taxonomy_limit'] );
		$offset = intval( $view_settings['taxonomy_offset'] );
	}
	if ( isset( $view_settings['query_type'] ) && $view_settings['query_type'][0] == 'users' ) {
		$limit = intval( $view_settings['users_limit'] );
		$offset = intval( $view_settings['users_offset'] );
	}
	if ( $context == 'embedded-info' ) {
		if ( $limit > 0 || $offset > 0 ) {
			if ( $offset > 0 ) {
				$output .= sprintf( _n( 'First result skipped', 'First %d results skipped', $offset, 'wpv-views' ), $offset );
				if ( $limit > 0 ) {
					$output .= sprintf( _n( ', then one result loaded', ', then %d results loaded', $limit, 'wpv-views' ), $limit );
				}
			} else if ( $limit > 0 ) {
				$output .= sprintf( _n( 'First result loaded', 'First %d results loaded', $limit, 'wpv-views' ), $limit );
			}
		} else {
			$output .= __( 'All results loaded', 'wpv-views' );
		}
	} else {
		if ( $limit > 0 ) {
			$output .= sprintf( _n( ', limit to 1 item', ', limit to %d items', $limit, 'wpv-views' ), $limit );
		}
		if ( $offset > 0 ) {
			$output .= sprintf( _n( ', skip first item', ', skip %d items', $offset, 'wpv-views' ), $offset );
		}
	}
	$output = esc_html( $output );
	return $output;
}
function add_view_limit_offset( $view_settings, $view_id ) {
	$view_settings = wpv_limit_offset_default_settings( $view_settings );
	$limit_options = array();
	$offset_options = array();
	for ( $index = 1; $index < 51; $index++ ) {
		$limit_options[$index] = $index;
		$offset_options[$index] = $index;
	}
	$limit_options = apply_filters( 'wpv_filter_extend_limit_options', $limit_options );
	$offset_options = apply_filters( 'wpv_filter_extend_offset_options', $offset_options );
	$hide = '';
	if (
		isset( $view_settings['sections-show-hide'] ) 
		&& isset( $view_settings['sections-show-hide']['limit-offset'] ) 
		&& 'off' == $view_settings['sections-show-hide']['limit-offset']
	) {
		$hide = ' hidden';
	}
	$section_help_pointer = WPV_Admin_Messages::edit_section_help_pointer( 'limit_and_offset' );
	?>
	<div class="wpv-setting-container wpv-settings-limit js-wpv-settings-limit-offset<?php echo $hide; ?>">
		<div class="wpv-settings-header">
			<h3>
				<?php _e( 'Limit and Offset', 'wpv-views' ) ?>
				<i class="icon-question-sign js-display-tooltip" 
					data-header="<?php echo esc_attr( $section_help_pointer['title'] ); ?>" 
					data-content="<?php echo esc_attr( $section_help_pointer['content'] ); ?>">
				</i>
			</h3>
		</div>
		<div class="wpv-setting js-wpv-setting">

			<div class="wpv-settings-query-type-posts"<?php echo ( $view_settings['query_type'][0] != 'posts' ) ? ' style="display: none;"' : ''; ?>>

				<p>
					<span class="wpv-combo">
						<label for="wpv-settings-limit"><?php _e( 'Display ', 'wpv-views' ) ?></label>
						<select name="_wpv_settings[limit]" id="wpv-settings-limit" class="js-wpv-limit" autocomplete="off">
							<option value="-1"><?php _e('No limit', 'wpv-views'); ?></option>
							<?php
							foreach ( $limit_options as $index => $value ) {
								?>
								<option value="<?php echo esc_attr( $index ); ?>" <?php selected( $view_settings['limit'], $index, true ); ?>><?php echo $value; ?></option>
								<?php
							}
							?>
						</select>
						<span><?php _e( 'items ', 'wpv-views' ) ?></span>
					</span>
					&nbsp;&nbsp;|&nbsp;&nbsp;
					<span class="wpv-combo">
						<label for="wpv-settings-offset"><?php _e( 'Skip first', 'wpv-views' ) ?></label>
						<select name="_wpv_settings[offset]" id="wpv-settings-offset" class="js-wpv-offset" autocomplete="off">
							<option value="0"><?php _e('None', 'wpv-views'); ?></option>
							<?php
							foreach ( $offset_options as $index => $value ) {
								?>
								<option value="<?php echo esc_attr( $index ); ?>" <?php selected( $view_settings['offset'], $index, true ); ?>><?php echo $value; ?></option>
								<?php
							}
							?>
						</select>
						<span><?php _e( 'items', 'wpv-views' ) ?></span>
					<span class="wpv-combo">
				</p>
			</div>

			<div class="wpv-settings-query-type-taxonomy"<?php echo ( $view_settings['query_type'][0] != 'taxonomy' ) ? ' style="display: none;"' : ''; ?>>

				<p>
					<span class="wpv-combo">
						<label for="wpv-settings-taxonomy-limit"><?php _e( 'Display ', 'wpv-views' ) ?></label>
						<select name="_wpv_settings[taxonomy_limit]" id="wpv-settings-taxonomy-limit" class="js-wpv-taxonomy-limit" autocomplete="off">
							<option value="-1"><?php _e('No limit', 'wpv-views'); ?></option>
							<?php
							foreach ( $limit_options as $index => $value ) {
								?>
								<option value="<?php echo esc_attr( $index ); ?>" <?php selected( $view_settings['taxonomy_limit'], $index, true ); ?>><?php echo $value; ?></option>
								<?php
							}
							?>
						</select>
						<span><?php _e( 'items ', 'wpv-views' ) ?></span>
					</span>
					&nbsp;&nbsp;|&nbsp;&nbsp;
					<span class="wpv-combo">
						<label for="wpv-settings-taxonomy-offset"><?php _e( 'Skip first', 'wpv-views' ) ?></label>
						<select name="_wpv_settings[taxonomy_offset]" id="wpv-settings-taxonomy-offset" class="js-wpv-taxonomy-offset" autocomplete="off">
							<option value="0"><?php _e('None', 'wpv-views'); ?></option>
							<?php
							foreach ( $offset_options as $index => $value ) {
								?>
								<option value="<?php echo esc_attr( $index ); ?>" <?php selected( $view_settings['taxonomy_offset'], $index, true ); ?>><?php echo $value; ?></option>
								<?php
							}
							?>
						</select>
						<span><?php _e( 'items', 'wpv-views' ) ?></span>
					</span>
				</p>
			</div>
			<div class="wpv-settings-query-type-users"<?php echo ( $view_settings['query_type'][0] != 'users' ) ? ' style="display: none;"' : ''; ?>>
			     <p>
                    <span class="wpv-combo">
						<label for="wpv-settings-users-limit"><?php _e( 'Display ', 'wpv-views' ) ?></label>
						<select name="_wpv_settings[users_limit]" id="wpv-settings-users-limit" class="js-wpv-users-limit" autocomplete="off">
							<option value="-1"><?php _e('No limit', 'wpv-views'); ?></option>
							<?php
							foreach ( $limit_options as $index => $value ) {
								?>
								<option value="<?php echo esc_attr( $index ); ?>" <?php selected( $view_settings['users_limit'], $index, true ); ?>><?php echo $value; ?></option>
								<?php
							}
							?>
						</select>
						<span><?php _e( 'items ', 'wpv-views' ) ?></span>
					</span>
					&nbsp;&nbsp;|&nbsp;&nbsp;
					<span class="wpv-combo">
						<label for="wpv-settings-users-offset"><?php _e( 'Skip first', 'wpv-views' ) ?></label>
						<select name="_wpv_settings[users_offset]" id="wpv-settings-users-offset" class="js-wpv-users-offset" autocomplete="off">
							<option value="0"><?php _e('None', 'wpv-views'); ?></option>
							<?php
							foreach ( $offset_options as $index => $value ) {
								?>
								<option value="<?php echo esc_attr( $index ); ?>" <?php selected( $view_settings['users_offset'], $index, true ); ?>><?php echo $value; ?></option>
								<?php
							}
							?>
						</select>
						<span><?php _e( 'items', 'wpv-views' ) ?></span>
					</span>
                </p>
			</div>
		</div>
		<span class="update-action-wrap auto-update js-wpv-update-action-wrap">
			<span class="js-wpv-message-container"></span>
			<input type="hidden" data-success="<?php echo esc_attr( __('Updated', 'wpv-views') ); ?>" data-unsaved="<?php echo esc_attr( __('Not saved', 'wpv-views') ); ?>" data-nonce="<?php echo wp_create_nonce( 'wpv_view_limit_offset_nonce' ); ?>" class="js-wpv-limit-offset-update" />
		</span>
	</div>
<?php }