<?php
/**
 * Presets de version PHP cible.
 *
 * @package PCC
 * @license GPL-2.0-or-later
 */

defined( 'ABSPATH' ) || exit;

class PCC_Presets {

	/**
	 * @return string[]
	 */
	public static function slugs() {
		return array_keys( self::all() );
	}

	/**
	 * @return array<string, array{label:string,desc:string,icon:string,settings:array}>
	 */
	public static function all() {
		$next = PCC_Scanner::next_minor_version( phpversion() );

		return array(
			'next' => array(
				'label'    => __( 'Next PHP version', 'php-compatibility-checker-by-volade' ),
				'desc'     => $next
					? sprintf(
						/* translators: %s: PHP version number */
						__( 'Scan against PHP %s (next step from your server).', 'php-compatibility-checker-by-volade' ),
						$next
					)
					: __( 'Scan against the next minor PHP version.', 'php-compatibility-checker-by-volade' ),
				'icon'     => '⬆️',
				'settings' => array(
					'target_php'   => $next ?: '8.4',
					'scan_plugins' => true,
					'scan_themes'  => true,
				),
			),
			'php83' => array(
				'label'    => 'PHP 8.3',
				'desc'     => __( 'Common hosting target — check full stack for 8.3.', 'php-compatibility-checker-by-volade' ),
				'icon'     => '8.3',
				'settings' => array(
					'target_php'   => '8.3',
					'scan_plugins' => true,
					'scan_themes'  => true,
				),
			),
			'php84' => array(
				'label'    => 'PHP 8.4',
				'desc'     => __( 'Prepare for PHP 8.4 before switching in hosting panel.', 'php-compatibility-checker-by-volade' ),
				'icon'     => '8.4',
				'settings' => array(
					'target_php'   => '8.4',
					'scan_plugins' => true,
					'scan_themes'  => true,
				),
			),
			'php85' => array(
				'label'    => 'PHP 8.5',
				'desc'     => __( 'Forward-looking scan for PHP 8.5.', 'php-compatibility-checker-by-volade' ),
				'icon'     => '8.5',
				'settings' => array(
					'target_php'   => '8.5',
					'scan_plugins' => true,
					'scan_themes'  => true,
				),
			),
			'hosting' => array(
				'label'    => __( 'Before host migration', 'php-compatibility-checker-by-volade' ),
				'desc'     => __( 'Next PHP version, active stack only, delta mode on.', 'php-compatibility-checker-by-volade' ),
				'icon'     => '🚀',
				'settings' => array(
					'target_php'       => $next ?: '8.4',
					'scan_plugins'     => true,
					'scan_themes'      => true,
					'delta_mode'       => true,
					'skip_vendor'      => true,
					'scan_active_first'=> true,
				),
			),
		);
	}

	/**
	 * @param string $slug Preset slug.
	 * @return array|null
	 */
	public static function get( $slug ) {
		$all = self::all();
		return $all[ $slug ] ?? null;
	}
}
