<?php
/**
 * Required plugins partial.
 *
 * @package EaLab\WP_Deployer
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Requires.
 */
require_once __DIR__ . '/array-to-li.php';

/**
 * Returns the HTML for the required plugins partial.
 *
 * Shows a list of plugins required by the current export or import.
 *
 * @param array $deployment_bundle The deployment bundle.
 *
 * @return string Markup.
 */
function deploy_sync_content__required_plugins( array $deployment_bundle = array() ): string {
	if ( empty( $deployment_bundle ) ) {
		return '';
	}

	$plugin_names = array();

	array_walk(
		$deployment_bundle,
		function ( $item ) use ( &$plugin_names ) {
			if ( ! empty( $item['plugin'] ) ) {
				$plugin_names[ $item['plugin'] ] = $item['plugin'];
			}
		}
	);

	if ( empty( $plugin_names ) ) {
		return '';
	}

	$title      = esc_html__( 'Required plugins', 'deploy-sync-content' );
	$list_items = wp_kses( deploy_sync_content__array_to_li( $plugin_names ), array( 'li' => array() ) );

	return '<div class="alert alert-warning" role="alert"><h4>' . $title . '</h4><ul>' . $list_items . '</ul></div>';
}
