{"html":"<div class=\"<%- config.containerClass %>\">\n    <nav aria-label=\"breadcrumbs\">\n        <ul class=\"fp-breadcrumb\">\n            <% if(!config.topLevel) { %>\n            <li class=\"fp-back\">\n                <a href=\"javascript:;\" data-action=\"back\"><span class=\"fp-back-icon\" aria-hidden=\"true\"></span> <%- backLabel %></a>\n                <span class=\"fp-back-separator\" aria-hidden=\"true\">|</span>\n            </li>\n            <% } %>\n            <%\n                var type = config.type || 'product',\n                    jsNavigationPath = fp.config.urls[type] || fp.S(stateManager.states.shop.self.url).trimRight(fp.routeDelimiter + '/').s,\n                    options = {\n                        type: type,\n                        relative: !(stateManager.contains(stateManager.current, stateManager.states.shop) || stateManager.contains(stateManager.current, stateManager.states.recipe)),\n                        js_navigation_path: jsNavigationPath,\n                        enableTemplate: true\n                    },\n                    params = {\n                        display: stateParams.display\n                    },\n                    topCategoryIndex = config.enableHome ? 1 : 0,\n                    parentUrl,\n                    nextParentItem,\n                    parentItems;\n\n                _.each(items, function(parentItem, parentIndex) {\n                    if(config.enableHome && !parentIndex) parentUrl = '/';\n                    else if(parentIndex == topCategoryIndex) {\n                        parentUrl = stateManager.href(stateManager.getStateFromUrl(jsNavigationPath, false, false).state, params);\n                    }\n                    else {\n                        parentUrl = stateManager.categoryHref(parentItem, options, params);\n                    }\n\n                    nextParentItem = null;\n                    if(!fp.isBot) {\n                        parentItems = parentItem.items;\n                        if(parentItems && !_.isArray(parentItems)) {\n                            if(_.isArray(parentItems.items)) parentItems = parentItems.items;\n                            else parentItems = null;\n                        }\n                        if(parentItems) nextParentItem = items[parentIndex + 1];\n                    }\n\n                    if(config.topLevel == 1 && !parentIndex) return;\n                    var wrapperId = _.uniqueId();\n                    \n                    var isCurrentPage = (parentIndex === items.length - 1 && fp.ui.router.location.isCurrentPage(parentUrl));\n                %>\n\n                <li class=\"<%= fp.ui.getClassName(parentIndex == items.length - 1, 'fp-selected ') + (parentItems ? 'fp-arrow-down' : '') %>\">\n                    <a href=\"<%= parentUrl %>\" id=\"breadcrumb-label-<%- parentItem.id %>\" data-id=\"<%- parentItem.id %>\"<%= isCurrentPage ? 'aria-current=\"page\"' : '' %>><%- parentItem.name %></a>\n                    <% if(parentItems) { %>\n                        <button class=\"fp-breadcrumb-dropdown-arrow\" aria-label=\"Toggle <%- parentItem.name %>\" aria-expanded=\"false\" aria-controls=\"fp-breadcrumb-wrapper-<%- wrapperId %>\" tabindex=\"0\">\n                            <span class=\"fp-icon fp-icon-caret-down-layered\"></span>\n                        </button>\n                        <div class=\"fp-department-wrapper\" id=\"fp-breadcrumb-wrapper-<%- wrapperId %>\" aria-labelledby=\"breadcrumb-label-<%- parentItem.id %>\">\n                            <div class=\"fp-department\">\n                                <div class=\"fp-department-title\">\n                                    <span role=\"heading\" aria-level=\"2\">Category</span><% if(parentIndex < items.length-1) { %><a href=\"<%= parentUrl %>\" aria-label=\"Clear\">Clear</a><% } %>\n                                </div>\n                                <ul class=\"fp-department-list\">\n                                    <%\n                                        var url;\n                                        _.each(parentItems, function(item, index) {\n                                            url = stateManager.categoryHref(item, options, params);\n\n                                        var isDropdownCurrentPage = (nextParentItem == item && fp.ui.router.location.isCurrentPage(url));\n                                    %>\n                                    <li class=\"<%= fp.ui.getClassName(nextParentItem == item, 'fp-selected') %>\">\n                                        <a href=\"<%= url %>\" data-id=\"<%-item.id%>\" aria-label=\"<%-item.name%>\"<%= isDropdownCurrentPage ? 'aria-current=\"page\"' : '' %>><%-item.name%></a>\n                                    </li>\n                                <% }); %>\n                                </ul>\n                            </div>\n                        </div>\n                    <% } %>\n                </li>\n                <span class=\"fp-breadcrumb-separator\" aria-hidden=\"true\">/</span>\n            <% }); %>\n            <% if(config.showProductCount && !stateManager.isDetail(['id', 'product_id'])) { %>\n                <span class=\"fp-breadcrumb-product-count\" data-role=\"product-count\"></span>\n            <% } %>\n            <% if(config.showProductName && stateManager.isDetail(['id', 'product_id'])) { %>\n                <li class=\"fp-breadcrumb-product-name\" data-role=\"product-name\"></li>\n            <% } %>\n            <li class=\"fp-search-text hidden\"></li>\n        </ul>\n    </nav>\n</div> ","js":"fp.Module.DepartmentBreadcrumb = fp.Module.extend({\n    construct: function (element, config, template) {\n        this._super(element, config, template);\n\n        _.defaults(this.config, {\n            enableLocale: true,\n            enableHome: false,\n            homeLabel: 'Home',\n            showSearch: false,\n            type: fp.S.getString(this.$element.attr('data-type'), 'product'),\n            containerClass: fp.S.getString(fp.config.containerClass, 'container')\n        });\n\n        // this.defaultCategory = {\n        //     id: '0',\n        //     name: this.config.type == 'recipe' ? 'Recipes' : 'Shop'\n        // };\n    },\n    init: function(autoRender) {\n        this.__attachScopeEvents();\n\n        this.$element.addClass('hidden');\n\n        var promiseMap;\n\n        switch(this.config.type) {\n            case 'recipe':\n                promiseMap = util.map.load({\n                    service: service.recipeService,\n                    cacheKey: 'recipeCategory',\n                    itemsKey: 'categories',\n                    payload: {\n                        fields: null,\n                        include_categories: true,\n                        category_id_cascade: true,\n                        no_limit: null,\n                        limit: 0\n                    }\n                });\n                break;\n        }\n\n        return $.when(this._super(false), promiseMap);\n    },\n    render: function (params) {\n        params = _.getObject(params);\n\n        var self = this,\n            scope = this.scope,\n            items = [],\n            type = this.config.type,\n            categoryId = params.categoryId,\n            searchContent = util.getStateValue(this.config.showSearch, params.searchContent),\n            category,\n            categoryField;\n\n        params.backLabel = this.config.backLabel || fp.ui.locale('shared-back', 'Back');\n\n        delete params.searchContent;\n\n        switch (type) {\n            case 'product':\n            case 'circular':\n                categoryField = 'department_id';\n                categoryId = util.getItemId(categoryId || this.scope.stateParams[categoryField] || fp.moduleDepartmentId);\n                if(categoryId) category = fp.departmentHash[categoryId];\n                else {\n                    var parentCategory = category = _.first(fp.departments);\n                    while(parentCategory && parentCategory.id && parentCategory.parent_id) {\n                        parentCategory = fp.departmentHash[parentCategory.parent_id];\n                        if(parentCategory && parentCategory.id) category = parentCategory;\n                    }\n                }\n                break;\n            case 'recipe':\n                categoryField = 'category_id';\n                categoryId = util.getItemId(categoryId || this.scope.stateParams[categoryField] || fp.moduleCategoryId);\n                var recipeCategories = util.map.get('recipeCategory');\n                if(categoryId) {\n                    category = recipeCategories.get(categoryId);\n                    if(!category.id) category = null;\n                }\n                if(!category) {\n                    var parentCategory = category = _.first(recipeCategories.items());\n                    while(parentCategory && parentCategory.id && parentCategory.parent_id) {\n                        parentCategory = recipeCategories.get(parentCategory.parent_id);\n                        if(parentCategory && parentCategory.id) category = parentCategory;\n                    }\n                }\n                break;\n        }\n\n        while(category && category.id) {\n            if(!category.parent_id && !searchContent) {\n                if(items.length) items.unshift(category);\n                break;\n            }\n            items.unshift(category);\n            category = category.parent_id ? (type == 'recipe' ? util.map.get('recipeCategory').get(category.parent_id) : fp.departmentHash[category.parent_id]) : null;\n        }\n\n        if(!items.length && category){\n            items.unshift(category);\n        }\n\n        if(config.enableHome) {\n            items.unshift({\n                id: '0',\n                name: config.homeLabel\n            });\n        }\n\n        params.items = items;\n\n        this._super(params);\n\n        var stateManager = scope.stateManager,\n            parentState = stateManager.current.parent,\n            hasParentState = (parentState && !parentState.abstract);\n\n        if(items.length < 2 && !searchContent && !hasParentState) {\n            this.$element.addClass('hidden');\n            return;\n        }\n\n        self.__setSearchContent(searchContent);\n        if (config.showProductName && params.productName && stateManager.isDetail(['id', 'product_id'])) {\n            this.$element.find('[data-role=\"product-name\"]').append('<span class=\"fp-breadcrumb-product-name\">' + params.productName + '</span>');\n        }\n\n        this.$element\n            .removeClass('hidden')\n            .hoverIntent({\n                selector: '.fp-breadcrumb > li',\n                interval: 250,\n                over: function() {\n                    // Clear any timers, and hide all opened breadcrumb menus\n                    self.$element.find('.fp-breadcrumb > li .fp-department-wrapper').hide();\n                    // Expand drop-down\n                    $(this).find('> .fp-department-wrapper').show();\n                },\n                out: function() {\n                    // Contract drop-down\n                    $(this).find('> .fp-department-wrapper').hide();\n                }\n            })\n            .on('click.breadcrumbAction.fp', '[data-action=\"back\"]', function(event){\n                event.preventDefault();\n                stateManager.back(type);\n            })\n            .on('keydown.breadcrumbAction.fp', 'a', function(event) {\n                if (event.keyCode == fp.constants.keycode.UP) {\n                    event.preventDefault();\n                    // Contract drop-down\n                    $(this).attr('aria-expanded', false).closest('li').find('.fp-department-wrapper').hide();\n                }\n                else if (event.keyCode == fp.constants.keycode.DOWN) {\n                    event.preventDefault();\n                    // Clear any timers, and hide all opened breadcrumb menus\n                    self.$element.find('.fp-breadcrumb > li .fp-department-wrapper').hide();\n                    // Expand drop-down\n                    $(this).attr('aria-expanded', true).closest('li').find('.fp-department-wrapper').show();\n                }\n            })\n            //Breadcrumb dropdown arrow functionality with keyboard support\n            .on('click', '.fp-breadcrumb-dropdown-arrow', function() {\n                var $this = $(this);\n                var $wrapper = $this.closest('li').find('.fp-department-wrapper');\n                if ($wrapper.is(':visible')) {\n                    $wrapper.hide();\n                    $this.attr('aria-expanded', false);\n                } else {\n                    $wrapper.show();\n                    $this.attr('aria-expanded', true);\n                }\n            })\n\n            // Focusout event to hide the menu when tabbing out\n            .on('focusout', '.fp-department-wrapper', function() {\n                var el = this;\n                var $el = $(el);\n                el.hideTimeout = setTimeout(function() {\n                    if (!el.contains(document.activeElement)) {\n                        $el.hide();\n                        var $arrow = $el.closest('li').find('.fp-breadcrumb-dropdown-arrow');\n                        $arrow.attr('aria-expanded', false);\n                    }\n                }, 100); // Added a delay to ensure focusout event is handled correctly\n            });\n\n        fp.trigger(fp.events.BREADCRUMB_LOADED, this);\n    },\n    __attachScopeEvents: function() {\n        this._super();\n\n        var self = this,\n            $element = this.$element,\n            $scope = $(this.scope),\n            onRendered = function() {\n                var module =  fp.Module.getViewModule({attrs: {enabled: true, initialized: true}}),\n                    payload;\n\n                if(!(module && module.config)) return;\n\n                switch(module.config.name) {\n                    case 'product-detail':\n                        if (self.scope.stateManager.is(self.scope.states.productDetail)) {\n                            payload = {categoryId: _.first(util.getValueFromNamespace('scope.item.department_id', module))};\n                        }\n                        break;\n                    case 'recipe-detail':\n                        if (self.scope.stateManager.is(self.scope.states.recipeDetail)) {\n                            payload = {categoryId: _.first(util.getValueFromNamespace('scope.item.category_ids', module))};\n                        }\n                        break;\n                    case 'circular':\n                        //we don't want to render module when circular renders (circular will trigger render)\n                        return;\n                }\n\n\n                self.render(payload);\n            };\n\n        $scope\n            .on(fp.events.RECIPES_LOADED, function(event, payload) {\n                if(!_.isObject(payload)) return;\n\n                var item = payload[self.config.type],\n                    categoryId;\n\n                if(_.isObject(item)) {\n                    categoryId = _.first(item.category_ids);\n                }\n\n                self.render({categoryId: categoryId});\n            })\n            .on(fp.events.MODULE_RENDERED, function() {\n                onRendered();\n            })\n            .on(fp.events.LOADED, function() {\n                onRendered();\n            })\n            .on(fp.events.SET_BREADCRUMB_SEARCH, function (event, payload) {\n                if (!_.isObject(payload)) return;\n                if (!fp.S(payload.type).startsWith(self.config.type)) return;\n\n                self.render({searchContent: payload.content});\n            })\n            .on(fp.events.DEPARTMENTS_LOADED, function (event) {\n                if(self.rendered) self.render();\n            })\n            .on(fp.events.PRODUCTS_LOADED, function(event, payload) {\n                var productTotal = util.getObjectFromNamespace('data', payload.scope);\n                if(productTotal && productTotal.total) $element.find('[data-role=\"product-count\"]').html(productTotal.total + ' ' + fp.ui.locale('shared-products', 'Products'));\n            });\n    },\n    __setSearchContent: function(value) {\n        if(!this.config.showSearch) return;\n\n        value = fp.S.getString(value);\n\n        var $element = this.$element,\n            $searchContent = $element.find('.fp-search-text');\n\n        if(value.length){\n            var stateManager = this.scope.stateManager,\n                state = stateManager.current,\n                params = _.omit(stateManager.stateParams, 'page');\n\n            _.each(params, function(value, key) {\n                key = fp.S(key);\n                if(key.ne('q') && !key.endsWith('_q')) return;\n                delete params[key.s];\n            });\n\n            value += ' <a href=\"' + stateManager.href(state, params) + '\" class=\"fp-btn-clear-search\">(Clear Search)</a>';\n            $searchContent.removeClass('hidden');\n            $element.addClass('breadcrumb-products-search');\n        }\n        else {\n            $searchContent.addClass('hidden');\n            $element.removeClass('breadcrumb-products-search');\n        }\n\n        $searchContent.html(value);\n    }\n});\n\nreturn fp.Module.DepartmentBreadcrumb;\n//# sourceURL=module/department-breadcrumb/department-breadcrumb.js"}