{"html":"<div class=\"<%- config.containerClass %> fp-item-details\">\n    <%\n    if(item.id) {\n        var images = _.getArray(item.images)\n            ,isAvailable = util.map.get('productStatus').get(item.status_id).identifier == 'available'\n            ,enableVarieties = _.size(item.varieties) > 0\n            ,enableSubstitution = (!config.disableSubstitution && fp.config.hasSubstitutions && isAvailable && _.size(substitutionTypes))\n            //,enableNotes = !isDropShip\n            ,enableNotes = !item.note_configuration || (item.note_configuration && item.note_configuration.is_allowed)\n            ,addFavoriteText = fp.ui.locale('shared-add-to-favorites', 'Add To Favorites')\n            ,removeText = fp.ui.locale('shared-remove-favorites', 'Remove From Favorites')\n            ,removeFromListLabel = (fp.config.removeFromListLabel && fp.config.removeFromListLabel.length > 0 ? fp.config.removeFromListLabel : fp.ui.locale('aria-remove-from-list', 'Remove From List'))\n            ,addToListLabel = (fp.config.addToListLabel && fp.config.addToListLabel.length > 0 ? fp.config.addToListLabel : fp.ui.locale('aria-add-to-list', 'Add To List'));\n    %>\n    <% _.each(otherProductTypes, function(type){ %>\n        <div class=\"fp-other-product-wrapper\">\n            <span class=\"fp-label\" role=\"heading\" aria-level=\"2\"><%- type.label %></span>\n            <div role=\"group\" aria-label=\"<%= fp.ui.locale('product', 'Product') %>\" class=\"fp-other-product-list\">\n                <% _.each(type.products, function(product){ %>\n                    <div class=\"fp-other-product <%- item.id === product.id ? 'fp-is-selected' : '' %>\" aria-selected=\"<%- item.id === product.id ? 'true' : 'false' %>\">\n                        <a aria-label=\"<%- product[type.productLabelType] + ' ' + (product.sale_price || product.price) %>\" class=\"fp-other-product-link\" data-identifier=\"<%- type.identifier %>\" href=\"<%- stateManager.href(states.productDetail, {id: product.id}, {canonical_url: product.canonical_url}) %>\" tabindex=\"0\">\n                            <span class=\"fp-other-product-label\"><%- product[type.productLabelType] %></span>\n                            <span class=\"fp-other-product-price\"><%- product.sale_price || product.price %></span>\n                        </a>\n                    </div>\n                <% }); %>\n            </div>\n        </div>\n    <% }); %>\n    <div class=\"row fp-row-details\">\n        <% if(!config.disableExtras) { %>\n        <div class=\"col-md-6 col-md-push-6 fp-col-item-image\">\n            <div class=\"fp-item-image fp-item-image-large\">\n                <img src=\"<%= util.getImageSrc(item, 'large') %>\" alt=\"<%- item.name %>\" width=\"100%\" height=\"100%\" />\n            </div>\n            <% if(images.length > 1) { %>\n            <div class=\"fp-item-images-wrapper\">\n                <% _.each(images, function(image, index) {\n                var imageName = item.name + ' ' + (index + 1);\n                if(index % 4 == 0) {\n                %>\n                <% if(index > 0) { %></ul><% } %>\n                <ul class=\"row fp-padding-top\">\n                <% } %>\n                    <li class=\"col-xs-3 col-3\">\n                        <span class=\"fp-item-images\">\n                            <a href=\"javascript:;\" class=\"fp-item-image\" role=\"button\"><img src=\"<%= util.getImageSrc(image) %>\" alt=\"<%- imageName %>\"/></a>\n                        </span>\n                    </li>\n                <% }); %>\n                </ul>\n            </div>\n            <% } %>\n        </div>\n        <% } %>\n        <div class=\"<%= !config.disableExtras ? 'col-md-6 col-md-pull-6' : 'col-md-12' %> fp-sm-margin-top fp-col-item-details <%= fp.store.price_mode_id == util.map.get('storePriceMode').get('select_price_required_store').id ? 'fp-select-price-required-store' : '' %>\">\n            <% if(config.intent === 'modal') { %>\n            <%= fp.ui.renderTemplate(fp.config.productDetailLayout, {item: item, disableGroup: true, disableAdmin: true, className: 'fp-item-detail-lg', disableRating: true}) %>\n            <% } %>\n            <% if(item.average_rating) { %>\n            <div class=\"fp-rating-wrapper fp-margin-top-sm\">\n                <% var averageRating = fp.numeralInstance.set(item.average_rating).round(1).value(); %>\n                <%= fp.ui.renderTemplate('component/0/rating.html', {rating: averageRating}) %>\n                <span class=\"fp-rating-more\"><% if(averageRating) { %>\n                    <span class=\"sr-only\"><%- averageRating %> star rating based on <%- util.getInteger(item.review_count) %> reviews</span>\n                    <span class=\"fp-review-rating\"><%= averageRating %></span><span class=\"fp-review-delimiter\">|</span><% } %>\n                    <span class=\"fp-review-count\"><%= util.getInteger(item.review_count) %> Review(s)</span>\n                    <span class=\"fp-review-delimiter\">|</span>\n                </span>\n                <a href=\"javascript:;\" class=\"fp-btn-link fp-btn-write-review\" role=\"button\" data-action=\"write-review\">Write a Review</a>\n            </div>\n            <% } %>\n            <% if(isAvailable || config.intent == 'product_admin') { %>\n            <form name=\"fp-form-product-detail\" class=\"fp-form fp-form-product-detail\">\n                <div data-role=\"notification\" class=\"fp-notification fp-margin-top\"></div>\n                <% if(enableVarieties) { %>\n                <%= fp.ui.renderTemplate('component/0/product-variety.html', {item: item, userProduct: userProduct }) %>\n                <% } %>\n                <% if(config.intent != 'product_admin') { %>\n                <div class=\"row fp-row-add-to-list\">\n                    <% if(item.quantity_on_hand_label) { %>\n                    <div class=\"clearfix\">\n                        <div class=\"col-xs-12\">                    \n                            <div class=\"fp-bold fp-margin-bottom-sm fp-item-quantity-on-hand\">\n                                <%- item.quantity_on_hand_label %>\n                            </div>                    \n                        </div>\n                    </div>\n                    <% } %>\n                    <div class=\"col-md-6 col-lg-6 <%= item.quantity_size_ratio_description ? 'fp-shift-correct' : '' %> <%- fp.ui.getClassName(_.size(item.varieties) > 0,'fp-item-has-variety') %>\">\n                        <% if(!item.disallow_adding_to_cart) { %>\n                        <div class=\"fp-item-action fp-item-action-lg <%- fp.ui.getClassName(fp.config.enableQtyDropDown, 'fp-is-qty-ddl') %>\" data-product-id=\"<%-item.id %>\" data-role=\"item-action-lg\">\n                            <span class=\"fp-btn-icon fp-btn-decrement\" aria-label=\"<%= fp.ui.locale('aria-remove-from-list', 'Decrease item quantity by 1: ') %><%- item.name %>\" role=\"button\" tabindex=\"0\"><span class=\"sr-only\"><%- 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') + ': ') %><%- item.name %>\" role=\"button\" tabindex=\"0\"><span class=\"sr-only\"><%- addToListLabel %></span></span>\n                            <% if(config.enableVarietyUpdate) { %>\n                            <span class=\"fp-btn-save\" role=\"button\" tabindex=\"0\"><%= fp.ui.locale('shared-save', 'Save') %></span>\n                            <% } %>\n                        </div>\n                        <% } %>\n                        <div class=\"fp-item-size-ratio <%- fp.ui.getClassName(!enableVarieties && !item.quantity_size_ratio_description, 'hidden') %>\"><%- item.quantity_size_ratio_description %></div>\n                    </div>\n                    <div class=\"col-md-6 col-lg-6 fp-sm-margin-top\">\n                        <% if (fp.util.isAuthenticated()) { %>\n                        <a href=\"javascript:;\" class=\"fp-item-favorite <%= item.is_favorite ? 'fp-is-favorite' : '' %>\" role=\"button\" data-product-id=\"<%-item.id %>\"><span class=\"fp-icon <%= item.is_favorite ? 'fp-icon-favorite' : 'fp-icon-favorite-o'%>\" aria-hidden=\"true\"></span><span class=\"fp-favorite-label\" data-add-text=\"<%- addFavoriteText %>\" data-remove-text=\"<%- removeText %>\"><%- item.is_favorite ? removeText : addFavoriteText %></span></a>\n                        <% } %>\n                    </div>\n                </div>\n                <% } %>\n\n                <% if(fp.store.price_mode_id == util.map.get('storePriceMode').get('select_price_required_store').id){ %>\n                <div class=\"fp-select-store\">\n                    <a href=\"<%- stateManager.href(states.storeLocator, {next: stateManager.href(states.productDetail, {id: item.id}, {canonical_url: item.canonical_url}), intent: 'price'}) %>\" class=\"fp-btn fp-btn-select-store\"><%- util.getStateValue(fp.config.seePriceLabel, fp.config.seePriceLabel, fp.ui.locale('shared-please-select-store', 'Select A Store To See Price')) %></a>\n                </div>\n                <% } %>\n\n                <% \n                var substitution = '';\n                if(enableSubstitution) { \n                    if(note) {\n                        substitution = fp.S(note).match(substitutionRegex);\n                    }\n                %>\n                <div class=\"fp-col-substitution-type\">\n                    <label>\n                        <span class=\"fp-label\"><%= fp.ui.locale('shared-substitution', 'Substitution') %></span><br/>\n                        <% if(enableSpecificSubstitution) { %>\n                        <button type=\"button\" class=\"fp-btn-search fp-btn <%- substitution ? 'hidden' : '' %>\" data-action=\"search-substitution\"><%= fp.ui.locale('shared-search-substitutions','Add Substitution') %></button>\n                        <% } %>\n                        <span class=\"fp-dropdown fp-dropdown-substitution-type <%- substitution ? 'hidden' : '' %>\" data-default=\"<%- substitutionType.name %>\">\n                            <input name=\"fp-input-substitution_type_id\" type=\"hidden\" value=\"<%- substitutionType.id %>\" />\n                            <button type=\"button\" class=\"fp-dropdown-value\" role=\"combobox\" aria-controls=\"fp-substitution-dropdown-list\">\n                                <span class=\"fp-value\"><%- substitutionType.name %></span>\n                                <span class=\"fp-dropdown-icon\"></span>\n                            </button>\n                            <span class=\"fp-dropdown-menu\">\n                                <ul class=\"fp-dropdown-list\" id=\"fp-substitution-dropdown-list\" role=\"listbox\">\n                                    <% _.each(substitutionTypes, function(option, optionIndex) { %>\n                                    <li class=\"fp-dropdown-list-item\" role=\"option\"><a href=\"javascript:;\" data-value=\"<%- option.id %>\"><%- option.name %></a></li>\n                                    <% }); %>\n                                </ul>\n                            </span>\n                        </span>\n                    </label>\n                </div>\n                <% } %>\n\n                <% if(enableNotes) { %>\n                <%\n                    var addText = fp.ui.locale('shared-add-notes', 'Add Notes'),\n                        maxlength = 1000;\n                    if(item.note_configuration){\n                        if(item.note_configuration.label){\n                            addText = item.note_configuration.label;\n                        }\n                        if(item.note_configuration.maximum_length){\n                            maxlength = item.note_configuration.maximum_length;\n                        }\n                    }\n                    if(note) note = fp.S(note).replace(substitutionRegex, '');\n                %>\n                <% if(obj.config.noteInstructions) { %>\n                <div class=\"fp-note-instructions\"><%- obj.config.noteInstructions %></div>\n                <% } %>\n                <div class=\"fp-col-substitution\">\n                    <div class=\"fp-item-substitution fp-margin-top-sm\" data-role=\"item-substitution\"><%- substitution %></div>\n                    <div class=\"fp-item-substitution-action fp-margin-top-sm <%- !substitution ? 'hidden' : '' %>\">\n                        <button type=\"button\" class=\"fp-btn\" data-action=\"change-substitution\"><%= fp.ui.locale('shared-change-substitutions','Change Substitution') %></button>\n                        <button type=\"button\" class=\"fp-btn\" data-action=\"clear-substitution\"><%= fp.ui.locale('shared-clear-substitutions','Clear') %></button>\n                    </div>            \n                </div>\n                <% if (!fp.config.globalDisableNotes) { %>\n                <div class=\"fp-col-note fp-margin-top-sm\" data-role=\"item-note\">\n                    <div class=\"fp-item-edit-note\">\n                        <div class=\"fp-item-note\"><%- note %></div>\n                        <a href=\"javascript:;\" class=\"fp-btn-link fp-btn-edit-note\" role=\"button\"><%- _.size(note) ? fp.ui.locale('shared-edit', 'Edit') : fp.ui.locale('shared-add-notes', config.addProductNotesLabel ? config.addProductNotesLabel : addText) %></a>\n                    </div>\n                    <div class=\"fp-item-save-note hidden\">\n                        <textarea name=\"fp-input-note\" class=\"fp-input-note\" maxlength=\"<%- maxlength %>\" aria-label=\"<%= fp.ui.locale('item-note-textarea-input', 'Item Notes Input') %>\" ><%- note %></textarea>\n                        <a href=\"javascript:;\" class=\"fp-btn-link fp-btn-save-note\" role=\"button\"><%= fp.ui.locale('shared-save', 'Save') %></a>\n                    </div>\n                </div>\n                <% } %>\n                <% } %>\n\n                <%\n                var mapSubstitutionType = enableSubstitution && util.map.get('substitutionType'),\n                    listItems;\n                if(enableVarieties) {\n                    listItems = _.getObject(listManager.getItem(item.id, {\n                        isProductId: true,\n                        multiple: true\n                    }));\n                }\n                %>\n\n                <% if(enableVarieties && _.size(listItems)) { %>\n                <ul class=\"fp-product-variety-list\">\n                <%\n                    var quantity = 0;\n                    _.each(listItems, function(listItem) {\n                        quantity += fp.ui.ListManager.getItemQuantity(listItem);\n                %>\n                    <li class=\"fp-product-variety-list-item\" data-list-item-id=\"<%- listItem.id %>\">\n                        <div class=\"row fp-row-product-variety\">\n                            <div class=\"col-xxs-12 col-xs-12 col-lg-12 fp-col-product-variety\">\n                                <div class=\"fp-product-variety\">\n                                    <%= (fp.DOMPurify.sanitize(fp.ui.ListManager.getItemVariety(listItem)) || item.name) %>\n                                </div>\n                            </div>\n                            <div class=\"col-xxs-12 col-xs-12 col-lg-12 fp-col-incrementer <%- fp.ui.getClassName(fp.config.enableQtyDropDown, 'fp-is-qty-ddl') %>\">\n                                <% if(config.enableVarietyUpdate) { %>\n                                <div class=\"fp-margin-bottom-sm\">\n                                    <a href=\"javascript:;\" role=\"button\" data-action=\"edit-variety\"><%= fp.ui.locale('shared-edit', 'Edit') %></a>\n                                </div>\n                                <% } %>\n                                <div class=\"fp-item-action fp-item-action-sm\" data-product-id=\"<%- listItem.product_id %>\" data-list-item-id=\"<%- listItem.id %>\" data-role=\"item-action-variety\">\n                                    <span class=\"fp-btn-icon fp-btn-decrement\" aria-label=\"<%= fp.ui.locale('aria-remove-from-list', 'Decrease item quantity by 1: ') %><%- item.name %>\" role=\"button\" tabindex=\"0\"><span class=\"sr-only\"><%- removeFromListLabel %></span></span>\n                                    <span class=\"fp-btn-add\"><%= util.getItemButtonHtml(item) %></span>\n                                    <span class=\"fp-btn-icon fp-btn-increment\" aria-label=\"<%-  addToListLabel + ': ' + item.name %>\" role=\"button\" tabindex=\"0\"><span class=\"sr-only\"><%- addToListLabel %></span></span>\n                                </div>\n                            </div>\n                        </div>\n\n                        <%\n                        var note = '',\n                            substitution = '';\n                        if (enableSubstitution) {\n                            var listItemSubstitutionType = mapSubstitutionType.get(listItem.substitution_type_id || fp.config.defaultProductSubstitution);\n                                \n                            if(listItem.note) {\n                                substitution = fp.S(listItem.note).match(substitutionRegex);\n                            }\n                        %>\n                        <div class=\"row\">\n                            <div class=\"col-xs-12 fp-col-substitution-type\">\n                                <label>\n                                    <span class=\"fp-label\"><%= fp.ui.locale('shared-substitution', 'Substitution') %></span><br/>\n                                    <% if(enableSpecificSubstitution) { %>\n                                    <button type=\"button\" class=\"fp-btn-search fp-btn <%- substitution ? 'hidden' : '' %>\" data-action=\"search-substitution\"><%= fp.ui.locale('shared-search-substitutions','Add Substitutions') %></button>\n                                    <% } %>\n                                    <span class=\"fp-dropdown fp-dropdown-substitution-type <%- substitution ? 'hidden' : '' %>\" data-default=\"<%- listItemSubstitutionType.name %>\">\n                                        <input name=\"fp-input-substitution_type_id\" type=\"hidden\" value=\"<%- listItemSubstitutionType.id %>\" />\n                                        <button type=\"button\" class=\"fp-dropdown-value\">\n                                            <span class=\"fp-value\"><%- listItemSubstitutionType.name %></span>\n                                            <span class=\"fp-dropdown-icon\"></span>\n                                        </button>\n                                        <span class=\"fp-dropdown-menu\">\n                                            <ul class=\"fp-dropdown-list\">\n                                                <% _.each(substitutionTypes, function(option, optionIndex) { %>\n                                                <li class=\"fp-dropdown-list-item\"><a href=\"javascript:;\" data-value=\"<%- option.id %>\"><%- option.name %></a></li>\n                                                <% }); %>\n                                            </ul>\n                                        </span>\n                                    </span>\n                                </label>\n                            </div>\n                        </div>\n                        <% } %>\n                        \n                        <% if(enableNotes) { %>\n                        <%\n                            var addText = fp.ui.locale('shared-add-notes', 'Add Notes'),\n                                maxlength = 1000;\n\n                            if(listItem.note) note = fp.S(listItem.note).replace(substitutionRegex, '');\n\n                            if(item.note_configuration){\n                                if(item.note_configuration.label){\n                                    addText = item.note_configuration.label;\n                                }\n                                if(item.note_configuration.maximum_length){\n                                    maxlength = item.note_configuration.maximum_length;\n                                }\n                            }\n                        %>\n                        <div class=\"row\">\n                            <div class=\"col-xs-12 fp-col-substitution\">\n                                <div class=\"fp-item-substitution\" data-role=\"item-substitution\"><%- substitution %></div>\n                                <div class=\"fp-item-substitution-action fp-margin-top-sm <%- !substitution ? 'hidden' : '' %>\">\n                                    <button type=\"button\" class=\"fp-btn\" data-action=\"change-substitution\"><%= fp.ui.locale('shared-change-substitutions','Change Substitution') %></button>\n                                    <button type=\"button\" class=\"fp-btn\" data-action=\"clear-substitution\"><%= fp.ui.locale('shared-clear-substitutions','Clear') %></button>\n                                </div>            \n                            </div>\n                            <% if (!fp.config.globalDisableNotes) { %>\n                            <div class=\"col-xs-12 fp-col-note\" data-role=\"item-note\">\n                                <div class=\"fp-item-edit-note\">\n                                    <div class=\"fp-item-note\"><%- note %></div>\n                                    <a href=\"javascript:;\" class=\"fp-btn-link fp-btn-edit-note\" role=\"button\"><%- _.size(note) ? fp.ui.locale('shared-edit', 'Edit') : addText %></a>\n                                </div>\n                                <div class=\"fp-item-save-note hidden\">\n                                    <textarea name=\"fp-input-note\" class=\"fp-input-note\" maxlength=\"<%- maxlength %>\" aria-label=\"<%= fp.ui.locale('item-note-textarea-input', 'Item Notes Input') %>\"><%- note %></textarea>\n                                    <a href=\"javascript:;\" class=\"fp-btn-link fp-btn-save-note\" role=\"button\"><%= fp.ui.locale('shared-save', 'Save') %></a>\n                                </div>\n                            </div>\n                        </div>\n                        <% } %>\n                        <% } %>\n                    </li>\n                    <% }); %>\n                    <li class=\"fp-product-variety-footer\">\n                        <div class=\"row\">\n                            <% if(item.quantity_size_ratio_description) { %>\n                            <div class=\"col-xs-7 col-lg-8 fp-item-size-ratio\"><%- item.quantity_size_ratio_description %></div>\n                            <% } %>\n                            <div class=\"<%= item.quantity_size_ratio_description ? 'col-xs-5 col-lg-4' : 'col-md-12' %> fp-product-variety-quantity\" data-role=\"product-variety-quantity\"><%- util.getItemQuantityLabel(_.firstObject(listItems), quantity) %></div>\n                        </div>\n                    </li>\n                </ul>\n                <% } %>\n\n                <% if(_.size(item.slot_message)) { %>\n                <div class=\"fp-notification fp-notification-slot-message\">\n                    <div class=\"fp-icon-notification\" aria-hidden=\"true\"></div>\n                    <div class=\"fp-notification-message\">\n                        <%- util.getMessage(item.slot_message) %>\n                    </div>\n                </div>\n                <% } %>\n\n                <% if (fp.config.enableCouponClipping && _.isObject(item.clippable_offer)) { %>\n                <div class=\"fp-margin-caps\">\n                    <hr />\n                </div> \n                <%= fp.ui.renderTemplate('component/0/clippable-offer.html', {item: item.clippable_offer}) %>\n                <% } %>\n                <div class=\"fp-offer-circular-tracker fp-hidden\"></div>\n\n                <% if(_.size(item.available_subscription_programs) && _.getObject(stateManager.getTopParent(stateManager.current)).name !== 'account') { %>\n                    <div data-role=\"product-subscription\">\n                    <% if(!_.size(obj.userProductSubscriptions)) { %>                    \n                        <%= fp.ui.renderTemplate('component/0/product-subscription-add.html', {availableSubcriptionPrograms: item.available_subscription_programs, fulfillmentTypes: obj.fulfillmentTypes, listItem: obj.listItem, productSubscriptionStatus: obj.productSubscriptionStatus }) %>\n                    <% } else { %>\n                        <%= fp.ui.renderTemplate('component/0/product-subscription-added.html', { userProductSubscription: _.firstObject(obj.userProductSubscriptions) }) %>\n                    <% } %>\n                    </div>\n                <% } %>\n\n                <% if(!config.disableExtras) { %>\n                <% if(!config.disableUpc) { %>\n                <div class=\"fp-margin-top fp-item-upc\">\n                    <%- config.upcLabel %>\n                    <% var sku = (fp.config.enableLikeCode && item.like_code) || item.identifier; %>\n                    <% if(util.hasRole(fp.constants.adminRole.PRODUCT_ADMIN)) { %>\n                    <a href=\"<%= util.formatString(fp.ui.getAdminUrl()+'/#!/products?store_id={0}&q={1}&product_id={2}', fp.S.getString(fp.store.id), item.identifier, item.id) %>\" target=\"_blank\"><%- sku %></a>\n                    <% } else { %>\n                    <%- sku %>\n                    <% } %>\n                    <% if(config.enableLikeCode) { %>\n                    <div class=\"fp-item-like-code\">SKU: <%- item.like_code %></div>\n                    <% } %>\n                </div>\n                <% } %>\n\n                <% if(!config.disableLocation && item.shopper_location) { %>\n                <div class=\"fp-item-location\"><%= fp.ui.locale('product-detail-location', 'Location') %>: <%- item.shopper_location %></div>\n                <% } %>\n\n                <% if(obj.fulfillmentType) { %>\n                <div class=\"fp-item-fulfillment-type\">\n                    <h4>\n                        <span><%- fulfillmentType.name %> Order</span>\n                        <span class=\"fp-icon fp-icon-fulfillment-<%- fulfillmentType.identifier %>\"></span>\n                    </h4>\n                    <div class=\"fp-item-fulfillment-type-description\">\n                        This product is a <%- fp.S(fulfillmentType.name).toLowerCase() %> only product.\n                    </div>\n                </div>\n                <% } %>\n                <%= fp.ui.renderTemplate('component/0/product-shelf-tags.html', {item: item, shelfTagsTitle: config.shelfTagsTitle, shelfTagMax: 4}) %>\n                <% } %>\n\n                <% if (_.size(item.other_attributes) && item.other_attributes.smart_label_url) { %>\n                    <a href=\"<%- item.other_attributes.smart_label_url %>\" title=\"SmartLabel\" target=\"_blank\" class=\"fp-smart-label\"><span class=\"fp-hidden\">SmartLabel</span></a>\n                <% } %>\n\n                <% if(item.indications) { %>\n                    <%= fp.ui.renderTemplate('component/0/item-indication.html', {item: item}) %>\n                <% } %>\n\n                <% if(_.size(linkedOffers)) { %>\n                <div class=\"fp-section-row\">\n                    <div class=\"fp-section-title fp-section-title-linked-offers\" data-section=\"linked-offers\"><h4><%= fp.ui.locale('shared-linked-offers', 'Offers') %></h4><hr/></div>\n                    <%\n                    var productListTemplate = fp.ui.getTemplate('component/0/product-list.html');\n                    _.each(linkedOffers, function(offer) {\n                    %>\n                    <% if(offer.config.text) { %><h5><%- offer.config.text %></h5><% } %>\n                    <%= fp.ui.renderTemplate(productListTemplate, {items: offer.products, listClass: 'fp-linked-offer-list', itemActionClass: 'fp-item-action-sm'}) %>\n                    <% }); %>\n                </div>\n                <% } %>\n            </form>\n            <% } %>\n        </div>\n        <% if(!config.disableExtras) {\n            if (item.smart_label_url) { %>\n                <div class=\"col-md-12 fp-margin-top\">\n                <iframe id=\"myframe\" src=\"<%= item.smart_label_url %>\" height=\"600px\" width=\"100%\"></iframe>\n                </div>\n            <% } else { %>\n        <div class=\"col-md-12\">\n            <%\n            var nutritionCount = _.size(item.nutritions),\n                copy,\n                warnings = util.getSequenceValue(item.warnings, '<p/>');\n            if(nutritionCount > 1) {\n                var nutritionTitle;\n            %>\n            <div class=\"fp-product-multiple\">\n                <div class=\"fp-dropdown fp-dropdown-products\">\n                    <% _.each(item.nutritions, function(nutrition, index) { %>\n                    <% nutritionTitle = fp.S.getString(nutrition.title, item.name); %>\n                    <% if(index == 0) { %>\n                    <input name=\"fp-dropdown-products\" type=\"hidden\" value=\"productItem_<%= index %>\" />\n                    <button type=\"button\" class=\"fp-dropdown-value\">\n                        <span class=\"fp-value\" value=\"productItem_<%= index %>\"><%- nutritionTitle %></span>\n                        <span class=\"fp-dropdown-icon\"></span>\n                    </button>\n                    <div class=\"fp-dropdown-menu\">\n                        <ul class=\"fp-dropdown-list\">\n                    <% } %>\n                            <li class=\"fp-dropdown-list-item\"><a href=\"javascript:;\" data-selected=\"<%= (index == 0) ? 'true' : '' %>\" data-value=\"productItem_<%= index %>\"><%- nutritionTitle %></a></li>\n                    <% }); %>\n                        </ul>\n                    </div>\n                </div>\n            </div>\n            <% } %>\n\n            <% if(item.video_config && item.video_config.video_url) { %>\n            <div class=\"fp-video-wrap fp-margin-top hidden\" data-role=\"video\"></div>\n            <% } %>\n\n            <!-- Nav tabs -->\n            <ul class=\"fp-nav-tabs\">\n                <% if(item.description_md || item.description){ %>\n                <li class=\"active\"><a href=\"#fp-detail-desc\" aria-label=\"Description\" role=\"link\" data-toggle=\"tab\">Description</a></li>\n                <% } %>\n                <% if(nutritionCount){ %>\n                <li><a href=\"#fp-detail-nutrition\" aria-label=\"Nutrition\" role=\"link\" data-toggle=\"tab\">Nutrition</a></li>\n                <% } %>\n                <% if(item.ingredients_md || item.ingredients){ %>\n                <li><a href=\"#fp-detail-ingredients\" aria-label=\"<%- config.labelIngredients %>\" role=\"link\" data-toggle=\"tab\"><%- config.labelIngredients %></a></li>\n                <% } %>\n                <% if(item.directions_md || item.directions){ %>\n                <li><a href=\"#fp-detail-instructions\" aria-label=\"Directions\" role=\"link\" data-toggle=\"tab\">Directions</a></li>\n                <% } %>\n            </ul>\n\n            <!-- Tab panes -->\n            <div class=\"tab-content\">\n                <%\n                var desc = item.description_md || item.description,\n                    otherDesc = item.other_description_md || item.other_description;\n\n                if(desc || otherDesc) {\n                %>\n                <div id=\"fp-detail-desc\" role=\"tabpanel\" class=\"tab-pane active\">\n                    <div class=\"fp-item-description\">\n                        <div class=\"fp-item-description-content\">\n                            <%if(desc) {%>\n                            <p><%= util.makeSanitizedHtml(desc) %></p>\n                            <%}%>\n                            <%if(otherDesc) {%>\n                            <p><%= util.makeSanitizedHtml(otherDesc) %></p>\n                            <%}%>\n                        </div>\n                    </div>\n                </div>\n                <% } %>\n\n                <% if(nutritionCount){ %>\n                <div id=\"fp-detail-nutrition\" role=\"tabpanel\" class=\"tab-pane\">\n                    <div class=\"tab-content\">\n                    <% _.each(item.nutritions, function(nutrition, index) { %>\n                        <div role=\"tabpanel\" class=\"tab-pane <%= (index == 0) ? 'active' : '' %>\" data-role=\"tab-pane-productItem_<%= index %>\">\n                            <div class=\"fp-section-row\">\n                                <%= fp.ui.renderTemplate('component/0/product-nutrition.html', {item: nutrition, warnings: warnings}) %>\n                            </div>\n                        </div>\n                        <% }); %>\n                    </div>\n                </div>\n                <% } %>\n\n                <%\n                copy = item.ingredients_md || item.ingredients;\n                if(copy) {\n                %>\n                <div id=\"fp-detail-ingredients\" role=\"tabpanel\" class=\"tab-pane\">\n                    <div class=\"fp-product-info\">\n                        <div class=\"fp-section-row fp-detail-ingredients\">\n                            <%= util.makeSanitizedHtml(copy) %>\n                        </div>\n                    </div>\n                </div>\n                <% } %>\n\n                <%\n                copy = item.directions_md || item.directions;\n                if(copy) {\n                %>\n                <div id=\"fp-detail-instructions\" class=\"tab-pane\" role=\"tabpanel\" data-role=\"tab-pane\">\n                    <div class=\"fp-section-row\">\n                        <%= util.makeSanitizedHtml(copy) %>\n                    </div>\n                </div>\n                <% } %>\n            </div>\n        </div>\n         <% } %>\n        <% } %>\n    </div>\n    <div class=\"hidden\" data-role=\"review-list\"></div>\n    <% if(fp.config.enableWebCollage) { %>\n    <syndigo-powerpage id=\"wc-power-page\" pageid=\"<%- item.id %>\" class=\"fp-web-collage fp-margin-top\"></syndigo-powerpage>\n    <% } %>\n    <% } else { %>\n    <div class=\"fp-text-center fp-not-found\">\n        <h1 class=\"fp-text-center\"><%= fp.ui.locale('shared-sorry', 'Sorry!') %></h1>\n        <hr />\n        <h4 class=\"fp-text-center\"><%= fp.ui.locale('product-detail-does-not-carry', 'This store does not carry the product you were looking for.') %></h4>\n    </div>\n    <% } %>\n</div>","js":"fp.Module.ProductDetail = fp.Module.View.extend({\n    construct: function ($element, config, template, parent) {\n        const self = this;\n\n        config = _.defaults(config, {\n            enableSEO: true,\n            listManager: fp.listManager,\n            intent: 'default',\n            showShelfTags: false,\n            shelfTagsTitle: fp.ui.locale('shared-shelf-tags', 'Shelf Tags'),\n            showTags: false,\n            requireStore: {},\n            labelIngredients: fp.ui.locale('shared-ingredients', 'Ingredients'),\n            enableShopIntentModal: util.getBoolean(fp.config.shopIntent.enabled),\n            enableLocale: true,\n            containerClass: 'container',\n            upcLabel: 'SKU/UPC:',\n            enableWebCollage: true\n        });\n\n        config.requireStore = _.defaults(config.requireStore, {\n            enableRedirect: true,\n            intent: 'shop',\n            disabled: !util.getBoolean(fp.config.requireStore)\n        });\n\n        this._super($element, config, template, parent);\n    },\n    init: function () {\n        var promise = this._super(false);\n        if(this.config.intent == 'default' && !this.scope.stateManager.isDetail(['id', 'product_id'])) {\n            $(this.scope).off();\n            return promise.always($.proxy(this.__attachScopeEvents, this));\n        }\n\n        var self = this,\n            config = this.config,\n            scope = this.scope,\n            stateParams = scope.stateParams,\n            storeId = util.getUndefinedIfEmpty(config.storeId || (_.contains(['modal', 'show-detail'], config.intent) ? config.listManager.getList().store_id : null)),\n            item,\n            linkedOffers,\n            userProduct,\n            productTagTypes,\n            reviewModule,\n            userProductSubscriptions,\n            otherProductTypes = [];\n\n        return promise\n            .then(function() {\n                if(config.intent != 'modal') {\n                    $(document.body).addClass('fp-state-product-detail');\n                }\n\n                const productId = fp.S(config.product_id || config.productId || stateParams.id || stateParams.product_id).trim().s\n\n                if(productId) {\n                    return service.productService\n                        .get({\n                            id: productId,\n                            store_id: config.assignedStoreId || storeId || _.first(fp.user.preference.last_used_store_ids),\n                            intent: util.getUndefinedIfEmpty(config.apiIntent),\n                            as_of_date: util.getUndefinedIfEmpty(stateParams.as_of_date),\n                            include_other_sizes: true,\n                            include_flavors: true\n                        }, {formatForRestfulId: true});\n                }\n            })\n            .then(function(resp) {\n                item = _.getObject(resp);\n\n                var multiplexId = _.uniqueId(),\n                    mapItems = [\n                        service.fulfillmentTypeService, {\n                            service: service.tagService,\n                            payload: {\n                                type: 'store_price_mode,product_status,sale_configuration_type'\n                            },\n                            options: {multiplexId: multiplexId}\n                        }, {\n                            service: service.serviceProviderConfigurationService,\n                            payload: {\n                                service_provider_type: 'store_setting'\n                            },\n                            options: {multiplexId: multiplexId}\n                        }\n                    ],\n                    promiseOffers,\n                    promiseUserProduct,\n                    promiseProductTags,\n                    promiseProductSubscriptionStatus,\n                    promiseUserProductSubscriptions,\n                    promiseStoreFullmentType;\n\n                if (item.id) {\n                    if (!item.__product_quantity) {\n                        var cachedProduct = fp.cache.product.items[item.id];\n                        if (cachedProduct && cachedProduct.__product_quantity) {\n                            item.__product_quantity = cachedProduct.__product_quantity;\n                        }\n                    }\n\n                    if (_.isArray(item.nutritions)) {\n                        // Nutrition rules:\n                        //  if we don't have either (serving size and number of servings) or calories\n                        //  then the nutritional information is not valid and will be removed\n                        var nutrition;\n\n                        for (var n = 0; n < item.nutritions.length; n++) {\n                            nutrition = item.nutritions[n];\n\n                            nutrition.__hasCoreNutrition = _.find(util.coreNutrition, function (key) {\n                                return nutrition[key + '_per_serving'] != null;\n                            });\n\n                            if (\n                                (nutrition.serving_size && (nutrition.servings_per_container || nutrition.number_of_servings)) ||\n                                nutrition.calories_per_serving ||\n                                nutrition.__hasCoreNutrition\n                            ) {\n                                continue;\n                            }\n\n                            item.nutritions.splice(n, 1);\n                        }\n                    }\n\n                    var linkedOfferIds = util.getValueFromNamespace('sale_offer.config.linked_offer_ids', item);\n                    if (_.size(linkedOfferIds)) {\n                        promiseOffers = service.offerService\n                            .get({\n                                id: linkedOfferIds.join(),\n                                store_id: storeId,\n                                intent: util.getUndefinedIfEmpty(config.apiIntent),\n                                as_of_date: util.getUndefinedIfEmpty(stateParams.as_of_date)\n                            })\n                            .then(function (resp) {\n                                linkedOffers = resp.items;\n                                return service.productService\n                                    .applyToItems(linkedOffers, {\n                                        store_id: storeId,\n                                        intent: util.getUndefinedIfEmpty(config.apiIntent),\n                                        as_of_date: util.getUndefinedIfEmpty(stateParams.as_of_date)\n                                    }, {\n                                        productIdField: 'product_ids',\n                                        productValueField: 'products'\n                                    })\n                                    .done(function () {\n                                        if (linkedOffers) {\n                                            var hashedProducts = {};\n                                            _.each(linkedOffers, function (item) {\n                                                _.each(item.products, function (product) {\n                                                    hashedProducts[product.id] = product;\n                                                });\n                                            });\n                                            linkedOffers.hashedProducts = hashedProducts;\n                                        }\n                                    });\n                            });\n                    }\n\n                    if (config.showTags && _.size(item.tag_ids)) {\n                        promiseProductTags = service.tagService\n                            .get({\n                                id: item.tag_ids.join()/*,\n                                type: 'product_tag'*/\n                            })\n                            .then(function (resp) {\n                                var productTags = resp.items;\n                                if(_.size(productTags)) {\n                                    var typeIds = '',\n                                        hashedTypeIds = {};\n                                    _.each(productTags, function(item) {\n                                        if(!hashedTypeIds[item.type_id] && item.type_identifier != 'shelf_tag') {\n                                            if(typeIds) typeIds += ',';\n                                            typeIds += item.type_id;\n                                            hashedTypeIds[item.type_id] = 1;\n                                        }\n                                    });\n\n                                    return service.tagTypeService\n                                        .get({id: typeIds})\n                                        .done(function(resp) {\n                                            productTagTypes = resp.items;\n                                            var departmentId = _.first(item.department_id);\n\n                                            _.each(productTagTypes, function(item) {\n                                                switch(item.identifier) {\n                                                    case 'department':\n                                                        item.name = 'Type/Varietal';\n                                                        item.stateParamKey = 'department_id';\n                                                        break;\n                                                    case 'product_country_origin':\n                                                        item.stateParamKey = 'country_id';\n                                                        break;\n                                                    default:\n                                                        item.stateParamKey = fp.S(item.identifier).trimLeft('product_').concat('_id').s;\n                                                        break;\n                                                }\n\n                                                item.tags = _.filter(productTags, function(tag) {\n                                                    var enabled = tag.type_id == item.id &&\n                                                        tag.type_identifier != 'product_tag';\n                                                    if(enabled && item.identifier == 'department' && tag.id != departmentId) {\n                                                        enabled = false;\n                                                    }\n                                                    return enabled;\n                                                });\n                                            });\n                                        });\n                                }\n                            });\n                    }\n\n                    if (config.intent != 'product_admin') {\n                        promiseUserProduct = service.userProductService\n                            .get({\n                                product_id: item.id,\n                                limit: 1\n                            }, {multiplexId: multiplexId})\n                            .done(function (resp) {\n                                userProduct = _.first(resp.items);\n                            });\n                    }\n\n                    if (!config.disableSubstitution) {\n                        mapItems.push({\n                            service: service.substitutionTypeService,\n                            payload: {\n                                store_id: storeId || fp.store.id,\n                                fields: 'id,identifier,name,sequence,is_default',\n                                sequence_sort: 'asc'\n                            },\n                            options: {multiplexId: multiplexId}\n                        });\n                    }\n\n                    if ((config.showShelfTags && !config.disableExtras) || fp.config.enableInventoryTagsOnGrid) {\n                        mapItems.push({\n                            service: service.tagService,\n                            options: {multiplexId: multiplexId},\n                            payload: {\n                                type: 'shelf_tag',\n                                sort: 'name',\n                                fields: null\n                            }\n                        });\n                    }\n                \n                    if(!util.isNullOrEmpty(item.video_config) && !util.isNullOrEmpty(item.video_config.video_url)){\n                        var videoUrl = fp.ui.getYouTubeEmbedUrl(item.video_config.video_url);\n                        if(videoUrl) item.video_config.video_url = videoUrl;\n                    }\n\n                    if(_.size(item.available_subscription_programs) > 0) {\n                        promiseProductSubscriptionStatus =  util.map.load({\n                            service: service.tagService,\n                            payload: {\n                                type: 'product_subscription_status'\n                            }\n                        })\n                        .then(function(){\n                            scope.productSubscriptionStatus = util.map.get('productSubscriptionStatus');\n                        });\n\n                        if(util.isAuthenticated()) {\n                            promiseUserProductSubscriptions = service.userProductSubscriptionService\n                                .get({\n                                    id: fp.user.id, \n                                    subscription_identifier: 'physical_goods_subscription',\n                                    is_current_only: true,\n                                    product_id: item.id\n                                }, \n                                { formatForRestfulId:true })\n                                .done(function(resp) {\n                                    userProductSubscriptions = _.filter(resp.items, function (subscription) {\n                                        return subscription.subscription_status_identifier == 'subscribed';\n                                    });\n                                });\n                        }\n                    }\n\n                    promiseStoreFullmentType = util.map.load({\n                        service: service.fulfillmentTypeService,\n                        payload: {\n                            store_id: storeId,\n                        },\n                        cacheKey: 'storeFulfillmentType'\n                    });\n                }\n\n                var promise = $.when(\n                    promiseUserProduct,\n                    promiseOffers,\n                    promiseProductTags,\n                    promiseProductSubscriptionStatus,\n                    promiseUserProductSubscriptions,\n                    promiseStoreFullmentType,\n                    self.__promiseOtherProduct({identifier: \"other_sizes\", productLabelType: \"product_size\", sort: \"base_price\"}, item, otherProductTypes),\n                    util.map.load.apply(util.map, mapItems)\n                );\n\n                service.multiplexService.run(multiplexId);\n\n                return promise;\n            })\n            .then(function() {\n                if(fp.productReviewSettings && item.id) {\n                    var moduleConfig = util.getValueFromNamespace('modules.reviewList', config);\n                    if (moduleConfig) {\n                        if (self.__reviewModule) {\n                            self.__reviewModule.destroy(true);\n                            delete self.__reviewModule;\n                        }\n\n                        moduleConfig.name = 'review-list';\n                        moduleConfig.elementSelector = $('<div class=\"hidden\" data-role=\"review-list\"></div>').appendTo(fp.__$freshop);\n                        moduleConfig.item = item;\n                        return fp.ui.loadModule(moduleConfig, self)\n                            .then(function (module) {\n                                reviewModule = module;\n\n                                var promise = module.init(false);\n                                promise\n                                    .catch(function (error) {\n                                        if (error instanceof Error) {\n                                            fp.notifier.notify(error, {\n                                                severity: 'error',\n                                                metaData: {\n                                                    'meta data': {\n                                                        'Module Name': module.config.name,\n                                                        'Module Selector': fp.S.getString(module.config.elementSelector).substr(0, 500),\n                                                        'Module Layout': module.config.layout\n                                                    }\n                                                }\n                                            });\n                                        }\n                                    });\n\n                                return promise;\n                            });\n                    }\n                }\n            })\n            .always(function() {\n                scope.item = item = _.getObject(item);\n                scope.userProduct = _.getObject(userProduct);\n                scope.userProduct.varieties = _.getObject(scope.userProduct.varieties);\n                delete scope.userProduct.defaultVarieties;\n                if(config.varietyDefault) {\n                    scope.userProduct.defaultVarieties = {};\n                    _.each(config.varietyDefault.split(','), function(variety) {\n                        variety = variety.split('=');\n                        scope.userProduct.defaultVarieties[variety[0]] = variety[1];\n                    });\n                }\n\n                scope.linkedOffers = linkedOffers;\n                scope.fulfillmentType = util.getProductFulfillmentType(item);\n                scope.isDropShip = scope.fulfillmentType && scope.fulfillmentType.identifier == 'drop_ship';\n                scope.otherItemAttributes = _.getObject(item.other_attributes);\n                scope.disclaimerConfig = _.getObject(util.map.get('spcStoreSetting').get('disclaimer').config);\n                scope.hideIndication = false;\n                scope.userProductSubscriptions = userProductSubscriptions;\n                scope.productTagTypes = productTagTypes;\n                scope.enableVarieties = _.size(item.varieties) > 0;\n                scope.substitutionRegex = /(\\n+)?Substitution:.*(\\n+)?/gim;\n                scope.enableSpecificSubstitution = item.id && util.map.get('substitutionType', null, config.disableSubstitution).get('specific_substitution').id ? true : false;\n\n                scope.otherProductTypes = otherProductTypes;\n                self.__reviewModule = reviewModule;\n\n                if(config.hideIndicationTagId && _.size(item.tag_ids)) {\n                    var hideWhenInStock =_.filter(item.tag_ids, function(item) {\n                        return item == config.hideIndicationTagId;\n                    });\n\n                    if(_.size(hideWhenInStock) && util.map.get('productStatus').get(item.status_id).identifier == 'available') scope.hideIndication = true;\n                }\n\n                self.render();\n            });\n    },\n    render: function (params) {\n        var self = this,\n            config = this.config,\n            $element = this.$element,\n            scope = this.scope;\n\n        scope.params = _.getObject(params);\n\n        var item = _.getObject(scope.params.item, scope.item),\n            listManager = config.listManager;\n\n        if(item.id) {\n            var listItem = {},\n                userProduct = _.getObject(scope.params.userProduct, scope.userProduct);\n\n            if (!scope.enableVarieties) {\n                listItem = _.getObject(listManager.getItem(item.id, true), listItem);\n                scope.listItem = listItem;\n            }\n\n            var additionalParams = {\n                varietiesSelected: _.getObject(listItem.varieties, userProduct.varieties),\n                note: scope.enableVarieties ? '' : fp.S.getString(listItem.note, userProduct.note),\n                listManager: listManager,\n                substitutionTypes: null\n            };\n\n            if(!config.disableSubstitution) {\n                var allowedSubstitutions = _.indexBy(item.substitution_type_ids),\n                    mapSubstitutionType = util.map.get('substitutionType'),\n                    mapSubstitutionTypes = mapSubstitutionType.items(),\n                    defaultSubType = _.findWhere(mapSubstitutionTypes, {is_default: true}) || _.firstObject(mapSubstitutionTypes),\n                    substitutionTypeId;\n                if (!scope.enableVarieties) substitutionTypeId = listItem.substitution_type_id;\n                if (!substitutionTypeId) {\n                    substitutionTypeId = userProduct.substitution_type_id || defaultSubType.id || mapSubstitutionType.get(fp.config.defaultProductSubstitution).id || mapSubstitutionType.get('best_comparable').id;\n                }\n\n                additionalParams.substitutionTypes = _.filter(mapSubstitutionTypes,\n                    function (item) {\n                        return _.has(allowedSubstitutions, item.id);\n                    }\n                );\n                additionalParams.substitutionType = _.findWhere(additionalParams.substitutionTypes, {id: substitutionTypeId}) || additionalParams.substitutionTypes[0];\n            }\n\n            additionalParams.substitutionType = _.getObject(additionalParams.substitutionType);\n            scope.additionalParams = additionalParams;\n            \n            _.defaults(scope.params, additionalParams);\n        }\n\n        this._super(scope.params);\n\n        fp.ui.renderOfferTracker($element, scope.item.id);\n\n        if(!_.contains(['modal', 'show-detail'], config.intent)) {\n            if(item.id) {\n                var metaDescription = config.metaDescription || fp.config.metaDescription;\n                if(metaDescription) fp.ui.setMetaDescription(metaDescription.replace('{title}', item.name));\n            }\n\n            const setTitlePayload = {\n                title: util.encodeForHtml(util.getStateValue(item.id, item.name, fp.ui.locale('shared-not-found', 'Not Found'))),\n                className: 'fp-has-product-detail'\n            };\n\n            if(item.id && fp.S(config.layout === 'layout-2')) {\n                setTitlePayload.controls = fp.ui.renderTemplate(fp.config.productDetailLayout, {\n                    item: scope.item,\n                    enableQuantityMinimum: true,\n                    enableCouponClipping: false,\n                    disableSizeRatioDescription: true,\n                    disableName: true, disableAdmin: true,\n                    className: 'fp-item-detail-lg'\n                });\n            }\n\n            fp.trigger(fp.events.PAGE_TITLE_SET_CONTENT, setTitlePayload);\n        }\n\n        var $productInfoPopOver = $element.find('[data-role=\"product-info\"]'),\n            $substitutionPopOver = $element.find('[data-role=\"substitution-info\"]');\n\n        if($productInfoPopOver.length) {\n            $productInfoPopOver\n                .popover({\n                    html: true,\n                    placement: 'bottom',\n                    trigger: 'hover',\n                    //trigger: 'click', //for testing,\n                    template: '<div class=\"popover fp-popover-product-info\"><div class=\"arrow\"></div><div class=\"popover-content\"></div></div>',\n                    animation: false\n                })\n                .on('show.bs.popover', function(event) {\n                    //small/touch devices do not get popovers\n                    if(fp.device.xs || fp.device.hasTouch) event.preventDefault();\n                });\n        }\n        \n        if($substitutionPopOver.length) {\n            $substitutionPopOver.popover({\n                html: true,\n                placement: 'bottom',\n                trigger: 'hover',\n                content: scope.disclaimerConfig.substitution_disclaimer,\n                template: '<div class=\"popover fp-popover-product-info fp-popover-disclaimer fp-popover-disclaimer-substitution\"><div class=\"arrow\"></div><div class=\"popover-content\"></div></div>',\n                animation: false\n            })\n            .on('show.bs.popover', function(event) {\n                //small/touch devices do not get popovers\n                if(fp.device.xs || fp.device.hasTouch) event.preventDefault();\n            });\n            \n            if(fp.device.xs || fp.device.hasTouch) {\n                $substitutionPopOver\n                   .on('click', function (event) {\n                        fp.ui.showModal({\n                            name: 'information-modal',\n                            template: 'component/0/modal.html',\n                            className: 'fp-confirm-modal fp-information-modal',\n                            title: fp.ui.locale('shared-more-information', 'More Information'),\n                            content: scope.disclaimerConfig.substitution_disclaimer\n                        });\n                    });\n            }\n        }\n        \n        if(scope.item.video_config && scope.item.video_config.video_url) self.__loadVideo(scope.item.video_config.video_url);\n\n        var reviewModule = this.__reviewModule;\n        if(reviewModule) {\n            var $reviewModule = reviewModule.$element.remove(),\n                $oldReviewModule = this.$element.find('[data-role=\"review-list\"]')\n                    .replaceWith($reviewModule);\n\n            _.each($oldReviewModule.attrs(), function(value, key) {\n                if(key == 'class') {\n                    $reviewModule.prependClass(value);\n                    return;\n                }\n\n                $reviewModule.attr(key, value);\n            });\n\n            $reviewModule.removeClass('hidden');\n            reviewModule.render();\n        }\n        \n        $element.find('.fp-dropdown-products').dropdown({\n            ariaLabel: fp.ui.locale('aria-label-dropdown-product', 'Select product'),\n            onChange: function (value) {\n                var $tabContent = $element.find('.tab-content');\n                if (!$tabContent.length) return;\n\n                $tabContent.find('[data-role*=\"tab-pane-\"]').removeClass('active');\n                $tabContent.find('[data-role=\"tab-pane-' + value + '\"]').addClass('active');\n\n                $element.find('.fp-nav-tabs > li')\n                    .removeClass('active')\n                    .filter(':nth-child(1)').addClass('active');\n            }\n        });\n\n        if(scope.enableVarieties) {\n            $element.find('.fp-col-varieties')\n                .find('[data-role^=\"option-\"]')\n                .addClass('hidden');\n\n            $element.find('.fp-dropdown-variety').dropdown({\n                ariaLabel: fp.ui.locale('aria-label-dropdown-variety', 'Select variety'),\n                onChange: function(value) {\n                    if(self.config.intent === 'product_admin') return;\n\n                    var $this = $(this),\n                        identifier = $this.find('input').attr('name').split('fp-variety-')[1];\n                        $options = $this.closest('.fp-col-varieties')\n                            .find('[data-role^=\"option-\"]')\n                            .addClass('hidden');\n\n                    if(!$this.data('fp.ui.Component').__disableVarietyUpdate) self.__updateVariety(identifier, value);\n                    \n                    if(value) {\n                        $options\n                            .filter(util.formatString('[data-role^=\"option-{0}\"]', util.encodeForHtml(value)))\n                            .removeClass('hidden');\n                    }\n                }\n            })\n            .each(function() {\n                var dropdown = $(this).data('fp.ui.Component');\n                if(dropdown) {\n                    dropdown.__disableVarietyUpdate = true;\n                    dropdown.onChange();\n                    delete dropdown.__disableVarietyUpdate\n                }\n            });\n\n            if(config.enableVarietyUpdate) {\n                $element\n                    .on('click', '[data-action=\"edit-variety\"]', function(event) {\n                        event.preventDefault();\n                        var $this = $(this),\n                            listItemId = $this.closest('[data-list-item-id]').attr('data-list-item-id'),\n                            listItem = listManager.getItem(listItemId);\n                        if(listItem) {\n                            var $form = $this.closest('form[name=\"fp-form-product-detail\"]'),\n                                otherAttributes = _.getObject(listItem.other_attributes),\n                                $input,\n                                $parent;\n\n                            $form.find('[data-role=\"item-action-lg\"]').attr('data-list-item-id', listItemId);\n\n                            _.each(listItem.varieties, function(value, key) {\n                                $input = $form.find(util.formatString('[name=\"fp-variety-{0}\"]', key));\n                                $parent = $input.parent();\n                                if($parent.hasClass('fp-dropdown')) {\n                                    var dropdown = $parent.data('fp.ui.Component');\n                                    dropdown.setValue(value);\n                                    if(dropdown) dropdown.onChange();\n                                }\n                                else {\n                                    $input.val(value);\n                                }\n\n                                _.each(otherAttributes[key], function(attributeValue, attributeKey) {\n                                    $form.find(util.formatString('[name=\"fp-variety-{0}-{1}\"]', value, attributeKey)).val(attributeValue);\n                                });\n                            });\n                        }\n                    });\n\n                if(config.listItemId) {\n                    $element\n                        .find(util.formatString('form[name=\"fp-form-product-detail\"] .fp-product-variety-list-item[data-list-item-id=\"{0}\"] [data-action=\"edit-variety\"]', config.listItemId))\n                        .trigger('click');\n                }\n            }\n        }\n\n        $element\n            .on('change', '.fp-checkbox-wrap input.fp-checkbox', function(event) {\n                var $selectedVariety = $(this).closest('.fp-checkbox-wrap'),\n                    selectedVarietyCheckBoxes = '',\n                    identifier = $selectedVariety.attr('data-id');\n\n                $selectedVariety.find('input.fp-checkbox:checked').each(function() {\n                    selectedVarietyCheckBoxes += ',' + $(this).attr('data-value');\n                });\n\n                selectedVarietyCheckBoxes = fp.S(selectedVarietyCheckBoxes).trimLeft(',').s;\n                self.__updateVariety(identifier, selectedVarietyCheckBoxes);\n            })\n            .on('change', '.fp-radio-wrap input.fp-radio', function(event) {\n                var $selectedVariety = $(this).closest('.fp-radio-wrap'),\n                    selectedVariety = '',\n                    identifier = $selectedVariety.attr('data-id');\n\n                $selectedVariety.find('input.fp-radio:checked').each(function() {\n                    selectedVariety = $(this).attr('data-value');\n                });\n\n                self.__updateVariety(identifier, selectedVariety);\n            });\n\n        $element.find('.fp-dropdown-substitution-type').dropdown({\n            ariaLabel: fp.ui.locale('aria-label-dropdown-substitution', 'Select substitution type'),\n            onChange: function(value) {\n                if(self.config.intent != 'product_admin') {\n                    self.__updateSubstitutionType(value, $(this).closest('.fp-product-variety-list-item').attr('data-list-item-id'));\n                }\n                if(value == util.map.get('substitutionType').get('specific_substitution').id) {\n                    var $parent = $element.find(util.formatString('[data-list-item-id=\"{0}\"]', $(this).closest('.fp-product-variety-list-item').attr('data-list-item-id')));\n                    if(!$parent.length) $parent = $element;\n                    $parent.find('button[data-action=\"search-substitution\"]').trigger('click');\n                }\n            }\n        });\n\n        $element.find('#fp-checkbox-substitution-type:checkbox').change(function() {\n            if(self.config.intent != 'product_admin') {\n                var $this = $(this),\n                    mapSubstitutionType = util.map.get('substitutionType'),\n                    substituteValue = mapSubstitutionType.get('no_substitution').id;\n\n                if($this.is(\":checked\")) substituteValue = mapSubstitutionType.get('best_comparable').id;     \n\n                self.__updateSubstitutionType(substituteValue, $this.closest('.fp-product-variety-list-item').attr('data-list-item-id'));\n            }\n        });\n\n        $element.find('[data-toggle=\"tab\"]').tab();\n\n        if(config.readMore && config.readMore.enabled){\n            var $itemDesc = $element.find('.fp-item-details .fp-item-description'),\n                readMoreHeight = parseInt($itemDesc.css('lineHeight'), 10),\n                lineCount = util.getFloat(config.readMore.lineCount, 3);\n\n            if(readMoreHeight) {\n                readMoreHeight = readMoreHeight * lineCount + util.getInteger(config.readMore.lineHeightOffset);\n            }\n            else {\n                readMoreHeight = parseInt($itemDesc.css('fontSize'), 10) * 1.176 * lineCount;\n            }\n\n            $element.find('.fp-item-description-content').readmore({\n                selector: '.fp-item-description-content',\n                moreLink: util.formatString('<a href=\"javascript:;\" class=\"fp-read-more\">{0}</a>', config.readMore.moreLinkLabel),\n                lessLink: util.formatString('<a href=\"javascript:;\" class=\"fp-read-more-close\">{0}</a>', config.readMore.lessLinkLabel),\n                collapsedHeight: Math.floor(readMoreHeight)\n            });\n\n            if(config.readMore.enableNutritionalFacts) {\n                var $nutritionalFacts = $element.find('[data-role=\"nutritional-facts-body\"]').hide();\n\n                $element.find('[data-section=\"nutrition\"]')\n                    .append($(util.formatString(\n                        '<a href=\"javascript:;\" class=\"fp-read-more fp-margin-left\" data-role=\"nutrition-read-more\">{0}</a><a href=\"javascript:;\" class=\"fp-read-more-close fp-margin-left hidden\" data-role=\"nutrition-read-less\">{1}</a>',\n                        config.readMore.moreLinkLabel,\n                        config.readMore.lessLinkLabel\n                    )));\n\n                $element\n                    .on('click', '[data-role^=\"nutrition-read\"]', function(event) {\n                        var $this = $(this);\n                        if ($this.attr('data-role') == 'nutrition-read-more') {\n                            $nutritionalFacts.slideDown('fast', function () {\n                                $this\n                                    .addClass('hidden')\n                                    .next().removeClass('hidden');\n                            });\n                        }\n                        else {\n                            $nutritionalFacts.slideUp('fast', function () {\n                                $this\n                                    .addClass('hidden')\n                                    .prev().removeClass('hidden');\n                            });\n                        }\n                    });\n            }\n        }\n\n        $element\n            .toggleClass('fp-is-item-in-list', listManager.getItem(item.id, true) != null)\n            .removeClass('fp-has-departments')\n            .addClass('fp-product-detail')\n            .on('click', '.fp-item-images > .fp-item-image', function(event) {\n                event.preventDefault();\n                var src = fp.S.getString($(this).find('img').attr('src'));\n                $element.find('.fp-item-details .fp-item-image-large > img:first')\n                    .attr('src', fp.config.enableImageOptimization ? util.getImageSrc(src, 'large') : src.replace('_medium', '_large'));\n            })\n            .on('click', '.fp-row-details .fp-item-favorite', function(event) {\n                event.preventDefault();\n                if(self.config.intent == 'product_admin') return;\n\n                var $this = $(this),\n                    $icon = $this.find('.fp-icon'),\n                    isFavorite = $icon.hasClass('fp-icon-favorite'),\n                    itemId = $this.data('product-id');\n\n                if($this.hasClass('fp-is-favorite')) $this.removeClass('fp-is-favorite');\n                else $this.addClass('fp-is-favorite');\n\n                var promise = service.userProductService\n                    .post({\n                        product_id: itemId,\n                        is_favorite: !isFavorite\n                    })\n                    .done(function(resp) {\n                        item.is_favorite = scope.userProduct.is_favorite = resp.is_favorite;\n                        fp.trigger(fp.events.PRODUCT_FAVORITED, {product: item});\n                    });\n\n                new fp.ui.Loading({\n                    appendTo: $this,\n                    promiseHide: promise,\n                    showOnInstantiate: true,\n                    destroyOnHide: true\n                });\n            })\n            .off('click.searchSubstitution')\n            .on('click.searchSubstitution', 'button[data-action=\"search-substitution\"], button[data-action=\"change-substitution\"]', function(event) {\n                event.preventDefault();\n                var $target = $(event.target),\n                    $parent = $element.find(util.formatString('[data-list-item-id=\"{0}\"]', $target.closest('.fp-product-variety-list-item').attr('data-list-item-id')));\n\n                if(!$parent.length) $parent = $element;\n                var $itemNote = $parent.find('[data-role=\"item-note\"]').first(),\n                    $saveNote = $itemNote.find('.fp-btn-save-note'),\n                    $itemSubstitution = $parent.find('[data-role=\"item-substitution\"]').first();\n\n                fp.trigger(fp.events.PRODUCTS_MODAL_SHOW, {\n                    mode: 'search',\n                    title: fp.ui.locale('shared-search-substitution-title', 'Search Product Substitution'),\n                    substitutionMode: true,\n                    promise: service.productSubstitutionSuggestionService.get({\n                        product_id: scope.item.id,\n                        store_id: fp.store.id\n                    }),\n                    onAddSubstitute: function(product) {\n                        if(product) {\n                            $itemSubstitution.text(fp.S('Substitution: UPC: ' + ((fp.config.enableLikeCode && product.like_code) || product.identifier) + ' ' + product.name).trim().s);\n                            $parent.find(\".fp-item-substitution-action\").removeClass('hidden');\n                            $parent.find('[data-action=\"search-substitution\"]').addClass('hidden');\n                            $parent.find(\".fp-dropdown-substitution-type\").addClass('hidden');\n                            $saveNote.trigger('click');\n                        }\n                    }\n                });\n            })\n            .on('click', 'button[data-action=\"clear-substitution\"]', function(event) {\n                event.preventDefault();\n  \n                var $target = $(event.target),\n                    $parent = $element.find(util.formatString('[data-list-item-id=\"{0}\"]', $target.closest('.fp-product-variety-list-item').attr('data-list-item-id')));\n                    \n                if(!$parent.length) $parent = $element;\n                var $itemNote = $parent.find('[data-role=\"item-note\"]').first(),\n                    $saveNote = $itemNote.find('.fp-btn-save-note'),\n                    $itemSubstitution = $parent.find('[data-role=\"item-substitution\"]').first();\n                    $itemSubstitution.text(\"\");\n                    $parent.find(\".fp-item-substitution-action\").first().addClass('hidden');\n                    $parent.find('[data-action=\"search-substitution\"]').first().removeClass('hidden');\n                    $parent.find(\".fp-dropdown-substitution-type\").first().removeClass('hidden');\n                    $saveNote.trigger('click');\n            })\n            .on('click', '.fp-btn-edit-note', function(event, disableSubstitution) {\n                if(self.config.intent == 'product_admin') return;\n\n                var $target = $(event.target),\n                    $parent = $target.closest('.fp-product-variety-list-item');\n                if(!$parent.length) $parent = $element;\n\n                var $itemNote = $target.closest('[data-role=\"item-note\"]').addClass('fp-is-item-note-open');\n                $itemNote.find('.fp-item-save-note').removeClass('hidden');\n                $itemNote.find('.fp-input-note').focus();\n            })\n            .on('click', '.fp-btn-save-note', function(event) {\n                if(self.config.intent == 'product_admin') return;\n\n                var $target = $(event.target),\n                    $itemNote = $target.closest('[data-role=\"item-note\"]').removeClass('fp-is-item-note-open'),\n                    $parent = $itemNote.closest('.fp-product-variety-list-item'),\n                    listItemId = $itemNote.closest('.fp-product-variety-list-item').find('[data-list-item-id]').attr('data-list-item-id'),\n                    listItem = listItemId ? listManager.getItem(listItemId) : listManager.getItem(item.id, true);\n\n                if(!$parent.length) $parent = $element;\n                let substitution = $parent.find('[data-role=\"item-substitution\"]').first().text(),\n                    note = fp.S($itemNote.find('.fp-input-note').val()).trim().append(' ').append(substitution).trim().s;\n\n                if ((listItemId && listItem) || (listItem && !_.size(item.varieties))) {\n                    fp.trigger(fp.events.LIST_ITEM_UPDATE, {listManager: listManager, item: {id: listItem.id, note: note}});\n                }\n                \n                if(!_.size(item.varieties)) {\n                    service.userProductService.create({product_id: item.id, note: note})\n                        .done(function(resp) {\n                            scope.userProduct.note = resp.note;\n                        });\n                }\n\n                // $itemNote.find('.fp-item-edit-note').removeClass('hidden');\n                $itemNote.find('.fp-item-save-note').addClass('hidden');\n                $itemNote.find('.fp-item-note').text(note);\n                $itemNote.find('.fp-btn-edit-note').text(fp.ui.locale('shared-edit', 'Edit')).trigger('focus');\n\n                if(!fp.S(note).trim().s) {\n                    var addText = fp.ui.locale('shared-add-notes', 'Add Notes');\n                    if(item.note_configuration && item.note_configuration.label){\n                        addText = item.note_configuration.label;\n                    }\n                    $itemNote.find('.fp-btn-edit-note').text(addText);\n                }\n            })\n            .on('click', '[data-action=\"show-offer-disclaimer\"]', function(event) {\n                event.preventDefault();\n\n                var clippableOffer = item.clippable_offer;\n                if(!(clippableOffer && clippableOffer.offer_disclaimer)) return;\n\n                fp.ui.showModal({\n                    name: 'offer-disclaimer',\n                    className: 'fp-offer-disclaimer-modal',\n                    title: fp.S.getString(clippableOffer.brand, fp.ui.locale('shared-disclaimer', fp.ui.locale('shared-disclaimer', 'Disclaimer'))),\n                    content: clippableOffer.offer_disclaimer\n                });\n            })\n            .on('click', '[data-action=\"clip-offer\"]', function(event) {\n                event.preventDefault();\n\n                if(!item.clippable_offer) return;\n\n                if(item.clippable_offer.is_clipped) {\n                    fp.ui.showOfferModal(item.clippable_offer);\n                    return;\n                }\n\n                var $this = $(this),\n                    hasProducts = _.size(item.clippable_offer.product_ids) > 0;\n\n                fp.ui.clipOffer(item.clippable_offer, {$button: $this, /*disableCouponUpSell: !hasProducts,*/ apiOptions: {errorSelector: self.$element.find('form[name=\"fp-form-product-detail\"] [data-role=\"notification\"]')}})\n                    .done(function() {\n                        $this\n                            .toggleClass('fp-is-offer-clipped', util.getBoolean(item.clippable_offer.is_clipped))\n                            .toggleClass('fp-disabled', util.getBoolean(item.clippable_offer.is_clipped && !hasProducts));\n                    });\n            })\n            .on('click', '[data-action=\"show-offer\"]', function(event) {\n                event.preventDefault();\n\n                if(!item.clippable_offer) return;\n\n                fp.ui.showOfferModal(item.clippable_offer, {target: event.target});\n            })\n            .on('click', '.fp-btn-select-store', function(event) {\n                if(!fp.config.enableSeePriceModal) return;\n\n                event.preventDefault();\n                event.stopImmediatePropagation();\n\n                fp.ui.showShopIntentModal({\n                    force: true,\n                    fulfillmentIdentifier: 'price',\n                    next:  stateManager.href(fp.config.routeStates.productDetail, {id: item.id}, {canonical_url: item.canonical_url})\n                });\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            .on('keydown', '.fp-other-product-link', function(event) {\n                if(event.keyCode === fp.constants.keycode.ENTER){\n                    scope.optionKepress = $(this).attr('data-identifier');\n                }\n            });\n\n        if(_.size(item.available_subscription_programs)) {\n            $element.find('.fp-dropdown-subscription-quantity').dropdown();\n            $element.find('.fp-dropdown-subscription-frequency').dropdown();\n\n            $element\n                .on('click', '[data-action$=\"-product-subscription\"]', function(event) {\n                    event.preventDefault();\n\n                    fp.ui.updateProductSubscription({\n                        button: this,\n                        product: item,\n                        listManager: self.config.listManager\n                    });\n                });\n        }\n\n        if(fp.config.enableBreinify) {\n            $element\n                .on('click', '[data-action=\"alert-me\"]', function(event) {\n                    event.preventDefault();\n                    fp.ui.showAlertMeModal(event, item);\n                });\n        }\n        var $navTabs = $element.find('.fp-nav-tabs'),\n            $tabContent = $element.find('.tab-content');\n        \n        if ($navTabs.length > 0 && $navTabs.children()) {\n            $navTabs.children().first().addClass('active');\n            $tabContent.children().first().addClass('active');\n            \n            if ($navTabs.children().length == 0) $navTabs.addClass('hidden');\n        }\n\n        this.__bindProductActions();\n\n        fp.trigger(fp.events.MODULE_RENDERED, {\n            name: config.name,\n            product: item,\n            productTagTypes: scope.productTagTypes\n        });\n\n        if(config.intent != 'modal') {\n            fp.trigger(fp.events.TRACK_EVENT, _.defaults({\n                label: item.name,\n                items: [item]\n            }, fp.constants.trackingEvents.ViewContent));\n        }\n    },\n    __updateVariety: function(id, value) {\n        var scope = this.scope,\n            $element = this.$element,\n            item = scope.item,\n            identifier = id,\n            listManager = this.config.listManager,\n            payload;\n\n        if (!scope.enableVarieties && listManager.getItem(item.id, true)) {\n            payload = {product_id: item.id};\n\n            if (value) payload[identifier] = value;\n            else payload[identifier + '_clear'] = true;\n\n            fp.trigger(fp.events.LIST_ITEM_UPDATE, {listManager: listManager, item: payload});\n            return;\n        }\n\n        $element.find('input[name=\"fp-variety-' + id + '\"]').val(value);\n        \n        //we need to be able to default the variety dropdown based off of prior selection\n        scope.userProduct.varieties[identifier] = value;\n\n        if (util.isAuthenticated() && !util.isGuestUser()) {\n            payload = {product_id: item.id};\n\n            if(value) payload[identifier] = value;\n            else payload[identifier + '_clear'] = true;\n\n            service.userProductService\n                .create(payload)\n                .done(function(resp) {\n                    scope.userProduct.varieties = _.getObject(resp.varieties);\n                });\n        }\n    },\n    __updateSubstitutionType: function(substituteValue, itemId) {\n        var scope = this.scope,\n            listManager = this.config.listManager,\n            item = _.getObject(scope.params.item, scope.item);\n           \n\n        var listItem;\n        if(!scope.enableVarieties && (listItem = listManager.getItem(item.id, true))) {\n                fp.trigger(fp.events.LIST_ITEM_UPDATE, {\n                    listManager: listManager,\n                    item: {id: listItem.id, substitution_type_id: substituteValue}\n                });\n        }\n        else {\n            service.userProductService\n                .create({product_id: item.id, substitution_type_id: substituteValue})\n                .done(function(resp) {\n                    scope.userProduct.substitution_type_id = resp.substitution_type_id;\n                });\n        }\n    },\n    /* My Code Start Here - Sayed - If we find a specific ID(Specific Substitution) then:\n    * Add a button next to the Saved Edit note\n    * Open the text edit field\n    * If the word substitution doesn't exist put it in the field\n    * Reverse changes if the id changes \n    * Open search functionality On the newly created button\n    * Once a specific item is selected, put the upc and item name in the text field and save it.\n    * If the user click on the edit button, remove the previous substitution item and search the new item.\n    * There is a new template for the substitution search modal in the UI.Core.js \n    */\n    __specificSubstitution: function(id, itemId) {\n        var $element = this.$element;\n\n        var $parent = $element.find(util.formatString('[data-list-item-id=\"{0}\"]', itemId));\n        if(!$parent.length) $parent = $element;\n\n        var $itemNote = $parent.find('[data-role=\"item-note\"]').first(),\n            $inputNote = $itemNote.find('.fp-input-note'),\n            $editButton = $itemNote.find('.fp-btn-edit-note'),\n            $saveNote = $itemNote.find('.fp-btn-save-note'),\n            isEditMode = $itemNote.hasClass('fp-is-item-note-open');\n\n        if(!id) {\n            id = $parent.find('.fp-col-substitution-type').first().find('[name=\"fp-input-substitution_type_id\"]').val();\n        }\n\n        $element.off('click.searchSubstitution');\n\n        if(util.map.get('substitutionType').get(id).identifier == 'specific_substitution') {\n            if(!isEditMode) $editButton.trigger('click', true);\n            if(!$itemNote.find('button[data-action=\"search-substitution\"]').length) {\n                var searchSubstitutions = fp.ui.localef('shared-search-substitutions', '<button type=\"button\" class=\"fp-btn fp-btn-sm pull-right\" data-action=\"search-substitution\">{0}</button>', 'Search Substitutions');\n                $saveNote.after(searchSubstitutions);\n            }\n\n            $element\n                .on('click.searchSubstitution', 'button[data-action=\"search-substitution\"]', function(event) {\n                    event.preventDefault();\n\n                    fp.trigger(fp.events.PRODUCTS_MODAL_SHOW, {\n                        mode: 'search',\n                        title: fp.ui.locale('shared-search-substitution-title', 'Search Product Substitution'),\n                        substitutionMode: true,\n                        promise: service.productSubstitutionSuggestionService.get({\n                            product_id: scope.item.id,\n                            store_id: fp.store.id\n                        }),\n                        onAddSubstitute: function(product) {\n                            if(product) {\n                                var note = $inputNote.val();\n                                note = note.replace(/(\\n+)?Substitution:.*(\\n+)?/gim, '');\n                                $inputNote.val(fp.S(note + '\\n\\nSubstitution: UPC: ' + ((fp.config.enableLikeCode && product.like_code) || product.identifier) + ' ' + product.name).trim().s);\n                                $saveNote.trigger('click');\n                            }\n                        }\n                    });\n                });\n        }\n        else {\n            $editButton.trigger('click', true);\n            $inputNote.val(fp.S($inputNote.val()).replace(/(\\n+)?Substitution:.*(\\n+)?/gim, ''));\n            if(!isEditMode) $saveNote.trigger('click');\n            $itemNote.find('button[data-action=\"search-substitution\"]').remove();\n        } \n    },\n    __loadVideo: function(video) {\n        var $element = this.$element;\n\n        $element.find('[data-role=\"video\"]')\n            .removeClass('hidden')\n            .html(fp.ui.renderTemplate('component/0/youtube.html', {\n                youtubeUrl: video\n            }));\n    },\n    __attachScopeEvents: function() {\n        this._super();\n\n        var config = this.config;\n        if(config.intent == 'product_admin') return;\n\n        var self = this,\n            $scope = $(this.scope),\n            listManager = config.listManager,\n            enableRoutes = !_.contains(['modal', 'show-detail'], config.intent);\n\n        if(enableRoutes) {\n            var storeId = fp.store.id;\n\n            $scope\n                .on(fp.events.VIEW_MODULE_RENDERED, function(event, payload) {\n                    if(self.scope.optionKepress){\n                        self.$element.find('.fp-is-selected [data-identifier=\"'+ self.scope.optionKepress +'\"]').focus();\n                        delete self.scope.optionKepress;\n                    }\n                })\n                .on(fp.events.STORE_CHANGED, function (event, payload) {\n                    if(S(storeId).eq(fp.store.id)) return;\n                    storeId = fp.store.id;\n                    $scope.off();\n                    self.init(true);\n                })\n                .on(fp.events.ROUTE_BEFORE_CHANGE, function(event, payload) {\n                    if (!fp.loaded) return;\n                    else if(!self.scope.stateManager.isDetail(['id', 'product_id'], payload.toParams)) {\n                        fp.ui.setMetaDescription();\n                        return;\n                    }\n\n                    fp.ui.blockUI();\n\n                    self.__deferredRouteChange = $.Deferred();\n                    payload.clientParams.promises.push(self.__deferredRouteChange.promise());\n\n                    //payload.clientParams.scrollTo = true;\n                })\n                .on(fp.events.ROUTE_CHANGED, function(event, payload) {\n                    if(!self.scope.stateManager.isDetail(['id', 'product_id'])) {\n                        $(document.body).removeClass('fp-state-product-detail');\n                        self.destroyChildComponents();\n                        return;\n                    }\n\n                    var promise;\n                    if(fp.S.getString(payload.fromParams.id ||\n                            payload.fromParams.product_id) != fp.S.getString(payload.toParams.id ||\n                            payload.toParams.product_id)\n                    ) {\n                        promise = self.init();\n                    }\n\n                    $.when(promise)\n                        .always(function () {\n                            if(!self.__deferredRouteChange) return;\n                            self.__deferredRouteChange.resolve();\n                            delete self.__deferredRouteChange;\n                        });\n                });\n\n            if(!self.scope.stateManager.isDetail(['id', 'product_id'])) return;\n        }\n\n        const onListItemsRefreshed = function(event, payload) {\n            if(payload.listManager.getList().id != listManager.getList().id) return;\n            if(enableRoutes && !self.scope.stateManager.isDetail(['id', 'product_id'])) return;\n\n            self.render();\n        };\n\n        $scope\n            .on(fp.events.LIST_ITEMS_REFRESHED, onListItemsRefreshed)\n            .on(fp.events.ORDER_LIST_ITEMS_REFRESHED, onListItemsRefreshed)\n            .on(fp.events.LIST_ITEM_BEFORE_CHANGE, function(event, payload) {\n                var scope = self.scope;\n                if(self.config.intent == 'default' && !scope.stateManager.isDetail(['id', 'product_id'])) return;\n\n                var item = scope.item;\n\n                if(payload.item.product_id != item.id) return;\n\n                var listItemChangeType = fp.constants.listItemChangeType;\n                switch(payload.itemChangeType) {\n                    case listItemChangeType.ADD:\n                        if(_.size(item.varieties)) {\n                            var substitution = self.$element.find('[data-role=\"item-substitution\"]').first().text(),\n                                note = fp.S(self.$element.find('textarea[name=\"fp-input-note\"]').first().val()).append(' ' + substitution).trim().s;\n                            if(note) payload.note = note;\n                            // payload.note = scope.userProduct.note;\n                        }\n                        break;\n                }\n            })\n            .on(fp.events.LIST_ITEM_CHANGED, function(event, payload) {\n                var scope = self.scope;\n                if(config.intent == 'default' && !scope.stateManager.isDetail(['id', 'product_id'])) return;\n\n                var item = scope.item;\n\n                if(payload.item.product_id != item.id) return;\n\n                var listItemChangeType = fp.constants.listItemChangeType;\n                switch(payload.itemChangeType) {\n                    case listItemChangeType.UPDATE_VARIETY:\n                        if(scope.enableVarieties && config.enableVarietyUpdate) {\n                            var $form = self.$element.find('form[name=\"fp-form-product-detail\"]'),\n                                listItem = payload.item,\n                                $input,\n                                $parent;\n\n                            $form.find('[data-role=\"item-action-lg\"]').removeAttr('data-list-item-id');\n\n                            $form.find(util.formatString('.fp-product-variety-list-item[data-list-item-id=\"{0}\"] .fp-product-variety', listItem.id))\n                                .html(fp.S.getString(fp.ui.ListManager.getItemVariety(listItem, true), item.name));\n\n                            $form.find('[name^=\"fp-variety-\"]')\n                                .each(function() {\n                                    $input = $(this);\n                                    $parent = $input.parent();\n                                    if($parent.hasClass('fp-dropdown')) {\n                                        var dropdown = $parent.data('fp.ui.Component');\n                                        dropdown.setValue('');\n                                        if(dropdown) dropdown.onChange();\n                                    }\n                                    else {\n                                        $input.val('');\n                                    }\n                                });\n                        }\n                        break;\n                    case listItemChangeType.INCREMENT:\n                        var listItems = listManager.getItem(payload.item.product_id, {isProductId: true, multiple: true}),\n                            quantity = 0;\n\n                        _.each(listItems, function(item) {\n                            quantity += fp.ui.ListManager.getItemQuantity(item);\n                        });\n\n                        self.$element.find('[data-role=\"product-variety-quantity\"]').text(util.getItemQuantityLabel(_.firstObject(listItems), quantity));\n                        break;\n                    case listItemChangeType.SUBSCRIPTION:\n                        var listItem = listManager.getItem(payload.item.product_id, {isProductId: true});\n                        self.$element.find('[data-role=\"product-subscription\"]').html(\n                            fp.ui.renderTemplate('component/0/product-subscription-add.html', {\n                                productSubscriptionStatus: scope.productSubscriptionStatus, \n                                availableSubcriptionPrograms: scope.item.available_subscription_programs, \n                                updatedSubscriptionItem: listItem.my_current_subscription, \n                                listItem: listItem\n                            })\n                        );\n\n                        self.$element.find('.fp-dropdown-subscription-quantity, .fp-dropdown-subscription-frequency').dropdown();\n                        break;\n                    // default:\n                    //     self.$element.toggleClass('fp-is-item-in-list', listManager.getItem(item.id, true) != null);\n                    //     break;\n                }\n            })\n            .on(fp.events.PRODUCT_FAVORITED, function(event, payload){\n                if(!util.isAuthenticated()) return;\n                if(self.config.intent == 'default' && !self.scope.stateManager.isDetail(['id', 'product_id'])) return;\n\n                var $item = self.$element.find('.fp-item-details'),\n                    $productFavorite = self.$element.find('.fp-item-favorite[data-product-id=\"' + payload.product.id + '\"]');\n\n                if(!$productFavorite.length) return;\n\n                var $icon = $item.find('.fp-icon'),\n                    className = 'fp-icon-favorite',\n                    startClassName = className,\n                    isFavorite = $icon.hasClass(className),\n                    $label = $item.find('.fp-favorite-label'),\n                    labelText;\n\n                if(isFavorite) {\n                    $icon.removeClass(className);\n                    labelText = $label.data('add-text');\n                    className += '-o';\n                }\n                else {\n                    startClassName += '-o';\n                    $icon.removeClass(startClassName);\n                    labelText = $label.data('remove-text');\n                }\n                $label.text(labelText);\n                $icon.addClass(className);\n            });\n    },\n    __bindProductActions: function() {\n        if(this.config.intent == 'product_admin') return;\n\n        var item = this.scope.item,\n            $itemDetails = this.$element.find('.fp-item-details'),\n            $itemAction = $itemDetails.find('[data-role=\"item-action-lg\"]'),\n            listManager = this.config.listManager;\n\n        new fp.ui.ProductActions($itemAction, {\n            item: item,\n            disableInList: _.size(item.varieties) > 0,\n            listManager: listManager\n        }, null, this);\n\n        this.$element.find('.fp-product-variety-list .fp-item-action').each(function() {\n            new fp.ui.ProductActions(this, {item: item, listManager: listManager});\n        }, null, this);\n\n\n        var hashedProducts = this.scope.linkedOffers && this.scope.linkedOffers.hashedProducts;\n        if(_.size(hashedProducts)) {\n            $itemDetails.find('.fp-product-list .fp-item-action').each(function () {\n                item = hashedProducts[$(this).attr('data-product-id')];\n                if(item) {\n                    new fp.ui.ProductActions(this, {\n                        item: item,\n                        listManager: listManager\n                    }, null, this);\n                }\n            });\n        }\n    },\n    __promiseOtherProduct: function(type, item, otherProductTypes){\n        let promiseOtherProduct;\n\n        if(item[type.identifier]){\n            let selectedOtherProduct = {\n                id: item.id, \n                canonical_url: item.canonical_url, \n                product_size: item.product_size, \n                price: item.price,\n                sale_price: item.sale_price\n            };\n            selectedOtherProduct[type.sort] = item[type.sort];\n            selectedOtherProduct[type.productLabelType] = item[type.productLabelType];\n            promiseOtherProduct = service.productService\n            .get({\n                fields: 'canonical_url,price,sale_price,base_price,' + type.productLabelType,\n                id: item[type.identifier][0].product_ids.join()\n            })\n            .done(function(resp) {\n                otherProducts = resp.items;\n                otherProducts.push(selectedOtherProduct);\n                otherProducts = _.sortBy(otherProducts, type.sort);\n                otherProducts = {\n                    identifier: type.identifier,\n                    label: item[type.identifier][0].label,\n                    products : otherProducts,\n                    productLabelType: type.productLabelType\n                }\n                otherProductTypes.push(otherProducts);\n            });\n        }\n\n        return promiseOtherProduct;\n    }\n});\n\nreturn fp.Module.ProductDetail;\n//# sourceURL=module/product-detail/product-detail.js"}