<?php
/**
 * Wishlist block — server-side registration and render callback.
 *
 * @package JWP_STK
 */

namespace JWP_STK\Blocks\Wishlist;

defined( 'ABSPATH' ) || exit;

/**
 * Block class.
 */
class Block {

	/**
	 * Register this block type with WordPress.
	 *
	 * @param string $asset_dir Absolute path to the compiled block directory.
	 * @return void
	 */
	public function register( string $asset_dir ) {
		register_block_type(
			$asset_dir,
			array(
				'render_callback' => array( $this, 'render' ),
			)
		);
	}

	/**
	 * Render the block on the frontend.
	 *
	 * Delegates to the Wishlist module shortcode so all configuration and
	 * guest / user logic is handled in one place.
	 *
	 * @param array<string, mixed> $attributes Block attributes.
	 * @param string               $content    Inner block content (unused — dynamic block).
	 * @return string
	 */
	public function render( array $attributes, string $content ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed,Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed -- Both params required by WP block render callback signature.
		if ( ! shortcode_exists( 'storetoolkit_wishlist' ) ) {
			return '';
		}

		return do_shortcode( '[storetoolkit_wishlist]' );
	}
}
