<div class="filterWrapper">
    <span class="filterTitle" onclick="toggleFilterDisplay('status');">
        <img src="images/go-down.svg" alt="QBT_TR(Collapse/expand)QBT_TR[CONTEXT=TransferListFiltersWidget]">QBT_TR(Status)QBT_TR[CONTEXT=TransferListFiltersWidget]
    </span>
    <ul class="filterList" id="statusFilterList">
        <li id="all_filter"><a href="#" onclick="setFilter('all');return false;"><img src="images/filter-all.svg" alt="All" />QBT_TR(All (0))QBT_TR[CONTEXT=StatusFilterWidget]</a></li>
        <li id="downloading_filter"><a href="#" onclick="setFilter('downloading');return false;"><img src="images/downloading.svg" alt="Downloading" />QBT_TR(Downloading (0))QBT_TR[CONTEXT=StatusFilterWidget]</a></li>
        <li id="seeding_filter"><a href="#" onclick="setFilter('seeding');return false;"><img src="images/upload.svg" alt="Seeding" />QBT_TR(Seeding (0))QBT_TR[CONTEXT=StatusFilterWidget]</a></li>
        <li id="completed_filter"><a href="#" onclick="setFilter('completed');return false;"><img src="images/checked-completed.svg" alt="Completed" />QBT_TR(Completed (0))QBT_TR[CONTEXT=StatusFilterWidget]</a></li>
        <li id="running_filter"><a href="#" onclick="setFilter('running');return false;"><img src="images/torrent-start.svg" alt="Running" />QBT_TR(Running (0))QBT_TR[CONTEXT=StatusFilterWidget]</a></li>
        <li id="stopped_filter"><a href="#" onclick="setFilter('stopped');return false;"><img src="images/stopped.svg" alt="Stopped" />QBT_TR(Stopped (0))QBT_TR[CONTEXT=StatusFilterWidget]</a></li>
        <li id="active_filter"><a href="#" onclick="setFilter('active');return false;"><img src="images/filter-active.svg" alt="Active" />QBT_TR(Active (0))QBT_TR[CONTEXT=StatusFilterWidget]</a></li>
        <li id="inactive_filter"><a href="#" onclick="setFilter('inactive');return false;"><img src="images/filter-inactive.svg" alt="Inactive" />QBT_TR(Inactive (0))QBT_TR[CONTEXT=StatusFilterWidget]</a></li>
        <li id="stalled_filter"><a href="#" onclick="setFilter('stalled');return false;"><img src="images/filter-stalled.svg" alt="Stalled" />QBT_TR(Stalled (0))QBT_TR[CONTEXT=StatusFilterWidget]</a></li>
        <li id="stalled_uploading_filter"><a href="#" onclick="setFilter('stalled_uploading');return false;"><img src="images/stalledUP.svg" alt="Stalled Uploading" />QBT_TR(Stalled Uploading (0))QBT_TR[CONTEXT=StatusFilterWidget]</a></li>
        <li id="stalled_downloading_filter"><a href="#" onclick="setFilter('stalled_downloading');return false;"><img src="images/stalledDL.svg" alt="Stalled Downloading" />QBT_TR(Stalled Downloading (0))QBT_TR[CONTEXT=StatusFilterWidget]</a></li>
        <li id="checking_filter"><a href="#" onclick="setFilter('checking'); return false;"><img src="images/force-recheck.svg" alt="Checking" />QBT_TR(Checking (0))QBT_TR[CONTEXT=StatusFilterWidget]</a></li>
        <li id="moving_filter"><a href="#" onclick="setFilter('moving'); return false;"><img src="images/set-location.svg" alt="Moving" />QBT_TR(Moving (0))QBT_TR[CONTEXT=StatusFilterWidget]</a></li>
        <li id="errored_filter"><a href="#" onclick="setFilter('errored');return false;"><img src="images/error.svg" alt="Errored" />QBT_TR(Errored (0))QBT_TR[CONTEXT=StatusFilterWidget]</a></li>
    </ul>
</div>
<div class="filterWrapper">
    <span class="filterTitle" onclick="toggleFilterDisplay('category');">
        <img src="images/go-down.svg" alt="QBT_TR(Collapse/expand)QBT_TR[CONTEXT=TransferListFiltersWidget]">QBT_TR(Categories)QBT_TR[CONTEXT=TransferListFiltersWidget]
    </span>
    <ul class="filterList" id="categoryFilterList">
    </ul>
