<?php

namespace Planaday\Platform\WordpressConfig\ShortcodeLinks;

use Planaday\Html\Tags\Test\TestPage\TestPage;
use Planaday\Utility\Debug\Log\Logging;
use Planaday\Utility\DependencyInjection\Container;
use Planaday\Utility\DependencyInjection\InjectionImpossibleException;
use Planaday\Utility\PluginData;

class TestingShortcodes {
	use Logging;

	/**
	 * @param PluginData $pluginData
	 * @param Container $registry
	 */
	public function __construct(
		protected PluginData $pluginData,
		protected Container $registry
	) {}

	public function addShortcodes(): void {
		add_shortcode($this->pluginData->getShortPrefix() . '-test', [$this, 'test']); // [padc-test]
	}

	public function test( $attributes ): string {
		try {
			return $this->registry->getInstance(ShortcodeToTagConverter::class)->getShortcode('pad-test', TestPage::TAG, $attributes);
		}
		catch (InjectionImpossibleException $e) {
			$this->logError( "failed to create ShortcodeToTagConverter, error: " . $e->getMessage() );
			return '<!-- dependency injection failed -->';
		}
	}
}