<?php
namespace PageVICO\Admin;

defined( 'ABSPATH' ) || exit;

class AnalyticsPages {
	public static function init() {
		add_action( 'admin_menu', array( __CLASS__, 'registerPages' ) );
	}

	public static function registerPages() {
		add_submenu_page(
			'pagevico-dashboard',
			// translators: %s: Page title
			__( 'Top Pages', 'page-visit-counter-analytics' ),
			// translators: %s: Menu title
			__( 'Top Pages', 'page-visit-counter-analytics' ),
			'manage_options',
			'pagevico-top-pages',
			array( 'PageVICO\Admin\Views\TopPages', 'render' )
		);

		add_submenu_page(
			'pagevico-dashboard',
			// translators: %s: Page title
			__( 'Top Posts', 'page-visit-counter-analytics' ),
			// translators: %s: Menu title
			__( 'Top Posts', 'page-visit-counter-analytics' ),
			'manage_options',
			'pagevico-top-posts',
			array( 'PageVICO\Admin\Views\TopPosts', 'render' )
		);

		// Only add the custom posts page if custom post types exist
		$custom_post_types = get_post_types(['_builtin' => false], 'names');
		if (!empty($custom_post_types)) {
			add_submenu_page(
				'pagevico-dashboard',
				// translators: %s: Page title
				__( 'Top Custom Posts', 'page-visit-counter-analytics' ),
				// translators: %s: Menu title
				__( 'Top Custom Posts', 'page-visit-counter-analytics' ),
				'manage_options',
				'pagevico-top-custom-posts',
				array( 'PageVICO\Admin\Views\TopCustomPosts', 'render' )
			);
		}

		add_submenu_page(
			'pagevico-dashboard',
			// translators: %s: Page title
			__( 'Top Countries', 'page-visit-counter-analytics' ),
			// translators: %s: Menu title
			__( 'Top Countries', 'page-visit-counter-analytics' ),
			'manage_options',
			'pagevico-top-countries',
			array( 'PageVICO\Admin\Views\TopCountries', 'render' )
		);

		add_submenu_page(
			'pagevico-dashboard',
			// translators: %s: Page title
			__( 'Top Devices', 'page-visit-counter-analytics' ),
			// translators: %s: Menu title
			__( 'Top Devices', 'page-visit-counter-analytics' ),
			'manage_options',
			'pagevico-top-devices',
			array( 'PageVICO\Admin\Views\TopDevices', 'render' )
		);

		add_submenu_page(
			'pagevico-dashboard',
			// translators: %s: Page title
			__( 'Top Sessions', 'page-visit-counter-analytics' ),
			// translators: %s: Menu title
			__( 'Top Sessions', 'page-visit-counter-analytics' ),
			'manage_options',
			'pagevico-top-sessions',
			array( 'PageVICO\Admin\Views\TopSessions', 'render' )
		);
	}
}