</div>
<div class="filterWrapper">
    <span class="filterTitle" onclick="toggleFilterDisplay('tag');">
        <img src="images/go-down.svg" alt="QBT_TR(Collapse/expand)QBT_TR[CONTEXT=TransferListFiltersWidget]">QBT_TR(Tags)QBT_TR[CONTEXT=TransferListFiltersWidget]
    </span>
    <ul class="filterList" id="tagFilterList">
    </ul>
</div>
<div class="filterWrapper">
    <span class="filterTitle" onclick="toggleFilterDisplay('tracker');">
        <img src="images/go-down.svg" alt="QBT_TR(Collapse/expand)QBT_TR[CONTEXT=TransferListFiltersWidget]">QBT_TR(Trackers)QBT_TR[CONTEXT=TransferListFiltersWidget]
    </span>
    <ul class="filterList" id="trackerFilterList">
    </ul>
</div>

<script>
    "use strict";

    if (window.qBittorrent === undefined)
        window.qBittorrent = {};

    window.qBittorrent.Filters = (function() {
        const exports = function() {
            return {
                categoriesFilterContextMenu: categoriesFilterContextMenu,
                tagsFilterContextMenu: tagsFilterContextMenu,
                trackersFilterContextMenu: trackersFilterContextMenu
            };
        };

        const categoriesFilterContextMenu = new window.qBittorrent.ContextMenu.CategoriesFilterContextMenu({
            targets: ".categoriesFilterContextMenuTarget",
            menu: "categoriesFilterMenu",
            actions: {
                createCategory: function(element, ref) {
                    createCategoryFN();
                },
                createSubcategory: function(element, ref) {
                    createSubcategoryFN(Number(element.id));
                },
                editCategory: function(element, ref) {
                    editCategoryFN(Number(element.id));
                },
                deleteCategory: function(element, ref) {
                    removeCategoryFN(Number(element.id));
                },
                deleteUnusedCategories: function(element, ref) {
                    deleteUnusedCategoriesFN();
                },
                startTorrentsByCategory: function(element, ref) {
                    startTorrentsByCategoryFN(Number(element.id));
                },
                stopTorrentsByCategory: function(element, ref) {
                    stopTorrentsByCategoryFN(Number(element.id));
                },
                deleteTorrentsByCategory: function(element, ref) {
                    deleteTorrentsByCategoryFN(Number(element.id));
                }
            },
            offsets: {
                x: -15,
                y: 2
            },
            onShow: function() {
                this.options.element.firstChild.click();
            }
        });

        const tagsFilterContextMenu = new window.qBittorrent.ContextMenu.TagsFilterContextMenu({
            targets: ".tagsFilterContextMenuTarget",
            menu: "tagsFilterMenu",
            actions: {
                createTag: function(element, ref) {
                    createTagFN();
                },
                deleteTag: function(element, ref) {
                    removeTagFN(Number(element.id));
                },
                deleteUnusedTags: function(element, ref) {
                    deleteUnusedTagsFN();
                },
                startTorrentsByTag: function(element, ref) {
                    startTorrentsByTagFN(Number(element.id));
                },
                stopTorrentsByTag: function(element, ref) {
                    stopTorrentsByTagFN(Number(element.id));
                },
                deleteTorrentsByTag: function(element, ref) {
                    deleteTorrentsByTagFN(Number(element.id));
                }
            },
            offsets: {
                x: -15,
                y: 2
            },
            onShow: function() {
                this.options.element.firstChild.click();
            }
        });

        const trackersFilterContextMenu = new window.qBittorrent.ContextMenu.ContextMenu({
            targets: ".trackersFilterContextMenuTarget",
            menu: "trackersFilterMenu",
            actions: {
                startTorrentsByTracker: function(element, ref) {
                    startTorrentsByTrackerFN(element.id);
                },
                stopTorrentsByTracker: function(element, ref) {
                    stopTorrentsByTrackerFN(element.id);
                },
                deleteTorrentsByTracker: function(element, ref) {
                    deleteTorrentsByTrackerFN(element.id);
                }
            },
            offsets: {
                x: -15,
                y: 2
            },
            onShow: function() {
                this.options.element.firstChild.click();
            }
        });

        if (LocalPreferences.get("filter_status_collapsed") === "true")
            toggleFilterDisplay("status");

        if (LocalPreferences.get("filter_category_collapsed") === "true")
            toggleFilterDisplay("category");

        if (LocalPreferences.get("filter_tag_collapsed") === "true")
            toggleFilterDisplay("tag");

        if (LocalPreferences.get("filter_tracker_collapsed") === "true")
            toggleFilterDisplay("tracker");

        return exports();
    })();

    Object.freeze(window.qBittorrent.Filters);
</script>
