<?php
namespace WPVOID\StockBeacon\Admin;

use WPVOID\StockBeacon\Core\WaitlistManager;

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

class ProductColumn {
	private WaitlistManager $manager;

	public function __construct( WaitlistManager $manager ) {
		$this->manager = $manager;
	}

	public function register(): void {
		add_filter( 'manage_edit-product_columns', array( $this, 'add_column' ) );
		add_action( 'manage_product_posts_custom_column', array( $this, 'render' ), 10, 2 );
	}

	public function add_column( array $columns ): array {
		$columns['stockbeacon_waitlist'] = '📋';
		return $columns;
	}

	public function render( string $column, int $post_id ): void {
		if ( 'stockbeacon_waitlist' !== $column ) {
			return;
		}
		$count = $this->manager->get_cached_count( $post_id );
		echo $count > 0 ? '<strong>' . esc_html( (string) $count ) . '</strong>' : '—';
	}
}
