<?php
/**
 * Search results template — Brentwood (mirrors the Laravel global-search
 * inline results page). Rich result rows are rendered by
 * bw_search_render_row() in inc/brentwood-search.php.
 *
 * Wraps with the real Kadence header/footer; the results live in a
 * self-contained .bw-searchpage container (assets/bw-searchpage.css).
 *
 * @package Kadence-Child
 */

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

get_header();

if ( function_exists( 'Kadence\kadence' ) ) {
	\Kadence\kadence()->print_styles( 'kadence-content' );
}

$bw_terms = get_search_query();
global $wp_query;
$bw_found = (int) $wp_query->found_posts;
?>
<div class="content-container site-container">
	<main id="main" class="site-main" role="main">
		<div class="content-wrap">
			<article class="entry content-bg bw-search-entry">
				<div class="entry-content-wrap">
<div class="bw-searchpage bw-searchpage--filtered">
	<h1 class="bw-searchpage__sr-title screen-reader-text"><?php esc_html_e( 'Search results', 'kadence-child' ); ?></h1>

	<div class="bw-searchpage__layout">
		<?php echo bw_search_render_sidebar( $bw_terms, $bw_found ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escaped in helper ?>

		<div class="bw-searchpage__content">
			<?php echo bw_search_inline_form( $bw_terms ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>

			<?php if ( '' !== $bw_terms ) : ?>
				<p class="bw-searchpage__for">
					<?php
					printf(
						/* translators: %s: search terms */
						esc_html__( 'Showing results for “%s”', 'kadence-child' ),
						'<strong>' . esc_html( $bw_terms ) . '</strong>'
					);
					?>
				</p>
			<?php endif; ?>

			<?php if ( have_posts() ) : ?>
				<div class="bw-search-results">
					<?php
					while ( have_posts() ) :
						the_post();
						echo bw_search_render_row( get_post(), $bw_terms ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escaped in helper
					endwhile;
					?>
				</div>

				<?php
				$bw_links = paginate_links(
					array(
						'mid_size'  => 2,
						'prev_text' => '‹',
						'next_text' => '›',
						'type'      => 'array',
					)
				);
				if ( $bw_links ) :
					?>
					<nav class="bw-searchpage__pagination" aria-label="Search results pages">
						<?php echo implode( '', $bw_links ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- core-generated links ?>
					</nav>
				<?php endif; ?>

			<?php else : ?>
				<p class="bw-search-empty">
					<?php
					if ( '' !== $bw_terms ) {
						printf(
							/* translators: %s: search terms */
							esc_html__( 'There are no search results for “%s”.', 'kadence-child' ),
							esc_html( $bw_terms )
						);
					} else {
						esc_html_e( 'Please enter a search term above.', 'kadence-child' );
					}
					?>
				</p>
			<?php endif; ?>
		</div>
	</div>

	<?php
	// Footer element (mirrors the Laravel search page footer).
	echo do_shortcode( '[kadence_element id="22041"]' );
	?>
</div>
				</div><!-- .entry-content-wrap -->
			</article>
		</div><!-- .content-wrap -->
	</main>
</div><!-- .content-container -->
<?php
get_footer();
