<?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" 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="field search">
                <label class="label" for="blog_search">
                    <span><?= $block->escapeHtml(__('Search')) ?></span>
                </label>
                <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"
                           maxlength="128" role="combobox"
                           aria-haspopup="false"
                           aria-autocomplete="both"
                           autocomplete="off">
                </div>
            </div>
            <div class="actions">
                <button type="submit"
                        onclick="return goBlogSearch(this);"
                        title="<?= $block->escapeHtml(__('Search')) ?>"
                        class="action search">
                    <span><?= $block->escapeHtml(__('Search')) ?></span>
                </button>
            </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>
