var e;e=()=>(()=>{var e={545:(e,t,n)=>{n.r(t),n.d(t,{createWrapper:()=>f,resolveWhen:()=>y});class o extends Error{constructor(e,t){super(t),this.name=e}}class i extends o{constructor(e,t){2===arguments.length&&(e+=` (Received: ${JSON.stringify(t)})`),super("ValidationError",`[Validation] ${e}`)}}function a(e,t){if("function"!=typeof e)throw new i(`${t} is not a function`,e)}function r(e,t){if(null===e||"object"!=typeof e)throw new i(`${t} is not an object`,e)}function s(e){let t=!0;if(e&&"object"==typeof e&&!Array.isArray(e)){t=!1;for(const n in e)if("boolean"!=typeof e[n]){t=!0;break}}if(t)throw new i("Consent Categories should be {[categoryName: string]: boolean}",e)}const l=new class{get debugLoggingEnabled(){return!0===window.SEGMENT_CONSENT_WRAPPER_DEBUG_MODE}enableDebugLogging(){window.SEGMENT_CONSENT_WRAPPER_DEBUG_MODE=!0}debug(...e){this.debugLoggingEnabled&&console.log("[consent wrapper debug]",...e)}};class d{constructor(){this.isAbortCalled=!1,this.isLoadCalled=!1,this.abortLoadOptions={loadSegmentNormally:!0},this.loadOptions={consentModel:"opt-in"}}load(e){this.isLoadCalled=!0,this.loadOptions={...this.loadOptions,...e},l.debug("ctx.load called",this.loadOptions)}abort(e){this.isAbortCalled=!0,this.abortLoadOptions={...this.abortLoadOptions,...e},l.debug("Abort consent wrapper",this.loadOptions)}validate(){if(this.isAbortCalled&&this.isLoadCalled)throw new i("both abort and load should not be called")}}const c=(e,...t)=>{const n=t.reduce(((e,t)=>n=>t(e(n))),(e=>e));return(...t)=>n(e(...t))},g=e=>{return t=Object.values(e).reduce(((e,t)=>e.concat(t))),Array.from(new Set(t));var t},u=(e,t)=>!(!t||t.hasUnmappedDestinations)&&Object.keys(e).filter((t=>e[t])).every((e=>!t.allCategories.includes(e))),p=(e,t,n,o={})=>{const{integrationCategoryMappings:i,shouldEnableIntegration:a}=o,r=(i?i[e]:(e=>{if(e&&"object"==typeof e&&"consentSettings"in e&&"object"==typeof e.consentSettings&&e.consentSettings&&"categories"in e.consentSettings&&Array.isArray(e.consentSettings.categories))return e.consentSettings.categories||void 0})(t.integrations[e]))??[];return a?a(r,n,{creationName:e}):((e,t)=>!e||!e.length||e.every((e=>t[e])))(r,n)};class h{get analytics(){return b(this.uninitializedAnalytics)}get cdnSettings(){return this.cdnSettingsDeferred.promise}async getAllCategories(){return(this.settings.integrationCategoryMappings?g(this.settings.integrationCategoryMappings):(await this.cdnSettings).consentSettings?.allCategories)??[]}async getCategories(){const e=await this.settings.getCategories();return s(e),e}constructor(e,t){var n,o,a,s;this.cdnSettingsDeferred=(a=!1,s=new Promise((function(e,t){n=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];a=!0,e.apply(void 0,t)},o=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];a=!0,t.apply(void 0,e)}})),{resolve:n,reject:o,promise:s,isSettled:function(){return a}}),this.createDisableOption=(e,t)=>!0===t||(n=>u(e,n.consentSettings)||"function"==typeof t&&t(n)),function(e){if(r(e,"analytics"),!("load"in e&&"addSourceMiddleware"in e&&"addDestinationMiddleware"in e&&"track"in e))throw new i("analytics is not an Analytics instance",e)}(e),this.settings=t,this.uninitializedAnalytics=e,this.ogAnalyticsLoad=e.load.bind(e)}async loadWithFilteredDeviceModeDestinations(...[e,t]){const n=await this.getCategories();return this.load(e,{...t,updateCDNSettings:c((e=>((e,t,n)=>{const{remotePlugins:o,integrations:i}=e,{integrationCategoryMappings:a,shouldEnableIntegration:r}=n,s={...e,remotePlugins:[...o||[]],integrations:{...i}},d=n=>p(n,e,t,{integrationCategoryMappings:a,shouldEnableIntegration:r});for(const e in i)d(e)?l.debug(`Enabled (opt-in): ${e}`):(l.debug(`Disabled (opt-in): ${e}`),s.remotePlugins=o?.filter((t=>t.creationName!==e)),delete s.integrations[e]);return s})(e,n,{shouldEnableIntegration:this.settings.shouldEnableIntegration,integrationCategoryMappings:this.settings.integrationCategoryMappings})),t?.updateCDNSettings??(e=>e)),disable:this.createDisableOption(n,t?.disable)})}load(...[e,t]){return this.ogAnalyticsLoad(e,{...t,updateCDNSettings:c(t?.updateCDNSettings||(e=>e),(e=>(l.debug("CDN settings loaded",e),this.cdnSettingsDeferred.resolve(e),e)))})}replaceLoadMethod(e){this.analytics.load=e}page(){this.analytics.page()}configureBlockingMiddlewareForOptOut(){var e,t,n;e=this.cdnSettings,t=this.analytics,n={integrationCategoryMappings:this.settings.integrationCategoryMappings,shouldEnableIntegration:this.settings.shouldEnableIntegration},t.addDestinationMiddleware("*",(async({integration:t,payload:o,next:i})=>{const a=await e,r=o.obj.context.consent.categoryPreferences,s=!p(t,a,r,n);if(l.debug(`Destination middleware called: ${t}`,{DROPPED:s,categoryPreferences:r,payload:o.obj,filterSettings:n}),s)return null;i(o)})),t.addSourceMiddleware((async({payload:t,next:o})=>{const i=await e,a=t.obj.context.consent.categoryPreferences,r=n.integrationCategoryMappings?{hasUnmappedDestinations:!1,allCategories:g(n.integrationCategoryMappings)}:i.consentSettings,s=u(a,r);if(l.debug("Source middleware called",{DROPPED:s,categoryPreferences:a,payload:t.obj,filterSettings:n,consentSettings:r}),s)return null;o(t)}))}configureConsentStampingMiddleware(){const{pruneUnmappedCategories:e}=this.settings,t=(n=async()=>{const t=await this.getCategories();return e?((e,t)=>{if(!t.length)throw new i("Invariant: No consent categories defined in Segment",[]);return n=e,t.reduce(((e,t)=>(t in n&&(e[t]=n[t]),e)),{});var n})(t,await this.getAllCategories()):t},async({payload:e,next:t})=>{e.obj.context.consent={...e.obj.context.consent,categoryPreferences:await n()},t(e)});var n;this.analytics.addSourceMiddleware(t)}consentChange(e){l.debug("Consent change",e);try{s(e)}catch(e){return console.error(e)}this.analytics.track("Segment Consent Preference Updated",void 0,{consent:{categoryPreferences:e}})}}const b=e=>{if(Array.isArray(e)){const t=e._loadOptions??{},n=window[t?.globalAnalyticsKey??"analytics"];if(n?.initialized)return n}return e},f=(...[e])=>{!function(e){if("object"!=typeof e||!e)throw new i("Options should be an object",e);a(e.getCategories,"getCategories"),e.shouldLoadSegment&&a(e.shouldLoadSegment,"shouldLoadSegment"),e.shouldEnableIntegration&&a(e.shouldEnableIntegration,"shouldEnableIntegration"),e.shouldDisableSegment&&a(e.shouldDisableSegment,"shouldDisableSegment"),e.integrationCategoryMappings&&r(e.integrationCategoryMappings,"integrationCategoryMappings"),e.registerOnConsentChanged&&a(e.registerOnConsentChanged,"registerOnConsentChanged")}(e);const{shouldDisableSegment:t,getCategories:n,shouldLoadSegment:o,integrationCategoryMappings:s,shouldEnableIntegration:c,registerOnConsentChanged:g,shouldLoadWrapper:u,enableDebugLogging:p}=e;return e=>{const i=new h(e,{integrationCategoryMappings:s,shouldEnableIntegration:c,getCategories:n});p&&l.enableDebugLogging();const a=u?.()||Promise.resolve();return a.then((()=>{g?.((e=>i.consentChange(e)))})),i.replaceLoadMethod((async(e,n)=>{if(n?.initialPageview&&(i.page(),n={...n,initialPageview:!1}),await(t?.()))return;await a;const r=await(e=>async()=>{const t=new d;return await(e?.(t)),t.validate(),t})(o)();if(r.isAbortCalled)!0===r.abortLoadOptions?.loadSegmentNormally&&i.load(e,n);else{if(i.configureConsentStampingMiddleware(),"opt-in"!==r.loadOptions.consentModel)return"opt-out"===r.loadOptions.consentModel?(i.configureBlockingMiddlewareForOptOut(),void i.load(e,n)):void function(e){throw new Error(`Unhandled discriminated union member: ${JSON.stringify(e)}`)}(r.loadOptions.consentModel);await i.loadWithFilteredDeviceModeDestinations(e,n)}})),e}};async function y(e,t){return new Promise(((n,o)=>{if(e())return void n();const i=()=>setTimeout((()=>{e()?n():i()}),t);i()}))}},156:function(e,t,n){var o=this&&this.__awaiter||function(e,t,n,o){return new(n||(n=Promise))((function(i,a){function r(e){try{l(o.next(e))}catch(e){a(e)}}function s(e){try{l(o.throw(e))}catch(e){a(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(r,s)}l((o=o.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.testHelpers=t.withTrustArc=void 0;const i=n(545),a=n(125),r=()=>o(void 0,void 0,void 0,(function*(){yield(0,i.resolveWhen)((()=>void 0!==(0,a.getTrustArcGlobal)()),500)})),s=()=>{const e=(0,a.getTrustArcGlobal)(),t=(0,a.coerceConsentModel)(e.eu.bindMap.behaviorManager);return(0,a.getNormalizedCategories)(t)},l=(e,t)=>o(void 0,void 0,void 0,(function*(){const n=(0,a.getTrustArcGlobal)(),o=t&&!0===t.enableDebugLogging;let r="opt-in";return null!=t.consentModelBasedOnConsentExperience&&1==t.consentModelBasedOnConsentExperience?(r=(0,a.coerceConsentModel)((0,a.getConsentExperience)()),o&&console.log(`Wrapper initilized with consent model based on consent experience: ${r}`)):void 0!==t.consentModel?(o&&console.log(`Wrapper initilized with overriden consent model: ${t.consentModel()}`),r=t.consentModel()):(r=(0,a.coerceConsentModel)(n.eu.bindMap.behaviorManager),o&&console.log(`Wrapper initilized with consent model: ${r}`)),"opt-out"===r?e.load({consentModel:"opt-out"}):(yield(0,i.resolveWhen)((()=>{if(null!=t.alwaysLoadSegment&&t.alwaysLoadSegment)return!0;const e=(0,a.getNormalizedActiveGroupIds)(r);return e.shift(),e.some((e=>e))}),500),e.load({consentModel:"opt-in"}))}));t.withTrustArc=(e,t={})=>(t&&!0===t.enableDebugLogging&&console.log("Loading Segment with TrustArc Wrapper",t),(0,i.createWrapper)({shouldLoadWrapper:r,shouldLoadSegment:e=>l(e,t),getCategories:s,registerOnConsentChanged:t.disableConsentChangedEvent?void 0:e=>{const t=(0,a.getTrustArcGlobal)(),n=(0,a.coerceConsentModel)(t.eu.bindMap.behaviorManager);window.addEventListener("message",(t=>{try{const o=t&&""!=t.data&&JSON.parse(t.data);if(o&&"submit_preferences"==o.message){const t=(0,a.getNormalizedCategories)(n);e(t)}}catch(t){}}),!1)},enableDebugLogging:t.enableDebugLogging})(e)),t.testHelpers={shouldLoadWrapper:r,getCategories:s,shouldLoadSegment:l}},125:(e,t)=>{var n,o;Object.defineProperty(t,"__esModule",{value:!0}),t.getConsentExperience=t.getNormalizedCategories=t.getNormalizedActiveGroupIds=t.getAllCategories=t.coerceConsentModel=t.getTrustArcGlobal=t.TaConsentExperience=t.TaConsentModel=void 0,function(e){e.eu="eu",e.us="us",e.na="na",e.an="an",e.af="af",e.as="as",e.sa="sa",e.oc="oc"}(n||(t.TaConsentModel=n={})),function(e){e.implied="implied",e.expressed="expressed"}(o||(t.TaConsentExperience=o={})),t.getTrustArcGlobal=()=>{if("undefined"==typeof window)return;const e=window.truste;return e&&e.cma&&e.cma.callApi&&e.eu&&e.eu.bindMap?e:void 0},t.coerceConsentModel=e=>{switch(e){case n.eu:case n.an:case n.af:case n.as:case n.sa:case n.oc:return"opt-in";case n.us:case n.na:case n.na:case"implied":return"opt-out";default:return"opt-in"}},t.getAllCategories=()=>{const e=(0,t.getTrustArcGlobal)();if(void 0===e)return[];const n=e.eu.bindMap.categoryCount,o=[];for(let e=1;e<=n;e++)o.push({groupId:`ta-${e}`});return o},t.getNormalizedActiveGroupIds=e=>{const n=(0,t.getTrustArcGlobal)();let o=[];if(!n)return[];const i=n.cma.callApi("getGDPRConsentDecision",n.eu.bindMap.domain);if("asserted"==i.source){for(let e=0;e<i.consentDecision.length;e++){const t=i.consentDecision[e];o.push(`ta-${t}`)}return o}return"opt-in"===e?["ta-1"]:(0,t.getAllCategories)().map((e=>e.groupId))},t.getNormalizedCategories=e=>{const n=(0,t.getNormalizedActiveGroupIds)(e);return(0,t.getAllCategories)().reduce(((e,t)=>Object.assign(Object.assign({},e),{[t.groupId]:n.includes(t.groupId)})),{})},t.getConsentExperience=()=>{const e=(0,t.getTrustArcGlobal)();return e?e.eu.bindMap.behavior:o.implied}}},t={};function n(o){var i=t[o];if(void 0!==i)return i.exports;var a=t[o]={exports:{}};return e[o].call(a.exports,a,a.exports,n),a.exports}return n.d=(e,t)=>{for(var o in t)n.o(t,o)&&!n.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n(156)})(),"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("TrustArcWrapper",[],e):"object"==typeof exports?exports.TrustArcWrapper=e():this.TrustArcWrapper=e();