{"html":"<% if(config.intent === 'slot-picker') return; %>\n<div class=\"container fp-container-checkout-banner\">\n    <div class=\"fp-table-display\">\n        <% if(fulfillmentTypeASAP) { %>\n            <div class=\"fp-row\">\n                <div class=\"fp-cell fp-cell-title\">\n                    <h3 aria-level=\"2\" class=\"fp-banner-title\"><span class=\"fp-value\"><%= fulfillmentLabelHtml %></span></h3>\n                </div>\n                <div class=\"fp-cell fp-cell-checkout-btn\">\n                    <a href=\"<%= config.customCheckOutUrl ? config.customCheckOutUrl : fp.ui.getCheckoutUrl() %>\" class=\"fp-btn fp-btn-checkout\" data-role=\"trigger-checkout\"><%= fp.ui.locale('shared-checkout', 'Checkout') %></a>\n                </div>\n            </div>\n        <% } else if(fp.config.shopIntent.enabled && !_.size(items)) { %>\n        <% if(fulfillmentType.identifier == 'drop_ship') { %>\n        <div class=\"fp-row fp-row-title\">\n            <div class=\"fp-cell fp-cell-title\">\n                <h3 aria-level=\"2\" class=\"fp-banner-title\"><span class=\"fp-value\">Order now from <a href=\"javascript:void(0);\" class=\"fp-btn-selected-store\" data-action=\"show-shop-intent-modal\" role=\"button\" title=\"<%= fp.store.name %>, <%= (shopIntentCallout || fp.ui.locale('checkout-banner-select-one', 'select to view other locations')) %>\"><%- fp.store.name %></a>!</span></h3>\n            </div>\n            <div class=\"fp-cell fp-cell-checkout-btn\">\n                <a href=\"<%= config.customCheckOutUrl ? config.customCheckOutUrl : fp.ui.getCheckoutUrl() %>\" class=\"fp-btn fp-btn-checkout\" data-role=\"trigger-checkout\"><%= fp.ui.locale('shared-checkout', 'Checkout') %></a>\n            </div>\n        </div>\n        <% } else { %>\n        <div class=\"fp-row\">\n            <div class=\"fp-cell fp-cell-title\">\n                <h3 aria-level=\"2\" class=\"fp-banner-title\"><span class=\"fp-value\"><%= fulfillmentLabelHtml %></span></h3>\n                <% if(shopIntentCallout !== '') { %>\n                <a href=\"javascript:void(0);\" class=\"fp-btn-selected-store\" data-action=\"show-shop-intent-modal\" role=\"button\" title=\"tilte no custom\"><%= (shopIntentCallout || fp.ui.locale('checkout-banner-select-one', 'select to view other locations')) %></a>\n                <% } %>\n            </div>\n        </div>\n        <% } %>\n        <% } else { %>\n        <div class=\"fp-row fp-row-title\">\n            <div class=\"fp-cell fp-cell-title\">\n                <h3 aria-level=\"2\" class=\"fp-banner-title\"><span class=\"fp-value\"><%= fulfillmentLabelHtml %></span></h3>\n                <% if(obj.storeSetting && !config.turnOffAvailability && !(!hasStoreSlotLabel && config.turnOffNoSlotModel)) { %>\n                    <% if (!config.customTimeSlotLabel) { %>\n                        <a href=\"javascript:void(0);\" class=\"fp-btn-available-times\" role=\"button\" data-role=\"trigger-available-times\" title=\"select to view other locations\"><%= fp.ui.locale('checkout-banner-view-available', 'View other available times') %></a>\n                    <% } else { %> \n                        <a href=\"javascript:void(0);\" class=\"fp-btn-available-times\" role=\"button\" data-role=\"trigger-available-times\" title=\"select to view other locations\"><%= fp.ui.locale('checkout-banner-view-available', config.customTimeSlotLabel) %></a>\n                    <% } %>\n                <% } %>\n            </div>\n            <div class=\"fp-cell fp-cell-checkout-btn\">\n                <a href=\"<%= config.customCheckOutUrl ? config.customCheckOutUrl : fp.ui.getCheckoutUrl() %>\" class=\"fp-btn fp-btn-checkout\" data-role=\"trigger-checkout\"><%= fp.ui.locale('shared-checkout', 'Checkout') %></a>\n            </div>\n        </div>\n        <div class=\"fp-row fp-row-available-btn\">\n            <div class=\"fp-cell\">\n                <% if(!config.turnOffAvailability) { %> \n                    <a href=\"javascript:void(0);\" class=\"fp-btn-available-times\" role=\"button\" data-role=\"trigger-available-times\" title=\"select to view other locations\"><%= fp.ui.locale('checkout-banner-view-available', 'View other available times') %></a>\n                <% }%> \n            </div>\n        </div>\n        <% if(config.subTitle) { %>\n        <div class=\"fp-row\">\n            <div class=\"fp-cell fp-cell-sub-title\">\n                <% \n                    var fulfillmentTypeName = fulfillmentType && fulfillmentType.name; \n                    if(fulfillmentTypeName) fulfillmentTypeName = fulfillmentTypeName.toLowerCase();\n                %>\n                <h4 class=\"fp-banner-sub-title\"><%- util.formatString(config.subTitle, fulfillmentTypeName )%></h4>\n            </div>\n        </div>\n        <% } %>\n        <% } %>\n    </div>\n</div>","js":"fp.Module.CheckoutBanner = fp.Module.extend({\n    construct: function(element, config, template, parent) {\n        this._super(element, config, template, parent);\n\n        _.defaults(this.config, {\n            calloutCheckoutInterval: 5 * 60 * 1000, //every 5 minutes\n            initializeOnStoreChange: true,\n            enableLocale: true,\n            enableCalendarTimeDisplay: false,\n            enableCalendarDisplay: false,\n            calendarDisplayLimit: 180,\n            enableOrderBy: true\n        });\n\n        if(this.config.enableCalendarDisplay) {\n            this.dependencies.load.file.push('flatpickr.js');\n        }\n\n        // if(fp.isLocal()) {\n        //     this.config.calloutCheckoutInterval = 15 * 1000; //every 15 seconds for testing\n        // }\n    },\n    init: function (autoRender) {\n        clearTimeout(this.__calloutCheckoutTimeoutId);\n\n        if(this.config.intent === 'slot-picker') {\n            this.scope.fulfillmentType = this.fulfillmentType;\n            return this._super(autoRender);\n        }\n\n        this.fulfillmentType = {\n            config: {}\n        };\n\n        if(!util.map.get('fulfillmentType').items().length) {\n            this.$element.addClass('hidden').attr('hidden', '');\n            return $.when();\n        }\n\n        const self = this,\n            scope = this.scope,\n            config = this.config;\n\n        return this._super(false)\n            .then(function() {\n                return util.map.load({\n                    service: service.serviceProviderConfigurationService,\n                    payload: {\n                        service_provider_type: 'checkout_setting'\n                    }\n                });\n            })\n            .then(this.__loadStoreSlots.bind(this))\n            .always(function() {\n                let fulfillmentLabelHtml = '',\n                    fulfillmentType = self.fulfillmentType,\n                    storeSlot = _.firstObject(scope.items),\n                    slotDateLabel = fp.ui.getFulfillmentSlotDateTimeLabel(storeSlot),\n                    fulfillmentTypeOptions = util.getObjectFromNamespace('config.slot_selection.options', fulfillmentType),\n                    fulfillmentTypeASAP = fulfillmentTypeOptions && fulfillmentTypeOptions.length === 1 && _.first(fulfillmentTypeOptions).identifier === 'asap' && _.first(fulfillmentTypeOptions),\n                    slotSetting = _.find(util.map.get('spcCheckoutSetting').items(), function(item) {\n                        return item.fulfillment_type_id === fulfillmentType.id && item.service_provider.identifier === 'slot_settings'\n                    });\n\n                if(fulfillmentTypeASAP){\n                    fulfillmentLabelHtml = util.formatString(\n                        '<span>{0}<span><br/>{1}',\n                        fulfillmentTypeASAP.title,\n                        fulfillmentTypeASAP.instruction\n                    );\n                }\n                else if (slotDateLabel.date && fp.dateFns.isValid(slotDateLabel.date)) {\n                    const isToday = fp.dateFns.isToday(slotDateLabel.date);\n\n                    let toForIdentifier = false;\n                    if(fulfillmentType.identifier === 'pickup'){\n                        if(fp.S(fulfillmentType.name).toLowerCase().s === 'in-store pick up') toForIdentifier = false;\n                        else toForIdentifier = true;\n                    }\n\n                    if(config.customLabel) {\n                        fulfillmentLabelHtml = util.formatString(\n                            config.customLabel,\n                            util.encodeForHtml(fp.S(fulfillmentType.name).toLowerCase().s),\n                            '<span class=\"fp-checkout-banner-time\">' + util.getStateValue(isToday, util.encodeForHtml(slotDateLabel.timeLabel), util.encodeForHtml(slotDateLabel.label)) + '</span>'\n                        );\n                    }\n                    else if(config.customLabelWithStoreName) {\n                        fulfillmentLabelHtml = util.formatString(\n                            config.customLabelWithStoreName,\n                            util.getStateValue(toForIdentifier, fp.ui.locale('checkout-banner-to', 'to'), fp.ui.locale('checkout-banner-for', 'for')),\n                            util.encodeForHtml(fp.S(fulfillmentType.name).toLowerCase().s),\n                            fulfillmentType.identifier === 'pickup' ? fp.ui.locale('shared-at', 'at') : fp.ui.locale('shared-from', 'from'),\n                            fp.store.name,\n                            util.getStateValue(isToday, slotDateLabel.hasEndTime ? fp.ui.locale('shared-today-between', 'today between') : fp.ui.locale('shared-today-at', 'today at')),\n                            '<span class=\"fp-checkout-banner-time\">' + util.getStateValue(isToday, util.encodeForHtml(slotDateLabel.timeLabel), util.encodeForHtml(slotDateLabel.label)) + '</span>',\n                            fp.config.shopIntent.enabled ? util.formatString(' from <a href=\"javascript:void(0);\" class=\"fp-btn-selected-store\" role=\"button\" data-action=\"show-shop-intent-modal\" title=\"' + util.encodeForHtml(fp.store.name) + ', select to view other locations\">{0}</a>', util.encodeForHtml(fp.store.name)) : null\n                        );\n                    }\n                    else {\n                        fulfillmentLabelHtml = util.formatString(\n                            fp.ui.locale('checkout-banner-order-now', 'Order now') + ' {0} {1} {2} {3}{4}!',\n                            util.getStateValue(toForIdentifier, fp.ui.locale('checkout-banner-to', 'to'), fp.ui.locale('checkout-banner-for', 'for')),\n                            util.encodeForHtml(fp.S(fulfillmentType.name).toLowerCase().s),\n                            util.getStateValue(isToday, slotDateLabel.hasEndTime ? fp.ui.locale('shared-today-between', 'today between') : fp.ui.locale('shared-today-at', 'today at')),\n                            '<span class=\"fp-checkout-banner-time\">' + util.getStateValue(isToday, util.encodeForHtml(slotDateLabel.timeLabel), util.encodeForHtml(slotDateLabel.label)) + '</span>',\n                            fp.config.shopIntent.enabled ? util.formatString(' from <a href=\"javascript:void(0);\" class=\"fp-btn-selected-store\" role=\"button\" data-action=\"show-shop-intent-modal\" title=\"' + util.encodeForHtml(fp.store.name) + ', select to view other locations\">{0}</a>', util.encodeForHtml(fp.store.name)) : null\n                        );\n                    }\n                }\n                else {\n                    let shopIntentConfig = fp.config.shopIntent;\n                    fulfillmentLabelHtml = slotSetting?.config?.custom_no_slot_message;\n                    if (!fulfillmentLabelHtml) {\n                        if(config.customNoSlotMessage) {\n                            fulfillmentLabelHtml = config.customNoSlotMessage;\n                        }\n                        else {\n                            if(shopIntentConfig.enabled){\n                                let fulfillmentTypes = util.map.get('fulfillmentType').items(),\n                                hashedEnabledFulfillmentTypes = _.size(shopIntentConfig.fulfillmentTypes) && _.indexBy(shopIntentConfig.fulfillmentTypes),\n                                enabledFulfillmentTypes = [];\n\n                                _.each(fulfillmentTypes, function (item) {\n                                    var fulfillmentLabel = item.name.toLowerCase();\n                                    if(config.enableFulfillmentLabelUpper) fulfillmentLabel = item.name;\n                                    if(!hashedEnabledFulfillmentTypes || _.has(hashedEnabledFulfillmentTypes, item.identifier)) {\n                                        \n                                        enabledFulfillmentTypes.push(fulfillmentLabel);\n                                    }\n                                });\n\n                                if(enabledFulfillmentTypes.length > 1) {\n                                    var last = enabledFulfillmentTypes.pop();\n                                    fulfillmentLabelHtml = enabledFulfillmentTypes.join(', ') + ' or ' + last;\n                                }\n                                else {\n                                    fulfillmentLabelHtml = enabledFulfillmentTypes[0];\n                                }\n                                fulfillmentLabelHtml = util.formatString(fp.ui.locale('shared-looking-for', 'Looking for {0}') + '?', fulfillmentLabelHtml);\n                            }\n                        }\n                    }\n                }\n                scope.hasStoreSlotLabel = slotDateLabel.date && fp.dateFns.isValid(slotDateLabel.date);\n                self.storeSlot = storeSlot;\n                self.slotDateLabel = slotDateLabel;\n                scope.fulfillmentLabelHtml = fulfillmentLabelHtml;\n                scope.fulfillmentType = fulfillmentType;\n                scope.fulfillmentTypeASAP = fulfillmentTypeASAP;\n                scope.storeSetting = slotSetting;\n                scope.shopIntentCallout = slotSetting?.config?.enable_shop_intent_callout === false ? '' : (slotSetting?.config?.shop_intent_callout || config.shopIntentCallout);\n                  \n                if(util.getBoolean(autoRender, true)) {\n                    self.render();\n                }\n            });\n    },\n    render: function(params) {\n        this._super(params);\n\n        const scope = this.scope,\n            $element = this.$element,\n            config = this.config;\n\n        if(config.intent !== 'slot-picker') {\n            const slotSelection = fp.util.getObjectFromNamespace('config.slot_selection', scope.fulfillmentType);\n\n            if(util.getStateValue(fp.store.id === fp.config.hideColumnStoreId, true, false)) {\n                $element.addClass('fp-hidden');\n            }\n            else {\n                $element\n                    .css('display', 'block');\n\n                if(scope.fulfillmentType.id){\n                    $element.toggleClass('fp-has-list-quantity', fp.ui.ListManager.getListQuantity() > 0);\n                }\n            }\n\n            if(\n                !(fp.config.shopIntent.enabled || _.size(scope.items) || config.customNoSlotMessage || scope.fulfillmentTypeASAP) ||\n                (scope.fulfillmentType.identifier === 'drop_ship' && config?.drop_ship?.hide) ||\n                (slotSelection?.mode === 'do_not_allow')\n            ) {\n                $element.addClass('hidden').attr('hidden', '');\n                return;\n            }\n\n            if (this.slotDateLabel.date && this.fulfillmentType.id) {\n                $element\n                    .on('click', '[data-role=\"trigger-checkout\"]', this.__onTriggerCheckout.bind(this));\n    \n                $element.find('[data-role=\"trigger-checkout\"]')\n                    .attr('data-slot-id', this.storeSlot.id)\n                    .attr('data-fulfillment-type-id', this.fulfillmentType.id);\n            }\n        }\n\n        let $modal = this.__$availableTimesModal;\n        if(!_.size($modal)) {\n            this.__$availableTimesModal = $modal = fp.__$freshop.find('[data-role=\"modal-container\"] [data-role=\"checkout-available-times-modal\"]');\n        }\n        if(!_.size($modal)) {\n            const modalTemplate = fp.ui.getTemplate('component/0/available-times-modal.html');\n            if (modalTemplate) {\n                this.__$availableTimesModal = $modal = $(fp.ui.renderTemplate(modalTemplate, null, null, true))\n                    .modal({\n                        show: false\n                    });\n            }\n        }\n\n        if(_.size($modal)) {\n            $modal.toggleClass('fp-checkout-available-times-picker-modal', this.config.intent === 'slot-picker');\n\n            const $parentElement = this.config.intent === 'slot-picker' ? this.parent.$element : $element;\n\n            $parentElement\n                .off('click', '[data-role=\"trigger-available-times\"]')\n                .on('click', '[data-role=\"trigger-available-times\"]', this.__onShowAvailableTimes.bind(this));\n\n            if(config.customAvailableTimeHeading){\n                $modal.find('.fp-heading [data-role=\"value\"]')\n                    .text(fp.ui.locale('checkout-banner-availability', config.customAvailableTimeHeading ));\n            }\n            else {\n                $modal.find('.fp-heading [data-role=\"value\"]')\n                    .text(this.fulfillmentType.name + ' ' + fp.ui.locale('checkout-banner-availability', 'Availability' ));\n            }\n\n            var hasListQuantity = fp.ui.ListManager.getListQuantity() > 0;\n            $modal.find('.fp-heading [data-role=\"list-quantity-warning\"]')\n                .toggleClass('hidden', hasListQuantity)\n                .toggleAttr('hidden', '', hasListQuantity);\n        }\n    },\n    __attachScopeEvents: function() {\n        this._super();\n\n        if(this.config.intent !== 'slot-picker') {\n            const self = this;\n\n            $(this.scope)\n                .on(fp.events.LIST_LOADED, function (event, payload) {\n                    if (!fp.loaded || payload.listManager.getList().id != fp.listManager.getList().id) return;\n\n                    self.init();\n                })\n                .on(fp.events.FULFILLMENT_TYPE_CHANGED, this.init.bind(this));\n        }\n    },\n    __loadStoreSlots: function() {\n        var self = this,\n            hasFulfillmentStore = fp.hasStoreFulfillment(),\n            items,\n            fulfillmentType,\n            deferred;\n\n        if(hasFulfillmentStore) {\n            deferred = $.Deferred();\n\n            fp.getDefaultStoreFulfillmentType(null, {\n                    handleErrors: false\n                })\n                .then(function (resp) {                 \n                    if (!resp) return;\n\n                    fulfillmentType = resp;\n                    if(!fulfillmentType.config) fulfillmentType.config = {};\n\n                    var fulfillmentTypeOptions = fp.util.getObjectFromNamespace('config.slot_selection.options', fulfillmentType);\n                    if(fulfillmentTypeOptions && fulfillmentTypeOptions.length === 1 && _.first(fulfillmentTypeOptions).identifier === 'asap') {\n                        return;\n                    }\n\n                    if(fulfillmentType.identifier !== 'drop_ship') {\n                        var listId = fp.listManager.getList().id,\n                            payload = {      \n                                for_order_id: util.getUndefinedIfEmpty(fp.session.preference.order_id),                          \n                                for_shopping_list_id: (listId && listId !== fp.defaultList.id) ? listId : undefined,\n                                store_id: self.config.forStoreId || fp.store.id,\n                                fulfillment_type_id: fulfillmentType.id,\n                                is_available: true,\n                                fields: 'id,sequence,fulfillment_type_id,location_id,location,date,time,slot_start,slot_end,booking_close_minutes_prior,additional_fee',\n                                sort: 'date',\n                                limit: 1,\n                                intent: 'teaser'\n                            },\n                            promise;\n                            \n                        if(fulfillmentType.identifier === 'delivery') {\n                            var address = Lockr.get('deliveryAddress'),\n                                fieldValue;\n\n                            if(!_.size(address)) {\n                                promise = service.userMeService.applyAddress();\n                            }\n\n                            promise = $.when(promise)\n                                .then(function() {\n                                    address = _.size(address) ? address : fp.user.address;\n                                    if(_.size(address)) {\n                                        _.each(['address_1', 'city', 'state', 'postal_code'], function(key) {\n                                            if(fieldValue = fp.S(address[key]).trim().s) {\n                                                payload[util.formatString('fulfillment_{0}', key)] = fieldValue;\n                                            }\n                                        });\n                                    }\n                                });\n                        }\n\n                        if(fp.store.id) {\n                            return $.when(promise)\n                                .then(function() {\n                                    return service.storeSlotService\n                                        .get(payload, {handleErrors: false})\n                                        .done(function (resp) {\n                                            items = resp.items;\n                                        });\n                                });\n                        }\n                        else return promise;\n                    }\n                })\n                .always(deferred.resolve);\n        }\n\n        return $.when(deferred)\n            .then(function() {\n                self.fulfillmentType = _.getObject(fulfillmentType);\n                if(!self.fulfillmentType.config) self.fulfillmentType.config = {};\n                self.scope.items = items;\n\n                if(hasFulfillmentStore && self.fulfillmentType.identifier !== 'drop_ship') {\n                    self.__calloutCheckoutTimeoutId = setTimeout(function () {\n                        self.init();\n                    }, self.config.calloutCheckoutInterval);\n                }\n            });\n    },\n    __onTriggerCheckout: function(event) {\n        const config = this.config;\n\n        if(config.intent !== 'slot-picker' && config.customCheckOutUrl) {\n            return;\n        }\n\n        event.preventDefault();\n\n        const $this = $(event.currentTarget),\n            $modal = this.__$availableTimesModal,\n            scope = this.scope;\n\n        if(config.intent === 'slot-picker') {\n            const slotId = $this.attr('data-slot-id');\n            let day = S(slotId).split('-'),\n                slot;\n\n            day.shift();\n            day = day.join('-');\n\n            slot = _.findWhere(scope.hashedSlots[day], {id: slotId});\n\n            if(_.isFunction(config.onSlotSelected)) {\n                config.onSlotSelected(slot);\n            }\n        }\n        else {\n            fp.trigger(fp.events.LIST_CHECKOUT, {\n                listManager: fp.listManager,\n                fulfillment_type_id: $this.attr('data-fulfillment-type-id'),\n                slot_id: $this.attr('data-slot-id')\n            });\n        }\n\n        if(_.size($modal)) {\n            var bsModal = $modal.data('bs.modal');\n            if(bsModal?.isShown) $modal.modal('hide');\n        }\n    },\n    __onShowAvailableTimes: function(event, startDate) {\n        event?.preventDefault();\n\n        var $modal = this.__$availableTimesModal;\n\n        if(!_.size($modal)) return $.when();\n\n        const bsModal = $modal.data('bs.modal'),\n            isShown = bsModal?.isShown,\n            config = this.config;\n\n        if(!bsModal) {\n            $modal.modal({\n                show: true\n            });\n        }\n\n        if(!config.slotLimit){\n            if(config.enableCalendarTimeDisplay) config.slotLimit = 50;\n            else config.slotLimit = 8;\n        }\n\n        const self = this,\n            $body = $modal.find('.modal-body .fp-modal-content'),\n            $seeMore = $body.find('[data-role=\"trigger-see-more\"]'),\n            listId = fp.listManager.getList().id,\n            payload = {\n                for_shopping_list_id: (listId && listId !== fp.defaultList.id) ? listId : undefined,\n                store_id: config.forStoreId || fp.store.id,\n                fulfillment_type_id: this.fulfillmentType.id,\n                is_available: true,\n                fields: 'id,sequence,fulfillment_type_id,location_id,location,date,time,slot_start,slot_end,booking_close_minutes_prior,additional_fee,message',\n                sort: 'date',\n                limit: config.slotLimit,\n                for_order_id: util.getUndefinedIfEmpty(config.forOrderId),\n                intent: config.intent === 'slot-picker' ? undefined : 'teaser'\n            };\n\n        let isAdvanced = false,\n            selectedDay = this.scope.stateParams.day,\n            selectedSlot,\n            promise;\n\n        if(config.enableCalendarDisplay) {\n            if(!startDate) {\n                selectedSlot = config.getSelectedSlot && config.getSelectedSlot();\n                startDate = fp.dateFns.parse(selectedSlot?.date, fp.serverDateFormat);\n                if(!fp.dateFns.isValid(startDate)) {\n                    const minMaxDates = config.getMinMaxDates && config.getMinMaxDates();\n                    startDate = minMaxDates?.minDate;\n                    if(!fp.dateFns.isValid(startDate)) startDate = new Date();\n                }\n            }\n            isAdvanced = fp.dateFns.isValid(startDate);\n        }\n\n        if(isAdvanced) {\n            selectedDay = util.formatDate(startDate, fp.serverDateFormat);\n            const now = new Date(),\n                maxDate = fp.dateFns.addDays(now, config.calendarDisplayLimit > 0 ? config.calendarDisplayLimit : 180);\n            now.setHours(0,0,0,0);\n            startDate = fp.dateFns.addDays(startDate, -7);\n            if(startDate < now) startDate = now;\n            let finishDate = fp.dateFns.addDays(startDate, 14);\n            if(finishDate > maxDate) finishDate = maxDate;\n\n            payload.start_date = util.formatDate(startDate, fp.serverDateFormat);\n            payload.finish_date = util.formatDate(finishDate, fp.serverDateFormat);\n        }\n\n        if(this.fulfillmentType.identifier === 'delivery') {\n            var address,\n                fieldValue;\n\n            if(_.isFunction(config.getAddress)) {\n                address = config.getAddress();\n            }\n\n            if(!_.size(address)) {\n                address = Lockr.get('deliveryAddress');\n            }\n            \n            if(!_.size(address)) {\n                promise = service.userMeService.applyAddress();\n            }\n\n            promise = $.when(promise)\n                .then(function() {\n                    address = _.size(address) ? address : fp.user.address;\n                    if(_.size(address)) {\n                        _.each(['address_1', 'city', 'state', 'postal_code'], function(key) {\n                            if(fieldValue = fp.S(address[key]).trim().s) {\n                                payload[util.formatString('fulfillment_{0}', key)] = fieldValue;\n                            }\n                        });\n                    }\n                });\n        }\n\n        if(!isShown) {\n            this.itemCount = 0;\n            $body.html(fp.ui.renderTemplate('component/0/animated-loading.html'));\n        }\n        else {\n            $seeMore.addClass('fp-animated-loading-container');\n\n            if(config.slotLimit > 0) {\n                payload.limit *= 2;\n                payload.skip = self.itemCount;\n            }\n        }\n\n        $modal.modal('show');\n\n        delete self.scope.slotNoMatchingAddress;\n\n        return $.when(promise)\n            .then(function() {\n                return service.storeSlotService\n                    .get(payload);\n            })\n            .done(function(resp) {\n                var bodyHtml = '',\n                    itemCount = _.size(resp.items),\n                    storeSlotMessage = [],\n                    noMatchingAddress,\n                    noMatchingProduct;\n\n                self.itemCount += itemCount;\n                \n                // Handle reasons if they exist in the response\n                if (_.size(resp.reasons)) {\n                    _.each(resp.reasons, function(item) {\n                        if(item.reason_message_md) storeSlotMessage.push(util.makeSanitizedHtml(item.reason_message_md));\n                        if(item.reason_code === 'undeliverable_delivery_area') {\n                            noMatchingAddress = true;\n                        }\n                        else if(item.reason_code === 'no_matching_slots_by_product') {\n                            noMatchingProduct = true;\n                        }\n                    });\n                    self.scope.slotNoMatchingAddress = noMatchingAddress;\n                }\n\n                if(itemCount || (isAdvanced && !noMatchingAddress)) {\n                    var content,\n                        location,\n                        slotDateLabel,\n                        message,\n                        fulfillmentType = self.fulfillmentType,\n                        fulfillmentTypeLabel = fp.S(fulfillmentType.name).toLowerCase().s,\n                        hasItems = fp.ui.ListManager.getListQuantity() > 0;\n                    \n                    if(config.enableCalendarTimeDisplay) {\n                        //var storeSlotsHash = _.indexBy(resp.items, 'date');\n                        var storeSlots = [],\n                            hashedSlots = {},\n                            slotLabelOptions = {\n                                dateFormat: fp.config.fulfillmentShortDateFormat,\n                                timeFormat: fp.config.fulfillmentShortTimeFormat\n                            };\n                        \n                        _.each(resp.items, function(item) {\n                            item.dateTimeLabel = fp.ui.getFulfillmentSlotDateTimeLabel(item, slotLabelOptions);\n\n                            storeSlot = hashedSlots[item.date];\n                            if(!storeSlot) storeSlot = hashedSlots[item.date] = [];\n                            storeSlot.push(item);\n                        });\n\n                        _.each(hashedSlots, function(item, key) {\n                            storeSlots.push({id: key, name: item[0].dateTimeLabel.dateLabel, items: util.sort(item, 'time')});\n                        });\n                        \n                        bodyHtml = fp.ui.renderTemplate('component/0/calendar-with-time-slots.html', {\n                            storeSlotsHash : hashedSlots,\n                            fulfillmentType: self.scope.fulfillmentType,\n                            enableOrderBy: self.config.enableOrderBy,\n                            enableCalendarDisplay: config.enableCalendarDisplay,\n                            selectedSlotId: selectedSlot?.id\n                        });\n                        self.scope.hashedSlots = hashedSlots;\n                    }\n                    else {\n                        _.each(resp.items, function(item) {\n                            slotDateLabel = fp.ui.getFulfillmentSlotDateTimeLabel(item);\n\n                            content = fp.dateFns.isToday(slotDateLabel.date) ? fp.ui.locale('shared-today', 'Today') + ' ' + (fulfillmentTypeLabel === 'pick up' ? fp.ui.locale('shared-at', 'at') + ' ' : fp.ui.locale('shared-between', 'between') + ' ') + slotDateLabel.timeLabel : slotDateLabel.label;\n                            location = item.location ? '<div class=\"fp-margin-top-sm\">' + item.location + '</div>' : '';\n                            message=item.message?'('+item.message+')':'';\n                            \n                            if(hasItems) {\n                                bodyHtml += ' \\\n                                    <div class=\"row\" ' + util.getStateValue(hasItems, 'data-role=\"trigger-checkout\" data-slot-id=\"' + item.id + '\" data-fulfillment-type-id=\"' + payload.fulfillment_type_id + '\"') + '> \\\n                                        <div class=\"col-md-12\"> \\\n                                            <a href=\"javascript:;\">' + content + '</a> \\\n                                            ' + location + '<br/> <span class=\"fp-slot-message\">'+ message +'</span>\\\n                                        </div>\\\n                                    </div> \\\n                                ';\n                            }\n                            else {\n                                bodyHtml += ' \\\n                                    <div class=\"row\"> \\\n                                        <div class=\"col-md-12\"> \\\n                                            ' + content + ' \\\n                                            ' + location + '<br/> <span class=\"fp-slot-message\">'+ message +'</span> \\\n                                        </div> \\\n                                    </div> \\\n                                ';\n                            }\n                        });\n                    }\n                }\n\n                // Display reasons as messages if any\n                if (storeSlotMessage.length) {\n                    bodyHtml = '<div class=\"fp-notification fp-warning show\">' + storeSlotMessage.join('<br>') + '</div>' + bodyHtml;\n                }\n\n                if(self.itemCount >= util.getInteger(resp.total)) {\n                    $seeMore.hide();\n                    $seeMore.attr('aria-expanded', 'true');\n                }\n\n                if(isShown && !isAdvanced) {\n                    let $prevItem;\n                    if($(event?.target).hasClass('fp-see-more-times')) {\n                        $prevItem = $seeMore.closest('[data-role=\"trigger-see-more\"]').prev();\n                    }\n\n                    $seeMore\n                        .removeClass('fp-animated-loading-container')\n                        .before(bodyHtml);\n\n                    if($prevItem) {\n                        let $focusParent = $prevItem.next('[data-role=\"trigger-checkout\"]');\n                        if(!$focusParent.length) $focusParent = $prevItem;\n                        $focusParent.find('a').trigger('focus');\n                    }\n                    return;\n                }\n\n                var checkOutBannerText = fp.config.customCheckOutBannerText ? fp.config.customCheckOutBannerText : fp.ui.locale(\"checkout-banner-see-more\", \"See More Times\" );\n\n                if(bodyHtml) {\n                    bodyHtml = ' \\\n                        <div class=\"fp-table fp-table-editable\"> \\\n                            <div class=\"fp-table-body\">' + bodyHtml + ' \\\n                                <div class=\"row\" data-role=\"trigger-see-more\" aria-expanded=\"false\"> \\\n                                    <div class=\"col-md-12\"> \\\n                                        <a href=\"javascript:;\" class=\"fp-see-more-times\" role=\"button\">' + checkOutBannerText + '</a> \\\n                                        <div class=\"fp-overlay\"></div>' + fp.ui.renderTemplate('component/0/animated-loading.html') + ' \\\n                                    </div> \\\n                                </div> \\\n                            </div> \\\n                        </div> \\\n                    ';\n                }\n\n                $body\n                    .off()\n                    .html(bodyHtml)\n                    .on('click', '[data-role=\"trigger-checkout\"]', self.__onTriggerCheckout.bind(self))\n                    .on('click', '[data-role=\"trigger-see-more\"]', function(event) {\n                        event.preventDefault();\n                        self.__onShowAvailableTimes(event);\n                    });\n                \n                if(config.enableCalendarTimeDisplay) {\n                    self.__refreshCalenderSlotTimes();\n\n                    $body\n                        .on('click', 'input[name=\"input-day\"]', function (event, selectedSlot) {\n                            const $target = $(this);\n                            $target.prop('checked', true).next('label').attr({tabindex: '0', 'aria-checked': 'true'});\n                            \n                            const value = $target.val(),\n                                $moreDays = $body.find('[data-role=\"slot-buttons\"]').find('label[for=\"fp-input-more-days\"]');\n                            let selectedSlots;\n\n                            if(config.enableCalendarDisplay && value === 'more') {\n                                $moreDays[0]?._flatpickr?.toggle();\n                            }\n                            else {\n                                $moreDays[0]?._flatpickr?.close();\n                                selectedSlots = self.scope.hashedSlots[value];\n                                $body.find('[data-role=\"slot-list\"]').html(\n                                    fp.ui.renderTemplate('component/0/calendar-with-time-slots/times.html', {\n                                        selectedSlots: selectedSlots,\n                                        fulfillmentType: self.scope.fulfillmentType,\n                                        enableOrderBy: config.enableOrderBy,\n                                        selectedSlotId: selectedSlot?.id\n                                    })\n                                );\n                            }\n                            self.__refreshCalenderSlotTimes(event, selectedSlots);\n                        })\n                        .on('click keydown', '[data-action^=\"toggle-list-group\"]', function(event) {\n                            if(\n                                event.type === 'click' ||\n                                (event.keyCode === fp.constants.keycode.SPACE || event.keyCode === fp.constants.keycode.ENTER)\n                            ) {\n                                event.preventDefault();\n                                const $this = $(this);\n                                $this.closest('.list-group').toggleClass('fp-list-group-show-all');\n                                $this.parent().find('[data-action^=\"toggle-list-group\"]:visible').trigger('focus');\n                            }\n                        })\n                        .on('click', 'input[name=\"fp-input-fulfillment_slot_id\"]', self.__onTriggerCheckout.bind(self))\n                        .on('keydown', 'input[name=\"fp-input-fulfillment_slot_id\"] + label [role=\"radio\"]', function (event) {\n                            if(event.keyCode === fp.constants.keycode.SPACE || event.keyCode === fp.constants.keycode.ENTER) {\n                                event.preventDefault();\n                                $(this).parent().prev('input[type=\"radio\"]').trigger('click');\n                            }\n                        })\n                        .on('blur', 'input[name=\"input-day\"] + label', function (event) {\n                            const $target = $(event.target);\n                            if(!$target.prev()[0].checked) $target.attr({tabindex: '-1'});\n                        })\n                        .on('keydown', 'input[name=\"input-day\"] + label', function (event) {\n                            const $target = $(event.target),\n                                keyCodes = fp.constants.keycode,\n                                $moreDays = self.__$availableTimesModal.find('[data-role=\"slot-buttons\"]').find('label[for=\"fp-input-more-days\"]');\n\n                            if(config.enableCalendarDisplay && $moreDays[0]?._flatpickr?.isOpen) {\n                                return;\n                            }\n\n                            switch(event.keyCode) {\n                                case keyCodes.UP:\n                                case keyCodes.LEFT:\n                                    setCheckedFocus('up');\n                                    break;\n                                case keyCodes.DOWN:\n                                case keyCodes.RIGHT:\n                                    setCheckedFocus('down');\n                                    break;\n                                case keyCodes.SPACE:\n                                case keyCodes.ENTER:\n                                    $target.prev('input').trigger('click');\n                                    break;\n                                case keyCodes.TAB:\n                                    $body.find('[data-role=\"slot-buttons\"]').find('input[name=\"input-day\"]:not(:checked) + label').attr('tabindex', '-1');\n                                    break;\n                                default:\n                                    break;\n                            }\n    \n                            function setCheckedFocus(direction) {\n                                const $radios = $body.find('[data-role=\"slot-buttons\"]').find('input[name=\"input-day\"] + label');\n                                let focusedIndex;\n                                $radios.each(function(index) {\n                                    if(this === $target[0]) {\n                                        focusedIndex = index;\n                                        return false;\n                                    }\n                                });\n                                if(focusedIndex >= 0) {\n                                    if(direction === 'up') {\n                                        focusedIndex--;\n                                        if(focusedIndex < 0) {\n                                            focusedIndex = $radios.length - 1;\n                                        }\n                                    }\n                                    else {\n                                        focusedIndex++;\n                                        if(focusedIndex === $radios.length) {\n                                            focusedIndex = 0;\n                                        }\n                                    }\n\n                                    $($radios[focusedIndex]).attr('tabindex', '0').trigger('focus');\n                                }\n                            }\n                        });\n\n                    //delay a few milliseconds to ensure proper scrollTo of day\n                    _.delay(function () {\n                        let $selectedRadio;\n                        if(selectedDay) {\n                            $selectedRadio = $body.find(`[data-role=\"slot-buttons\"] input[id$=\"${selectedDay}\"]:first`);\n                        }\n                        if(!$selectedRadio?.length) {\n                            $selectedRadio = $body.find('[data-role=\"slot-buttons\"] input[name=\"input-day\"]:first');\n                        }\n\n                        $selectedRadio.trigger('click', selectedSlot);\n\n                        self.__initDatePicker();\n                    }, 200);\n                }\n            });\n    },\n    __refreshCalenderSlotTimes: function(event, selectedSlots) {\n        const scope = this.scope,\n            $modal = this.__$availableTimesModal || fp.__$freshop.find('[data-role=\"modal-container\"] [data-role=\"checkout-available-times-modal\"]'),\n            $slots = $modal.find('[data-role=\"slot-list\"]').find('[data-role=\"slot-order-by\"]');\n\n        if(event) {\n            const $slotButtons = $modal.find('[data-role=\"slot-buttons\"]'),\n                $checked = $slotButtons.find('input[type=\"radio\"]:checked').next('label');\n            if($checked.length) $slotButtons.scrollTo($checked, {axis: 'x', speed: 'fast'});\n        }\n\n        if($slots.length) {\n            if(!selectedSlots) {\n                var selectedDay = (scope.fulfillmentSlot && scope.fulfillmentSlot.date) || scope.stateParams.day;\n                if(selectedDay && !_.has(scope.hashedSlots, selectedDay)) selectedDay = null;\n                if(!selectedDay) selectedDay = _.first(_.keys(scope.hashedSlots));\n\n                selectedSlots = scope.hashedSlots[selectedDay];\n            }\n        }\n\n        if(this.config.enableOrderBy && _.size(selectedSlots)) {\n            clearInterval(this.__intervalStoreSlots);\n            this.__intervalStoreSlots = setInterval(function() {\n                var $slot,\n                    slotId;\n                    \n                $slots.each(function() {\n                    $slot = $(this);\n                    slotId = $slot.attr('data-slot-id');\n                    $slot.html(fp.ui.getSlotOrderByHtml(_.findWhere(selectedSlots, {id: slotId})));\n                });\n            }, 1000);\n\n            $modal\n                .off('hide.bs.modal.availableTimes')\n                .on('hide.bs.modal.availableTimes', function() {\n                    clearInterval(this.__intervalStoreSlots);\n                    $modal.find('[data-role=\"slot-buttons\"]').find('label[for=\"fp-input-more-days\"]')[0]?._flatpickr?.destroy();\n                });\n        }\n    },\n    __initDatePicker: function () {\n        const self = this,\n            $moreDays = this.__$availableTimesModal.find('[data-role=\"slot-buttons\"]').find('label[for=\"fp-input-more-days\"]');\n        if(this.config.enableCalendarDisplay && !$moreDays[0]?._flatpickr) {\n            const stateManager = this.scope.stateManager,\n                now = _.now();\n\n            $moreDays.flatpickr({\n                disableMobile: true,\n                allowInput: true,\n                wrap: true,\n                onOpen: function(selectedDates, dateStr, instance) {\n                    $(instance.calendarContainer).addClass('fp-flatpickr-calendar-modal');\n                },\n                onChange: function(selectedDates, dateStr, instance) {\n                    const promise = self.__onShowAvailableTimes(null, selectedDates[0])\n                        .done(function() {\n                            self.__$availableTimesModal.find('[data-role=\"slot-buttons\"]').find('label[aria-checked=\"true\"]').trigger('focus');\n                        });\n\n                    new fp.ui.Loading({\n                        appendTo: $moreDays,\n                        promiseHide: promise,\n                        showOnInstantiate: true,\n                        destroyOnHide: true\n                    });\n                },\n                appendTo: this.__$availableTimesModal[0],\n                altInput: true,\n                altFormat: fp.config.calendarDateFormat,\n                locale: fp.config.locale || 'en',\n                minDate: now,\n                maxDate: fp.dateFns.addDays(now, this.config.calendarDisplayLimit > 0 ? this.config.calendarDisplayLimit : 180)\n            });\n        }\n    }\n});\n\nreturn fp.Module.CheckoutBanner;\n//# sourceURL=module/checkout-banner/checkout-banner.js"}