{"html":"<!-- Layout 5 used for short and wide carousels -->\n<div class=\"<%- config.containerClass %>\" role=\"region\" aria-roledescription=\"carousel\" aria-label=\"<%- title ? title : 'carousel' %>\">\n    <div class=\"fp-notification\"></div>\n    <% if(_.size(items)){ %>\n    <% if(title) { %>\n    <div class=\"fp-product-carousel-header\">\n        <h3><%- title %></h3>\n    </div>\n    <a href=\"<%- viewAllUrl %>\" class=\"fp-btn fp-btn-view-all hidden\" aria-label=\"<%= fp.ui.locale('aria-view-all','View All: ') %><%- title %>\"><%- config.viewAllLabel ? config.viewAllLabel : fp.ui.locale('shared-view-all', 'View All') %> <span class=\"fp-product-carousel-view-all-icon hidden\"></span></a>\n    <% } %>\n    <div class=\"fp-result-list fp-product-list fp-product-list-sm\" data-role=\"carousel\">\n        <% if(hasProductService){ %>\n        <%\n            var priceSizeHtml,\n                salePriceSizeHtml,\n                stateManager = fp.ui.router.stateManager,\n                productUrl,\n                availableStatusId = util.map.get('productStatus').get('available').id,\n                priceDisclaimer,\n                nuValConfig = _.getObject(fp.store.nu_val_config),\n                otherAttributes,\n                product,\n                isProductAd,\n                fulfillmentType;\n        %>\n        <% _.each(items, function(item) { %>\n        <%\n            product = util.getProduct(item);\n            if(!product.id) return;\n\n            priceSizeHtml = util.getPriceSizeComboHtml(item);\n            salePriceSizeHtml = util.getSalePriceSizeComboHtml(item);\n            priceDisclaimer = util.getPriceDisclaimer(item);\n            productUrl = stateManager.href(states.productDetail, {id: product.id, department_id: departmentId}, {canonical_url: product.canonical_url});\n            otherAttributes = _.getObject(nuValConfig.prefix ? product.other_attributes : null);\n            isProductAd = util.isProductAd(item);\n        %>\n        <div class=\"fp-item <%- fp.ui.getClassName(fp.config.enableQtyDropDown, 'fp-is-qty-ddl') %> <%- fp.ui.getItemClassName(product) %>\" data-product-id=\"<%- product.id %>\">\n            <div class=\"fp-item-container\">\n                <% if(fp.config.enableSaleIndicator && product.sale_price) { %>\n                <div class=\"fp-item-header\">\n                    <div class=\"fp-item-sale-indicator\"></div>\n                </div>\n                <% } %>\n                <div class=\"fp-item-content\">\n                    <div class=\"fp-item-image fp-item-image-md\">\n                        <a href=\"<%= productUrl %>\" aria-hidden=\"true\">\n                            <img src=\"<%= fp.blankImageUrl %>\" data-src=\"<%= util.getImageSrc(item, 'medium') %>\" alt=\"<%- product.name %> <%= fp.ui.locale('shared-details', 'Details') %>\" />\n                            <% if(otherAttributes.nu_val_score) { %>\n                            <img src=\"<%= nuValConfig.prefix + otherAttributes.nu_val_score %>-new-Blue-ShelfTag.gif\" alt=\"\" class=\"fp-item-other-nutrition-score\" />\n                            <% } %>\n                        </a>\n                        <% if(isProductAd && obj.adConfig.label) { %>\n                        <div class=\"fp-tag fp-tag-ad\"><%- obj.adConfig.label %></div>\n                        <% } %>\n                        <% if(fulfillmentType = util.getProductFulfillmentType(product)) { %>\n                        <div class=\"fp-item-fulfillment-type\">\n                            <div class=\"fp-icon fp-icon-fulfillment-<%- fulfillmentType.identifier %>\" title=\"<%- fulfillmentType.name %>\"></div>\n                        </div>\n                        <% } %>\n                    </div>\n                    <div class=\"fp-item-detail<%= fp.ui.getClassName(product.status_id != availableStatusId, ' fp-is-item-detail-not-available') + fp.ui.getClassName(priceDisclaimer, ' fp-has-item-detail-price-disclaimer') + ' ' + util.getItemSaleClass(item) + fp.ui.getClassName(util.getItemHasSaleModifier(item), ' fp-is-item-detail-sale-modifier') %>\">\n                        <div class=\"fp-item-name notranslate\"><a href=\"<%= productUrl %>\"><%- product.name %></a></div>\n                        <div class=\"fp-item-group\">\n                            <div class=\"fp-item-sale<%= (salePriceSizeHtml ? '' : ' hidden') %>\"><%= salePriceSizeHtml %></div>\n                            <div class=\"fp-item-price<%= (priceSizeHtml ? '' : ' hidden') %>\"><%= priceSizeHtml %></div>\n                           <% if(product.tax_class_label) { %><div class=\"fp-item-tax-label\"><%- product.tax_class_label %></div><% } %>\n                        </div>\n                        <% if(product.status_id == availableStatusId && !product.disallow_adding_to_cart) { %>\n                        <div class=\"fp-item-action\" data-product-id=\"<%- product.id %>\">\n                            <span class=\"fp-btn-icon fp-btn-decrement\" aria-label=\"<%= fp.ui.locale('aria-remove-from-list', 'Decrease item quantity by 1: ') %><%- product.name %>\" role=\"button\" tabindex=\"0\"><span class=\"sr-only\"><%- fp.config.removeFromListLabel %></span></span>\n                            <span class=\"fp-btn-add\"><%= util.getItemButtonHtml(item) %></span>\n                            <span class=\"fp-btn-icon fp-btn-increment\" aria-label=\"<%= fp.ui.locale('aria-add-to-list', (fp.config.addToListLabel || 'Add to Cart') + ': ') %><%- product.name %>\" role=\"button\" tabindex=\"0\"></span>\n                        </div>\n                        <% } %>\n                    </div>\n                </div>\n            </div>\n        </div>\n        <% }); %>\n        <% } else if(hasOfferService || hasCircularOfferService){ %>\n        <%= fp.ui.renderTemplate('component/1/offer-carousel.html', obj) %>\n        <% } %>\n    </div>\n    <% } %>\n</div> ","js":"fp.Module.ProductCarousel = fp.Module.extend({\n    construct: function(element, config, template, parent) {\n        _.defaults(config, {\n            priority: util.getStateValue(\n                _.contains(['right_vertical', 'top_horizontal'], config.location),\n                fp.constants.priority.MINOR,\n                fp.constants.priority.TRIVIAL\n            ),\n            enableLazyInit: util.getBoolean(fp.config.enableLazyInit) &&\n                (config.location != 'right_vertical') //right_vertical modules need to always initialize currently\n        });\n\n        this._super(element, config, template, parent);\n\n        _.defaults(config, {\n            enableLocale: true,\n            limit: 16,\n            limitXs: 16,\n            itemDisplayCount: 5,\n            itemDisplayRowCount: 1,\n            disableViewAll: false,\n            disableNavigation: false,\n            disableShowProgress: true,\n            displayVariable: false,\n            initializeOnStoreChange: true,\n            enableCarouselXs: fp.config.enableCarouselXs,\n            containerClass: fp.S.getString(fp.config.containerClass, 'container'),\n            carouselSelector: '[data-role=\"carousel\"]'\n        });\n\n        var layout = fp.S(config.layout).trimLeft('layout-');\n        this.scope.isMiniCarousel = layout.eq('5') || layout.eq('6');\n        if(util.isNull(config.showProductModal)) {\n            config.showProductModal = config.filter == 'product_ads' && this.scope.isMiniCarousel;\n        }\n\n        switch(config.filter) {\n            case 'product_ads':\n                config.useStateParams = _.without(fp.adContextFields, 'product_id');\n\n                if(!_.has(config, 'enableAnimateIn')) {\n                    config.enableAnimateIn = util.getBoolean(fp.config.enableAnimateIn, this.scope.isMiniCarousel);\n                }\n\n                this.dependencies.init.module.push('circular');\n                if (config.location == 'below_grid') {\n                    this.dependencies.init.module.push('products');\n                }\n\n                if(this.scope.isMiniCarousel) {\n                    config.title = '';\n                }\n                break;\n            case 'circular_offers':\n                if(fp.S(config.sort).startsWith('saving')) {\n                    if (!_.has(config, 'hideIfLessThan')) config.hideIfLessThan = 3;\n                    config.useStateParams = [\n                        'department_id'\n                    ];\n                }\n                break;\n        }\n\n        _.concat(this.dependencies.init.module, config.dependencies);\n\n        config.hideIfLessThan = util.getInteger(config.hideIfLessThan, 1);\n    },\n    init: function(autoRender, initOptions) {\n        var self = this,\n            config = this.config,\n            scope = this.scope,\n            stateManager = scope.stateManager,\n            stateParams = scope.stateParams,\n            urlParams = fp.ui.router.routeManager.urlParams,\n            departmentId = config.department_id || config.category_id || config.category_ids,\n            viewAllParams = {},\n            viewAllState = scope.states.product,\n            data;\n\n        return this._super(false, initOptions)\n            .then(function() {\n                var itemsCustom = config.itemsCustom;\n\n                if(!_.isArray(itemsCustom)) {\n                    itemsCustom = config.itemsCustom = [\n                        [480, 0],\n                        [768, 3],\n                        [992, config.itemDisplayCount - 1],\n                        [1200, config.itemDisplayCount]\n                    ];\n\n                    if(config.enableCarouselXs) {\n                        itemsCustom.unshift([0, 1]);\n                        itemsCustom[1] = [424, 2];\n                    }\n\n                    if(config.containerClass == 'container-fluid') {\n                        itemsCustom.push([1600, config.itemDisplayCount + 2])\n                    }\n                }\n\n                if(!_.isArray(config.itemDisplayRowCustom)) {\n                    config.itemDisplayRowCustom = [\n                        [0, 1]\n                    ];\n                }\n\n                itemsCustom.sort(self.__sortItemsCustom);\n                config.itemDisplayRowCustom.sort(self.__sortItemsCustom);\n\n                var payload = {\n                        limit: (fp.device.xs && config.limitXs ? config.limitXs : config.limit),\n                        location: config.location\n                    },\n                    options = {\n                        handleErrors: false,\n                        disableShowProgress: config.disableShowProgress\n                    },\n                    filter = config.filter,\n                    serviceCall = service.productService,\n                    isEnabled = true,\n                    tagTypes = 'sale_configuration_type,product_status',\n                    mapItems = [],\n                    promiseItems;\n\n                if(_.size(config.defaultPayload)) {\n                    _.defaults(payload, config.defaultPayload);\n                }\n\n                scope.hasProductService = true;\n                scope.hasRecipeService = false;\n                scope.hasCouponService = false;\n                scope.hasOfferService = false;\n                scope.hasCircularOfferService = false;\n                scope.viewAllUrl = '';\n                scope.departmentId = null;\n                scope.items = null;\n                scope.data = null;\n                scope.adConfig = fp.sponsoredAdConfig;\n\n                var isProductDetail = stateManager.isDetail(['id', 'product_id']) &&\n                        (stateManager.current.abstract || stateManager.is(stateManager.getTopParent(stateManager.current), stateManager.states.shop)),\n                    isRecipeDetail = !isProductDetail && stateManager.isDetail(['id', 'recipe_id']);\n\n                if(isProductDetail || isRecipeDetail) {\n                    if(isProductDetail) {\n                        var productDetailConfig = fp.config.modules.productDetail;\n                        if(!_.isArray(productDetailConfig)) productDetailConfig = [productDetailConfig];\n                        if(_.findWhere(productDetailConfig, {authorized: true})) {\n                            productDetailConfig = config;\n\n                            if(_.has(config, 'productDetail')) {\n                                productDetailConfig = config.productDetail;\n                            }\n\n                            if(productDetailConfig) {\n                                if (productDetailConfig.filter) filter = productDetailConfig.filter;\n                                scope.title = productDetailConfig.title;\n                                config.disableViewAll = true;\n                            }\n                            else isEnabled = false;\n                        }\n                    }\n                    else {\n                        var recipeDetailConfig = fp.config.modules.recipeDetail;\n                        if(!_.isArray(recipeDetailConfig)) recipeDetailConfig = [recipeDetailConfig];\n                        if(_.findWhere(recipeDetailConfig, {authorized: true})) {\n                            recipeDetailConfig = config;\n\n                            if(_.has(config, 'recipeDetail')) {\n                                recipeDetailConfig = config.recipeDetail;\n                            }\n\n                            if(recipeDetailConfig) {\n                                if (recipeDetailConfig.filter) filter = recipeDetailConfig.filter;\n                                scope.title = recipeDetailConfig.title;\n                                config.disableViewAll = true;\n                            }\n                            else isEnabled = false;\n                        }\n                     }\n                }\n                else {\n                    var productsConfig = config;\n                    if(_.has(config, 'products')) {\n                        productsConfig = config.products;\n                    }\n\n                    if(productsConfig) {\n                        if(_.isObject(productsConfig)) {\n                            if (productsConfig.filter) filter = productsConfig.filter;\n                            scope.title = productsConfig.title;\n                            config.disableViewAll = productsConfig.disableViewAll;\n                        }\n                    }\n                    else isEnabled = false;\n                }\n\n                if (!scope.title) scope.title = fp.S.getString(config.title);\n\n                if(isEnabled && _.has(config, 'authenticate')) {\n                    var isAuthenticated = util.isAuthenticated();\n                    if (config.authenticate && !isAuthenticated) isEnabled = false;\n                    else if (!config.authenticate && isAuthenticated) isEnabled = false;\n                }\n\n                if(isEnabled) {\n                    isEnabled = util.getBoolean(scope.hasRecipeService || !fp.config.requireStore || fp.store.id);\n                }\n\n                if(isEnabled) {\n                    var require = config.require;\n                    var change = config.change;\n                    if (_.isObject(require)) {\n                        if (require.store_id) isEnabled = require.store_id == fp.store.id;\n                        if (isEnabled && require.state) {\n                            isEnabled = fp.S(require.state).eq(fp.store.state || _.getObject(fp.Lockr.get('deliveryAddress')).state, true);\n                        }\n                    }\n                    if (_.isObject(change)) {\n                        if(isEnabled && change){\n                            isChange = fp.S(change.state).eq(fp.store.state || _.getObject(fp.Lockr.get('deliveryAddress')).state, true);\n                            if(isChange && change.title) scope.title = change.title;\n                        }\n                    }\n                }\n\n                if(isEnabled) {\n                    var productId = util.getUndefinedIfEmpty(stateParams.id || stateParams.product_id || urlParams.product_id),\n                        list = fp.listManager.getList(),\n                        listId = util.getStateValue(list.id !== fp.defaultList.id, list.id);\n                    if (filter) viewAllParams.filter = filter;\n\n                    switch (filter) {\n                        case 'is_featured':\n                            payload.is_featured = true;\n                            isEnabled = util.getBoolean(fp.store.has_featured_products, false);\n                            break;\n                        case 'is_personalized':\n                            payload.is_personalized = true;\n                            payload.for_order_id = fp.session.preference.order_id;\n                            payload.for_shopping_list_id = listId;\n                            payload.store_id = fp.store.id;\n                            scope.hasProductService = util.isAuthenticated();\n                            var firstName = util.isAuthenticated() ? fp.user.first_name : '';\n                            scope.title = scope.title.replace('__firstName__, ', firstName ? `${firstName}, ` : '').replace('__firstName__', firstName);\n                            break;\n                        case 'is_bought_by_me':\n                            serviceCall = service.userProductBuyService;\n                            payload.for_order_id = fp.session.preference.order_id;\n                            payload.for_shopping_list_id = listId;\n                            payload.store_id = fp.store.id;\n                            options.enableProducts = true;\n                            break;\n                        case 'filter_by_id':\n                            if(_.size(config.product_ids)) {\n                                payload.id = viewAllParams.product_ids = config.product_ids;\n                            }\n                            delete viewAllParams.filter;\n                            break;\n                        case 'filter_by_q':\n                            if(_.size(config.q)) payload.q = config.q;\n                            break;\n                        case 'user_upsell':\n                            serviceCall = service.userProductUpsellService;\n                            payload.for_order_id = fp.session.preference.order_id;\n                            payload.for_shopping_list_id = listId;\n                            payload.store_id = fp.store.id;\n                            options.enableProducts = true;\n                            viewAllParams.filter = 'is_bought_by_me';\n\n                            //if(fp.isLocal()) {\n                            //    payload.hang_for = 15;\n                            //}\n                            break;\n                        case 'has_offer':\n                        case 'is_on_sale':\n                            payload.has_offer = true;\n                            viewAllParams.filter = 'is_on_sale';\n                            if(config.sort) payload.sort = config.sort;\n                            break;\n                        case 'is_top_deal':\n                            payload.has_offer = true;\n                            payload.top_deal = true;\n                            if(config.sort) payload.sort = config.sort;\n                            break;\n                        case 'has_clippable_offer':\n                            payload.has_clippable_offer = true;\n                            viewAllState = scope.states.coupon;\n                            break;\n                        case 'recent':\n                        case 'variation':\n                            options.childServiceCall = filter;\n                            break;\n                        case 'offered_together':\n                            payload.include_offered_together = true;\n                            payload.fields = 'offered_together';\n                            payload.id = productId;\n                            break;\n                        case 'bought_together':\n                            payload.include_bought_together = true;\n                            payload.fields = 'bought_together';\n                            payload.id = productId;\n                            break;\n                        case 'include_recipes':\n                            payload.include_recipes = true;\n                            payload.fields = 'recipes';\n                            scope.hasProductService = false;\n                            scope.hasRecipeService = true;\n                            viewAllState = scope.states.recipe;\n                            payload.product_id = productId;\n                            break;\n                        case 'recipe_products':\n                            payload.include_recipes = true;\n                            payload.fields = 'recipes';\n                            scope.hasProductService = false;\n                            scope.hasRecipeService = true;\n                            viewAllState = scope.states.recipe;\n                            payload.recipe_id = util.getUndefinedIfEmpty(stateParams.id || stateParams.recipe_id || urlParams.recipe_id);\n                            break;\n                        case 'relevance':\n                            payload.sort = 'relevance';\n                            break;\n                        case 'popularity':\n                            payload.sort = 'popularity';\n                            break;\n                        case 'coupon':\n                            payload.sort = 'start_date';\n                            payload.is_clipped = false;\n                            scope.hasProductService = false;\n                            scope.hasCouponService = true;\n                            viewAllState = scope.states.coupon;\n                            viewAllParams.filter = 'is_clipped!';\n                            break;\n                        case 'circular_offers':\n                            if(fp.S(config.sort).startsWith('saving')) {\n                                if(_.has(config, 'clippable_offer_tag')) {\n                                    payload.clippable_offer_tag = util.getUndefinedIfEmpty(config.clippable_offer_tag);\n                                    payload.has_clippable_offer = true;\n                                    viewAllState = scope.states.coupon;\n                                }\n                                else {\n                                    payload.intent = config.intent || 'circular';\n                                    viewAllState = scope.states.weeklyAd;\n                                }\n                                payload.circular_id = config.circularId;\n                                payload.sort = config.sort;\n\n                                _.each(config.useStateParams, function (key) {\n                                    payload[key] = util.getUndefinedIfEmpty(stateParams[key]);\n                                });\n                                payload.q = util.getUndefinedIfEmpty(stateManager.getQ().value);\n                            }\n                            else {\n                                payload.sort = 'popularity';\n                                viewAllState = scope.states.weeklyAd;\n                            }\n\n                            scope.hasProductService = false;\n                            scope.hasCircularOfferService = true;\n                            if(fp.store.has_circular_grid) viewAllParams.display = 'grid';\n                            if(config.hasClippable) {\n                                payload.is_clipped = false;\n                                viewAllParams.filter = 'has_clippable_offer';\n                            }\n                            else delete viewAllParams.filter;\n                            tagTypes += ',offer_status';\n                            break;\n                        //case 'offers':\n                        //    payload.sort = 'popularity';\n                        //    scope.hasProductService = false;\n                        //    scope.hasOfferService = true;\n                        //    viewAllState = scope.states.weeklyAd;\n                        //    if(fp.store.has_circular_grid) viewAllParams.display = 'grid';\n                        //    delete viewAllParams.filter;\n                        //    tagTypes += ',offer_status';\n                        //    break;\n                        case 'product_ads':\n                            options.priority = config.priority;\n                            serviceCall = service.productAdService;\n\n                            //for product ads  limit will be controlled by view width (no paging)\n                            payload.limit = self.__getItemDisplayCount(config.itemsCustom) * self.__getItemDisplayCount(config.itemDisplayRowCustom);\n\n                            payload.q = util.getUndefinedIfEmpty(stateManager.getQ().value);\n\n                            _.each(config.useStateParams, function (key) {\n                                payload[key] = util.getUndefinedIfEmpty(stateParams[key]);\n                            });\n\n                            var paramFilter = fp.S(stateParams.filter).trim().s;\n                            if(paramFilter) {\n                                _.each(paramFilter.split(','), function (key) {\n                                    payload[key] = true;\n                                });\n                            }\n\n                            if (stateManager.is(scope.states.productDetail)) {\n                                payload.product_id = productId;\n                                delete payload.department_id;\n                            }\n\n                            var circular = fp.Module.get('circular', {attrs: {enabled: true, initialized: true}});\n                            if(circular) {\n                                if(circular.scope.activeCircular) {\n                                    payload.for_circular_id = circular.scope.activeCircular.id;\n                                    payload.for_circular_type_id = circular.scope.activeCircular.type_id;\n                                }\n                                if(circular.config.offer_type_id) {\n                                    payload.for_offer_type_id = circular.config.offer_type_id;\n                                }\n                            }\n\n                            break;\n                        case 'product_id':\n                            if(_.size(config.product_id)) {\n                                payload.product_id = config.product_id;\n                                payload.sort = 'custom';\n                            }\n                            else isEnabled = false;\n                            break;\n                        case 'product_tag':\n                            if(_.size(config.tag_id)) {\n                                payload.tag_id = config.tag_id;\n                            }\n                            else if(_.size(config.tag_identifier)) {\n                                payload.tag = config.tag_identifier;\n                            }\n                            else isEnabled = false;\n                            break;\n                        case 'top_department':\n                            if(_.has(config, 'department_index') && _.size(fp.department.items)) {\n                                departmentId = config.department_id = _.getObject(fp.department.items[util.getInteger(config.department_index)]).id;\n                            }\n                            break;\n                        case 'recipe':\n                        case 'recipe_popularity':\n                        case 'recipe_is_featured':\n                        case 'recipe_personalized':\n                        case 'recipe_recent':\n                            if(filter == 'recipe_popularity') {\n                                payload.sort = 'popularity';\n                                payload.is_favorite = true;\n                                payload.last_updated_at_sort = 'desc';\n                                payload.popularity_sort = 'asc';\n                            }\n\n                            if(filter == 'recipe_recent') {\n                                payload.created_at_sort = 'desc';\n                                payload.sort = 'created_at!';\n\n                                if(config.filter_tag_ids) {\n                                    payload.filter_ids = config.filter_tag_ids;\n                                    payload.last_updated_at_sort = 'desc';\n                                }\n                            }\n\n                            payload.limit = 24;\n                            payload.fields = 'id,name,cover_image';\n\n                            scope.hasProductService = false;\n                            scope.hasRecipeService = true;\n                            scope.isRecipeService = true;\n                            scope.title = config.title;\n\n                            viewAllState = scope.states.recipe;\n                            payload.recipe_id = util.getUndefinedIfEmpty(stateParams.id || stateParams.recipe_id || urlParams.recipe_id);\n                            break;\n                    }\n\n                    if(isEnabled){\n                        if(payload.tag_id) viewAllParams.tag_id = payload.tag_id;\n                        else if(payload.tag) viewAllParams.tag = payload.tag;\n                    }\n\n                    if(isEnabled && departmentId) {\n                        if(!scope.isRecipeService) {\n                            var department = _.getObject(fp.departmentHash[departmentId]);\n                            payload.department_id = departmentId;\n                            if (departmentId == config.department_id) {\n                                viewAllParams.department_id = departmentId;\n\n                                scope.title = self.$element.attr('data-freshop-title');\n                                if (util.isNull(scope.title))  scope.title = department.name;\n                            }\n                        }\n\n                        if(fp.config.enableMobile && stateParams.display) {\n                            payload.category_ids = departmentId;\n                            if(_.isObject(config.hashedFilteredCategories)) {\n                                var category = _.getObject(config.hashedFilteredCategories[departmentId]);\n\n                                if(scope.isRecipeService) {\n                                    viewAllParams.category_id = departmentId;\n\n                                    scope.title = self.$element.attr('data-freshop-title');\n                                    if (util.isNull(scope.title))  scope.title = category.name;\n                                }\n\n                                var childCategories = _.filter(category.items, function(item) {\n                                    return config.hashedFilteredCategories[item.id];\n                                });\n                                if (_.size(childCategories)) viewAllParams.display = 'category';\n                                else if (scope.hasProductService) viewAllParams.display = 'grid';\n                            }\n                        }\n                    }\n\n                    const isLazyInit = !self.initialized && config.enableLazyInit;\n\n                    if(isEnabled && !isLazyInit) {\n                        if(payload.department_id) {\n                            payload.department_id_cascade = true;\n                        }\n\n                        if(_.isObject(config.payload)) $.extend(payload, config.payload);\n\n                        if (scope.hasProductService) {\n                            payload.status_id = util.map.get('productStatus').get('available').id;\n                            if(!fp.config.enableKiosk) payload.has_cover_image = true;\n\n                            var promiseProducts = serviceCall.get(payload, options);\n\n                            if (filter == 'product_ads') {\n                                service.productAdService.queue.add(promiseProducts, config.priority);\n                            }\n\n                            if(fp.config.showShelfTagsOnGrid || fp.config.enableInventoryTagsOnGrid) {\n                                mapItems.push({\n                                    service: service.tagService,\n                                    payload: {\n                                        type: 'shelf_tag',\n                                        sort: 'name',\n                                        fields: null\n                                    }\n                                });\n                            }\n\n                            promiseItems = promiseProducts\n                                .then(function (resp) {\n                                    switch (filter) {\n                                        case 'offered_together':\n                                            var item = _.firstObject(_.firstObject(resp.items).offered_together);\n\n                                            if (!_.size(item.product_ids)) {\n                                                delete resp.items;\n                                                return resp;\n                                            }\n\n                                            if (item.label) scope.title = item.label;\n\n                                            return service.productService\n                                                .get({\n                                                    id: item.product_ids.join(),\n                                                    fields: fp.productFields\n                                                }, {\n                                                    handleErrors: false,\n                                                    disableShowProgress: config.disableShowProgress\n                                                });\n                                        case 'bought_together':\n                                            var item = _.firstObject(_.firstObject(resp.items).bought_together);\n\n                                            if (!_.size(item.product_ids)) {\n                                                delete resp.items;\n                                                return resp;\n                                            }\n\n                                            if (item.label) scope.title = item.label;\n\n                                            return service.productService\n                                                .get({\n                                                    id: item.product_ids.join(),\n                                                    fields: fp.productFields\n                                                }, {\n                                                    handleErrors: false,\n                                                    disableShowProgress: config.disableShowProgress\n                                                });\n                                        case 'product_id':\n                                            if(_.size(config.product_id) && _.size(resp.items)) {\n                                                //sort returned items in order of config.product_id\n                                                var hashedItems = _.indexBy(resp.items, 'id');\n\n                                                _.empty(resp.items);\n                                                _.each(config.product_id.split(','), function(id, index) {\n                                                    id = fp.S(id).trim().s;\n                                                    if(id) {\n                                                        item = hashedItems[id];\n                                                        if (item) resp.items[index] = item;\n                                                    }\n                                                });\n                                            }\n                                            break;\n                                    }\n\n                                    return resp;\n                                });\n                        }\n                        else if (scope.hasRecipeService) {\n                            if(!scope.isRecipeService) {\n                                promiseItems = service.productService.get(payload, options)\n                                    .then(function (resp) {\n                                        var recipeIds = [],\n                                            label,\n                                            recipes;\n\n                                        _.each(resp.items, function(item) {\n                                            recipes = _.first(item.recipes);\n                                            if(!recipes) return;\n                                            if (!label) label = recipes.label;\n\n                                            _.concat(recipeIds, recipes.recipe_ids);\n                                        });\n\n                                        if (label) scope.title = label;\n\n                                        if(!_.size(recipeIds)) {\n                                            delete resp.items;\n                                            return resp;\n                                        }\n\n                                        return service.recipeService\n                                            .get({\n                                                id: _.unique(recipeIds).join(),\n                                                fields: 'id, name, cover_image'\n                                            });\n                                    });\n                            }\n                            else promiseItems = service.recipeService.get(payload, options);\n                        }\n                        else if (scope.hasCouponService) {\n                            payload.is_clippable = true;\n                            promiseItems = service.offerService.get(payload, options);\n                            if(departmentId && util.isNull(scope.title)) {\n                                promiseItems = promiseItems\n                                    .then(function(offerResp) {\n                                        if(_.size(offerResp.items)) {\n                                            return service.offerService\n                                                .get({\n                                                    include_departments: true,\n                                                    is_clippable: true\n                                                })\n                                                .then(function(resp) {\n                                                    const department = _.findWhere(resp.departments, { id: departmentId });\n                                                    if(department) {\n                                                        viewAllParams.coupon_department_id = departmentId;\n                                                        scope.title = department.name;\n                                                    }\n                                                    return offerResp;\n                                                });\n                                        }\n                                        return offerResp;\n                                    });\n                            }\n                        }\n                        else if (scope.hasOfferService) {\n                            promiseItems = service.offerService.get(payload, options);\n                            //if(isLazyInit) return promiseItems;\n                        }\n                        else if (scope.hasCircularOfferService) {\n                            var circularId = payload.circular_id;\n\n                            if (!circularId && payload.intent == 'circular') {\n                                promiseItems = service.circularService\n                                    .get({\n                                        limit: 1,\n                                        id: util.getNullIfEmpty(payload.circular_id),\n                                        type_id: util.getNullIfEmpty(util.getStateValue(!payload.circular_id, payload.circular_type_id || '1'))\n                                    })\n                                    .done(function (resp) {\n                                        var circular = _.first(resp.items);\n                                        if (circular) circularId = circular.id;\n                                    });\n                            }\n\n                            promiseItems = $.when(promiseItems)\n                                .then(function () {\n                                    if (!circularId && payload.intent == 'circular') return {};\n\n                                    payload.circular_id = circularId;\n                                    var offerResp,\n                                        promiseMap = util.map.load(service.offerStatusService),\n                                        promiseOffers = service.offerService\n                                            .get(payload, options)\n                                            .done(function (resp) {\n                                                offerResp = resp;\n                                            });\n\n                                    return $.when(promiseMap, promiseOffers)\n                                        .then(function () {\n                                            return offerResp;\n                                        });\n                                });\n                        }\n\n                        if (promiseItems) {\n                            promiseItems\n                                .done(function (resp) {\n                                    data = resp;\n                                });\n                        }\n                    }\n                }\n\n                mapItems.push({\n                    service: service.tagService,\n                    payload: {\n                        type: tagTypes,\n                        sort: 'name'\n                    }\n                });\n\n                return $.when(\n                    util.map.load.apply(util.map, mapItems),\n                    promiseItems\n                );\n            })\n            //.then(function() {\n            //    return util.delayPromise(null, 1000 * 20);\n            //})\n            .always(function () {\n                scope.items = data && data.items;\n                if(config.itemDisplayAtLeast && _.size(scope.items) <= config.itemDisplayAtLeast){\n                    scope.items = null;\n                }\n\n                scope.data = data;\n                var state;\n\n                if(config.js_navigation_path) {\n                    state = stateManager.getStateFromUrl(config.js_navigation_path, true).state;\n                }\n                if(state && state != stateManager.root) {\n                    viewAllState = state;\n                }\n\n                scope.viewAllUrl = stateManager.href(viewAllState, viewAllParams);\n                scope.departmentId = departmentId;\n\n                if(util.getBoolean(autoRender, true)) {\n                    self.render();\n                }\n            });\n    },\n    renderPlaceholder: function(params, options) {\n        const config = this.config;\n        if(config.enableLazyInit) {\n            const items = [];\n            _.times(fp.device.xs && config.limitXs ? config.limitXs : config.limit, function() {\n                items.push({id: _.uniqueId('item-'), name: ''});\n            });\n\n            this.scope.items = items;\n\n            this.render(null, $.extend(options, {force: true}));\n\n            this.$element.addClass('fp-item-placeholder');\n        }\n\n        return this._super();\n    },\n    render: function(params, options) {\n        var config = this.config,\n            scope = this.scope,\n            $element = this.$element,\n            isEnabled = util.getBoolean(scope.hasRecipeService || !fp.config.requireStore || fp.store.id),\n            mediaChangePayload = {\n                newWidth: $(window).width()\n            },\n            isProductAd = config.filter == 'product_ads';\n\n        scope.itemDisplayRowCount = this.__getItemDisplayCount(config.itemDisplayRowCustom, mediaChangePayload.newWidth);\n\n        this._super(params, options);\n\n        //this should eventually be moved into a parent class\n        $element.replaceClass('fp-module', 'fp-module fp-carousel');\n\n        if(!this.initialized && !_.getObject(options).force) return;\n\n        if(!isEnabled || (_.size(scope.items) < config.hideIfLessThan)) {\n            $element.empty();\n            $element.addClass('hidden');\n            return;\n        }\n\n        if(config.displayVariable) {\n            this.displayVariableCarousel();\n            if(!$element.filter(':visible').length) return;\n        }\n\n        if(config.filter) {\n            $element.addClass(util.formatString('fp-product-carousel-{0}', config.filter));\n        }\n\n        //if(!_.size(scope.items) || (!scope.hasProductService && !fp.util.isAuthenticated())) {\n        //    $element.addClass('hidden');\n        //    returnFrom = true;\n        //}\n        //\n        //if(scope.hasRecipeService && _.size(scope.items)) returnFrom = false;\n\n        $element\n            .removeClass('hidden')\n            .toggleClass('fp-hide-arrows', _.size(scope.items) <= 4);\n\n        var self = this;\n        scope.hashedItems = {};\n\n        _.each(scope.items, function (item) {\n            scope.hashedItems[util.getProduct(item).id] = item;\n        });\n\n        $element\n            .on('click contextmenu', '.fp-item .fp-item-price .fp-price-link', function(event) {\n                var isClick = event.type == 'click';\n                if(isClick) {\n                    event.preventDefault();\n                    event.stopImmediatePropagation();\n                }\n\n                var  productId = $(this).closest('.fp-item').attr('data-product-id');\n                if(!productId) return;\n\n                var item = scope.hashedItems[productId],\n                    promise = fp.ui.onProductAdClick(event, item, {\n                        showProductModal: config.showProductModal\n                    });\n\n                if(isClick && !self.config.showProductModal) {\n                    promise\n                        .always(function () {\n                            var next = scope.stateManager.href(scope.states.productDetail, {id: productId}, {canonical_url: util.getProduct(item).canonical_url});\n                            if(fp.config.enableSeePriceModal) {\n                                fp.ui.showShopIntentModal({\n                                    force: true,\n                                    fulfillmentIdentifier: 'price',\n                                    next:  next\n                                });\n                            }\n                            else scope.stateManager.go(scope.states.storeLocator, {next: next, intent: 'price'});\n                        });\n                }\n            })\n            .on('click keypress', '.fp-item .fp-item-favorite', function(event) {\n                if(event.type === 'click' || event.keyCode === fp.constants.keycode.RETURN) {\n                    event.preventDefault();\n\n                    var $this = $(this),\n                        $item = $this.closest('.fp-item'),\n                        productId = $item.attr('data-product-id');\n                    if(!productId) return;\n\n                    if(!fp.util.isAuthenticated()) return;\n\n                    var item = scope.hashedItems[productId];\n\n                    //product ad events bubble up\n                    if(!util.isProductAd(item)) event.stopImmediatePropagation();\n\n                    var isFavorite = $item.hasClass('fp-is-item-favorite');\n                    (isFavorite) ? $this.attr('aria-current', 'false') : $this.attr('aria-current', 'true');\n                    (isFavorite) ? $this.attr('aria-label', fp.ui.locale('shared-add-to-favorites', 'Add to My Favorites')) : $this.attr('aria-label', fp.ui.locale('shared-remove-favorites', 'Remove From My Favorites'));\n                    service.userProductService\n                        .create({product_id: productId, is_favorite: !isFavorite})\n                        .done(function(resp) {\n                            var product = util.getProduct(item);\n                            product.is_favorite = resp.is_favorite;\n                            fp.trigger(fp.events.PRODUCT_FAVORITED, {product: product });\n                        });\n                }\n            })\n            .on('click', '.fp-owl-prev, .fp-owl-next', function(event) {\n                    event.preventDefault();\n                    event.stopImmediatePropagation();\n    \n                    var $owlCarousel = $element.find(config.carouselSelector),\n                        owlCarousel = $owlCarousel.data('owlCarousel'),\n                        $target = $(event.target);\n    \n                    if ($target.hasClass('fp-owl-next')) owlCarousel.next();\n                    else owlCarousel.prev();\n            })\n            .on('click', '[data-action=\"dismiss-item\"]', function(event) {\n                event.preventDefault();\n\n                var productId = $(this).closest('.fp-item').attr('data-product-id'),\n                    item = _.removeWhere(scope.items, {product_id: productId});\n                delete scope.hashedItems[productId];\n\n                if(item) self.render();\n            })\n            .on('click', '[data-action=\"clip-offer\"]', function(event) {\n                if(scope.hasCouponService) return;\n\n                event.preventDefault();\n\n                var $this = $(this),\n                    item = {},\n                    productId = $this.closest('.fp-item').attr('data-offer-id');\n\n                if(!productId) {\n                    productId = $this.closest('.fp-item').attr('data-product-id');\n                }\n\n                item = _.findWhere(scope.items, {id: productId});\n                if(!item) {\n                    item = _.findWhere(scope.items, {product_id: productId});\n                    item = item.product;\n                }\n\n                if(!(item && item.clippable_offer)) return;\n\n                if(item.clippable_offer.is_clipped) {\n                    fp.ui.showOfferModal(item.clippable_offer);\n                    return;\n                }\n\n                fp.ui.clipOffer(item.clippable_offer, {$button: $this})\n                    .done(function() {\n                        var hashedProducts = _.indexBy(scope.items, 'id'),\n                            product,\n                            $this;\n\n                        if(hashedProducts.undefined) hashedProducts = _.indexBy(scope.items, 'product_id');\n\n                        $element.find('.fp-item')\n                            .each(function() {\n                                $this = $(this);\n                                product = hashedProducts[$this.attr('data-offer-id')];\n\n                                if(!product) {\n                                    product = hashedProducts[$this.closest('.fp-item').attr('data-product-id')];\n                                    if(product && product.product) product = product.product;\n                                }\n\n                                if((product && product.clippable_offer) && (product.clippable_offer.id == item.clippable_offer.id)) {\n                                    $this.find('[data-action=\"clip-offer\"]')\n                                        .toggleClass('fp-is-offer-clipped', util.getBoolean(item.clippable_offer.is_clipped))\n                                        .toggleClass('fp-disabled', util.getBoolean(item.clippable_offer.is_clipped));\n                                }\n                            });\n                    });\n            })\n            .on('click', '[data-action=\"add-single\"]', function(event) {\n                event.preventDefault();\n                var productId = $(this).closest('.fp-item-action-group').attr('data-product-id');\n                fp.trigger(fp.events.LIST_ITEM_ADD, {listManager: fp.listManager, item: util.getProduct(scope.hashedItems[productId]), formValues: {} });\n            })\n            .on('click', '.fp-item-name, .fp-item-image', function(event){\n                var title = scope.title || util.getStateValue(scope.hasProductService, 'Products', 'Carousel'),\n                    productId = $(this).closest('.fp-item').attr('data-product-id');\n                fp.trigger(fp.events.TRACK_EVENT, _.defaults({\n                    label: title,\n                    listName: title,\n                    items: scope.hasProductService ? util.getProduct(scope.hashedItems[productId]) : undefined,\n                    widgetId: config.widgetId,\n                    widgetType: config.widgetType,\n                    widgetPosition: config.widgetPosition\n                }, fp.constants.trackingEvents.ClickedRecommendation));\n            })\n            .on('click', '.fp-shelf-tag-video_url', function(event) {\n                event.preventDefault();\n\n                var $videoAttribute = $(this),\n                    videoUrl = $videoAttribute.attr('href');\n\n                if(!util.isNullOrEmpty(videoUrl)) {\n                    var embedUrl = fp.ui.getYouTubeEmbedUrl(videoUrl);\n                    if(embedUrl) videoUrl = embedUrl;\n                }\n\n                fp.ui.showModal({\n                    name: 'video-url',\n                    template: 'component/0/modal.html',\n                    className: 'fp-video-url',\n                    title: $videoAttribute.attr('data-product-title'),\n                    content: fp.ui.renderTemplate('component/0/youtube.html', { youtubeUrl: embedUrl}),\n                    buttons: [{title: fp.ui.locale('shared-close', 'Close'), action: 'cancel', className: 'fp-btn-cancel'}]\n                });\n            });\n\n        if (isProductAd) {\n            var productAdsData = {}\n            $element\n                .on('click contextmenu', '.fp-item', function (event) {\n                    var productId = $(this).attr('data-product-id');\n                    if (!productId) return;\n\n                    var item = scope.hashedItems[productId],\n                        promise = fp.ui.onProductAdClick(event, item, {\n                            showProductModal: self.config.showProductModal,\n                            title: config.productModalTitle ? config.productModalTitle : null,\n                            triggerTrackUrl: util.isProductAd(item) ? true : null,\n                            productAdsData: productAdsData\n                        });\n\n                    if(event.type == 'click' && scope.isMiniCarousel && !self.config.showProductModal) {\n                        promise\n                            .always(function () {\n                                scope.stateManager.go(scope.states.productDetail, {id: productId}, {canonical_url: util.getProduct(item).canonical_url});\n                            });\n                    }\n                });\n        }\n\n        if(fp.config.enableBreinify) {\n            $element\n                .on('click', '[data-action=\"alert-me\"]', function (event) {\n                    event.preventDefault();\n                    var productId = $(this).closest('[data-product-id]').attr('data-product-id'),\n                        product = scope.hashedItems[productId],\n                        item = util.getProduct(product);\n                    fp.ui.showAlertMeModal(event, item);\n                });\n        }\n\n        if(scope.hasProductService){\n            var carouselSelector = config.layout == 'layout-7' || config.layout == 'layout-9' ? '.fp-result-list' : config.carouselSelector,\n                $productList = $element.find(carouselSelector);\n\n            if(!config.enableCarouselXs) {\n                $productList\n                    .addClass(util.formatString('fp-product-list-xs-limit-{0}', config.itemDisplayCount));\n            }\n\n            if(!(isProductAd && scope.isMiniCarousel)) {\n                var ProductActions = fp.ui.ProductActions,\n                    listName = scope.title || util.getStateValue(scope.hasProductService, 'Products', 'Carousel'),\n                    $item,\n                    actionOptions;\n\n                $productList.find('.fp-item .fp-item-action')\n                    .each(function (index) {\n                        $item = $(this);\n                        actionOptions = {\n                            item: util.getProduct(scope.hashedItems[$item.attr('data-product-id')]),\n                            stopPropagation: !isProductAd,\n                            listName: listName,\n                            listPosition: index + 1\n                        };\n\n                        if(config.filter == 'user_upsell') {\n                            actionOptions.onRefreshUI = function(event, payload) {\n                                scope.lastInteractionId = payload.item && payload.item.product_id;\n                            };\n                        }\n\n                        new ProductActions($item, actionOptions);\n                    });\n            }\n        }\n        else if(scope.hasCouponService) {\n            $element\n                .on('click', '[data-action=\"clip-offer\"]', function (event) {\n                    event.preventDefault();\n\n                    var $this = $(this),\n                        item = scope.hashedItems[$this.closest('.fp-item').attr('data-id')];\n\n                    if (!item) return;\n\n                    if (item.is_clipped) {\n                        fp.ui.showOfferModal(item);\n                        return;\n                    }\n\n                    var hasProducts = _.size(item.product_ids) > 0;\n\n                    fp.ui.clipOffer(item, {\n                        $button: $this,\n                        enableAnonymous: self.config.enableAnonymous,\n                        apiOptions: {errorSelector: self.$element.find('.fp-container-results [data-role=\"notification\"]')}\n                    })\n                    .done(function () {\n                        $this\n                            .toggleClass('fp-is-offer-clipped', util.getBoolean(item.is_clipped))\n                            .toggleClass('fp-disabled', util.getBoolean(item.is_clipped && !hasProducts));\n                    });\n                })\n                .on('click', '[data-action=\"show-offer\"]', function (event) {\n                    event.preventDefault();\n\n                    var itemId = $(this).closest('[data-id]').attr('data-id'),\n                        item = scope.hashedItems[itemId];\n\n                    if (!item) return;\n\n                    fp.ui.showOfferModal(item, {target: event.target});\n                })\n                .on('click', '[data-action=\"show-description\"]', function(event) {\n                    event.preventDefault();\n\n                    var item = scope.hashedItems[$(this).attr('data-id')];\n                    if(!item) return;\n                    if(!item.offer_disclaimer && !item.description) return;\n\n                    var content = item.description + (_.size(item.offer_disclaimer) ? '<br />' + item.offer_disclaimer : '');\n\n                    fp.ui.showModal({\n                        name: 'offer-disclaimer',\n                        className: 'fp-offer-disclaimer-modal',\n                        title: fp.S.getString(item.brand, 'Disclaimer'),\n                        content: content\n                    });\n                });\n        }\n        else if(scope.hasOfferService || scope.hasCircularOfferService){\n            this.__initOffers();\n        }\n\n        $element.find('.fp-btn-view-all')\n            .toggleClass('hidden', config.disableViewAll);\n\n        self.onMediaWidthChange(null, mediaChangePayload);\n\n        if(isProductAd) {\n            fp.ui.triggerTrackUrls(scope.data);\n\n            if(!$element.find(config.carouselSelector).data('owlCarousel')) {\n                fp.ui.triggerTrackUrls(scope.items);\n            }\n            fp.ui.beaconOnClick(scope.data, $element);\n        }\n\n        fp.ui.renderOfferTracker($element);\n\n        if($element.length) {\n            fp.lozad($element[0].querySelectorAll('img[data-src]')).observe();\n        }\n    },\n    destroyChildComponents: function(persistUI) {\n        this.destroyCarousel();\n        this._super(persistUI);\n    },\n    destroyCarousel: function(persistUI) {\n        var $owlCarousel = this.$element.find(this.config.carouselSelector),\n            owlCarousel = $owlCarousel.data('owlCarousel');\n\n        if (owlCarousel) owlCarousel.destroy();\n        $owlCarousel.removeClass('owl-carousel');\n    },\n    initCarousel: function() {\n        var self = this,\n            $element = this.$element,\n            scope = this.scope,\n            config = this.config,\n            $owlCarousel = this.$element.find(config.carouselSelector).attr('role', 'region'),\n            owlCarousel = $owlCarousel.data('owlCarousel'),\n            disableNavigation = util.getBoolean(config.disableNavigation, false);\n\n        if(owlCarousel) return;\n\n        $owlCarousel.prependClass('owl-carousel');\n\n        if(config.enable_number_of_items && config.enable_number_of_items != 'false' && _.size(scope.items) <= config.itemDisplayCount) {\n            config.itemDisplayCount = _.size(scope.items);\n            config.itemsCustom = false;\n        }\n\n        $owlCarousel\n            .owlCarousel({\n                items: config.itemDisplayCount,\n                slideSpeed: 400,\n                rewindSpeed: 400,\n                scrollPerPage: true,\n                itemsCustom : config.itemsCustom,\n                responsive: true,\n                autoPlay: false,\n                navigation: !disableNavigation,\n                mouseDrag: false,\n                navigationText: config.navigationText || [\n                    '<span aria-label=\"Previous\" class=\"fp-icon fp-icon-angle-left fp-icon-carousel-prev\"></span>',\n                    '<span aria-label=\"Next\" class=\"fp-icon fp-icon-angle-right fp-icon-carousel-next\"></span>'\n                ],\n                afterInit: function(){\n                    if(self.initialized && config.filter == 'product_ads') {\n                        fp.ui.pageBeaconOnView(scope.data, this.$elem);\n                    }\n                },\n                afterAction: function() {\n                    if(self.initialized) {\n                        if(config.filter == 'product_ads') {\n                            let items = disableNavigation ? scope.items : scope.hasProductService && scope.items && scope.items[this.currentItem];\n                            if(items) {\n                                fp.ui.triggerTrackUrls(items);\n                            }\n\n                            let owlCarousel = this;\n                            // delay because of the slider animation may cause the element not be in view on time\n                            setTimeout(function(){self.__productsOnView(owlCarousel)}, 1000);\n                        }\n\n                        var title = scope.title || util.getStateValue(scope.hasProductService, 'Products', 'Carousel');\n                        fp.trigger(fp.events.TRACK_EVENT, _.defaults({\n                            label: title,\n                            listName: title,\n                            items: scope.hasProductService ? scope.items : undefined\n                        }, fp.constants.trackingEvents.ViewSlider));\n                    }\n                }\n            })\n            .off('mousedown.productCarousel.fp')\n            .on('mousedown.productCarousel.fp', function(event){\n                var $active = $(document.activeElement);\n                if($active.hasClass('fp-input-qty-txt')) $active.trigger('blur');\n            });\n    },\n    __productsOnView: function(owlCarousel){\n        let self = this,\n            scope = self.scope,\n            currentItems = [],\n            itemsAmountPerRow = self.__getItemDisplayCount(self.config.itemsCustom) * self.__getItemDisplayCount(self.config.itemDisplayRowCustom);\n\n        // get the items in each row\n        if(_.size(scope.items)) {\n            for(let i = itemsAmountPerRow * owlCarousel.currentItem; i < scope.items.length && i < itemsAmountPerRow * (owlCarousel.currentItem + 1); i++){\n                if(scope.items[i]) currentItems.push(scope.items[i]);\n            }\n        }\n        if(currentItems) fp.ui.productsBeaconOnView(scope.data, owlCarousel.$elem, currentItems);\n    },\n    handleApiError: function(resp) {\n        if(!resp.error_code) return;\n\n        var error = fp.S(resp.error_message).trim();\n        switch(resp.error_code) {\n            case 'store_card_required':\n            case 'store_card_invalid':\n                var errorStoreCard = fp.config.storeCard.profileCardTitle || 'Store Card';\n\n                if(error.length && !error.endsWith('.')) error = error.concat('.');\n                error = error.concat(util.formatString(' Please go to <a href=\"{0}\">My Account</a> and add a valid card/key tag number under the {1} section.', this.scope.stateManager.href(this.scope.states.account), errorStoreCard));\n                break;\n        }\n\n        fp.util.showError(error.s, this.$element.find('.fp-notification'));\n    },\n    onMediaWidthChange: function(event, payload) {\n        var oldItemDisplayRowCount = this.scope.itemDisplayRowCount;\n        this.scope.itemDisplayRowCount = this.__getItemDisplayCount(this.config.itemDisplayRowCustom, payload.newWidth);\n\n        if(oldItemDisplayRowCount != this.scope.itemDisplayRowCount) {\n            this.render();\n            return;\n        }\n\n        //determine if we need to toggle carousel\n        if (\n            !(fp.enableMobile && fp.config.enableMobile) && //if we are on a mobile device (enableMobile) and site is configured for mobile (enableMobile) we do not need Owl Carousel\n            this.__getItemDisplayCount(this.config.itemsCustom, payload.newWidth) //if there are items configured for this device width we will use Owl Carousel\n        ) {\n            this.initCarousel();\n            //this.matchHeight();\n        }\n        else {\n            this.destroyCarousel();\n        }\n    },\n    displayVariableCarousel: function() {\n        if(_.size(fp.ui.router.routeManager.urlParams)) this.$element.hide();\n        else this.$element.show();\n    },\n    __attachScopeEvents: function() {\n        this._super();\n\n        var self = this,\n            $scope = $(this.scope),\n            config = this.config;\n\n        $scope\n            .on(fp.events.RESIZE, function() {\n                self.resize();\n            })\n            //.on(fp.events.STORE_CHANGED, function(event, payload) {\n            //    self.init(true);\n            //})\n            .on(fp.events.PRODUCT_FAVORITED, function(event, payload) {\n                var carouselSelector = config.layout == 'layout-7' || config.layout == 'layout-9' ? '.fp-result-list' : config.carouselSelector,\n                    $item = self.$element\n                        .find(carouselSelector)\n                        .find(util.formatString('.fp-item[data-product-id=\"{0}\"]',  payload.product.id));\n\n                if(!$item.length) return;\n\n                $item.toggleClass('fp-is-item-favorite');\n\n                var isFavorite = $item.hasClass('fp-is-item-favorite'),\n                    $favoriteLink = $item.find('fp-item-favorite'),\n                    titleText;\n\n                if(isFavorite) titleText = $favoriteLink.data('add-text');\n                else titleText = $favoriteLink.data('remove-text');\n\n                $favoriteLink.prop('title', titleText);\n\n                if(!event.handled) {\n                    fp.user.product_favorite_count = util.getInteger(fp.user.product_favorite_count) + (isFavorite ? 1 : -1);\n                    event.handled = true;\n                }\n            })\n            .on(fp.events.MEDIA_WIDTH_CHANGE, $.proxy(self.onMediaWidthChange, self))\n            .on(fp.events.ROUTE_CHANGED, function() {\n                if(!self.config.displayVariable) return;\n                self.displayVariableCarousel();\n            })\n            .on(fp.events.LIST_ITEM_CHANGED, function (event, payload) {\n                if (payload.listManager.getList().id != fp.listManager.getList().id) return;\n            })\n            .on(fp.events.LIST_ITEMS_REFRESHED, function (event, payload) {\n                fp.ui.renderOfferTracker(self.$element);\n            });\n\n        //in most cases the parent module will handle loading the child module\n        //on route change, but the layout module will not\n        if(!(this.parent instanceof fp.Module) || (this.parent instanceof fp.Module.Layout)) {\n            $scope\n                .on(fp.events.ROUTE_CHANGED, function (event, payload) {\n                    var delay = self.config.filter == 'product_ads' ? (self.config.priority * 50) : 0;\n\n                    _.delay(function () {\n                        if (payload.fromState != payload.toState) {\n                            self.init(true);\n                            return;\n                        }\n\n                        var keys = _.concat([\n                            'id',\n                            'filter',\n                            'page',\n                            'display',\n                            self.scope.stateManager.getQ().identifier\n                        ], fp.adContextFields);\n\n                        if (!_.size(_.pick(payload.changedParams, keys))) return;\n\n                        self.init(true);\n                    }, delay);\n                });\n        }\n    },\n    __sortItemsCustom: function (a, b) {\n        return a[0] - b[0];\n    },\n    __getItemDisplayCount: function(itemsCustom, viewWidth) {\n        viewWidth = viewWidth || $(window).width();\n\n        var itemDisplayCount = itemsCustom && itemsCustom[0][1];\n        _.find(itemsCustom, function (item) {\n            if (item[0] > viewWidth) return true;\n            itemDisplayCount = item[1];\n        });\n\n        return util.getInteger(itemDisplayCount, 1);\n    },\n    __showProductsModal: function(event) {\n        event.preventDefault();\n        event.stopImmediatePropagation();\n\n        var $item = $(event.target).closest('[data-offer-id]'),\n            offerId = $item.attr('data-offer-id');\n        if(!offerId) return;\n\n        var offer = _.findWhere(this.scope.items, {id: offerId});\n        if(!offer) return;\n\n        var self = this,\n            title = fp.S.getString(fp.config.modalOfferTitle, offer.name);\n\n        fp.trigger(fp.events.PRODUCTS_MODAL_SHOW, {\n            title: title,\n            subTitle: offer.description,\n            productIds: offer.product_ids,\n            note: title,\n            onRefreshUI: function() {\n                if(self.config.filter == 'product_ads' && self.scope.isMiniCarousel) {\n                    return;\n                }\n                self.__refreshProductAction($item);\n            }\n        });\n    },\n    __initOffers: function() {\n        var self = this,\n            config = this.config,\n            scope = this.scope,\n            $element = this.$element,\n            onAddToListProxy = $.proxy(this.__showProductsModal, this);\n\n        if(config.filter == 'product_ads' && scope.isMiniCarousel) {\n            $element.on('click', '.fp-item', onAddToListProxy);\n            return;\n        }\n\n        var listManager = fp.listManager,\n            item,\n            offer,\n            $itemAction;\n\n        $element\n            .on('click', util.formatString('{0} a', config.carouselSelector), onAddToListProxy)\n            .find(config.carouselSelector)\n            .find('.fp-item').each(function () {\n                var $item = $(this);\n                $itemAction = $item.find('.fp-item-action')\n                    .off('click', '[class^=\"fp-btn-\"]', onAddToListProxy)\n                    .on('click', '[class^=\"fp-btn-\"]', onAddToListProxy);\n\n                item = null;\n                offer = scope.hashedItems[$item.attr('data-offer-id')];\n\n                if(offer) {\n                    _.find(offer.product_ids, function (id) {\n                        item = listManager.getItem(id, true);\n                        return item != null;\n                    });\n                }\n\n                new fp.ui.ProductActions($itemAction, {\n                    item: item,\n                    stopPropagation: true,\n                    enableQtyDropDown: false,\n                    onRefreshUI: function() {\n                        self.__refreshProductAction($item);\n                    }\n                });\n            });\n    },\n    __refreshProductAction: function($item) {\n        if(!_.size($item)) return;\n\n        var offer = this.scope.hashedItems[$item.attr('data-offer-id')];\n\n        if(!(offer && _.size(offer.product_ids))) {\n            //must be a generic item\n            //don't do anything\n            return;\n        }\n\n        var quantity = 0,\n            listManager = fp.listManager,\n            lm = fp.ui.ListManager,\n            item,\n            firstItem = null,\n            $itemAction = $item.find('.fp-item-action');\n\n        if(offer && _.size(offer.product_ids)) {\n            _.each(offer.product_ids, function (id) {\n                item = listManager.getItem(id, true);\n                if(!item) return;\n                if(!firstItem) firstItem = item;\n\n                quantity += lm.getItemQuantity(item, false, false, true);\n            });\n        }\n\n        $item\n            .toggleClass('fp-is-item-in-list', quantity > 0)\n            .find('.fp-item-quantity').text(quantity);\n\n        $itemAction.toggleClass('fp-is-item-in-list', quantity > 0);\n        $itemAction.find('.fp-btn-add').html(util.getItemButtonHtml(firstItem, quantity));\n    }\n});\n\nreturn fp.Module.ProductCarousel;\n\n//# sourceURL=module/product-carousel/product-carousel.js"}