<?php
/**
 * Copyright © Magefan (support@magefan.com). All rights reserved.
 * Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement).
 *
 * Glory to Ukraine! Glory to the heroes!
 */
?>
<?php
/**
 * Blog sidebar search form template
 *
 * @var $block \Magefan\Blog\Block\Sidebar\Search
 */
?>

<div class="widget block blog-search mb-8" data-bind="scope: 'blog-search'">
    <div class="block-content">
        <form class="form" id="blog_search_mini_form"
              action="<?= $block->escapeUrl($block->getFormUrl()) ?>"
              method="get">
            <div class="search mt-0">
                <label class="label hidden" for="blog_search">
                    <span><?= $block->escapeHtml(__('Search')) ?></span>
                </label>

                <div class="flex">
                    <div class="control">
                        <input id="blog_search"
                               type="text"
                               name="q"
                               value="<?= $block->escapeHtml($block->getQuery()) ?>"
                               placeholder="<?= $block->escapeHtml(__('Search posts here...')) ?>"
                               class="input-text p-3"
                               maxlength="128" role="combobox"
                               aria-haspopup="false"
                               aria-autocomplete="both"
                               autocomplete="off">
                    </div>
                    <div class="actions ml-2">
                        <button type="submit"
                                onclick="return goBlogSearch(this);"
                                title="<?= $block->escapeHtml(__('Search')) ?>"
                                class="action search btn btn-primary">
                            <span><?= $block->escapeHtml(__('Search')) ?></span>
                        </button>
                    </div>
                </div>
            </div>

        </form>
    </div>
</div>
<script type="text/javascript">
    function goBlogSearch(e)
    {
        var value = document.getElementById('blog_search').value;
        if (value) {
            var a = e.form.action;
            window.location = a + ( ('/' != a.charAt(a.length - 1)) ? '/' : '' ) + encodeURI(value) + '/';
        }
        return false;
    }
</script>
