<?php
namespace WPUltimateSecurity\UltimateSecurity\Modules\Monitoring\SiteHealth\Formatters;

use WPUltimateSecurity\UltimateSecurity\Modules\Monitoring\SiteHealth\Services\HealthCheckService;

/**
 * Tab Formatter
 *
 * Formats health check data into tabs for UI display
 */
class TabFormatter
{
	/**
	 * Format collectors into tabs
	 *
	 * @param HealthCheckService $service Health check service
	 * @return array Formatted tabs
	 */
	public function format(HealthCheckService $service): array
	{
		$tabs = [];
		$collectors = $service->getCollectors();

		foreach ($collectors as $name => $collector) {
			$tabs[] = [
				'id' => $name,
				'label' => $collector->getLabel(),
				'icon' => $this->getIconForTab($name),
			];
		}

		return $tabs;
	}

	/**
	 * Get icon for tab
	 *
	 * @param string $tab_name Tab name
	 * @return string Icon class or emoji
	 */
	private function getIconForTab(string $tab_name): string
	{
		$icons = [
			'wordpress' => 'dashicons-wordpress',
			'server' => 'dashicons-admin-settings',
			'database' => 'dashicons-database',
			'themes' => 'dashicons-admin-appearance',
			'plugins' => 'dashicons-admin-plugins',
			'media' => 'dashicons-admin-media',
			'filesystem' => 'dashicons-portfolio',
			'constants' => 'dashicons-admin-generic',
		];

		return $icons[$tab_name] ?? 'dashicons-info';
	}

	/**
	 * Format single tab data
	 *
	 * @param string $tab_id Tab ID
	 * @param array $data Tab data
	 * @return array Formatted tab data
	 */
	public function formatTab(string $tab_id, array $data): array
	{
		return [
			'id' => $tab_id,
			'data' => $data,
			'count' => count($data),
		];
	}
}
