<?php
/**
 * Page builder section frontend renderers.
 *
 * @package EasySite_Pro
 */

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

/**
 * Hero section.
 *
 * @param array $d Fields.
 */
function easysite_pb_render_hero( $d ) {
	$bg       = easysite_pb_image( $d, 'bg_image', 'hero' );
	$style    = easysite_pb_field( $d, 'style', 'centered' );
	$gradient = easysite_pb_field( $d, 'gradient', 'brand' );
	if ( 'none' === $gradient && in_array( $style, array( 'gradient-bg', 'gradient-overlay' ), true ) ) {
		$gradient = 'brand';
	}
	$grad_class = easysite_gradient_class( in_array( $style, array( 'gradient-bg', 'gradient-overlay' ), true ) ? $gradient : 'none' );
	$grad_vars  = in_array( $style, array( 'gradient-bg', 'gradient-overlay' ), true ) ? easysite_gradient_vars_style( $gradient ) : '';
	$grad_style = '';
	if ( 'gradient-bg' === $style && 'none' !== $gradient ) {
		$grad_style = easysite_gradient_bg_style( $gradient );
	}
	$bg_style = 'gradient-bg' === $style ? $grad_style : "background-image:url('" . esc_url( $bg ) . "')";
	if ( $grad_vars ) {
		$bg_style .= $grad_vars;
	}
	?>
	<section class="easysite-pb-section easysite-pb-hero easysite-pb-hero--<?php echo esc_attr( $style ); ?><?php echo esc_attr( $grad_class ); ?>" style="<?php echo esc_attr( $bg_style ); ?>"<?php echo easysite_ve_active() ? ' data-esb-field="bg_image" data-esb-type="bg-image"' : ''; ?>>
		<div class="easysite-container easysite-pb-hero__inner">
			<?php
			$t = easysite_pb_field( $d, 'title' );
			$title = easysite_ve_display( $t, __( 'Click to edit headline', 'easysite-pro' ) );
			if ( $title || easysite_ve_active() ) :
				$ph = $t ? '' : ' esb-placeholder';
				?>
				<h1 class="easysite-pb-hero__title<?php echo esc_attr( $ph ); ?>"<?php echo easysite_ve_attr( 'title' ); ?> data-placeholder="<?php esc_attr_e( 'Click to edit headline', 'easysite-pro' ); ?>"><?php echo esc_html( $title ); ?></h1>
			<?php endif; ?>
			<?php
			$s = easysite_pb_field( $d, 'subtitle' );
			$sub = easysite_ve_display( $s, __( 'Click to edit subheadline', 'easysite-pro' ) );
			if ( $sub || easysite_ve_active() ) :
				$ph = $s ? '' : ' esb-placeholder';
				?>
				<p class="easysite-pb-hero__subtitle<?php echo esc_attr( $ph ); ?>"<?php echo easysite_ve_richtext_attr( 'subtitle' ); ?> data-placeholder="<?php esc_attr_e( 'Click to edit subheadline', 'easysite-pro' ); ?>"><?php echo easysite_pb_output_html( $sub ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></p>
			<?php endif; ?>
			<?php
			$bt = easysite_pb_field( $d, 'button_text' );
			$btn = easysite_ve_display( $bt, __( 'Button text', 'easysite-pro' ) );
			if ( $btn || easysite_ve_active() ) :
				$ph = $bt ? '' : ' esb-placeholder';
				?>
				<a class="easysite-btn easysite-btn-lg esb-editable-button<?php echo esc_attr( $ph ); ?>" href="<?php echo esc_url( home_url( easysite_pb_field( $d, 'button_url', '/contact' ) ) ); ?>"<?php echo easysite_ve_attr( 'button_text' ); ?> data-esb-link-field="button_url" title="<?php esc_attr_e( 'Shift+click to edit link', 'easysite-pro' ); ?>"><?php echo esc_html( $btn ); ?></a>
			<?php endif; ?>
		</div>
	</section>
	<?php
}

/**
 * Text block.
 *
 * @param array $d Fields.
 */
function easysite_pb_render_text( $d ) {
	$align    = easysite_pb_field( $d, 'align', 'left' );
	$gradient = easysite_pb_field( $d, 'gradient', 'none' );
	$grad_class = easysite_gradient_class( $gradient );
	$grad_style = '';
	if ( 'none' !== $gradient ) {
		$grad_style = easysite_gradient_bg_style( $gradient ) . easysite_gradient_vars_style( $gradient );
	}
	?>
	<section class="easysite-pb-section easysite-pb-text easysite-text-align-<?php echo esc_attr( $align ); ?><?php echo esc_attr( $grad_class ); ?>" <?php echo $grad_style ? 'style="' . esc_attr( $grad_style ) . '"' : ''; ?>>
		<div class="easysite-container easysite-pb-narrow">
			<?php
			$t = easysite_pb_field( $d, 'title' );
			$title = easysite_ve_display( $t, __( 'Click to edit heading', 'easysite-pro' ) );
			if ( $title || easysite_ve_active() ) :
				?>
				<h2<?php echo easysite_ve_attr( 'title' ); ?> class="<?php echo $t ? '' : 'esb-placeholder'; ?>"><?php echo esc_html( $title ); ?></h2>
			<?php endif; ?>
			<?php
			$c = easysite_pb_field( $d, 'content' );
			$content = easysite_ve_display( $c, __( 'Click to edit text…', 'easysite-pro' ) );
			if ( $content || easysite_ve_active() ) :
				?>
				<div class="easysite-pb-prose"><div<?php echo easysite_ve_richtext_attr( 'content' ); ?> class="esb-richtext <?php echo $c ? '' : 'esb-placeholder'; ?>"><?php echo $c ? easysite_pb_output_html( $content ) : esc_html( $content ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></div></div>
			<?php endif; ?>
		</div>
	</section>
	<?php
}

/**
 * Image + text.
 *
 * @param array $d Fields.
 */
function easysite_pb_render_image_text( $d ) {
	$layout = easysite_pb_field( $d, 'layout', 'left' );
	$img    = easysite_pb_image( $d, 'image', 'team' );
	?>
	<section class="easysite-pb-section easysite-pb-image-text easysite-pb-split easysite-pb-split--<?php echo esc_attr( $layout ); ?>">
		<div class="easysite-container easysite-pb-split__grid">
			<div class="easysite-pb-split__media esb-editable-image" data-esb-field="image" data-esb-type="image">
				<img src="<?php echo esc_url( $img ); ?>" alt="" loading="lazy" />
				<?php if ( easysite_ve_active() ) : ?>
					<button type="button" class="esb-ve-img-overlay"><span class="dashicons dashicons-format-image"></span> <?php esc_html_e( 'Change image', 'easysite-pro' ); ?></button>
				<?php endif; ?>
			</div>
			<div class="easysite-pb-split__content">
				<?php
				$t = easysite_pb_field( $d, 'title' );
				$title = easysite_ve_display( $t, __( 'Click to edit heading', 'easysite-pro' ) );
				if ( $title || easysite_ve_active() ) :
					?>
					<h2<?php echo easysite_ve_attr( 'title' ); ?> class="<?php echo $t ? '' : 'esb-placeholder'; ?>"><?php echo esc_html( $title ); ?></h2>
				<?php endif; ?>
				<?php
				$c = easysite_pb_field( $d, 'content' );
				$content = easysite_ve_display( $c, __( 'Click to edit text…', 'easysite-pro' ) );
				if ( $content || easysite_ve_active() ) :
					?>
					<p<?php echo easysite_ve_richtext_attr( 'content' ); ?> class="esb-richtext <?php echo $c ? '' : 'esb-placeholder'; ?>"><?php echo $c ? easysite_pb_output_html( $content ) : esc_html( $content ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></p>
				<?php endif; ?>
				<?php
				$bt = easysite_pb_field( $d, 'btn_text' );
				$btn = easysite_ve_display( $bt, __( 'Button text', 'easysite-pro' ) );
				if ( $btn || easysite_ve_active() ) :
					?>
					<a class="easysite-btn esb-editable-button<?php echo $bt ? '' : ' esb-placeholder'; ?>" href="<?php echo esc_url( home_url( easysite_pb_field( $d, 'btn_url', '#' ) ) ); ?>"<?php echo easysite_ve_attr( 'btn_text' ); ?> data-esb-link-field="btn_url"><?php echo esc_html( $btn ); ?></a>
				<?php endif; ?>
			</div>
		</div>
	</section>
	<?php
}

/**
 * Services grid.
 *
 * @param array $d Fields.
 */
function easysite_pb_render_services( $d ) {
	?>
	<section class="easysite-pb-section easysite-pb-services">
		<div class="easysite-container">
			<?php
			$t = easysite_pb_field( $d, 'title' );
			$title = easysite_ve_display( $t, __( 'Section title', 'easysite-pro' ) );
			if ( $title || easysite_ve_active() ) :
				?>
				<h2 class="easysite-pb-section-title<?php echo $t ? '' : ' esb-placeholder'; ?>"<?php echo easysite_ve_attr( 'title' ); ?>><?php echo esc_html( $title ); ?></h2>
			<?php endif; ?>
			<div class="easysite-pb-cards easysite-pb-cards--3">
				<?php for ( $i = 1; $i <= 3; $i++ ) :
					$title = easysite_pb_field( $d, "item{$i}_title" );
					if ( ! $title && ! easysite_ve_active() ) {
						continue;
					}
					$item_title = easysite_ve_display( $title, sprintf( __( 'Service %d title', 'easysite-pro' ), $i ) );
					$item_text  = easysite_ve_display( easysite_pb_field( $d, "item{$i}_text" ), __( 'Service description', 'easysite-pro' ) );
					?>
					<div class="easysite-pb-card">
						<div class="easysite-pb-card__icon"><?php echo easysite_icon( 'service' ); // phpcs:ignore ?></div>
						<h3<?php echo easysite_ve_attr( "item{$i}_title" ); ?> class="<?php echo $title ? '' : 'esb-placeholder'; ?>"><?php echo esc_html( $item_title ); ?></h3>
						<p<?php echo easysite_ve_richtext_attr( "item{$i}_text" ); ?> class="esb-richtext <?php echo easysite_pb_field( $d, "item{$i}_text" ) ? '' : 'esb-placeholder'; ?>"><?php echo easysite_pb_output_html( $item_text ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></p>
						<?php
						$p = easysite_pb_field( $d, "item{$i}_price" );
						$price = easysite_ve_display( $p, __( 'Price', 'easysite-pro' ) );
						if ( $price || easysite_ve_active() ) :
							?>
							<p class="easysite-pb-price<?php echo $p ? '' : ' esb-placeholder'; ?>"<?php echo easysite_ve_attr( "item{$i}_price" ); ?>><?php echo esc_html( $price ); ?></p>
						<?php endif; ?>
					</div>
				<?php endfor; ?>
			</div>
		</div>
	</section>
	<?php
}

/**
 * Testimonials.
 *
 * @param array $d Fields.
 */
function easysite_pb_render_testimonials( $d ) {
	?>
	<section class="easysite-pb-section easysite-pb-testimonials">
		<div class="easysite-container">
			<?php
			$t = easysite_pb_field( $d, 'title' );
			$title = easysite_ve_display( $t, __( 'Section title', 'easysite-pro' ) );
			if ( $title || easysite_ve_active() ) :
				?>
				<h2 class="easysite-pb-section-title<?php echo $t ? '' : ' esb-placeholder'; ?>"<?php echo easysite_ve_attr( 'title' ); ?>><?php echo esc_html( $title ); ?></h2>
			<?php endif; ?>
			<div class="easysite-pb-cards easysite-pb-cards--2">
				<?php for ( $i = 1; $i <= 2; $i++ ) :
					$q = easysite_pb_field( $d, "q{$i}" );
					if ( ! $q && ! easysite_ve_active() ) {
						continue;
					}
					$quote = easysite_ve_display( $q, __( 'Customer quote', 'easysite-pro' ) );
					?>
					<blockquote class="easysite-pb-quote">
						<p<?php echo easysite_ve_richtext_attr( "q{$i}" ); ?> class="esb-richtext <?php echo $q ? '' : 'esb-placeholder'; ?>">"<?php echo easysite_pb_output_html( $quote ); // phpcs:ignore ?>"</p>
						<cite>
							<span<?php echo easysite_ve_attr( "n{$i}" ); ?> class="<?php echo easysite_pb_field( $d, "n{$i}" ) ? '' : 'esb-placeholder'; ?>"><?php echo esc_html( easysite_ve_display( easysite_pb_field( $d, "n{$i}" ), __( 'Name', 'easysite-pro' ) ) ); ?></span>
							 — 
							<span<?php echo easysite_ve_attr( "r{$i}" ); ?> class="<?php echo easysite_pb_field( $d, "r{$i}" ) ? '' : 'esb-placeholder'; ?>"><?php echo esc_html( easysite_ve_display( easysite_pb_field( $d, "r{$i}" ), __( 'Role', 'easysite-pro' ) ) ); ?></span>
						</cite>
					</blockquote>
				<?php endfor; ?>
			</div>
		</div>
	</section>
	<?php
}

/**
 * Pricing table.
 *
 * @param array $d Fields.
 */
function easysite_pb_render_pricing( $d ) {
	?>
	<section class="easysite-pb-section easysite-pb-pricing">
		<div class="easysite-container">
			<?php
			$t = easysite_pb_field( $d, 'title' );
			$title = easysite_ve_display( $t, __( 'Section title', 'easysite-pro' ) );
			if ( $title || easysite_ve_active() ) :
				?>
				<h2 class="easysite-pb-section-title<?php echo $t ? '' : ' esb-placeholder'; ?>"<?php echo easysite_ve_attr( 'title' ); ?>><?php echo esc_html( $title ); ?></h2>
			<?php endif; ?>
			<div class="easysite-pb-cards easysite-pb-cards--3">
				<?php for ( $i = 1; $i <= 3; $i++ ) :
					$name = easysite_pb_field( $d, "p{$i}_name" );
					if ( ! $name && ! easysite_ve_active() ) {
						continue;
					}
					?>
					<div class="easysite-pb-card easysite-pb-card--pricing <?php echo 2 === $i ? 'is-featured' : ''; ?>">
						<h3<?php echo easysite_ve_attr( "p{$i}_name" ); ?> class="<?php echo $name ? '' : 'esb-placeholder'; ?>"><?php echo esc_html( easysite_ve_display( $name, __( 'Plan name', 'easysite-pro' ) ) ); ?></h3>
						<p class="easysite-pb-price-lg<?php echo easysite_pb_field( $d, "p{$i}_price" ) ? '' : ' esb-placeholder'; ?>"<?php echo easysite_ve_attr( "p{$i}_price" ); ?>><?php echo esc_html( easysite_ve_display( easysite_pb_field( $d, "p{$i}_price" ), '£0' ) ); ?></p>
						<p<?php echo easysite_ve_richtext_attr( "p{$i}_desc" ); ?> class="esb-richtext <?php echo easysite_pb_field( $d, "p{$i}_desc" ) ? '' : 'esb-placeholder'; ?>"><?php echo easysite_pb_output_html( easysite_ve_display( easysite_pb_field( $d, "p{$i}_desc" ), __( 'Plan description', 'easysite-pro' ) ) ); // phpcs:ignore ?></p>
						<a href="<?php echo esc_url( home_url( '/contact' ) ); ?>" class="easysite-btn"><?php esc_html_e( 'Choose plan', 'easysite-pro' ); ?></a>
					</div>
				<?php endfor; ?>
			</div>
		</div>
	</section>
	<?php
}

/**
 * CTA section.
 *
 * @param array $d Fields.
 */
function easysite_pb_render_cta( $d ) {
	$style    = easysite_pb_field( $d, 'style', 'gradient' );
	$gradient = easysite_pb_field( $d, 'gradient', 'brand' );
	$grad_class = '';
	$inline     = '';

	if ( 'gradient' === $style && 'none' !== $gradient ) {
		$grad_class = easysite_gradient_class( $gradient );
		$inline     = easysite_gradient_bg_style( $gradient ) . easysite_gradient_vars_style( $gradient );
	}
	?>
	<section class="easysite-pb-section easysite-pb-cta easysite-pb-cta--<?php echo esc_attr( $style ); ?><?php echo esc_attr( $grad_class ); ?>" <?php echo $inline ? 'style="' . esc_attr( $inline ) . '"' : ''; ?>>
		<div class="easysite-container easysite-pb-cta__inner">
			<?php
			$t = easysite_pb_field( $d, 'title' );
			$title = easysite_ve_display( $t, __( 'Click to edit headline', 'easysite-pro' ) );
			if ( $title || easysite_ve_active() ) :
				?>
				<h2<?php echo easysite_ve_attr( 'title' ); ?> class="<?php echo $t ? '' : 'esb-placeholder'; ?>"><?php echo esc_html( $title ); ?></h2>
			<?php endif; ?>
			<?php
			$s = easysite_pb_field( $d, 'subtitle' );
			$sub = easysite_ve_display( $s, __( 'Click to edit text', 'easysite-pro' ) );
			if ( $sub || easysite_ve_active() ) :
				?>
				<p<?php echo easysite_ve_richtext_attr( 'subtitle' ); ?> class="<?php echo $s ? '' : 'esb-placeholder'; ?>"><?php echo easysite_pb_output_html( $sub ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></p>
			<?php endif; ?>
			<?php
			$bt = easysite_pb_field( $d, 'button_text' );
			$btn = easysite_ve_display( $bt, __( 'Button text', 'easysite-pro' ) );
			if ( $btn || easysite_ve_active() ) :
				?>
				<a class="easysite-btn easysite-btn-lg easysite-btn-white esb-editable-button<?php echo $bt ? '' : ' esb-placeholder'; ?>" href="<?php echo esc_url( home_url( easysite_pb_field( $d, 'button_url', '/contact' ) ) ); ?>"<?php echo easysite_ve_attr( 'button_text' ); ?> data-esb-link-field="button_url"><?php echo esc_html( $btn ); ?></a>
			<?php endif; ?>
		</div>
	</section>
	<?php
}

/**
 * Contact form section.
 *
 * @param array $d Fields.
 */
function easysite_pb_render_contact( $d ) {
	?>
	<section class="easysite-pb-section easysite-pb-contact">
		<div class="easysite-container easysite-pb-narrow">
			<?php
			$t = easysite_pb_field( $d, 'title' );
			$title = easysite_ve_display( $t, __( 'Contact us', 'easysite-pro' ) );
			if ( $title || easysite_ve_active() ) :
				?>
				<h2 class="easysite-pb-section-title<?php echo $t ? '' : ' esb-placeholder'; ?>"<?php echo easysite_ve_attr( 'title' ); ?>><?php echo esc_html( $title ); ?></h2>
			<?php endif; ?>
			<?php
			$tx = easysite_pb_field( $d, 'text' );
			$text = easysite_ve_display( $tx, __( 'Send us a message and we will get back to you soon.', 'easysite-pro' ) );
			if ( $text || easysite_ve_active() ) :
				?>
				<p class="easysite-pb-lead<?php echo $tx ? '' : ' esb-placeholder'; ?>"<?php echo easysite_ve_richtext_attr( 'text' ); ?>><?php echo easysite_pb_output_html( $text ); // phpcs:ignore ?></p>
			<?php endif; ?>
			<?php echo do_shortcode( '[easysite_contact_form]' ); ?>
		</div>
	</section>
	<?php
}

/**
 * Spacer.
 *
 * @param array $d Fields.
 */
function easysite_pb_render_spacer( $d ) {
	$size = easysite_pb_field( $d, 'size', 'medium' );
	echo '<div class="easysite-pb-spacer easysite-pb-spacer--' . esc_attr( $size ) . '" aria-hidden="true"></div>';
}

/**
 * FAQ section (bundle).
 *
 * @param array $d Fields.
 */
function easysite_pb_render_faq( $d ) {
	?>
	<section class="easysite-pb-section easysite-pb-faq">
		<div class="easysite-container easysite-pb-narrow">
			<?php
			$t = easysite_pb_field( $d, 'title' );
			$title = easysite_ve_display( $t, __( 'FAQ', 'easysite-pro' ) );
			if ( $title || easysite_ve_active() ) :
				?>
				<h2 class="easysite-pb-section-title<?php echo $t ? '' : ' esb-placeholder'; ?>"<?php echo easysite_ve_attr( 'title' ); ?>><?php echo esc_html( $title ); ?></h2>
			<?php endif; ?>
			<?php for ( $i = 1; $i <= 3; $i++ ) :
				$q = easysite_pb_field( $d, "q{$i}" );
				$a = easysite_pb_field( $d, "a{$i}" );
				if ( ! $q && ! $a && ! easysite_ve_active() ) {
					continue;
				}
				?>
				<details class="easysite-pb-faq-item" <?php echo easysite_ve_active() ? 'open' : ''; ?>>
					<summary<?php echo easysite_ve_attr( "q{$i}" ); ?> class="<?php echo $q ? '' : 'esb-placeholder'; ?>"><?php echo esc_html( easysite_ve_display( $q, __( 'Question', 'easysite-pro' ) ) ); ?></summary>
					<p<?php echo easysite_ve_richtext_attr( "a{$i}" ); ?> class="esb-richtext <?php echo $a ? '' : 'esb-placeholder'; ?>"><?php echo easysite_pb_output_html( easysite_ve_display( $a, __( 'Answer', 'easysite-pro' ) ) ); // phpcs:ignore ?></p>
				</details>
			<?php endfor; ?>
		</div>
	</section>
	<?php
}

/**
 * Team section (bundle).
 *
 * @param array $d Fields.
 */
function easysite_pb_render_team( $d ) {
	?>
	<section class="easysite-pb-section easysite-pb-team">
		<div class="easysite-container">
			<?php
			$t = easysite_pb_field( $d, 'title' );
			$title = easysite_ve_display( $t, __( 'Meet the Team', 'easysite-pro' ) );
			if ( $title || easysite_ve_active() ) :
				?>
				<h2 class="easysite-pb-section-title<?php echo $t ? '' : ' esb-placeholder'; ?>"<?php echo easysite_ve_attr( 'title' ); ?>><?php echo esc_html( $title ); ?></h2>
			<?php endif; ?>
			<div class="easysite-pb-cards easysite-pb-cards--3">
				<?php for ( $i = 1; $i <= 3; $i++ ) :
					$name = easysite_pb_field( $d, "m{$i}_name" );
					if ( ! $name && ! easysite_ve_active() ) {
						continue;
					}
					$img = easysite_pb_image( $d, "m{$i}_img", 'team' );
					?>
					<div class="easysite-pb-card easysite-pb-card--team">
						<div class="esb-editable-image" data-esb-field="m<?php echo esc_attr( (string) $i ); ?>_img" data-esb-type="image">
							<img src="<?php echo esc_url( $img ); ?>" alt="" loading="lazy" />
							<?php if ( easysite_ve_active() ) : ?>
								<button type="button" class="esb-ve-img-overlay"><span class="dashicons dashicons-format-image"></span> <?php esc_html_e( 'Change photo', 'easysite-pro' ); ?></button>
							<?php endif; ?>
						</div>
						<h3<?php echo easysite_ve_attr( "m{$i}_name" ); ?> class="<?php echo $name ? '' : 'esb-placeholder'; ?>"><?php echo esc_html( easysite_ve_display( $name, __( 'Name', 'easysite-pro' ) ) ); ?></h3>
						<p<?php echo easysite_ve_attr( "m{$i}_role" ); ?> class="<?php echo easysite_pb_field( $d, "m{$i}_role" ) ? '' : 'esb-placeholder'; ?>"><?php echo esc_html( easysite_ve_display( easysite_pb_field( $d, "m{$i}_role" ), __( 'Role', 'easysite-pro' ) ) ); ?></p>
					</div>
				<?php endfor; ?>
			</div>
		</div>
	</section>
	<?php
}

/**
 * Stats section (bundle).
 *
 * @param array $d Fields.
 */
function easysite_pb_render_stats( $d ) {
	?>
	<section class="easysite-pb-section easysite-pb-stats">
		<div class="easysite-container">
			<div class="easysite-pb-stats__grid">
				<?php for ( $i = 1; $i <= 4; $i++ ) :
					$num = easysite_pb_field( $d, "n{$i}_num" );
					if ( ! $num && ! easysite_ve_active() ) {
						continue;
					}
					?>
					<div class="easysite-pb-stat">
						<strong<?php echo easysite_ve_attr( "n{$i}_num" ); ?> class="<?php echo $num ? '' : 'esb-placeholder'; ?>"><?php echo esc_html( easysite_ve_display( $num, '100+' ) ); ?></strong>
						<span<?php echo easysite_ve_attr( "n{$i}_label" ); ?> class="<?php echo easysite_pb_field( $d, "n{$i}_label" ) ? '' : 'esb-placeholder'; ?>"><?php echo esc_html( easysite_ve_display( easysite_pb_field( $d, "n{$i}_label" ), __( 'Label', 'easysite-pro' ) ) ); ?></span>
					</div>
				<?php endfor; ?>
			</div>
		</div>
	</section>
	<?php
}

/**
 * Gallery (bundle).
 *
 * @param array $d Fields.
 */
function easysite_pb_render_gallery( $d ) {
	?>
	<section class="easysite-pb-section easysite-pb-gallery">
		<div class="easysite-container">
			<?php
			$t = easysite_pb_field( $d, 'title' );
			$title = easysite_ve_display( $t, __( 'Gallery', 'easysite-pro' ) );
			if ( $title || easysite_ve_active() ) :
				?>
				<h2 class="easysite-pb-section-title<?php echo $t ? '' : ' esb-placeholder'; ?>"<?php echo easysite_ve_attr( 'title' ); ?>><?php echo esc_html( $title ); ?></h2>
			<?php endif; ?>
			<div class="easysite-pb-gallery__grid">
				<?php for ( $i = 1; $i <= 4; $i++ ) :
					$img = easysite_pb_field( $d, "img{$i}" );
					if ( ! $img && ! easysite_ve_active() ) {
						continue;
					}
					if ( ! $img ) {
						$img = easysite_placeholder_image( 'team' );
					}
					?>
					<figure class="esb-editable-image" data-esb-field="img<?php echo esc_attr( (string) $i ); ?>" data-esb-type="image">
						<img src="<?php echo esc_url( $img ); ?>" alt="" loading="lazy" />
						<?php if ( easysite_ve_active() ) : ?>
							<button type="button" class="esb-ve-img-overlay"><span class="dashicons dashicons-format-image"></span></button>
						<?php endif; ?>
					</figure>
				<?php endfor; ?>
			</div>
		</div>
	</section>
	<?php
}

/**
 * Video embed (bundle).
 *
 * @param array $d Fields.
 */
function easysite_pb_render_video( $d ) {
	$url = easysite_pb_field( $d, 'url' );
	?>
	<section class="easysite-pb-section easysite-pb-video">
		<div class="easysite-container easysite-pb-narrow">
			<?php
			$t = easysite_pb_field( $d, 'title' );
			$title = easysite_ve_display( $t, __( 'Watch our video', 'easysite-pro' ) );
			if ( $title || easysite_ve_active() ) :
				?>
				<h2 class="easysite-pb-section-title<?php echo $t ? '' : ' esb-placeholder'; ?>"<?php echo easysite_ve_attr( 'title' ); ?>><?php echo esc_html( $title ); ?></h2>
			<?php endif; ?>
			<?php
			$tx = easysite_pb_field( $d, 'text' );
			$text = easysite_ve_display( $tx, __( 'Video description', 'easysite-pro' ) );
			if ( $text || easysite_ve_active() ) :
				?>
				<p class="easysite-pb-lead<?php echo $tx ? '' : ' esb-placeholder'; ?>"<?php echo easysite_ve_richtext_attr( 'text' ); ?>><?php echo easysite_pb_output_html( $text ); // phpcs:ignore ?></p>
			<?php endif; ?>
			<?php if ( $url ) : ?>
				<div class="easysite-pb-video__embed">
					<?php echo wp_oembed_get( $url ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
				</div>
			<?php elseif ( easysite_ve_active() ) : ?>
				<p class="esb-placeholder"><?php esc_html_e( 'Add a video URL in section settings (gear icon).', 'easysite-pro' ); ?></p>
			<?php endif; ?>
		</div>
	</section>
	<?php
}

/**
 * Two columns (bundle).
 *
 * @param array $d Fields.
 */
function easysite_pb_render_columns( $d ) {
	?>
	<section class="easysite-pb-section easysite-pb-columns">
		<div class="easysite-container easysite-pb-split__grid">
			<div>
				<?php
				$lt = easysite_pb_field( $d, 'left_title' );
				$left_title = easysite_ve_display( $lt, __( 'Left heading', 'easysite-pro' ) );
				if ( $left_title || easysite_ve_active() ) :
					?>
					<h3<?php echo easysite_ve_attr( 'left_title' ); ?> class="<?php echo $lt ? '' : 'esb-placeholder'; ?>"><?php echo esc_html( $left_title ); ?></h3>
				<?php endif; ?>
				<p<?php echo easysite_ve_richtext_attr( 'left_text' ); ?> class="esb-richtext <?php echo easysite_pb_field( $d, 'left_text' ) ? '' : 'esb-placeholder'; ?>"><?php echo easysite_pb_output_html( easysite_ve_display( easysite_pb_field( $d, 'left_text' ), __( 'Left column text', 'easysite-pro' ) ) ); // phpcs:ignore ?></p>
			</div>
			<div>
				<?php
				$rt = easysite_pb_field( $d, 'right_title' );
				$right_title = easysite_ve_display( $rt, __( 'Right heading', 'easysite-pro' ) );
				if ( $right_title || easysite_ve_active() ) :
					?>
					<h3<?php echo easysite_ve_attr( 'right_title' ); ?> class="<?php echo $rt ? '' : 'esb-placeholder'; ?>"><?php echo esc_html( $right_title ); ?></h3>
				<?php endif; ?>
				<p<?php echo easysite_ve_richtext_attr( 'right_text' ); ?> class="esb-richtext <?php echo easysite_pb_field( $d, 'right_text' ) ? '' : 'esb-placeholder'; ?>"><?php echo easysite_pb_output_html( easysite_ve_display( easysite_pb_field( $d, 'right_text' ), __( 'Right column text', 'easysite-pro' ) ) ); // phpcs:ignore ?></p>
			</div>
		</div>
	</section>
	<?php
}

/**
 * Booking form (bundle).
 *
 * @param array $d Fields.
 */
function easysite_pb_render_booking( $d ) {
	if ( ! easysite_is_bundle() ) {
		return;
	}
	?>
	<section class="easysite-pb-section easysite-pb-booking">
		<div class="easysite-container easysite-pb-narrow">
			<?php
			$t = easysite_pb_field( $d, 'title' );
			$title = easysite_ve_display( $t, __( 'Book an appointment', 'easysite-pro' ) );
			if ( $title || easysite_ve_active() ) :
				?>
				<h2 class="easysite-pb-section-title<?php echo $t ? '' : ' esb-placeholder'; ?>"<?php echo easysite_ve_attr( 'title' ); ?>><?php echo esc_html( $title ); ?></h2>
			<?php endif; ?>
			<?php
			$tx = easysite_pb_field( $d, 'text' );
			$text = easysite_ve_display( $tx, __( 'Pick a time that works for you.', 'easysite-pro' ) );
			if ( $text || easysite_ve_active() ) :
				?>
				<p class="easysite-pb-lead<?php echo $tx ? '' : ' esb-placeholder'; ?>"<?php echo easysite_ve_richtext_attr( 'text' ); ?>><?php echo easysite_pb_output_html( $text ); // phpcs:ignore ?></p>
			<?php endif; ?>
			<?php echo do_shortcode( '[easysite_booking_form]' ); ?>
		</div>
	</section>
	<?php
}
