import{r as e,h as l}from"./p-1a7a8b00.js";import{P as t,t as n}from"./p-487241b6.js";const i=class{constructor(l){e(this,l)}resetState(){}truncate(e=""){return e.length>140?e.substring(0,140):e}connectedCallback(){this.resetState()}handleAnalyticsPage(e){var l,t;const n=null===(l=e.detail)||void 0===l?void 0:l.pageData,i=null===(t=window.BpSdk)||void 0===t?void 0:t.analytics;i&&n&&i.page(n)}handleIdentify(e){var l;const{userId:t,traits:n={},options:i={}}=e.detail,a=null===(l=window.BpSdk)||void 0===l?void 0:l.analytics;a&&t&&a.identify(t,n,i)}handleTrack(e){var l;const{eventName:n,eventOptions:i={}}=e.detail;let{eventPayload:a={}}=e.detail;const o=null===(l=window.BpSdk)||void 0===l?void 0:l.analytics;o&&n&&(a=Object.assign(Object.assign({},o.storage.getItem(t.storageKey)),a),o.track(n,a,i))}handleVariables({detail:e}){var l;const n=null===(l=window.BpSdk)||void 0===l?void 0:l.analytics;if(n){const l=Object.assign(Object.assign({},n.storage.getItem(t.storageKey)),e);n.storage.setItem(t.storageKey,l)}}onClick(e){let l,t={};const{tagName:n=""}=e.target;switch(n){case"BUTTON":l="ButtonClick",t={label:e.target.innerText,value:0};break;case"A":l="LinkClick",t={label:e.target.innerText,value:0}}l&&this.handleTrack(new CustomEvent("bpAnalyticsTrack",{detail:{eventName:l,eventPayload:t}}))}onInput(e){var l,t,i,a,o,d,v,s,c;let u,r,h={};const{tagName:b="",type:k=""}=e.target,p=e.target.closest("bp-sdk-dynamic-input-event-container");switch(p&&(u=p.answer),b){case"INPUT":case"TEXTAREA":if(k!==n.Radio&&k!==n.CheckBox)r="TextBoxChange",h={label:this.truncate(null===(l=null==u?void 0:u.question)||void 0===l?void 0:l.code),dt:this.truncate(null===(t=null==u?void 0:u.question)||void 0===t?void 0:t.text),dataValue:(null===(i=null==u?void 0:u.question)||void 0===i?void 0:i.trackable)?u.value:"",value:0};else if(k===n.Radio){const e=null===(o=null===(a=null==u?void 0:u.question)||void 0===a?void 0:a.choices)||void 0===o?void 0:o.find((e=>e.id===(null==u?void 0:u.choice_id))),l=e?e.value:"";r="RadioButtonChange",h={label:this.truncate(null===(d=null==u?void 0:u.question)||void 0===d?void 0:d.code),dt:this.truncate(null===(v=null==u?void 0:u.question)||void 0===v?void 0:v.text),dataValue:l,value:0}}else if(k===n.CheckBox){let e="Uncheck";(null==u?void 0:u.value)&&(e="Check"),r="BoxCheck",h={label:this.truncate(null===(s=null==u?void 0:u.question)||void 0===s?void 0:s.code),dt:this.truncate(null===(c=null==u?void 0:u.question)||void 0===c?void 0:c.text),dataValue:e,value:0}}break;case"SELECT":let e;if(r="DropdownChange",u.question.multiple)e=u.choice_ids.map((e=>{const l=u.question.choices.find((l=>l.id===e));if(l)return l.value})).join("&");else if(e="",u.choice_id){const l=u.question.choices.find((e=>e.id===u.choice_id));l&&(e=l.value)}h={label:this.truncate(u.question.code),dt:this.truncate(u.question.text),dataValue:this.truncate(e),value:0}}r&&this.handleTrack(new CustomEvent("bpAnalyticsTrack",{detail:{eventName:r,eventPayload:h}}))}render(){return l("slot",{key:"62445afb9c8e9d90d0cee2fff8936b1e412cc9a5"})}};export{i as bp_sdk_analytics_container}