'rank_math/analytics/clear_cache',
		'status' => \ActionScheduler_Store::STATUS_PENDING,
	]
);
$db_info        = DB::info();
$is_queue_empty = empty( $actions );
$disable        = ( ! Authentication::is_authorized() || ! $is_queue_empty ) ? true : false;
if ( ! empty( $db_info ) ) {
	$db_info = [
		/* translators: number of days */
		'
 ' . sprintf( esc_html__( 'Storage Days: %s', 'rank-math' ), '' . $db_info['days'] . '' ) . '
',
		/* translators: number of rows */
		' ' . sprintf( esc_html__( 'Data Rows: %s', 'rank-math' ), '' . Str::human_number( $db_info['rows'] ) . '' ) . '
',
		/* translators: database size */
		' ' . sprintf( esc_html__( 'Size: %s', 'rank-math' ), '' . size_format( $db_info['size'] ) . '' ) . '
',
	];
}
$actions = as_get_scheduled_actions(
	[
		'order'  => 'DESC',
		'hook'   => 'rank_math/analytics/data_fetch',
		'status' => \ActionScheduler_Store::STATUS_PENDING,
	]
);
if ( Authentication::is_authorized() && ! empty( $actions ) ) {
	$action    = current( $actions );
	$schedule  = $action->get_schedule();
	$next_date = $schedule->get_date();
	if ( $next_date ) {
		$cmb->add_field(
			[
				'id'      => 'console_data_empty',
				'type'    => 'raw',
				/* translators: date */
				'content' => sprintf(
					'' . __( 'Next data fetch on %s', 'rank-math' ),
					date_i18n( 'd M, Y H:m:i', $next_date->getTimestamp() ) . ''
				),
			]
		);
	}
}
// phpcs:enable
$cmb->add_field(
	[
		'id'   => 'search_console_ui',
		'type' => 'raw',
		'file' => rank_math()->admin_dir() . '/wizard/views/search-console-ui.php',
	]
);
if ( ! Authentication::is_authorized() ) {
	return;
}
$is_fetching = 'fetching' === get_option( 'rank_math_analytics_first_fetch' );
$buttons     = '
' .
	'' .
	'  ' .
	'  ';
$buttons .= '
' . join( '', $db_info );
// Translators: placeholder is a link to rankmath.com, with "free version" as the anchor text.
$description = sprintf( __( 'Enter the number of days to keep Analytics data in your database. The maximum allowed days are 90 in the %s. Though, 2x data will be stored in the DB for calculating the difference properly.', 'rank-math' ), '' . __( 'free version', 'rank-math' ) . '' );
$description = apply_filters_deprecated( 'rank_math/analytics/options/cahce_control/description', [ $description ], '1.0.61.1', 'rank_math/analytics/options/cache_control/description' );
$description = apply_filters( 'rank_math/analytics/options/cache_control/description', $description );
$cmb->add_field(
	[
		'id'              => 'console_caching_control',
		'type'            => 'text',
		'name'            => __( 'Analytics Database', 'rank-math' ),
		// translators: Anchor text 'free version', linking to pricing page.
		'description'     => $description,
		'default'         => 90,
		'sanitization_cb' => function( $value ) {
			$max   = apply_filters( 'rank_math/analytics/max_days_allowed', 90 );
			$value = absint( $value );
			if ( $value > $max ) {
				$value = $max;
			}
			return $value;
		},
		'after_field'     => $buttons,
	]
);
$cmb->add_field(
	[
		'id'          => 'analytics_stats',
		'type'        => 'toggle',
		'name'        => __( 'Frontend Stats Bar', 'rank-math' ),
		'description' => esc_html__( 'Enable this option to show Analytics Stats on the front just after the admin bar.', 'rank-math' ),
		'default'     => 'on',
	]
);
if ( RankMath\Analytics\Email_Reports::are_fields_hidden() ) {
	return;
}
$preview_url = home_url( '?rank_math_analytics_report_preview=1' );
$title       = esc_html__( 'Email Reports', 'rank-math' );
// Translators: Placeholders are the opening and closing tag for the link.
$description = sprintf( esc_html__( 'Receive periodic SEO Performance reports via email. Once enabled and options are saved, you can see %1$s the preview here%2$s.', 'rank-math' ), '', '' );
$cmb->add_field(
	[
		'id'      => 'email_reports_title',
		'type'    => 'raw',
		'content' => sprintf( '', $title, $description ),
	]
);
$cmb->add_field(
	[
		'id'          => 'console_email_reports',
		'type'        => 'toggle',
		'name'        => __( 'Email Reports', 'rank-math' ),
		'description' => __( 'Turn on email reports.', 'rank-math' ),
		'default'     => Helper::get_settings( 'general.console_email_reports' ) ? 'on' : 'off',
		'classes'     => 'nob',
	]
);
$is_pro_active = defined( 'RANK_MATH_PRO_FILE' );
$pro_badge     = '' . __( 'PRO', 'rank-math' ) . '';
$args          = [
	'id'         => 'console_email_frequency',
	'type'       => 'select',
	'name'       => esc_html__( 'Email Frequency', 'rank-math' ) . ( ! $is_pro_active ? $pro_badge : '' ),
	'desc'       => wp_kses_post( __( 'Email report frequency.', 'rank-math' ) ),
	'default'    => 'monthly',
	'options'    => [
		'monthly' => esc_html__( 'Every 30 days', 'rank-math' ),
	],
	'dep'        => [ [ 'console_email_reports', 'on' ] ],
	'attributes' => ! $is_pro_active ? [ 'disabled' => 'disabled' ] : [],
	'before_row' => ! $is_pro_active ? '' : '',
	'after_row'  => ! $is_pro_active ? '
' : '',
];
$cmb->add_field( $args );