<?php

/**
 * Class BookingForm
 *
 * Handles the functionality related to displaying the booking form using shortcodes.
 */
namespace RadiusTheme\RadiusBooking\Shortcodes;

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}

/**
 * Class BookingForm
 *
 * Responsible for managing and rendering the booking form functionality via shortcode integration.
 */
class BookingForm {

	/**
	 * Output booking form.
	 *
	 * Echoes the rendered template. Output is captured by
	 * Shortcodes::shortcode_wrapper() via ob_start().
	 *
	 * @param array|string $atts Shortcode attributes.
	 *
	 * @return void
	 */
	public static function output( $atts ): void {
		$atts = shortcode_atts(
			array(
				'modal'       => 'false',
				'service_id'  => '',
				'staff_id'    => '',
				'button_text' => '',
				'flow'        => 'service_first',
			),
			$atts,
			'radius_booking_form'
		);

		$atts['modal']       = filter_var( $atts['modal'], FILTER_VALIDATE_BOOLEAN );
		$atts['service_id']  = absint( $atts['service_id'] );
		$atts['staff_id']    = absint( $atts['staff_id'] );
		$atts['button_text'] = sanitize_text_field( $atts['button_text'] );
		$atts['flow']        = in_array( $atts['flow'], array( 'service_first', 'staff_first' ), true ) ? $atts['flow'] : 'service_first';

		self::booking_form( $atts );
	}

	/**
	 * Render the booking form template.
	 *
	 * @param array $atts Normalized shortcode attributes.
	 *
	 * @return void
	 */
	private static function booking_form( $atts ) {
		rtrb_get_template( 'bookings/booking.php', array( 'atts' => $atts ) );
	}
}