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

use RadiusTheme\RadiusBooking\Helpers\SettingsHelper;

$is_modal   = $atts['modal'] ?? false;
$service_id = $atts['service_id'] ?? 0;
$staff_id   = $atts['staff_id'] ?? 0;
$flow       = $atts['flow'] ?? 'service_first';

// Resolve button text: shortcode attribute → global setting (Appointment Settings > Button Text) → default.
$button_text = $atts['button_text'] ?? '';
if ( empty( $button_text ) ) {
	$service_list_settings = SettingsHelper::get_setting( 'serviceList' );
	$button_text           = $service_list_settings['buttonText'] ?? __( 'Book Now', 'radius-booking' );
}
?>
<?php if ( $is_modal ) : ?>
	<div class="rtrb-shortcode-modal-wrapper">
		<button type="button" class="rtrb-shortcode-modal-trigger"
			<?php echo $service_id ? 'data-service-id="' . esc_attr( $service_id ) . '"' : ''; ?>
			<?php echo $staff_id ? 'data-employee-id="' . esc_attr( $staff_id ) . '"' : ''; ?>
			data-flow="<?php echo esc_attr( $flow ); ?>"
		>
			<?php echo esc_html( $button_text ); ?>
		</button>
		<div class="rtrb-shortcode-modal" style="display:none; position:fixed; inset:0; z-index:999999; background:rgba(0,0,0,0.6); align-items:center; justify-content:center; padding:20px;">
			<div class="rtrb-root rt-radius-booking-form has-modal"
				<?php echo $service_id ? 'data-service-id="' . esc_attr( $service_id ) . '"' : ''; ?>
				<?php echo $staff_id ? 'data-employee-id="' . esc_attr( $staff_id ) . '"' : ''; ?>
				data-flow="<?php echo esc_attr( $flow ); ?>"
			>
				<div class="rtrb-initial-loader" style="display:flex;align-items:center;justify-content:center;min-height:400px;">
					<svg width="36" height="36" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="animation:rtrb-spin 1s linear infinite;color:#6B7280;">
						<path d="M21 12a9 9 0 1 1-6.219-8.56"/>
					</svg>
				</div>
			</div>
		</div>
	</div>
<?php else : ?>
	<div class="rtrb-root rt-radius-booking-form no-modal"
		<?php echo $service_id ? 'data-service-id="' . esc_attr( $service_id ) . '"' : ''; ?>
		<?php echo $staff_id ? 'data-employee-id="' . esc_attr( $staff_id ) . '"' : ''; ?>
		data-flow="<?php echo esc_attr( $flow ); ?>"
	>
		<div class="rtrb-initial-loader" style="display:flex;align-items:center;justify-content:center;min-height:400px;">
			<svg width="36" height="36" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="animation:rtrb-spin 1s linear infinite;color:#6B7280;">
				<path d="M21 12a9 9 0 1 1-6.219-8.56"/>
			</svg>
		</div>
	</div>
<?php endif; ?>
<style>@keyframes rtrb-spin{to{transform:rotate(360deg)}}</style>
