<?php
/**
 * Editor Widgets — the editorial view.
 *
 * Content quality and pipeline: drafts/pending awaiting action, top posts by
 * engagement, recent comments to triage.
 *
 * @package Platform\Helm\Modules\Persona_Dashboards\Widgets
 */

declare( strict_types = 1 );

namespace Platform\Helm\Modules\Persona_Dashboards\Widgets;

use Platform\Helm\Modules\Persona_Dashboards\DataProviders;
use Platform\Helm\Modules\Persona_Dashboards\Renderer;

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

final class EditorWidgets {

	public function __construct( private DataProviders $data ) {}

	public function render_pipeline(): void {
		Renderer::print_css_once();
		echo Renderer::stat_row( [ // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
			[ 'label' => __( 'Drafts', 'platform-helm' ),   'value' => number_format_i18n( $this->data->draft_count() ) ],
			[ 'label' => __( 'Pending', 'platform-helm' ),  'value' => number_format_i18n( $this->data->pending_count() ) ],
			[ 'label' => __( 'To moderate', 'platform-helm' ), 'value' => number_format_i18n( $this->data->pending_comments_count() ) ],
		] );

		echo '<div class="phelm-pd-section-title">' . esc_html__( 'Top posts by engagement', 'platform-helm' ) . '</div>';
		$top = $this->data->top_posts_by_comments( 5 );
		if ( empty( $top ) ) {
			echo Renderer::empty_note( __( 'No commented posts yet.', 'platform-helm' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
			return;
		}
		echo '<ul class="phelm-pd-list">';
		foreach ( $top as $p ) {
			printf(
				'<li><span class="phelm-pd-li-main"><a href="%s">%s</a></span><span class="phelm-pd-li-meta">%s</span></li>',
				esc_url( (string) $p['edit_link'] ),
				esc_html( (string) $p['title'] ),
				esc_html( sprintf( _n( '%s comment', '%s comments', (int) $p['comments'], 'platform-helm' ), number_format_i18n( (int) $p['comments'] ) ) )
			);
		}
		echo '</ul>';
	}
}
