(function(){'use strict';var customerData,storage=$.storage.ns('mage-cache-storage'),storageInvalidation=$.storage.ns('mage-cache-storage-section-invalidation');function invalidateCacheBySessionTimeOut(settings){var date=new Date(Date.now()+parseInt(settings.cookieLifeTime,10)*1000);if(new Date(storage.get('mage-cache-timeout'))0){this.reload(sectionNames);}},getExpiredSectionNames:function(){var expiredSectionNames=storageInvalidation.keys(),cookieSectionTimestamps=$.cookies.getJson('section_data_ids')||{},sectionLifetime=this.options.expirableSectionLifetime*60,currentTimestamp=Math.floor(Date.now()/ 1000),sectionData;_.each(this.options.expirableSectionNames,function(sectionName){sectionData=storage.get(sectionName);if(sectionData&§ionData.data_id+sectionLifetime<=currentTimestamp){expiredSectionNames.push(sectionName);}});_.each(cookieSectionTimestamps,function(cookieSectionTimestamp,sectionName){sectionData=storage.get(sectionName);if(!sectionData||sectionData.data_id!=cookieSectionTimestamp){expiredSectionNames.push(sectionName);}});expiredSectionNames=_.intersection(expiredSectionNames,$.sections.getSectionNames());return _.uniq(expiredSectionNames);},reload:function(sections,forceNewSectionTimestamp){var params={};if(!this.options){return this.invalidate(sections);} sections=sections||[];if(sections.length){params.sections=sections.join(',');} if(forceNewSectionTimestamp){params.force_new_section_timestamp=true;} $.request.get({url:this.options.sectionLoadUrl,data:params,accept:'json',success:function(data){var sectionDataIds=$.cookies.getJson('section_data_ids')||{};$.each(data,function(sectionName,sectionData){if(sectionName==='messages'){sectionData={data_id:sectionData.data_id,messages:[]};} sectionDataIds[sectionName]=sectionData.data_id;storage.set(sectionName,sectionData);storageInvalidation.remove(sectionName);$.sections.set(sectionName,sectionData);});$(document).trigger('customer-data-reload',{sections:sections,response:data});$.cookies.setJson('section_data_ids',sectionDataIds,{domain:false});}});},invalidate:function(sections){var sectionDataIds=$.cookies.getJson('section_data_ids')||{};sections=_.contains(sections,'*')?$.sections.getSectionNames():sections;$(document).trigger('customer-data-invalidate',{sections:sections});storage.remove(sections);$(sections).filter(function(){return!$.sections.isClientSideSection(this);}).each(function(){sectionDataIds[this]+=1000;storageInvalidation.set(this,true);});$.cookies.setJson('section_data_ids',sectionDataIds,{domain:false});}};$(document).on('customerData:reload',function(event,data){customerData.reload(data.sections,data.forceNewSectionTimestamp);});$(document).on('customerData:invalidate',function(event,data){customerData.invalidate(data.sections);});$(document).on('breeze:load',function(){customerData.initialize(window.customerDataConfig);window.customerDataCmp=customerData;});})();