<?php
/**
 * AbstractView.php.
 *
 * @package RewardsWP
 */

namespace Awesomemotive\Rewardswp\Abstracts;

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

use Awesomemotive\Rewardswp\Interfaces\ViewInterface;

/**
 * Base abstract view with render and buffering helpers.
 */
abstract class AbstractView implements ViewInterface {
	/**
	 * Classes must implement a method to output the contents.
	 *
	 * @since 1.0.0
	 *
	 * @param array $args Optional arguments to control rendering.
	 *
	 * @return void
	 */
	abstract function render( array $args = [] ): void;

	/**
	 * A simple method to return the content instead of echoing.
	 *
	 * @since 1.0.0
	 *
	 * @param array $args Optional arguments to control rendering.
	 *
	 * @return string The captured output buffer contents.
	 */
	public function get_contents( array $args = [] ): string {
		ob_start();
		$this->render( $args );
		return ob_get_clean();
	}
}
