<?php
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Templates use local variables supplied by the render context.
if (!defined('ABSPATH')) {
    exit;
}
$wrapper_id = sanitize_html_class((string) ($wrapper_id ?? wp_unique_id('nexdirectory-widget-bento-')));
$template = sanitize_html_class((string) ($template ?? '1'));
$title = sanitize_text_field((string) ($title ?? ''));
$subtitle = sanitize_text_field((string) ($subtitle ?? ''));
$style_vars = trim((string) ($style_vars ?? ''));
$custom_class = trim((string) ($custom_class ?? ''));
$results_markup = (string) ($results_markup ?? '');
$query_count = absint((int) ($query_count ?? 0));
$custom_css = trim((string) ($custom_css ?? ''));
$custom_css_scoped = '';
if ($custom_css !== '') {
    $custom_css_scoped = str_replace('{{WRAPPER}}', '#' . $wrapper_id, $custom_css);
    if (strpos($custom_css_scoped, '{') === false) {
        $custom_css_scoped = '#' . $wrapper_id . '{' . $custom_css_scoped . '}';
    }
}
$wrapper_classes = trim('nexdirectory-widget-block nexdirectory-widget-bento-block nexdirectory-widget-template-' . $template . ' ' . $custom_class);
?>
<section id="<?php echo esc_attr($wrapper_id); ?>" class="<?php echo esc_attr($wrapper_classes); ?>"<?php echo $style_vars !== '' ? ' style="' . esc_attr($style_vars) . '"' : ''; ?>>
    <?php if ($title !== '' || $subtitle !== '') : ?>
        <header class="nexdirectory-widget-header">
            <?php if ($title !== '') : ?>
                <h3 class="nexdirectory-widget-title"><?php echo esc_html($title); ?></h3>
            <?php endif; ?>
            <?php if ($subtitle !== '') : ?>
                <p class="nexdirectory-widget-subtitle"><?php echo esc_html($subtitle); ?></p>
            <?php endif; ?>
        </header>
    <?php endif; ?>

    <div class="nexdirectory-widget-meta">
        <?php /* translators: 1: Placeholder value 1, 2: Placeholder value 2. */ ?>
        <span class="nexdirectory-widget-count"><?php echo esc_html(sprintf(_n('%d result', '%d results', $query_count, 'nexdirectory'), $query_count)); ?></span>
    </div>

    <div class="nexdirectory-widget-results-wrap">
        <?php echo wp_kses((string) $results_markup, NEXDIRECTORY_Escaping::allowed_html()); ?>
    </div>

    <?php if ($custom_css_scoped !== '') : ?>
        <?php $this->enqueue_inline_style_asset('nexdirectory-widget-events-bento-custom', nexdirectory_strip_all_tags($custom_css_scoped)); ?>
    <?php endif; ?>
</section>
