<?xml version="1.0"?>
<t name="Topbar" t-name="website_event.index_topbar">
    <div class="container">
        <section class="o_wevent_index_topbar_filters d-flex d-print-none align-items-center justify-content-lg-end flex-wrap gap-2 mt-4 mb-3">
            <h2 class="me-auto mb-0 h4">Events</h2>
            <t t-foreach="categories" t-as="category">
                <div t-if="category.is_published and category.tag_ids and any(tag.color for tag in category.tag_ids)" class="dropdown d-none d-lg-block">
                    <t t-set="searched_category_tags" t-value="search_tags.filtered(lambda tag: tag.category_id == category)"/>
                    <button type="button" class="btn btn-light dropdown-toggle" data-bs-toggle="dropdown" title="Filter by category" aria-label="Filter by category" aria-expanded="false">
                        <t t-out="category.name"/>
                        <span t-if="len(searched_category_tags)" t-out="len(searched_category_tags)" class="badge bg-primary ms-1"/>
                    </button>
                    <div class="dropdown-menu">
                        <span t-att-data-post="keep_event_url(tags=slugify_tags((search_tags - searched_category_tags).ids), prevent_redirect=True)" t-attf-class="post_link cursor-pointer dropdown-item d-flex align-items-center justify-content-between #{'active' if not searched_category_tags else ''}">
                            All
                        </span>
                        <t t-foreach="category.tag_ids" t-as="tag">
                            <span t-if="tag.color" t-att-data-post="keep_event_url(tags=slugify_tags(search_tags.ids, toggle_tag_id=tag.id), prevent_redirect=True)" t-attf-class="post_link cursor-pointer dropdown-item d-flex align-items-center justify-content-between #{'active' if tag in search_tags else ''}">
                                <t t-out="tag.name"/>
                            </span>
                        </t>
                    </div>
                </div>
            </t>
            <div class="o_wevent_search d-flex w-100 w-lg-25">
                <t t-call="website.website_search_box_input">
                    <t t-set="_form_classes" t-valuef="flex-grow-1"/>
                    <t t-set="_classes" t-valuef="o_wevent_event_searchbar_form"/>
                    <t t-set="search_type">events</t>
                    <t t-set="action" t-value="'/event/'"/>
                    <t t-set="display_description" t-valuef="true"/>
                    <t t-set="display_detail" t-valuef="false"/>
                    <t t-set="search" t-value="search or searches and searches['search']"/>
                    <t t-set="placeholder">Search an event..</t>
                    <t t-foreach="searches" t-as="item">
                        <input t-if="item != 'search' and item_value != 'all'" type="hidden" t-att-name="item" t-att-value="item_value"/>
                    </t>
                </t>
                <button class="o_not_editable btn btn-light position-relative ms-2 d-lg-none" data-bs-toggle="offcanvas" data-bs-target="#o_wevent_index_offcanvas">
                    <i class="fa fa-sliders"/>
                </button>
            </div>
            <t t-if="search_tags" t-call="website_event.searched_tags"/>
        </section>
        <!-- Off canvas filters on mobile-->
        <div id="o_wevent_index_offcanvas" class="o_website_offcanvas offcanvas offcanvas-end d-lg-none p-0 overflow-visible">
            <div class="offcanvas-header">
                <h5 class="offcanvas-title">Filters</h5>
                <button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"/>
            </div>
            <div class="offcanvas-body p-0">
                <div class="accordion accordion-flush">
                    <div class="accordion-item" t-foreach="categories" t-as="category">
                        <h2 class="accordion-header">
                            <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" t-attf-aria-controls="o_wevent_offcanvas_cat_#{category.id}" t-att-data-bs-target="'.o_wevent_offcanvas_cat_%s' % category.id" aria-expanded="false">
                                <t t-out="category.name"/>
                            </button>
                        </h2>
                        <div t-attf-id="o_wevent_offcanvas_cat_#{category.id}" t-attf-class="o_wevent_offcanvas_cat_#{category.id} accordion-collapse collapse">
                            <div class="accordion-body pt-0">
                                <ul class="list-group list-group-flush">
                                    <t t-if="category.is_published and category.tag_ids and any(tag.color for tag in category.tag_ids)" t-foreach="category.tag_ids" t-as="tag">
                                        <li t-if="tag.color" class="list-group-item border-0 px-0">
                                            <span t-att-data-post="keep_event_url(tags=slugify_tags(search_tags.ids, toggle_tag_id=tag.id), prevent_redirect=True)" class="post_link text-reset cursor-pointer" t-att-title="tag.name">
                                                <div class="form-check">
                                                    <input class="form-check-input pe-none" type="checkbox" t-attf-name="#{tag.color}" t-att-checked="tag in search_tags"/>
                                                    <label class="form-check-label" t-attf-for="#{tag.color}" t-out="tag.name"/>
                                                </div>
                                            </span>
                                        </li>
                                    </t>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</t>

