<?php
/**
 * Product search widget.
 *
 * @package ecommerce-product-catalog
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}
require_once AL_BASE_PATH . '/includes/widgets/class-product-widget-search.php';

/**
 * Returns search widget placeholder
 *
 * @param array|null $instance Widget instance data.
 *
 * @return string
 */
function ic_get_search_widget_placeholder( $instance = null ) {
	if ( is_plural_form_active() ) {
		$names = get_catalog_names();
		/* translators: %s: singular catalog label. */
		$label = sprintf( __( '%s Search', 'ecommerce-product-catalog' ), ic_ucfirst( $names['singular'] ) );
	} else {
		$label = __( 'Product Search', 'ecommerce-product-catalog' );
	}

	return apply_filters( 'product_search_placeholder', $label, $instance );
}

/**
 * Returns search widget button text
 *
 * @return type
 */
function ic_get_search_widget_button_text() {
	return apply_filters( 'product_search_button_text', '' );
}

/**
 * Shows search widget form
 */
function ic_show_search_widget_form() {
	ob_start();
	ic_show_template_file( 'widgets/search-widget.php' );
	$form = apply_filters( 'ic_get_search_form', ob_get_clean() );
	// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Search form HTML is generated by the widget/template stack.
	echo $form;
}
