<?php
/**
 * WordPress environment collector.
 *
 * @package MonitorCat\Modules\Diagnostics\Collector
 */

declare(strict_types=1);

namespace MonitorCat\Modules\Diagnostics\Collector;

defined( 'ABSPATH' ) || exit;

/**
 * Collects WordPress environment information including version, configuration, and settings.
 */
final class WordPressCollector {

	/**
	 * Collect WordPress environment data.
	 *
	 * @return array{label: string, icon: string, items: array<int, array{label: string, value: string, status?: string}>}
	 */
	public function collect(): array {
		return array(
			'label' => __( 'WordPress', 'monitor-cat' ),
			'icon'  => 'fa-globe',
			'items' => array(
				array(
					'label'  => __( 'Version', 'monitor-cat' ),
					'value'  => get_bloginfo( 'version' ),
					'status' => version_compare( get_bloginfo( 'version' ), '6.0', '>=' ) ? 'good' : 'warning',
				),
				array(
					'label' => __( 'Site URL', 'monitor-cat' ),
					'value' => get_site_url(),
				),
				array(
					'label' => __( 'Home URL', 'monitor-cat' ),
					'value' => get_home_url(),
				),
				array(
					'label' => __( 'Multisite', 'monitor-cat' ),
					'value' => is_multisite()
						? __( 'Yes', 'monitor-cat' )
						: __( 'No', 'monitor-cat' ),
				),
				array(
					'label'  => __( 'WP_DEBUG', 'monitor-cat' ),
					'value'  => defined( 'WP_DEBUG' ) && WP_DEBUG
						? __( 'On', 'monitor-cat' )
						: __( 'Off', 'monitor-cat' ),
					'status' => ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ? 'warning' : 'good',
				),
				array(
					'label' => __( 'WP_DEBUG_LOG', 'monitor-cat' ),
					'value' => defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG
						? __( 'On', 'monitor-cat' )
						: __( 'Off', 'monitor-cat' ),
				),
				array(
					'label' => __( 'SCRIPT_DEBUG', 'monitor-cat' ),
					'value' => defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG
						? __( 'On', 'monitor-cat' )
						: __( 'Off', 'monitor-cat' ),
				),
				array(
					'label' => __( 'Memory Limit', 'monitor-cat' ),
					'value' => defined( 'WP_MEMORY_LIMIT' ) ? WP_MEMORY_LIMIT : __( 'Not set', 'monitor-cat' ),
				),
				array(
					'label' => __( 'Max Memory Limit', 'monitor-cat' ),
					'value' => defined( 'WP_MAX_MEMORY_LIMIT' ) ? WP_MAX_MEMORY_LIMIT : __( 'Not set', 'monitor-cat' ),
				),
				array(
					'label' => __( 'DISALLOW_FILE_EDIT', 'monitor-cat' ),
					'value' => defined( 'DISALLOW_FILE_EDIT' ) && DISALLOW_FILE_EDIT
						? __( 'Yes', 'monitor-cat' )
						: __( 'No', 'monitor-cat' ),
				),
				array(
					'label' => __( 'DISALLOW_FILE_MODS', 'monitor-cat' ),
					'value' => ! wp_is_file_mod_allowed( 'monitorcat_diagnostics' )
						? __( 'Yes', 'monitor-cat' )
						: __( 'No', 'monitor-cat' ),
				),
				array(
					'label'  => __( 'DISABLE_WP_CRON', 'monitor-cat' ),
					'value'  => defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON
						? __( 'Yes', 'monitor-cat' )
						: __( 'No', 'monitor-cat' ),
					'status' => ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) ? 'warning' : 'good',
				),
				array(
					'label' => __( 'AUTOMATIC_UPDATER_DISABLED', 'monitor-cat' ),
					'value' => defined( 'AUTOMATIC_UPDATER_DISABLED' ) && AUTOMATIC_UPDATER_DISABLED
						? __( 'Yes', 'monitor-cat' )
						: __( 'No', 'monitor-cat' ),
				),
				array(
					'label' => __( 'Environment Type', 'monitor-cat' ),
					'value' => function_exists( 'wp_get_environment_type' )
						? wp_get_environment_type()
						: __( 'Unknown', 'monitor-cat' ),
				),
				array(
					'label' => __( 'Locale', 'monitor-cat' ),
					'value' => get_locale(),
				),
				array(
					'label' => __( 'Timezone', 'monitor-cat' ),
					'value' => wp_timezone_string(),
				),
			),
		);
	}
}
