<?php

declare( strict_types=1 );

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

/**
 * Registers [playard] and [playard_bookings] shortcodes
 * and provides the shared render helper used by the Gutenberg block.
 */
class Playard_Shortcodes {

	/**
	 * Renders the booking widget for a given set of shortcode attributes.
	 * Also used by the Gutenberg block render callback and render.php.
	 *
	 * @param array<string,string> $atts  Expects 'field' (comma-separated IDs or empty) and 'theme'.
	 * @return string  HTML output.
	 */
	public function render_booking_widget( array $atts ): string {
		$atts = [
			'field' => sanitize_text_field( (string) ( $atts['field'] ?? '' ) ),
			'theme' => sanitize_text_field( (string) ( $atts['theme'] ?? 'light' ) ),
		];

		ob_start();
		do_action( 'playard_before_booking_widget', $atts );
		include PLAYARD_PATH . 'public/views/booking-widget.php';
		do_action( 'playard_after_booking_widget', $atts );
		return (string) ob_get_clean();
	}

	/**
	 * Renders the [playard_bookings] shortcode (customer my-bookings view).
	 *
	 * @return string  HTML output.
	 */
	public function render_my_bookings(): string {
		ob_start();
		include PLAYARD_PATH . 'public/views/my-bookings.php';
		return (string) ob_get_clean();
	}
}
