<?php
/**
 * Search Template for PaapiPlugin Product Search for Amazon
 *
 * React is the only frontend. This template processes the search request
 * and outputs the React container with initial data for hydration.
 */

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

// Include handler and view helpers
require_once PSFA_PLUGIN_DIR . 'src/core/frontend/handler.php';
require_once PSFA_PLUGIN_DIR . 'src/core/frontend/react-container.php';
require_once PSFA_PLUGIN_DIR . 'src/core/search/view-helpers.php';
require_once PSFA_PLUGIN_DIR . 'src/core/shared/theme-manager.php';
require_once PSFA_PLUGIN_DIR . 'src/core/shared/customization-helpers.php';
require_once PSFA_PLUGIN_DIR . 'src/core/api/class-offer-data-extractor.php';

// Get shortcode attributes
global $psfa_shortcode_atts;
$psfa_shortcode_atts = isset($psfa_shortcode_atts) ? $psfa_shortcode_atts : array(
    'category'     => '',
    'query'        => '',
    'brand'        => '',
    'sort'         => '',
    'hide_search'  => false,
    'hide_filters' => false,
    'pagination'   => 'infinite',
    'count'        => 20,
);

// Process search request and get structured data
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Local variable, not global
$search_data = psfa_handle_search_request();

// Output React container with initial data for hydration
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- All attributes escaped in psfa_render_react_container()
echo psfa_render_react_container($search_data, $psfa_shortcode_atts);
