<?php

namespace Planaday\Platform\WordpressConfig;

use Planaday\Platform\PlatformAbstraction\HtmlService;
use Planaday\Utility\Debug\Log\Logging;
use Planaday\Utility\PluginData;

class WPHtmlService implements HtmlService {
	use Logging;

	public function __construct(
		protected PluginData $pluginData
	) {}

	public function getAdminTextArea( string $content, string $id, array $settings ): string {
		ob_start();
		wp_editor( $content, $id, $settings );
		$editor = ob_get_clean();

		if ($editor === false) {
			$this->logError('Failed to get WordPress editor');
			return '';
		}

		return $editor;
	}

	public function getNonceCheckField( string $nonceName ): string {
		return wp_nonce_field( $this->pluginData->getShortPrefix() . $nonceName );
	}
}