@appstorys/react-web 1.1.0 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- var Yi=Object.defineProperty;var Nt=(t,e)=>()=>(t&&(e=t(t=0)),e);var Qi=(t,e)=>{for(var o in e)Yi(t,o,{get:e[o],enumerable:!0})};var tt,Kt=Nt(()=>{"use strict";tt=class{static async getItem(e){try{return localStorage.getItem(e)}catch{return null}}static async setItem(e,o){try{localStorage.setItem(e,o)}catch{}}static async removeItem(e){try{localStorage.removeItem(e)}catch{}}}});import{create as Gi}from"zustand";function kt(){return lo.getState().userId}async function dt(){return tt.getItem("access_token")}function mn(t){if(!t)return;let e=String(t||"").trim();if(e)return lo.getState().variantMappings?.[e]}var lo,F,K=Nt(()=>{"use strict";Kt();lo=Gi(t=>({userId:"",appId:"",accountId:"",currentScreen:"",campaigns:[],allCampaigns:[],campaignVersion:2,trackedEvents:[],trackedEventMetadata:{},isVisible:!0,isAnonymousUser:!1,variantMappings:{},personalizationData:{},screenCaptureEnabled:!1,baseUrl:void 0,trackingUrl:void 0,saveCampaigns:e=>t({campaigns:e}),saveAllCampaigns:e=>t({allCampaigns:e}),setCampaignVersion:e=>t({campaignVersion:e}),setUserId:e=>t({userId:e}),setAppId:e=>t({appId:e}),setAccountId:e=>t({accountId:e}),setCurrentScreen:e=>t({currentScreen:e}),setAttributes:e=>t({attributes:e}),setTrackedEvents:e=>t({trackedEvents:e}),setTrackedEventMetadata:e=>t({trackedEventMetadata:e}),setVisibility:e=>t({isVisible:e}),setIsAnonymousUser:e=>t({isAnonymousUser:e}),setVariantMappings:e=>t({variantMappings:e}),setPersonalizationData:e=>t({personalizationData:e}),setScreenCaptureEnabled:e=>t({screenCaptureEnabled:e}),setBaseUrl:e=>t({baseUrl:e}),setTrackingUrl:e=>t({trackingUrl:e})}));F=lo});async function qt(){try{return{browser:navigator.userAgent,language:navigator.language,platform:"web",screen_width_px:window.innerWidth,screen_height_px:window.innerHeight,screen_density:window.devicePixelRatio,orientation:window.innerWidth<window.innerHeight?"portrait":"landscape",timezone:Intl.DateTimeFormat().resolvedOptions().timeZone}}catch(t){return console.error("Error fetching device info:",t),{}}}var Ae=Nt(()=>{"use strict"});async function Et(t,e,o){try{let i={account_id:t,app_id:e,user_id:o};if(await tt.getItem(hn))console.log("Device info already sent previously - skipping");else{let c=await qt();i.attributes={...c},console.log("First time verification - including device info in attributes")}let s=F.getState().baseUrl||"https://users.appstorys.co",a=await fetch(`${s}/${t}/validate-account`,{method:"POST",body:JSON.stringify(i),headers:{Accept:"application/json","Content-Type":"application/json"}});if(console.log("Verify account body",i),console.log("Verifying account",a.status,a.statusText),a.ok){let c=await a.json();console.log("Account verified",c);let{access_token:u,refresh_token:x}=c;if(u&&x)return await tt.setItem("access_token",u),await tt.setItem("refresh_token",x),i.attributes&&(await tt.setItem(hn,"true"),console.log("Device info sent flag set")),!0}return!1}catch(i){return console.error("Error when verifying AppStorys account",i),!1}}var hn,Ee=Nt(()=>{"use strict";Kt();Ae();K();hn="device_info_sent"});async function Ze(t,e){if(!e||e.length===0){console.info("AppStorys: identifyWidgetPositions called with empty positionList; skipping");return}let o=await dt();if(!o){console.error("AppStorys: identifyWidgetPositions - access token not found");return}try{let i="https://backend.appstorys.co/api/v2/appinfo/identify-positions/";console.info("AppStorys: identifyWidgetPositions payload",{screen_name:t,position_list:e});let n=await fetch(i,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o}`,Accept:"application/json"},body:JSON.stringify({screen_name:t,position_list:e})});n.ok?console.info("AppStorys: identifyWidgetPositions OK"):console.error("AppStorys: identifyWidgetPositions failed",n.status,await n.text())}catch(i){console.error("AppStorys: identifyWidgetPositions error",i)}}var Di=Nt(()=>{"use strict";K()});function to(t){return t&&(t.startsWith("widget_")?t:`widget_${t}`)}function $i(){try{let t=F.getState().allCampaigns||[],e=[];return t.forEach(o=>{o&&o.position&&typeof o.position=="string"&&e.push(String(o.position));try{if(o&&o.campaign_type==="WID"&&o.details){let i=o.details;typeof i=="object"&&(i.id&&typeof i.id=="string"&&e.push(String(i.id)),i.variants&&typeof i.variants=="object"&&Object.values(i.variants).forEach(n=>{n&&n.id&&typeof n.id=="string"&&e.push(String(n.id))}))}}catch{}}),e.filter(o=>!!o).map(o=>to(String(o))).filter(o=>!!o)}catch{return[]}}function $s(t){try{let e=$i();if(!e||e.length===0)return[];let o=[];return e.forEach(i=>{let n=i.replace(/^widget_/,""),r=[`[data-as-id="${n}"]`,`#${n}`,`.${n}`,`[data-widget="${n}"]`],s=null;for(let a of r)if(s=document.querySelector(a),s)break;if(s){let a=s.getBoundingClientRect(),c={x:Math.round(a.left),y:Math.round(a.top),width:Math.round(a.width),height:Math.round(a.height),screenWidth:window.innerWidth,screenHeight:window.innerHeight};Qt.addLayoutInfo(t,n,c),o.push(n)}}),console.info("AppStorys: mapServerPositionsToDOM mapped",o.length,"server positions to DOM elements",o),o}catch(e){return console.warn("AppStorys: mapServerPositionsToDOM error",e),[]}}function Ws(t){return ke[t]||(ke[t]=[]),ke[t]}function _i(t,e,o,i){let n=new FormData,r=t.replace(/[^a-z0-9]/gi,"_"),s=`screenshot_${e}_${r}_${Date.now()}.png`,a=new File([i],s,{type:"image/png"});n.append("screenName",t),n.append("user_id",e),n.append("children",o),n.append("screenshot",a);try{console.groupCollapsed("AppStorys: FormData Payload Diagnostic"),console.info(" screenName:",t),console.info(" user_id:",e),console.info(" children:",JSON.parse(o)),console.info(" screenshot:",a.name,`(${a.size} bytes)`),console.groupEnd()}catch(c){console.warn("AppStorys: Could not run FormData diagnostics",c)}return n}var ke,Qt,Wi=Nt(()=>{"use strict";K();Ee();Di();K();ke={};Qt=class{static setup(e,o){let i=F.getState();i.setScreenCaptureEnabled(o),i.setCurrentScreen(e)}static addLayoutInfo(e,o,i){let n=Ws(e),r=n.findIndex(c=>c.id===o),s={...i,screenWidth:i.screenWidth||window.innerWidth,screenHeight:i.screenHeight||window.innerHeight},a={id:o,frame:s};r>=0?n[r]=a:n.push(a)}static collectElements(e){this.clearLayoutData(e);let o=document.querySelectorAll("[data-as-id]"),i=window.innerWidth,n=window.innerHeight,r=[];o.forEach(s=>{let a=s.getAttribute("data-as-id");if(a){r.push(a);let c=s.getBoundingClientRect();this.addLayoutInfo(e,a,{x:Math.round(c.left),y:Math.round(c.top),width:Math.round(c.width),height:Math.round(c.height),screenWidth:i,screenHeight:n})}}),console.info(`AppStorys: Identified ${o.length} elements:`,r)}static clearLayoutData(e){ke[e]=[]}static getLayoutData(e){return ke[e]||[]}static async takeScreenshot(e,o){try{if(!e)return console.error("AppStorys: Screen name is required"),!1;console.info("AppStorys: Starting takeScreenshot for",e),F.getState().setCurrentScreen(e),this.collectElements(e);try{let g=$s(e);g&&g.length>0&&console.info("AppStorys: mapServerPositionsToDOM added",g.length,"elements")}catch{}await new Promise(g=>setTimeout(g,100));let n=window,r=null;if(typeof n.html2canvas!="function")try{await new Promise((g,v)=>{let f=document.createElement("script");f.src="https://html2canvas.hertzen.com/dist/html2canvas.min.js",f.onload=()=>g(),f.onerror=()=>v(new Error("Failed to load html2canvas")),document.head.appendChild(f)})}catch(g){console.warn("AppStorys: html2canvas load error",g)}if(typeof n.html2canvas=="function")try{let g=await n.html2canvas(document.documentElement,{useCORS:!0,allowTaint:!0,logging:!1,scale:window.devicePixelRatio||1});r=await new Promise(v=>g.toBlob(f=>v(f),"image/png"))}catch(g){console.warn("AppStorys: html2canvas capture failed (falling back to getDisplayMedia)",g),r=null}if(!r&&navigator.mediaDevices&&navigator.mediaDevices.getDisplayMedia)try{let g=await navigator.mediaDevices.getDisplayMedia({video:!0}),v=document.createElement("video");v.srcObject=g,await v.play();let f=document.createElement("canvas");f.width=v.videoWidth||window.innerWidth,f.height=v.videoHeight||window.innerHeight;let b=f.getContext("2d");b&&b.drawImage(v,0,0,f.width,f.height),r=await new Promise(h=>f.toBlob(y=>h(y),"image/png")),v.pause(),g.getTracks().forEach(h=>h.stop())}catch(g){console.warn("AppStorys: getDisplayMedia capture failed",g)}if(!r)return console.warn("AppStorys: Capture failed \u2014 no blob generated"),!1;let s=await dt(),a=kt();if(!a)return console.warn("AppStorys: No userId"),!1;if(!s){let g=F.getState();g.accountId&&g.appId&&g.userId&&await Et(g.accountId,g.appId,g.userId)&&(s=await dt())}if(!s)return console.warn("AppStorys: No token available"),!1;let c="https://backend.appstorys.co/api/v1/appinfo/identify-elements/",u=JSON.stringify(this.getLayoutData(e)||[]),x=_i(e,a,u,r);console.info("AppStorys: Sending identify-elements with payload size:",u.length);let m=await fetch(c,{method:"POST",headers:{Authorization:`Bearer ${s}`,Accept:"application/json"},body:x});if(m.status===401){console.warn("AppStorys: 401 response \u2014 retrying once");let g=F.getState();if(g.accountId&&g.appId&&g.userId&&await Et(g.accountId,g.appId,g.userId)){let f=await dt();f&&(m=await fetch(c,{method:"POST",headers:{Authorization:`Bearer ${f}`,Accept:"application/json"},body:_i(e,a,u,r)}))}}if(!m.ok){let g=await m.text();return console.error("AppStorys: identify-elements failed",m.status,g),!1}console.info("AppStorys: identify-elements success \u2713");try{let g=o,v=[];!g||g.length===0?v=(this.getLayoutData(e)||[]).map(y=>to(y.id)).filter(y=>!!y):v=g.map(h=>to(h)).filter(h=>!!h);let f=$i(),b=Array.from(new Set([...v,...f]));console.info("AppStorys: identifyWidgetPositions will send",b.length,"positions (collected + server)",b),await Ze(e,b)}catch(g){console.warn("AppStorys: identifyWidgetPositions failed",g)}return!0}catch(i){return console.error("AppStorys: takeScreenshot error",i),!1}}};(function(){try{let e=window;e.AppStorysForceIdentifyPositions=async o=>{let i=F.getState(),n=o||i.currentScreen;if(!n){console.warn("AppStorys: AppStorysForceIdentifyPositions - no screen name available");return}let s=(Qt.getLayoutData(n)||[]).map(a=>to(a.id)).filter(a=>!!a);console.info("AppStorys: AppStorysForceIdentifyPositions sending",s.length,"positions for",n,s);try{await Ze(n,s),console.info("AppStorys: AppStorysForceIdentifyPositions completed")}catch(a){console.error("AppStorys: AppStorysForceIdentifyPositions error",a)}}}catch{}})()});var Oi={};Qi(Oi,{mountScreenCaptureButton:()=>Mi});function Ms(){if(document.getElementById("appstorys-capture-styles"))return;let t=document.createElement("style");t.id="appstorys-capture-styles",t.innerHTML=`
1
+ var ls=Object.defineProperty;var Me=(t,e)=>()=>(t&&(e=t(t=0)),e);var ds=(t,e)=>{for(var o in e)ls(t,o,{get:e[o],enumerable:!0})};var Ct,Oe=Me(()=>{"use strict";Ct=class{static async getItem(e){try{return localStorage.getItem(e)}catch{return null}}static async setItem(e,o){try{localStorage.setItem(e,o)}catch{}}static async removeItem(e){try{localStorage.removeItem(e)}catch{}}}});import{create as cs}from"zustand";function ee(){return hn.getState().userId}async function Et(){return Ct.getItem("access_token")}function hi(t){if(!t)return;let e=String(t||"").trim();if(e)return hn.getState().variantMappings?.[e]}var hn,P,yt=Me(()=>{"use strict";Oe();hn=cs(t=>({userId:"",appId:"",accountId:"",currentScreen:"",campaigns:[],allCampaigns:[],campaignVersion:2,trackedEvents:[],trackedEventMetadata:{},isVisible:!0,isAnonymousUser:!1,variantMappings:{},personalizationData:{},screenCaptureEnabled:!1,baseUrl:void 0,trackingUrl:void 0,saveCampaigns:e=>t({campaigns:e}),saveAllCampaigns:e=>t({allCampaigns:e}),setCampaignVersion:e=>t({campaignVersion:e}),setUserId:e=>t({userId:e}),setAppId:e=>t({appId:e}),setAccountId:e=>t({accountId:e}),setCurrentScreen:e=>t({currentScreen:e}),setAttributes:e=>t({attributes:e}),setTrackedEvents:e=>t({trackedEvents:e}),setTrackedEventMetadata:e=>t({trackedEventMetadata:e}),setVisibility:e=>t({isVisible:e}),setIsAnonymousUser:e=>t({isAnonymousUser:e}),setVariantMappings:e=>t({variantMappings:e}),setPersonalizationData:e=>t({personalizationData:e}),setScreenCaptureEnabled:e=>t({screenCaptureEnabled:e}),setBaseUrl:e=>t({baseUrl:e}),setTrackingUrl:e=>t({trackingUrl:e})}));P=hn});async function Pe(){try{return{browser:navigator.userAgent,language:navigator.language,platform:"web",screen_width_px:window.innerWidth,screen_height_px:window.innerHeight,screen_density:window.devicePixelRatio,orientation:window.innerWidth<window.innerHeight?"portrait":"landscape",timezone:Intl.DateTimeFormat().resolvedOptions().timeZone}}catch(t){return console.error("Error fetching device info:",t),{}}}var Mo=Me(()=>{"use strict"});async function he(t,e,o){try{let n={account_id:t,app_id:e,user_id:o};if(await Ct.getItem(vi))console.log("Device info already sent previously - skipping");else{let d=await Pe();n.attributes={...d},console.log("First time verification - including device info in attributes")}let l=P.getState().baseUrl||"https://users.appstorys.co",c=await fetch(`${l}/${t}/validate-account`,{method:"POST",body:JSON.stringify(n),headers:{Accept:"application/json","Content-Type":"application/json"}});if(console.log("Verify account body",n),console.log("Verifying account",c.status,c.statusText),c.ok){let d=await c.json();console.log("Account verified",d);let{access_token:S,refresh_token:p}=d;if(S&&p)return await Ct.setItem("access_token",S),await Ct.setItem("refresh_token",p),n.attributes&&(await Ct.setItem(vi,"true"),console.log("Device info sent flag set")),!0}return!1}catch(n){return console.error("Error when verifying AppStorys account",n),!1}}var vi,Po=Me(()=>{"use strict";Oe();Mo();yt();vi="device_info_sent"});async function gn(t,e){if(!e||e.length===0){console.info("AppStorys: identifyWidgetPositions called with empty positionList; skipping");return}let o=await Et();if(!o){console.error("AppStorys: identifyWidgetPositions - access token not found");return}try{let n="https://backend.appstorys.co/api/v2/appinfo/identify-positions/";console.info("AppStorys: identifyWidgetPositions payload",{screen_name:t,position_list:e});let i=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o}`,Accept:"application/json"},body:JSON.stringify({screen_name:t,position_list:e})});i.ok?console.info("AppStorys: identifyWidgetPositions OK"):console.error("AppStorys: identifyWidgetPositions failed",i.status,await i.text())}catch(n){console.error("AppStorys: identifyWidgetPositions error",n)}}var es=Me(()=>{"use strict";yt()});function fn(t){return t&&(t.startsWith("widget_")?t:`widget_${t}`)}function Fl(){try{let t=P.getState().allCampaigns||[],e=[];return t.forEach(o=>{o&&o.position&&typeof o.position=="string"&&e.push(String(o.position));try{if(o&&o.campaign_type==="WID"&&o.details){let n=o.details;typeof n=="object"&&(n.id&&typeof n.id=="string"&&e.push(String(n.id)),n.variants&&typeof n.variants=="object"&&Object.values(n.variants).forEach(i=>{i&&i.id&&typeof i.id=="string"&&e.push(String(i.id))}))}}catch{}}),e.filter(o=>!!o).map(o=>fn(String(o))).filter(o=>!!o)}catch{return[]}}function Tl(t){try{let e=Fl();if(!e||e.length===0)return[];let o=[];return e.forEach(n=>{let i=n.replace(/^widget_/,""),s=[`[data-as-id="${i}"]`,`#${i}`,`.${i}`,`[data-widget="${i}"]`],l=null;for(let c of s)if(l=document.querySelector(c),l)break;if(l){let c=l.getBoundingClientRect(),d={x:Math.round(c.left),y:Math.round(c.top),width:Math.round(c.width),height:Math.round(c.height),screenWidth:window.innerWidth,screenHeight:window.innerHeight};We.addLayoutInfo(t,i,d),o.push(i)}}),console.info("AppStorys: mapServerPositionsToDOM mapped",o.length,"server positions to DOM elements",o),o}catch(e){return console.warn("AppStorys: mapServerPositionsToDOM error",e),[]}}function zl(t){return Bo[t]||(Bo[t]=[]),Bo[t]}function os(t,e,o,n){let i=new FormData,s=t.replace(/[^a-z0-9]/gi,"_"),l=`screenshot_${e}_${s}_${Date.now()}.png`,c=new File([n],l,{type:"image/png"});i.append("screenName",t),i.append("user_id",e),i.append("children",o),i.append("screenshot",c);try{console.groupCollapsed("AppStorys: FormData Payload Diagnostic"),console.info(" screenName:",t),console.info(" user_id:",e),console.info(" children:",JSON.parse(o)),console.info(" screenshot:",c.name,`(${c.size} bytes)`),console.groupEnd()}catch(d){console.warn("AppStorys: Could not run FormData diagnostics",d)}return i}var Bo,We,ns=Me(()=>{"use strict";yt();Po();es();yt();Bo={};We=class{static setup(e,o){let n=P.getState();n.setScreenCaptureEnabled(o),n.setCurrentScreen(e)}static addLayoutInfo(e,o,n){let i=zl(e),s=i.findIndex(d=>d.id===o),l={...n,screenWidth:n.screenWidth||window.innerWidth,screenHeight:n.screenHeight||window.innerHeight},c={id:o,frame:l};s>=0?i[s]=c:i.push(c)}static collectElements(e){this.clearLayoutData(e);let o=document.querySelectorAll("[data-as-id]"),n=window.innerWidth,i=window.innerHeight,s=[];o.forEach(l=>{let c=l.getAttribute("data-as-id");if(c){s.push(c);let d=l.getBoundingClientRect();this.addLayoutInfo(e,c,{x:Math.round(d.left),y:Math.round(d.top),width:Math.round(d.width),height:Math.round(d.height),screenWidth:n,screenHeight:i})}}),console.info(`AppStorys: Identified ${o.length} elements:`,s)}static clearLayoutData(e){Bo[e]=[]}static getLayoutData(e){return Bo[e]||[]}static async takeScreenshot(e,o){try{if(!e)return console.error("AppStorys: Screen name is required"),!1;console.info("AppStorys: Starting takeScreenshot for",e),P.getState().setCurrentScreen(e),this.collectElements(e);try{let u=Tl(e);u&&u.length>0&&console.info("AppStorys: mapServerPositionsToDOM added",u.length,"elements")}catch{}await new Promise(u=>setTimeout(u,100));let i=window,s=null;if(typeof i.html2canvas!="function")try{await new Promise((u,C)=>{let h=document.createElement("script");h.src="https://html2canvas.hertzen.com/dist/html2canvas.min.js",h.onload=()=>u(),h.onerror=()=>C(new Error("Failed to load html2canvas")),document.head.appendChild(h)})}catch(u){console.warn("AppStorys: html2canvas load error",u)}if(typeof i.html2canvas=="function")try{let u=await i.html2canvas(document.documentElement,{useCORS:!0,allowTaint:!0,logging:!1,scale:window.devicePixelRatio||1});s=await new Promise(C=>u.toBlob(h=>C(h),"image/png"))}catch(u){console.warn("AppStorys: html2canvas capture failed (falling back to getDisplayMedia)",u),s=null}if(!s&&navigator.mediaDevices&&navigator.mediaDevices.getDisplayMedia)try{let u=await navigator.mediaDevices.getDisplayMedia({video:!0}),C=document.createElement("video");C.srcObject=u,await C.play();let h=document.createElement("canvas");h.width=C.videoWidth||window.innerWidth,h.height=C.videoHeight||window.innerHeight;let g=h.getContext("2d");g&&g.drawImage(C,0,0,h.width,h.height),s=await new Promise(b=>h.toBlob(m=>b(m),"image/png")),C.pause(),u.getTracks().forEach(b=>b.stop())}catch(u){console.warn("AppStorys: getDisplayMedia capture failed",u)}if(!s)return console.warn("AppStorys: Capture failed \u2014 no blob generated"),!1;let l=await Et(),c=ee();if(!c)return console.warn("AppStorys: No userId"),!1;if(!l){let u=P.getState();u.accountId&&u.appId&&u.userId&&await he(u.accountId,u.appId,u.userId)&&(l=await Et())}if(!l)return console.warn("AppStorys: No token available"),!1;let d="https://backend.appstorys.co/api/v1/appinfo/identify-elements/",S=JSON.stringify(this.getLayoutData(e)||[]),p=os(e,c,S,s);console.info("AppStorys: Sending identify-elements with payload size:",S.length);let y=await fetch(d,{method:"POST",headers:{Authorization:`Bearer ${l}`,Accept:"application/json"},body:p});if(y.status===401){console.warn("AppStorys: 401 response \u2014 retrying once");let u=P.getState();if(u.accountId&&u.appId&&u.userId&&await he(u.accountId,u.appId,u.userId)){let h=await Et();h&&(y=await fetch(d,{method:"POST",headers:{Authorization:`Bearer ${h}`,Accept:"application/json"},body:os(e,c,S,s)}))}}if(!y.ok){let u=await y.text();return console.error("AppStorys: identify-elements failed",y.status,u),!1}console.info("AppStorys: identify-elements success \u2713");try{let u=o,C=[];!u||u.length===0?C=(this.getLayoutData(e)||[]).map(g=>fn(g.id)).filter(g=>!!g):C=u.map(h=>fn(h)).filter(h=>!!h),console.info("AppStorys: identifyWidgetPositions will send",C.length,"positions (DOM-verified)",C),await gn(e,C)}catch(u){console.warn("AppStorys: identifyWidgetPositions failed",u)}return!0}catch(n){return console.error("AppStorys: takeScreenshot error",n),!1}}};(function(){try{let e=window;e.AppStorysForceIdentifyPositions=async o=>{let n=P.getState(),i=o||n.currentScreen;if(!i){console.warn("AppStorys: AppStorysForceIdentifyPositions - no screen name available");return}let l=(We.getLayoutData(i)||[]).map(c=>fn(c.id)).filter(c=>!!c);console.info("AppStorys: AppStorysForceIdentifyPositions sending",l.length,"positions for",i,l);try{await gn(i,l),console.info("AppStorys: AppStorysForceIdentifyPositions completed")}catch(c){console.error("AppStorys: AppStorysForceIdentifyPositions error",c)}}}catch{}})()});var rs={};ds(rs,{mountScreenCaptureButton:()=>is});function Il(){if(document.getElementById("appstorys-capture-styles"))return;let t=document.createElement("style");t.id="appstorys-capture-styles",t.innerHTML=`
2
2
  @keyframes appstorys-spin {
3
3
  0% { transform: rotate(0deg); }
4
4
  100% { transform: rotate(360deg); }
@@ -11,7 +11,7 @@ var Yi=Object.defineProperty;var Nt=(t,e)=>()=>(t&&(e=t(t=0)),e);var Qi=(t,e)=>{
11
11
  border-radius: 50%;
12
12
  animation: appstorys-spin 0.8s linear infinite;
13
13
  }
14
- `,document.head.appendChild(t)}function Os(){Ms();let t=document.createElement("button");return t.id="appstorys-screen-capture-btn",t.title="Capture screen",Object.assign(t.style,{position:"fixed",left:"16px",bottom:"16px",width:"100px",height:"56px",borderRadius:"28px",background:"#ff6a00",color:"#fff",border:"none",boxShadow:"0 6px 18px rgba(0,0,0,0.2)",zIndex:"2147483647",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"14px",fontWeight:"600",fontFamily:"sans-serif",transition:"all 0.2s ease"}),t.innerText="Capture",t}function Mi(){try{let t=F.getState(),o=!!window.__APPSTORYS_DEBUG_CAPTURE;if(console.info("AppStorys: mountScreenCaptureButton called, screenCaptureEnabled=",t.screenCaptureEnabled,"debugForce=",o),!t.screenCaptureEnabled&&!o||document.getElementById("appstorys-screen-capture-btn"))return null;let i=Os();return i.addEventListener("click",async()=>{i.disabled=!0;let n=i.innerText;i.innerHTML='<div class="appstorys-spinner"></div>';let s=F.getState().currentScreen||(typeof window<"u"?window.location.pathname:"");try{await Qt.takeScreenshot(s)}catch(a){console.error("CaptureService error",a)}i.disabled=!1,i.innerText=n,i.animate([{transform:"scale(1.0)"},{transform:"scale(1.05)"},{transform:"scale(1.0)"}],{duration:300})}),document.body.appendChild(i),console.info("AppStorys: screen capture button mounted"),i}catch(t){return console.error("mountScreenCaptureButton error",t),null}}var ji=Nt(()=>{"use strict";K();Wi();try{window.AppStorysMountCapture=function(){try{return Mi()}catch(t){return console.error("AppStorysMountCapture failed",t),null}}}catch{}try{window.AppStorysDebugState=function(){try{let t=F.getState();return console.info("AppStorys store state:",t),t}catch(t){return console.error("AppStorysDebugState failed",t),null}}}catch{}try{window.AppStorysDebugToken=function(){try{let t=localStorage.getItem("access_token")||"",e=t.length,o=t?t.slice(0,20)+"..."+t.slice(-10):"(none)";if(console.info("Token length:",e,"masked:",o),t&&t.includes("."))try{let i=t.split(".");if(i.length===3){let n=JSON.parse(atob(i[1]));if(console.info("Token payload:",n),n.exp){let r=new Date(n.exp*1e3),s=new Date;console.info("Token expires:",r.toISOString(),"Expired:",s>r)}}}catch(i){console.warn("Could not decode JWT:",i)}return t?"Token present":"No token"}catch(t){return console.error("AppStorysDebugToken failed",t),null}}}catch{}});var fn=(n=>(n.uninitialized="uninitialized",n.initializing="initializing",n.initialized="initialized",n.error="error",n))(fn||{});K();import{useState as _e,useEffect as vn,useRef as sr}from"react";import*as Zt from"lottie-react";K();import{useMemo as Xi}from"react";K();var Ji=t=>F.getState().variantMappings[t];function co(t){return!!(t.details&&typeof t.details=="object"&&"variants"in t.details)}function yt(t){if(!co(t))return t;let e=Ji(t.id||"");if(!e)return t;let o=t.details?.variants;if(!o||typeof o!="object")return t;let i=o[e];if(!i)return t;let n=typeof t.details=="object"?Object.fromEntries(Object.entries(t.details).filter(([s])=>s!=="variants")):{};return{...t,details:{...n,...i},_variantId:e}}var Be="__back_press_triggered__";function yn(t){return(t||"").trim().toLowerCase()}function Ki(t,e){let o=yn(t),i=yn(e);return!o||o===i}function Zi(t,e,o){let i=Number(t),n=Number(o),r=!isNaN(i)&&!isNaN(n);switch(e){case"eq":return r?i===n:t===o;case"neq":return r?i!==n:t!==o;case"gt":return r?i>n:t>o;case"gte":return r?i>=n:t>=o;case"lt":return r?i<n:t<o;case"lte":return r?i<=n:t<=o;default:return!1}}function tr(t,e){let o=t.filter(i=>i.back_press==null);return o.length===0?!0:e.some(i=>o.every(n=>{let r=i[n.key];return r==null?!1:Zi(String(r),n.operator,n.value)}))}function er(t,e,o){let i=t,n=i.trigger_event??i.trigger,r=t.id;return!n}function po(){let{campaigns:t,trackedEvents:e,trackedEventMetadata:o,currentScreen:i}=F.getState();return t.some(n=>{if(n.screen&&n.screen!==i)return!1;let r=n.trigger_event;if(!r||typeof r=="string")return!1;let{event:s,event_config:a}=r;if(!(a??[]).some(x=>x.back_press===!0)||e.includes(Be)||!e.includes(s))return!1;let c=(a??[]).filter(x=>x.back_press==null);if(c.length===0)return!0;let u=o[s]||[];return tr(c,u)})}function pt(t,e){let o=F(c=>c.currentScreen),i=F(c=>c.campaigns),n=F(c=>c.allCampaigns),r=F(c=>c.trackedEvents),s=F(c=>c.trackedEventMetadata),a=F(c=>c.variantMappings);return Xi(()=>{let c=m=>m.find(g=>Ki(g.screen,o)&&g.campaign_type===t&&(e?.position?g.position===e.position:!0)&&er(g,r,s)),x=(i&&i.length>0?c(i):void 0)??c(n||[]);if(x)return yt(x)},[i,n,r,s,a,t,e,o])}K();Ae();Kt();K();Ee();var bn="appstorys_offline_queue";async function xn(){let t=await tt.getItem(bn);return t?JSON.parse(t):[]}async function Sn(t){await tt.setItem(bn,JSON.stringify(t))}function or(t){return Math.min(3e4*Math.pow(2,t),12e4)}function nr(t){let o=t.retryCount||0,i=t.lastAttempt||0,n=or(o);return o<3&&Date.now()-i>=n}async function ir(){let t=F.getState();return!t.accountId||!t.appId?!1:await Et(t.accountId,t.appId,t.userId)}async function Cn(t,e){if(await ir()){let i=await tt.getItem("access_token");i&&(t.headers={...t.headers,Authorization:`Bearer ${i}`}),t.authRetried=!0,t.lastAttempt=Date.now(),e(t)}}async function Le(t,e){let o=(t.retryCount||0)+1;o<=3&&(t.retryCount=o,t.lastAttempt=Date.now(),e(t))}async function Pe(t){let e=await xn();e.push(t),await Sn(e)}async function rr(){let t=await xn();if(t.length===0)return;let e=[];for(let o of t){if(!nr(o)){e.push(o);continue}try{let i=await fetch(o.url,{method:o.method,headers:o.headers,body:JSON.stringify(o.body)});if(i.ok)continue;i.status===401||i.status===403?o.authRetried||await Cn(o,n=>e.push(n)):i.status>=500&&await Le(o,n=>e.push(n))}catch{await Le(o,n=>e.push(n))}}await Sn(e)}async function De(t){if(!navigator.onLine){await Pe(t);return}await rr();try{let e=await fetch(t.url,{method:t.method,headers:t.headers,body:JSON.stringify(t.body)});return e.ok||(e.status===401||e.status===403?await Cn(t,Pe):e.status>=500&&await Le(t,Pe)),e}catch{await Le(t,Pe);return}}async function H(t,e,o){try{if(!t)return;let i=await dt(),n=F.getState(),r=["viewed","clicked","csat captured","survey captured","shared"];if(!r.includes(t)){let u=n.trackedEvents;if(!u.includes(t))n.setTrackedEvents([...u,t]);else{let x=u.filter(m=>m!==t);x.push(t),n.setTrackedEvents(x)}if(o&&Object.keys(o).length>0){let x=n.trackedEventMetadata||{},m=x[t]||[];n.setTrackedEventMetadata({...x,[t]:[...m,o]})}}let s={...o||{}};if(!r.includes(t)){let u=await qt();s={...s,...u}}if(e&&String(e).trim()!==""){let u=mn(e);u&&(s.variant_id=u)}let a={user_id:kt(),event:t,metadata:s};e&&(a.campaign_id=e);let c=n.trackingUrl||"https://tracking.appstorys.co";i&&await De({url:`${c}/capture-event`,method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${i}`},body:a})}catch(i){console.error("Error in trackEvent",i)}}K();function ht(t){if(!t)return!1;let e=F.getState(),o=e.allCampaigns||[],i=e.campaigns||[],n=String(t).trim(),r=o.find(c=>{if(!c)return!1;let u=String(c.id||"").trim(),x=c.details||{},m=String(x.campaign||x.id||"").trim();return!!(u&&u===n||m&&m===n||u&&n.includes(u)||m&&n.includes(m))});if(!r)return!1;let s={...r};delete s.trigger_event,delete s.trigger,s.display_trigger=!0;let a=i.findIndex(c=>String(c.id||"")===String(s.id||""));if(a===-1)e.saveCampaigns([s,...i]);else{let c=i[a];if(!!(c.trigger_event??c.trigger)){let x=[...i];x[a]=s,e.saveCampaigns(x)}}return!0}import{jsx as uo,jsxs as lr}from"react/jsx-runtime";var wn=Zt.default?.default??Zt.default??Zt.Lottie??Zt,ar=()=>{let t=pt("BAN"),e=F(w=>w.isVisible),[o,i]=_e(!1),[n,r]=_e(null),[s,a]=_e(null),c=sr(null),[u,x]=_e(0);if(vn(()=>{t&&(i(!1),H("viewed",t.id),t.details.lottie_data&&fetch(t.details.lottie_data).then(w=>w.json()).then(w=>{r(w),w.w&&w.h&&a(w.h/w.w)}).catch(w=>console.error("Error loading Lottie:",w)))},[t]),vn(()=>{let w=()=>{c.current&&x(c.current.offsetWidth)};return w(),window.addEventListener("resize",w),()=>window.removeEventListener("resize",w)},[t,o]),!t||o||!e)return null;let{details:m}=t,g=m.styling||{},v=m.height||"auto";s&&u&&(v=u*s);let f={position:"fixed",left:g.marginLeft?`${g.marginLeft}px`:"10px",right:g.marginRight?`${g.marginRight}px`:"10px",bottom:g.marginBottom?`${g.marginBottom}px`:"10px",backgroundColor:"transparent",borderRadius:`${g.topRightRadius||0}px ${g.topLeftRadius||0}px ${g.bottomRightRadius||0}px ${g.bottomLeftRadius||0}px`,overflow:"hidden",zIndex:9999,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",cursor:m.link?"pointer":"default"},b={width:"100%",height:typeof v=="number"?`${v}px`:v,display:"block",objectFit:"cover"},h=w=>{w.stopPropagation(),i(!0),H("banner_closed",t.id)};return lr("div",{ref:c,style:f,onClick:()=>{if(m.link)if(H("clicked",t.id),m.link.startsWith("http"))window.open(m.link,"_blank");else{try{if(ht(m.link))return}catch(w){console.warn("revealCampaignFromLink error",w)}console.log("Internal link:",m.link)}},children:[n?(()=>{let w=wn.default||wn;return uo(w,{animationData:n,loop:!0,autoplay:e,style:b})})():m.image?uo("img",{src:m.image,alt:"Campaign Banner",style:b}):null,g.crossButton?.enabled&&uo("button",{onClick:h,style:{position:"absolute",top:"5px",right:"5px",background:"rgba(0,0,0,0.3)",color:"white",border:"none",borderRadius:"50%",width:"24px",height:"24px",lineHeight:"22px",textAlign:"center",cursor:"pointer",padding:"0",fontSize:"14px",display:"flex",alignItems:"center",justifyContent:"center",zIndex:10},children:"\u2715"})]})};import{useEffect as fo,useMemo as Fn,useRef as In,useState as pe}from"react";K();function We(t){let e=t.trim();return e.startsWith("http://")||e.startsWith("https://")}function kn(t){try{let o=new URL(t).pathname.split("/").pop()||t;return o.split("?")[0].replace(/\.[^.]+$/,"")||`font_${o.length}`}catch{return(t.split("/").pop()??t).split("?")[0].replace(/\.[^.]+$/,"")||`font_${t.length}`}}function Rn(t,e){if(typeof document>"u")return;let o=`appstorys-font-${t}`;if(document.getElementById(o))return;let i=document.createElement("style");i.id=o,i.type="text/css",i.textContent=`@font-face{font-family:"${t}";src:url("${e}");font-style:normal;font-weight:normal;font-display:swap;}`,document.head.appendChild(i)}var $e=new Map;async function dr(t,e){try{Rn(e.name,t);let o=globalThis.FontFace;if(typeof document<"u"&&o&&document.fonts?.add){let i=new o(e.name,`url(${t})`);await i.load(),document.fonts.add(i)}else typeof document<"u"&&document.fonts?.load&&await document.fonts.load(`1em "${e.name}"`);e.status="loaded",e.listeners.forEach(i=>i(e.name))}catch(o){console.warn(`[FontManager] Failed to load font from "${t}":`,o),e.status="failed",e.listeners.forEach(i=>i(void 0))}finally{e.listeners=[]}}var go={async load(t){if(!t||!We(t))return;let e=$e.get(t);if(e)return e.status==="loaded"?e.name:e.status==="failed"?void 0:new Promise(r=>e.listeners.push(r));let i={status:"pending",name:kn(t),listeners:[]};$e.set(t,i);let n=new Promise(r=>i.listeners.push(r));return dr(t,i),n},ensure(t){if(!t||!We(t))return;let e=kn(t);return Rn(e,t),go.load(t),e},getSync(t){if(!t)return;let e=$e.get(t);return e?.status==="loaded"?e.name:void 0},_clearCache(){$e.clear()}};function ct(t){if(t)return We(t)?go.ensure(t):t}function cr(t){let e=new Set,o=new WeakSet,i=n=>{if(n!=null&&typeof n!="string"){if(Array.isArray(n)){for(let r of n)i(r);return}if(typeof n=="object"){if(o.has(n))return;o.add(n);for(let[r,s]of Object.entries(n))r==="fontFamily"&&typeof s=="string"&&We(s)&&e.add(s),i(s)}}};return i(t),Array.from(e)}async function Tn(t){let e=new Set;for(let o of t)cr(o).forEach(i=>e.add(i));await Promise.all(Array.from(e).map(o=>go.load(o)))}import{jsx as at,jsxs as Ut}from"react/jsx-runtime";var mo=t=>(t||"").trim().toLowerCase(),It=(t,e)=>{let o=Number(t);return Number.isFinite(o)?o:e};function pr({iconType:t,color:e}){let o=e||"#FFFFFF";return t==="close"?Ut("svg",{viewBox:"0 0 24 24",width:"70%",height:"70%","aria-hidden":!0,children:[at("line",{x1:"6",y1:"6",x2:"18",y2:"18",stroke:o,strokeWidth:"2.2",strokeLinecap:"round"}),at("line",{x1:"18",y1:"6",x2:"6",y2:"18",stroke:o,strokeWidth:"2.2",strokeLinecap:"round"})]}):t==="expand"?Ut("svg",{viewBox:"0 0 24 24",width:"70%",height:"70%","aria-hidden":!0,children:[at("polyline",{points:"8,3 3,3 3,8",fill:"none",stroke:o,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),at("line",{x1:"3",y1:"3",x2:"9",y2:"9",stroke:o,strokeWidth:"2",strokeLinecap:"round"}),at("polyline",{points:"16,21 21,21 21,16",fill:"none",stroke:o,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),at("line",{x1:"15",y1:"15",x2:"21",y2:"21",stroke:o,strokeWidth:"2",strokeLinecap:"round"})]}):t==="minimize"?Ut("svg",{viewBox:"0 0 24 24",width:"70%",height:"70%","aria-hidden":!0,children:[at("polyline",{points:"9,9 3,9 3,3",fill:"none",stroke:o,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),at("line",{x1:"3",y1:"9",x2:"9",y2:"3",stroke:o,strokeWidth:"2",strokeLinecap:"round"}),at("polyline",{points:"15,15 21,15 21,21",fill:"none",stroke:o,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),at("line",{x1:"15",y1:"21",x2:"21",y2:"15",stroke:o,strokeWidth:"2",strokeLinecap:"round"})]}):t==="mute"?Ut("svg",{viewBox:"0 0 24 24",width:"70%",height:"70%","aria-hidden":!0,children:[at("polygon",{points:"4,10 8,10 13,6 13,18 8,14 4,14",fill:"none",stroke:o,strokeWidth:"2",strokeLinejoin:"round"}),at("line",{x1:"16",y1:"8",x2:"21",y2:"16",stroke:o,strokeWidth:"2",strokeLinecap:"round"}),at("line",{x1:"21",y1:"8",x2:"16",y2:"16",stroke:o,strokeWidth:"2",strokeLinecap:"round"})]}):Ut("svg",{viewBox:"0 0 24 24",width:"70%",height:"70%","aria-hidden":!0,children:[at("polygon",{points:"4,10 8,10 13,6 13,18 8,14 4,14",fill:"none",stroke:o,strokeWidth:"2",strokeLinejoin:"round"}),at("path",{d:"M16 10 Q18 12 16 14",fill:"none",stroke:o,strokeWidth:"2",strokeLinecap:"round"}),at("path",{d:"M18 8 Q22 12 18 16",fill:"none",stroke:o,strokeWidth:"2",strokeLinecap:"round"})]})}function yo({iconType:t,config:e,imageOverride:o,onClick:i}){let n=It(e?.size,18),r=Math.max(24,n+10),s=e?.margin||{},a=o||e?.image,c=e?.color?.cross||"#FFFFFF",u=e?.color?.fill||"rgba(0,0,0,0.55)",x=e?.color?.stroke||"rgba(255,255,255,0.35)";return at("button",{"data-control-button":"true",type:"button",onPointerDown:m=>{m.preventDefault(),m.stopPropagation()},onPointerUp:m=>{m.preventDefault(),m.stopPropagation()},onMouseDown:m=>{m.preventDefault(),m.stopPropagation()},onTouchStart:m=>{m.preventDefault(),m.stopPropagation()},onClick:m=>{m.preventDefault(),m.stopPropagation(),i()},title:e?.selectedStyle||t,style:{width:r,height:r,borderRadius:999,pointerEvents:"auto",zIndex:10030,position:"relative",border:`1px solid ${x}`,background:u,color:c,display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0,marginTop:It(s.top,0),marginRight:It(s.right,0),marginBottom:It(s.bottom,0),marginLeft:It(s.left,0)},children:a?at("img",{src:a,alt:t,style:{width:n,height:n,objectFit:"contain"}}):at(pr,{iconType:t,color:c})})}var ur=()=>{let t=pt("PIP"),e=F(q=>q.campaigns),o=F(q=>q.allCampaigns),i=F(q=>q.currentScreen),n=F(q=>q.isVisible),[r,s]=pe(!1),[a,c]=pe(!1),[u,x]=pe(!0),[m,g]=pe(!1),[v,f]=pe(null),b=In({x:0,y:0}),h=In(null),y=Fn(()=>{if(t)return t;let q=mo(i),Q=lt=>lt.find(mt=>{let nt=mt,Ct=nt.campaign_type==="PIP",gt=!mo(nt.screen)||mo(nt.screen)===q,vt=!!(nt.trigger_event??nt.trigger),jt=nt.display_trigger!==!1&&!vt;return Ct&&gt&&jt}),Y=Q(e)??Q(o);return Y?yt(Y):void 0},[t,e,o,i]),w=Fn(()=>y,[y?.id,y?.details?.id]);if(fo(()=>{if(!w)return;let q=w.details||{},Q=q?.styling?.soundToggle?.defaultSound||q?.styling?.appearance?.defaultSound||"yes";x(String(Q).toLowerCase()!=="yes"),s(!1),c(!1),f(null),H("viewed",w.id)},[w]),fo(()=>{h.current&&(h.current.muted=u)},[u]),fo(()=>{if(!m)return;let q=Y=>{let lt=Y.clientX-b.current.x,mt=Y.clientY-b.current.y;f({x:Math.max(0,lt),y:Math.max(0,mt)})},Q=()=>{g(!1)};return window.addEventListener("mousemove",q),window.addEventListener("mouseup",Q),()=>{window.removeEventListener("mousemove",q),window.removeEventListener("mouseup",Q)}},[m]),!w||!w.details||r||!n)return null;let I=w.details,z=I.styling||{},R=z.appearance||{},d=It(I.width??R.pipWidth,150),T=It(I.height??R.pipHeight,300),l=Math.max(d,T),p=Math.min(d,T),M=z.cta?.container||{},B=z.cta?.text||{},L=!!(I.button_text&&I.button_text.trim().length>0),C=It(z.cta?.container?.height,42),S=L?C+24:0,_=It(z.pipBottomPadding,20),E=It(z.pipTopPadding,0),$=a?I.large_video||I.small_video:I.small_video||I.large_video,D=(I.position||w.position||"right").toLowerCase(),k=!!z.isMovable,P=z.soundToggle?.enabled!==!1,O=z.crossButton?.enabled!==!1,G=z.expandControls?.enabled!==!1&&String(z.expandablePip||"yes").toLowerCase()==="yes",ut=z.crossButton,j=a?z.expandControls?.minimise:z.expandControls?.maximise,X=u?z.soundToggle?.mute:z.soundToggle?.unmute,J={position:"fixed",zIndex:10020,width:a?"100vw":l,height:a?"100vh":p,borderRadius:0,overflow:"hidden",background:"#000",boxShadow:"0 16px 40px rgba(0,0,0,0.35)",cursor:m?"grabbing":k&&!a?"grab":"default",transition:m?"none":"width 180ms ease, height 180ms ease, transform 180ms ease"};v&&!a?(J.left=v.x,J.top=v.y):a?(J.left=0,J.top=0,J.right=0,J.bottom=0):(D==="left"?J.left=24:J.right=24,E>0?J.top=E:J.bottom=_+20);let V=q=>{if(!k||a||q.target.closest("[data-control-button='true']"))return;let Y=q.currentTarget.getBoundingClientRect();b.current={x:q.clientX-Y.left,y:q.clientY-Y.top},f({x:Y.left,y:Y.top}),g(!0)},et=()=>{if(!I.link)return;H("clicked",w.id);let q=String(I.link).trim();try{let Q=F.getState(),Y=Q.allCampaigns||[],lt=Q.campaigns||[],mt=Y.find(nt=>nt.id===q);if(console.log("[Pip] clicked link=",q,"allCount=",Y.length,"visibleCount=",lt.length,"referenced=",!!mt),mt){let nt={...mt};delete nt.trigger_event,delete nt.trigger,nt.display_trigger=!0;let Ct=lt.findIndex(gt=>gt.id===nt.id);if(Ct===-1)Q.saveCampaigns([nt,...lt]);else{let gt=lt[Ct];if(!!(gt.trigger_event??gt.trigger)){let jt=[...lt];jt[Ct]=nt,Q.saveCampaigns(jt)}}return}}catch{}window.open(I.link,"_blank")};return $?Ut("div",{style:J,onMouseDown:V,children:[at("video",{ref:h,src:$,autoPlay:!0,loop:!0,playsInline:!0,muted:u,style:{width:"100%",height:a&&L?`calc(100% - ${S}px)`:"100%",objectFit:a?"contain":"cover"},onClick:et,onEnded:()=>{y&&H("analyze",y.id)}}),Ut("div",{style:{position:"absolute",top:8,right:8,display:"flex",gap:8,zIndex:2},children:[P&&at(yo,{iconType:u?"mute":"unmute",config:X,imageOverride:u?I.muteImage:I.unmuteImage,onClick:()=>x(q=>!q)}),G&&at(yo,{iconType:a?"minimize":"expand",config:j,imageOverride:a?I.minimiseImage:I.maximiseImage,onClick:()=>{console.log("[Pip] expand button clicked - isExpanded before:",a),c(q=>{let Q=!q;return Q&&w?.id&&(H("viewed",w.id),H("analyze",w.id)),Q})}}),O&&at(yo,{iconType:"close",config:ut,imageOverride:I.crossButtonImage,onClick:()=>s(!0)})]}),a&&L&&at("button",{"data-control-button":"true",onClick:et,style:{position:"absolute",left:12,right:12,bottom:12,height:M.height||42,width:M.ctaFullWidth?"auto":M.ctaWidth||"auto",margin:M.ctaFullWidth?"0":"0 auto",background:M.backgroundColor||"#F7921C",color:B.color||"#fff",border:`${M.borderWidth||0}px solid ${M.borderColor||"transparent"}`,borderRadius:10,fontSize:B.fontSize||14,fontFamily:ct(B.fontFamily),fontWeight:600,cursor:I.link?"pointer":"default"},children:I.button_text})]}):null};import gr,{useEffect as ho,useRef as bo,useState as Me}from"react";import{LottiePlayer as fr}from"lottie-react";K();import{jsx as te}from"react/jsx-runtime";var xt=(t,e=0)=>{let o=Number(t);return Number.isFinite(o)?o:e},xo=t=>(t||"").trim().toLowerCase(),mr="appstorysmediabucketdev.s3.ap-south-1.amazonaws.com",yr=t=>{try{if(typeof window>"u")return[t];let e=new URL(t);if(e.hostname!==mr)return[t];let o=!!window.location.port,i=`/appstorys-media${e.pathname}${e.search}`;return o?[i,t]:[t]}catch{return[t]}},hr=t=>{if(!t||typeof t!="object"||Array.isArray(t))return!1;let e=t;return Array.isArray(e.layers)||Array.isArray(e.assets)||typeof e.v=="string"},So=class extends gr.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(){this.props.onError()}render(){return this.state.hasError?null:this.props.children}},br=()=>{let[t,e]=Me(null),[o,i]=Me([]),[n,r]=Me(!1),[s,a]=Me(!1),c=bo(null),u=bo(null),x=pt("FLT"),m=F(C=>C.campaigns),g=F(C=>C.allCampaigns),v=F(C=>C.currentScreen),f=F(C=>C.isVisible),b=bo(null),h=x??(()=>{let C=[...m,...g].find(S=>{let _=S;if(_.campaign_type!=="FLT")return!1;let E=!!(_.trigger_event??_.trigger);return _.display_trigger===!1||E?!1:!xo(_.screen)||xo(_.screen)===xo(v)});if(C)try{return yt(C)}catch{return C}})(),y=h?.id,w=F(C=>y?C.variantMappings[y]:void 0);if(ho(()=>{if(!h?.id||!f||co(h)&&!w)return;let S=`${h.id}:${w||""}`;b.current!==S&&(b.current=S,H("viewed",h.id))},[h?.id,w,f]),ho(()=>{let C=h?.details?.lottie_data;if(e(null),i([]),r(!1),a(!1),!C)return;if(hr(C)){e(C),a(!0);return}if(typeof C!="string"){r(!0);return}let S=yr(C);i(S),a(!0)},[h?.details?.lottie_data]),ho(()=>{if(!h?.details?.lottie_data||!c.current)return;let C=fr;if(!C||typeof C.loadAnimation!="function"){r(!0),a(!1);return}let S=!1,_=null,E=()=>{_&&typeof _.destroy=="function"&&_.destroy(),_=null,u.current=null},$=(D,k)=>{if(S)return;if(k>=D.length){r(!0),a(!1),console.error("[Floater] lottie load failed",{lottieUrls:D});return}E();let P=C.loadAnimation({container:c.current,renderer:"svg",loop:!0,autoplay:!0,path:D[k]});_=P,u.current=P,P.addEventListener("DOMLoaded",()=>{S||a(!1)}),P.addEventListener("data_failed",()=>{S||$(D,k+1)})};if(t){E();let D=C.loadAnimation({container:c.current,renderer:"svg",loop:!0,autoplay:!0,animationData:t});_=D,u.current=D,D.addEventListener("DOMLoaded",()=>{S||a(!1)}),D.addEventListener("data_failed",()=>{S||(r(!0),a(!1))})}else o.length>0&&$(o,0);return()=>{S=!0,E()}},[h?.details?.lottie_data,t,o]),!h||!h.details||!f)return null;let{details:I}=h,z=I.styling||{},d=(typeof I.position=="string"?I.position:typeof h.position=="string"?h.position:"right").toLowerCase()==="left"?"left":"right",T={position:"fixed",left:d==="left"?xt(z.marginLeft,12):void 0,right:d==="left"?void 0:xt(z.marginRight,12),top:xt(z.marginTop,0)>0?xt(z.marginTop,0):void 0,bottom:xt(z.marginTop,0)>0?void 0:xt(z.marginBottom,80),zIndex:10040,display:"flex"},l={width:xt(I.width,60),height:xt(I.height,60),background:"transparent",overflow:"hidden",borderBottomLeftRadius:xt(z.bottomLeftRadius,0),borderBottomRightRadius:xt(z.bottomRightRadius,0),borderTopLeftRadius:xt(z.topLeftRadius,0),borderTopRightRadius:xt(z.topRightRadius,0),display:"flex",alignItems:"center",justifyContent:"center",cursor:I.link?"pointer":"default",boxShadow:"0 8px 18px rgba(0,0,0,0.2)"},p=async()=>{if(!I.link)return;await H("clicked",h.id);let C=String(I.link).trim();try{let S=F.getState(),_=S.allCampaigns||[],E=S.campaigns||[],$=_.find(D=>{if(!D)return!1;let k=String(D.id||"").trim(),P=D.details||{},O=String(P.campaign||P.id||"").trim();return!!(k&&k===C||O&&O===C||k&&C.includes(k)||O&&C.includes(O))});if(console.log("[Floater] clicked link=",C,"allCampaignsCount=",_.length,"visibleCount=",E.length),console.log("[Floater] all ids=",_.map(D=>D.id).slice(0,50)),console.log("[Floater] referenced found=",!!$,$&&($.id||$.details?.campaign||$.details?.id)),$){let D={...$};delete D.trigger_event,delete D.trigger,D.display_trigger=!0;let k=E.findIndex(P=>P.id===D.id);if(k===-1)console.log("[Floater] revealing campaign (prepended)",D.id),S.saveCampaigns([D,...E]);else{let P=E[k];if(!!(P.trigger_event??P.trigger)){let G=[...E];G[k]=D,console.log("[Floater] replacing existing triggered campaign with revealed one",D.id),S.saveCampaigns(G)}else console.log("[Floater] campaign already visible and not trigger-driven",D.id)}return}}catch(S){console.warn("[Floater] error while resolving referenced campaign",S)}try{window.open(I.link,"_blank")}catch{}},M=!!(I.lottie_data&&!n),B=!!I.image,L=!!(I.lottie_data&&s&&!t&&!n);return!M&&!B&&!L?null:te("div",{style:T,children:te("div",{style:l,onClick:()=>{p()},children:M?te(So,{onError:()=>r(!0),children:te("div",{ref:c,style:{width:"100%",height:"100%",display:"block"}})},String(I.lottie_data)):L?te("div",{style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.08)",color:"#333",fontSize:10,fontWeight:600},children:"..."}):te("img",{src:I.image,alt:"floater",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}})})})},xr=br;K();function zn(t){return(t||"").trim().toLowerCase()}function Co(t,e){let o=zn(t.screen),i=zn(e);return!o||o===i}async function vo(t){try{let e=F.getState(),o=await dt(),i=e.accountId;if(!o||!i)return;e.setCurrentScreen(t),e.setTrackedEvents([]);let n=e.baseUrl||"https://users.appstorys.co",r=await fetch(`${n}/v2/${i}/track-user-res`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o}`},body:JSON.stringify({user_id:kt(),screenName:t})});if(!r.ok)return;let s=await r.json();if(typeof s.screen_capture_enabled<"u"&&e.setScreenCaptureEnabled(!!s.screen_capture_enabled),s.variants&&s.variants.length>0){let y={};s.variants.forEach(w=>{y[w.id]=w.v_id}),e.setVariantMappings(y)}s.personalization_data&&e.setPersonalizationData(s.personalization_data);let a=e.allCampaigns||[],c=s.eligibleCampaignList||[],u=a.filter(y=>c.includes(y.id)&&Co(y,t)),x=u.map(y=>y.id),m=c.filter(y=>!x.includes(y)),g=[];if(m.length>0){let y=await fetch(`${n}/load-campaign-data`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o}`},body:JSON.stringify(m)});y.ok&&(g=(await y.json()).filter(I=>Co(I,t)))}let v=[...u,...g],f=a.filter(y=>{let w=!!(y.trigger_event??y.trigger);return Co(y,t)&&y.display_trigger===!0&&!w}),b=[...v],h=new Set(b.map(y=>y.id));for(let y of f)h.has(y.id)||(b.push(y),h.add(y.id));e.saveCampaigns(b)}catch(e){console.error("Error when tracking screen:",t,e)}}Ee();K();Ae();async function wo(t){try{let e=await dt(),o=kt(),i=F.getState();if(!e||!o){console.warn("AppStorys: Missing accessToken or userId. Ensure SDK is initialized before setting user properties.");return}let n={...t||{}},r=await qt();n={...n,...r};let s={user_id:o,attributes:n},a=i.baseUrl||"https://users.appstorys.co";await De({url:`${a}/update-user-atr`,method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`},body:s})}catch(e){console.error("AppStorys: Error in setUserProperties:",e)}}K();function Oe(t){if(!t||t.trim()==="")return t;let e=F.getState().personalizationData;if(!e||Object.keys(e).length===0)return Sr(t);let o=/\{\{([^|}\s]+)\s*\|\s*([^}]+)\}\}/g;return t.replace(o,(i,n,r)=>{let s=n.trim(),a=r.trim();return e[s]??a})}function Sr(t){let e=/\{\{[^|}\s]+\s*\|\s*([^}]+)\}\}/g;return t.replace(e,(o,i)=>i.trim())}Kt();K();K();var ko="appstorys_campaigns_cache",Bn="appstorys_campaigns_etag",Ro="appstorys_campaigns_version";async function To(t,e){try{let o=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),i=o?`/appstorys-campaigns/clients/${t}/campaigns.json`:`https://dev-cdn-campaign-appstorys.s3.ap-south-1.amazonaws.com/clients/${t}/campaigns.json`,n=await tt.getItem(ko),r=await tt.getItem(Bn),s=await tt.getItem(Ro),a={Accept:"application/json"};!o&&r&&(a["If-None-Match"]=r);let c=await fetch(i,{method:"GET",headers:a,...o?{cache:"no-store"}:{}});if(c.status===304)return{campaigns:n?JSON.parse(n):[],version:s?parseInt(s):1};let u=c.headers.get("ETag"),x=await c.json(),m=2,g=x,v=e;if(!v)try{let f=await dt(),b=kt(),y=await fetch(`${o?"/appstorys-users":"https://users.appstorys.co"}/v2/${t}/track-user-res`,{method:"POST",headers:{"Content-Type":"application/json",...f?{Authorization:`Bearer ${f}`}:{}},body:JSON.stringify({user_id:b,screenName:typeof window<"u"&&window.location&&window.location.pathname?window.location.pathname:"",silentUpdate:!0})});if(y.ok){let w=await y.json();console.info("AppStorys: fetchAllCampaigns track-user-res returned",w);let I=w?.screenName||w?.screen||w?.currentScreen||w?.screen_name||w?.current_screen;I&&(v=I);try{let z=F.getState();typeof w.screen_capture_enabled<"u"&&z.setScreenCaptureEnabled(!!w.screen_capture_enabled)}catch{}}}catch(f){console.warn("Could not fetch screen name from track-user-res:",f)}if(x.length>0&&x[0].version!==void 0&&(m=x[0].version,g=x.slice(1)),!g||g.length===0)try{let f=await dt(),b=kt(),y=await fetch(`${o?"/appstorys-users":"https://users.appstorys.co"}/v2/${t}/track-user-res`,{method:"POST",headers:{"Content-Type":"application/json",...f?{Authorization:`Bearer ${f}`}:{}},body:JSON.stringify({user_id:b,screenName:typeof window<"u"&&window.location&&window.location.pathname?window.location.pathname:"",silentUpdate:!0})});if(y.ok){let w=await y.json(),I=w?.user_id||w?.id||w?.userId||b;try{let z=F.getState();typeof w.screen_capture_enabled<"u"&&z.setScreenCaptureEnabled(!!w.screen_capture_enabled)}catch{}if(I){let R=await fetch(o?"/appstorys-users/load-campaign-data":"https://users.appstorys.com/load-campaign-data",{method:"POST",headers:{"Content-Type":"application/json",...f?{Authorization:`Bearer ${f}`}:{}},body:JSON.stringify({user_id:I})});if(R.ok){let d=await R.json();console.log(`Fetched ${d.length} missing campaigns from fallback`),console.log("Fallback campaigns:",JSON.stringify(d,null,2)),d&&d.length>0&&(g=d)}else console.error("Failed to fetch missing campaigns:",await R.text())}}}catch(f){console.error("Error fetching missing campaigns via fallback:",f)}if(v&&g&&g.length>0){let f=h=>(h||"").trim().toLowerCase(),b=f(v);g=g.filter(h=>!f(h.screen)||f(h.screen)===b)}return await tt.setItem(ko,JSON.stringify(g)),await tt.setItem(Ro,m.toString()),u&&await tt.setItem(Bn,u),{campaigns:g,version:m}}catch(o){console.error("Error fetching campaigns:",o);let i=await tt.getItem(ko),n=await tt.getItem(Ro);return{campaigns:i?JSON.parse(i):[],version:n?parseInt(n):1}}}K();K();K();async function je(t,e){try{let o=await dt(),i=F.getState();if(!o)return console.error("AppStorys: Access token not found for reconciliation"),!1;let n={anonymous_user_id:t,identified_user_id:e},r=i.baseUrl||"https://users.appstorys.co",s=await fetch(`${r}/reconcile-anonymous-user`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o}`},body:JSON.stringify(n)});if(s.ok)return!0;{let a=await s.text();return console.error("AppStorys: Failed to reconcile anonymous user:",s.status,a),!1}}catch(o){return console.error("AppStorys: Error in reconcileAnonymousUser:",o),!1}}K();var Fo=class{isInitialized=!1;setup(){this.isInitialized||typeof window>"u"||(document.addEventListener("mouseleave",this.handleMouseLeave),window.addEventListener("popstate",this.handlePopState),window.history.state!=="appstorys_navigation"&&window.history.pushState("appstorys_navigation",""),this.isInitialized=!0)}destroy(){!this.isInitialized||typeof window>"u"||(document.removeEventListener("mouseleave",this.handleMouseLeave),window.removeEventListener("popstate",this.handlePopState),this.isInitialized=!1)}handleMouseLeave=e=>{e.clientY<=0&&po()&&this.triggerCampaign()};handlePopState=()=>{po()&&(window.history.pushState("appstorys_navigation",""),this.triggerCampaign())};triggerCampaign(){let e=F.getState(),{trackedEvents:o}=e;o.includes(Be)||(console.log("AppStorys: Exit Intent triggered. Displaying campaign."),e.setTrackedEvents([...o,Be]))}},An=new Fo;K();var Io=class{isInitialized=!1;setup(){this.isInitialized||typeof document>"u"||(document.addEventListener("visibilitychange",this.handleVisibilityChange),this.updateVisibility(document.visibilityState==="visible"),this.isInitialized=!0)}destroy(){!this.isInitialized||typeof document>"u"||(document.removeEventListener("visibilitychange",this.handleVisibilityChange),this.isInitialized=!1)}handleVisibilityChange=()=>{this.updateVisibility(document.visibilityState==="visible")};updateVisibility(e){let o=F.getState();o.isVisible!==e&&(console.log(`AppStorys: SDK visibility changed to ${e?"visible":"hidden"}`),o.setVisibility(e))}},zo=new Io;Kt();var Ne="anonymous_user_id";async function En(){let t=Date.now(),e=navigator.userAgent.split(" ")[0].replace(/[^a-zA-Z0-9]/g,"_");return`${t}_${e}`}async function Pn(){try{let t=await tt.getItem(Ne);if(t)return t;let e=await En();return await tt.setItem(Ne,e),e}catch(t){return console.error("Error managing anonymous user ID:",t),await En()}}async function Bo(){try{await tt.removeItem(Ne)}catch(t){console.error("Error clearing anonymous user ID:",t)}}async function Ao(){try{return await tt.getItem(Ne)}catch(t){return console.error("Error getting stored anonymous user ID:",t),null}}function Cr(){if(document.getElementById("appstorys-widget-debug-styles"))return;let t=document.createElement("style");t.id="appstorys-widget-debug-styles",t.innerHTML=`
14
+ `,document.head.appendChild(t)}function Bl(){Il();let t=document.createElement("button");return t.id="appstorys-screen-capture-btn",t.title="Capture screen",Object.assign(t.style,{position:"fixed",left:"16px",bottom:"16px",width:"100px",height:"56px",borderRadius:"28px",background:"#ff6a00",color:"#fff",border:"none",boxShadow:"0 6px 18px rgba(0,0,0,0.2)",zIndex:"2147483647",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"14px",fontWeight:"600",fontFamily:"sans-serif",transition:"all 0.2s ease"}),t.innerText="Capture",t}function is(){try{let t=P.getState(),o=!!window.__APPSTORYS_DEBUG_CAPTURE;if(console.info("AppStorys: mountScreenCaptureButton called, screenCaptureEnabled=",t.screenCaptureEnabled,"debugForce=",o),!t.screenCaptureEnabled&&!o||document.getElementById("appstorys-screen-capture-btn"))return null;let n=Bl();return n.addEventListener("click",async()=>{n.disabled=!0;let i=n.innerText;n.innerHTML='<div class="appstorys-spinner"></div>';let l=P.getState().currentScreen||(typeof window<"u"?window.location.pathname:"");try{await We.takeScreenshot(l)}catch(c){console.error("CaptureService error",c)}n.disabled=!1,n.innerText=i,n.animate([{transform:"scale(1.0)"},{transform:"scale(1.05)"},{transform:"scale(1.0)"}],{duration:300})}),document.body.appendChild(n),console.info("AppStorys: screen capture button mounted"),n}catch(t){return console.error("mountScreenCaptureButton error",t),null}}var ss=Me(()=>{"use strict";yt();ns();try{window.AppStorysMountCapture=function(){try{return is()}catch(t){return console.error("AppStorysMountCapture failed",t),null}}}catch{}try{window.AppStorysDebugState=function(){try{let t=P.getState();return console.info("AppStorys store state:",t),t}catch(t){return console.error("AppStorysDebugState failed",t),null}}}catch{}try{window.AppStorysDebugToken=function(){try{let t=localStorage.getItem("access_token")||"",e=t.length,o=t?t.slice(0,20)+"..."+t.slice(-10):"(none)";if(console.info("Token length:",e,"masked:",o),t&&t.includes("."))try{let n=t.split(".");if(n.length===3){let i=JSON.parse(atob(n[1]));if(console.info("Token payload:",i),i.exp){let s=new Date(i.exp*1e3),l=new Date;console.info("Token expires:",s.toISOString(),"Expired:",l>s)}}}catch(n){console.warn("Could not decode JWT:",n)}return t?"Token present":"No token"}catch(t){return console.error("AppStorysDebugToken failed",t),null}}}catch{}});var yi=(i=>(i.uninitialized="uninitialized",i.initializing="initializing",i.initialized="initialized",i.error="error",i))(yi||{});yt();import{useState as No,useEffect as Ti,useRef as zi}from"react";import*as je from"lottie-react";yt();import{useMemo as fs}from"react";yt();var bi="appstorys_variant_mappings",uo={};function us(t){let e=0;for(let o=0;o<t.length;o++){let n=t.charCodeAt(o);e=(e<<5)-e+n,e|=0}return Math.abs(e)}function xi(){if(typeof window>"u")return{};try{let t=localStorage.getItem(bi);if(t)return JSON.parse(t)}catch{}return{}}function ps(t,e){if(!(!t||!e)){uo[t]=e;try{let o=P.getState(),n=o.variantMappings||{};n[t]!==e&&o.setVariantMappings({...n,[t]:e})}catch{}if(typeof window<"u")try{let o=xi();o[t]=e,localStorage.setItem(bi,JSON.stringify(o))}catch{}}}var Si=t=>{if(!t)return;if(uo[t])return uo[t];let e=P.getState().variantMappings?.[t];if(e)return uo[t]=e,e;let o=xi();if(o[t]){uo[t]=o[t];try{P.getState().setVariantMappings({...P.getState().variantMappings||{},[t]:o[t]})}catch{}return o[t]}};function Eo(t){if(!t)return!1;if(t.hasVariants===!0||t.variants&&typeof t.variants=="object"&&Object.keys(t.variants).length>0)return!0;if(t.details&&typeof t.details=="object"&&t.details.variants){let e=t.details.variants;if(typeof e=="object"&&Object.keys(e).length>0)return!0}return!1}function gs(t,e){let o=Object.keys(t);if(o.length===0)return;let n=o.filter(l=>t[l]&&t[l].isActive!==!1),i=n.length>0?n:o,s=i.reduce((l,c)=>l+(Number(t[c]?.weight)||0),0);if(s>0){let l=P.getState().userId||"default",c=`${e||"campaign"}_${l}`,S=us(c)%1e4/1e4*s;for(let p of i){let y=Number(t[p]?.weight)||0;if(S<y)return p;S-=y}}return i[0]}function Nt(t){if(!t||!Eo(t))return t;let e=t,o=e.variants||e.details?.variants;if(!o||typeof o!="object"||Object.keys(o).length===0)return t;let n=Si(e.id||"");if((!n||!o[n])&&(n=gs(o,e.id),e.id&&n&&ps(e.id,n)),!n||!o[n])return t;let i=o[n],l={...e.details&&typeof e.details=="object"?Object.fromEntries(Object.entries(e.details).filter(([c])=>c!=="variants")):{},...i};return{...t,details:l,_variantId:n}}function Wl(t){if(t){if("_variantId"in t)return t._variantId;if(Eo(t))return Si(t.id||"")}}var Ao="__back_press_triggered__";function Ci(t){return(t||"").trim().toLowerCase()}function ms(t,e){let o=Ci(t),n=Ci(e);return!o||o===n}function ys(t,e,o){let n=Number(t),i=Number(o),s=!isNaN(n)&&!isNaN(i);switch(e){case"eq":return s?n===i:t===o;case"neq":return s?n!==i:t!==o;case"gt":return s?n>i:t>o;case"gte":return s?n>=i:t>=o;case"lt":return s?n<i:t<o;case"lte":return s?n<=i:t<=o;default:return!1}}function hs(t,e){let o=t.filter(n=>n.back_press==null);return o.length===0?!0:e.some(n=>o.every(i=>{let s=n[i.key];return s==null?!1:ys(String(s),i.operator,i.value)}))}function bs(t,e,o){let n=t,i=n.trigger_event??n.trigger,s=t.id;return!i}function bn(){let{campaigns:t,trackedEvents:e,trackedEventMetadata:o,currentScreen:n}=P.getState();return t.some(i=>{if(i.screen&&i.screen!==n)return!1;let s=i.trigger_event;if(!s||typeof s=="string")return!1;let{event:l,event_config:c}=s;if(!(c??[]).some(p=>p.back_press===!0)||e.includes(Ao)||!e.includes(l))return!1;let d=(c??[]).filter(p=>p.back_press==null);if(d.length===0)return!0;let S=o[l]||[];return hs(d,S)})}function xn(t){return Array.isArray(t)?[...t].sort((o,n)=>{let i=typeof o?.order=="number"?o.order:0,s=typeof n?.order=="number"?n.order:0;return i-s}).map(o=>{if(!o||!Array.isArray(o.slides))return o;let n=[...o.slides].sort((i,s)=>{let l=typeof i?.order=="number"?i.order:0,c=typeof s?.order=="number"?s.order:0;return l-c});return{...o,slides:n}}):[]}function At(t,e){let o=P(d=>d.currentScreen),n=P(d=>d.campaigns),i=P(d=>d.allCampaigns),s=P(d=>d.trackedEvents),l=P(d=>d.trackedEventMetadata),c=P(d=>d.variantMappings);return fs(()=>{let d=u=>u.find(C=>{if(C.campaign_type!==t||e?.position&&C.position!==e.position||!bs(C,s,l))return!1;if(e?.screenContains){let h=(e.screenContains||"").trim().toLowerCase();return(C.screen||"").trim().toLowerCase().includes(h)}return ms(C.screen,o)}),p=(n&&n.length>0?d(n):void 0)??d(i||[]);if(!p)return;let y=Nt(p);return y&&y.details&&Array.isArray(y.details)&&(y.details=xn(y.details)),y},[n,i,s,l,c,t,e,o])}yt();Mo();Oe();yt();Po();var wi="appstorys_offline_queue";async function ki(){let t=await Ct.getItem(wi);return t?JSON.parse(t):[]}async function Ri(t){await Ct.setItem(wi,JSON.stringify(t))}function xs(t){return Math.min(3e4*Math.pow(2,t),12e4)}function Ss(t){let o=t.retryCount||0,n=t.lastAttempt||0,i=xs(o);return o<3&&Date.now()-n>=i}async function Cs(){let t=P.getState();return!t.accountId||!t.appId?!1:await he(t.accountId,t.appId,t.userId)}async function Fi(t,e){if(await Cs()){let n=await Ct.getItem("access_token");n&&(t.headers={...t.headers,Authorization:`Bearer ${n}`}),t.authRetried=!0,t.lastAttempt=Date.now(),e(t)}}async function _o(t,e){let o=(t.retryCount||0)+1;o<=3&&(t.retryCount=o,t.lastAttempt=Date.now(),e(t))}async function Do(t){let e=await ki();e.push(t),await Ri(e)}async function vs(){let t=await ki();if(t.length===0)return;let e=[];for(let o of t){if(!Ss(o)){e.push(o);continue}try{let n=await fetch(o.url,{method:o.method,headers:o.headers,body:JSON.stringify(o.body)});if(n.ok)continue;n.status===401||n.status===403?o.authRetried||await Fi(o,i=>e.push(i)):n.status>=500&&await _o(o,i=>e.push(i))}catch{await _o(o,i=>e.push(i))}}await Ri(e)}async function Wo(t){if(!navigator.onLine){await Do(t);return}await vs();try{let e=await fetch(t.url,{method:t.method,headers:t.headers,body:JSON.stringify(t.body)});return e.ok||(e.status===401||e.status===403?await Fi(t,Do):e.status>=500&&await _o(t,Do)),e}catch{await _o(t,Do);return}}async function rt(t,e,o){try{if(!t)return;let n=await Et(),i=P.getState(),s=["viewed","clicked","csat captured","survey captured","shared"];if(!s.includes(t)){let S=i.trackedEvents;if(!S.includes(t))i.setTrackedEvents([...S,t]);else{let p=S.filter(y=>y!==t);p.push(t),i.setTrackedEvents(p)}if(o&&Object.keys(o).length>0){let p=i.trackedEventMetadata||{},y=p[t]||[];i.setTrackedEventMetadata({...p,[t]:[...y,o]})}}let l={...o||{}};if(!s.includes(t)){let S=await Pe();l={...l,...S}}if(e&&String(e).trim()!==""){let S=o?.variant_id||hi(e);S&&(l.variant_id=S)}let c={user_id:ee(),event:t,metadata:l};e&&(c.campaign_id=e);let d=i.trackingUrl||"https://tracking.appstorys.co";n&&await Wo({url:`${d}/capture-event`,method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:c})}catch(n){console.error("Error in trackEvent",n)}}yt();function Pt(t){if(!t)return!1;let e=P.getState(),o=e.allCampaigns||[],n=e.campaigns||[],i=String(t).trim(),s=o.find(d=>{if(!d)return!1;let S=String(d.id||"").trim(),p=d.details||{},y=String(p.campaign||p.id||"").trim();return!!(S&&S===i||y&&y===i||S&&i.includes(S)||y&&i.includes(y))});if(!s)return!1;let l={...s};delete l.trigger_event,delete l.trigger,l.display_trigger=!0;let c=n.findIndex(d=>String(d.id||"")===String(l.id||""));if(c===-1)e.saveCampaigns([l,...n]);else{let d=n[c];if(!!(d.trigger_event??d.trigger)){let p=[...n];p[c]=l,e.saveCampaigns(p)}}return!0}import{jsx as $o,jsxs as ks}from"react/jsx-runtime";var ws=({config:t,onPress:e,style:o,ignoreSizeAndMargin:n=!1})=>{if(!t||!t.enabled)return null;let i=t.size,s=t.margin,l=t.color,c=t.image,d=t.selectedStyle,S=i!=null&&i>=0?i:18,p=n?40:S,y=s?.top!==void 0&&s?.top!==null&&s.top>=0?s.top:0,u=s?.bottom!==void 0&&s?.bottom!==null&&s.bottom>=0?s.bottom:0,C=s?.left!==void 0&&s?.left!==null&&s.left>=0?s.left:0,h=s?.right!==void 0&&s?.right!==null&&s.right>=0?s.right:0,g={marginTop:n?0:y,marginBottom:n?0:u,marginLeft:n?0:C,marginRight:n?0:h,width:p,height:p,backgroundColor:l?.fill||"transparent",borderColor:l?.stroke||"transparent",borderWidth:p*.05,borderRadius:"50%",justifyContent:"center",alignItems:"center",zIndex:1e6,position:"absolute",display:"flex",padding:0,cursor:"pointer",outline:"none",borderStyle:l?.stroke?"solid":"none",...o},b=()=>{let m=l?.cross||"#ffffff";return ks("svg",{viewBox:"0 0 24 24",width:"70%",height:"70%","aria-hidden":!0,children:[$o("line",{x1:"6",y1:"6",x2:"18",y2:"18",stroke:m,strokeWidth:"2.2",strokeLinecap:"round"}),$o("line",{x1:"18",y1:"6",x2:"6",y2:"18",stroke:m,strokeWidth:"2.2",strokeLinecap:"round"})]})};return $o("button",{type:"button","data-control-button":"true",onMouseDown:m=>m.stopPropagation(),onClick:m=>{m.stopPropagation(),m.preventDefault(),e(m)},style:g,children:c&&c.trim()!==""?$o("img",{src:c,style:{width:p,height:p,objectFit:"contain"},alt:"close"}):b()})},Dt=ws;import{jsx as Oo,jsxs as Fs}from"react/jsx-runtime";var Ii=je.default?.default??je.default??je.Lottie??je,Rs=()=>{let t=At("BAN"),e=P(T=>T.isVisible),[o,n]=No(!1),[i,s]=No(null),[l,c]=No(null),d=zi(null),[S,p]=No(0),y=zi(null);if(Ti(()=>{t?.id&&y.current!==t.id&&(y.current=t.id,n(!1),rt("viewed",t.id),t.details?.lottie_data&&fetch(t.details.lottie_data).then(T=>T.json()).then(T=>{s(T),T.w&&T.h&&c(T.h/T.w)}).catch(T=>console.error("Error loading Lottie:",T)))},[t?.id]),Ti(()=>{let T=()=>{d.current&&p(d.current.offsetWidth)};return T(),window.addEventListener("resize",T),()=>window.removeEventListener("resize",T)},[t,o]),!t||o||!e)return null;let{details:u}=t,C=u.styling||{},h=u.height||"auto";l&&S&&(h=S*l);let g=parseFloat(String(u.height)),b=parseFloat(String(u.originalWidth??u.styling?.originalWidth)),m=parseFloat(String(u.originalHeight??u.styling?.originalHeight)),E=Number.isFinite(g)&&g>0&&Number.isFinite(b)&&b>0&&Number.isFinite(m)&&m>0?g*(b/m):null,O=E!==null?`${E}px`:void 0,D=typeof h=="number"?`${h}px`:h||void 0,L=Number(C.marginRight),v=Number(C.marginBottom),w={position:"fixed",right:Number.isFinite(L)?`${L}px`:"0px",bottom:Number.isFinite(v)?`${v}px`:"0px",zIndex:9999,display:"block",cursor:u.link?"pointer":"default"},_={position:"relative",width:O||"100%",height:D||"auto",backgroundColor:"transparent",borderRadius:`${C.topRightRadius||0}px ${C.topLeftRadius||0}px ${C.bottomRightRadius||0}px ${C.bottomLeftRadius||0}px`,overflow:"hidden"},$={width:"100%",height:"100%",display:"block",objectFit:"contain"},V=T=>{T.stopPropagation(),n(!0),rt("banner_closed",t.id)};return Oo("div",{ref:d,style:w,onClick:()=>{if(u.link)if(rt("clicked",t.id),u.link.startsWith("http"))window.open(u.link,"_blank");else{try{if(Pt(u.link))return}catch(T){console.warn("revealCampaignFromLink error",T)}console.log("Internal link:",u.link)}},children:Fs("div",{style:_,children:[i?(()=>{let T=Ii.default||Ii;return Oo(T,{animationData:i,loop:!0,autoplay:e,style:$})})():u.image?Oo("img",{src:u.image,alt:"Campaign Banner",style:$}):null,C.crossButton?.enabled&&Oo(Dt,{config:C.crossButton,onPress:V,style:{top:C.crossButton?.margin?.top!==void 0?0:5,right:C.crossButton?.margin?.right!==void 0?0:5}})]})})};import{useEffect as po,useMemo as _i,useRef as go,useState as fo}from"react";yt();function qo(t){let e=t.trim();return e.startsWith("http://")||e.startsWith("https://")}function Bi(t){try{let o=new URL(t).pathname.split("/").pop()||t;return o.split("?")[0].replace(/\.[^.]+$/,"")||`font_${o.length}`}catch{return(t.split("/").pop()??t).split("?")[0].replace(/\.[^.]+$/,"")||`font_${t.length}`}}function Li(t,e){if(typeof document>"u")return;let o=`appstorys-font-${t}`;if(document.getElementById(o))return;let n=document.createElement("style");n.id=o,n.type="text/css",n.textContent=`@font-face{font-family:"${t}";src:url("${e}");font-style:normal;font-weight:normal;font-display:swap;}`,document.head.appendChild(n)}var jo=new Map;async function Ts(t,e){try{Li(e.name,t);let o=globalThis.FontFace;if(typeof document<"u"&&o&&document.fonts?.add){let n=new o(e.name,`url(${t})`);await n.load(),document.fonts.add(n)}else typeof document<"u"&&document.fonts?.load&&await document.fonts.load(`1em "${e.name}"`);e.status="loaded",e.listeners.forEach(n=>n(e.name))}catch(o){console.warn(`[FontManager] Failed to load font from "${t}":`,o),e.status="failed",e.listeners.forEach(n=>n(void 0))}finally{e.listeners=[]}}var Sn={async load(t){if(!t||!qo(t))return;let e=jo.get(t);if(e)return e.status==="loaded"?e.name:e.status==="failed"?void 0:new Promise(s=>e.listeners.push(s));let n={status:"pending",name:Bi(t),listeners:[]};jo.set(t,n);let i=new Promise(s=>n.listeners.push(s));return Ts(t,n),i},ensure(t){if(!t||!qo(t))return;let e=Bi(t);return Li(e,t),Sn.load(t),e},getSync(t){if(!t)return;let e=jo.get(t);return e?.status==="loaded"?e.name:void 0},_clearCache(){jo.clear()}};function st(t,e){if(!t)return e;let o=String(t).trim();if(!o)return e;if(qo(o)){let n=Sn.ensure(o);return n?`"${n}", ${e||"sans-serif"}`:e}return o.includes(",")||o.includes('"')||o.includes("'")?o:`"${o}", ${e||"sans-serif"}`}function zs(t){let e=new Set,o=new WeakSet,n=i=>{if(i!=null&&typeof i!="string"){if(Array.isArray(i)){for(let s of i)n(s);return}if(typeof i=="object"){if(o.has(i))return;o.add(i);for(let[s,l]of Object.entries(i))s==="fontFamily"&&typeof l=="string"&&qo(l)&&e.add(l),n(l)}}};return n(t),Array.from(e)}async function Ei(t){let e=new Set;for(let o of t)zs(o).forEach(n=>e.add(n));await Promise.all(Array.from(e).map(o=>Sn.load(o)))}import{jsx as Se,jsxs as Ai}from"react/jsx-runtime";var be=({config:t,onPress:e,ignoreSizeAndMargin:o=!1,enabled:n,style:i,type:s})=>{if(!t||!n)return null;let{size:l=18,margin:c,color:d,image:S,selectedStyle:p}=t,y=o?40:l,u=o?0:c?.top??0,C=o?0:c?.bottom??0,h=o?0:c?.left??0,g=o?0:c?.right??0,b={marginTop:u,marginBottom:C,marginLeft:h,marginRight:g,width:y,height:y,backgroundColor:d?.fill||"transparent",borderColor:d?.stroke||"transparent",borderWidth:y*.05,borderRadius:"50%",justifyContent:"center",alignItems:"center",zIndex:1e6,display:"flex",...o?{}:{marginTop:t.margin?.top??0,marginRight:t.margin?.right??0,marginBottom:t.margin?.bottom??0,marginLeft:t.margin?.left??0},...i},m=()=>{let E=d?.cross||"#ffffff";return s==="mute"?Ai("svg",{viewBox:"0 0 24 24",width:"70%",height:"70%","aria-hidden":!0,children:[Se("polygon",{points:"4,10 8,10 13,6 13,18 8,14 4,14",fill:"none",stroke:E,strokeWidth:"2.2",strokeLinejoin:"round"}),Se("line",{x1:"16",y1:"8",x2:"21",y2:"16",stroke:E,strokeWidth:"2.2",strokeLinecap:"round"}),Se("line",{x1:"21",y1:"8",x2:"16",y2:"16",stroke:E,strokeWidth:"2.2",strokeLinecap:"round"})]}):Ai("svg",{viewBox:"0 0 24 24",width:"70%",height:"70%","aria-hidden":!0,children:[Se("polygon",{points:"4,10 8,10 13,6 13,18 8,14 4,14",fill:"none",stroke:E,strokeWidth:"2.2",strokeLinejoin:"round"}),Se("path",{d:"M16 10 Q18 12 16 14",fill:"none",stroke:E,strokeWidth:"2.2",strokeLinecap:"round"}),Se("path",{d:"M18 8 Q22 12 18 16",fill:"none",stroke:E,strokeWidth:"2.2",strokeLinecap:"round"})]})};return Se("button",{type:"button","data-control-button":"true",onMouseDown:E=>E.stopPropagation(),onClick:E=>{E.stopPropagation(),E.preventDefault(),e(E)},style:{...b,border:b.borderColor?`${b.borderWidth}px solid ${b.borderColor}`:"none",padding:0,cursor:"pointer",outline:"none"},children:S&&S.trim()!==""?Se("img",{src:S,style:{width:y,height:y,objectFit:"contain"},alt:s}):m()})};import{jsx as le,jsxs as Mi}from"react/jsx-runtime";var Pi=({config:t,onPress:e,ignoreSizeAndMargin:o=!1,enabled:n,style:i,type:s})=>{if(!t||!n)return null;let{size:l=18,margin:c,color:d,image:S,selectedStyle:p}=t,y=o?40:l,u={marginTop:o?0:c?.top??0,marginBottom:o?0:c?.bottom??0,marginLeft:o?0:c?.left??0,marginRight:o?0:c?.right??0,width:y,height:y,backgroundColor:d?.fill||"transparent",borderColor:d?.stroke||d?.cross||"#ffffff",borderWidth:d?.stroke?Math.max(1,y*.05):2,borderRadius:"50%",justifyContent:"center",alignItems:"center",zIndex:1e6,display:"flex",padding:0,cursor:"pointer",outline:"none",borderStyle:"solid",boxSizing:"border-box",...o?{}:{marginTop:t.margin?.top??0,marginRight:t.margin?.right??0,marginBottom:t.margin?.bottom??0,marginLeft:t.margin?.left??0},...i},C=()=>{let h=d?.cross||"#ffffff";return s==="maximise"?Mi("svg",{viewBox:"0 0 24 24",width:"60%",height:"60%","aria-hidden":!0,children:[le("polyline",{points:"15,5 19,5 19,9",fill:"none",stroke:h,strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round"}),le("line",{x1:"19",y1:"5",x2:"14",y2:"10",stroke:h,strokeWidth:"2.2",strokeLinecap:"round"}),le("polyline",{points:"9,19 5,19 5,15",fill:"none",stroke:h,strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round"}),le("line",{x1:"5",y1:"19",x2:"10",y2:"14",stroke:h,strokeWidth:"2.2",strokeLinecap:"round"})]}):Mi("svg",{viewBox:"0 0 24 24",width:"60%",height:"60%","aria-hidden":!0,children:[le("polyline",{points:"14,6 14,10 18,10",fill:"none",stroke:h,strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round"}),le("line",{x1:"14",y1:"10",x2:"19",y2:"5",stroke:h,strokeWidth:"2.2",strokeLinecap:"round"}),le("polyline",{points:"6,14 10,14 10,18",fill:"none",stroke:h,strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round"}),le("line",{x1:"10",y1:"14",x2:"5",y2:"19",stroke:h,strokeWidth:"2.2",strokeLinecap:"round"})]})};return le("button",{type:"button","data-control-button":"true",onMouseDown:h=>h.stopPropagation(),onClick:h=>{h.stopPropagation(),h.preventDefault(),e(h)},style:u,children:S&&S.trim()!==""?le("img",{src:S,style:{width:y,height:y,objectFit:"contain"},alt:s}):C()})};import{jsx as Cn,jsxs as Bs}from"react/jsx-runtime";var Is=({styling:t,mode:e,muted:o,expanded:n,onClose:i,onToggleMute:s,onToggleExpand:l,containerStyle:c})=>{if(!t)return null;let d=e==="LARGE",S={position:"absolute",pointerEvents:"auto",...d?{top:15,right:15}:{top:0,right:0}},p={position:"absolute",pointerEvents:"auto",...d?{top:15,right:60}:{top:0,left:0}},y={position:"absolute",pointerEvents:"auto",...d?{top:15,left:15}:{bottom:0,right:0}},u=o?t.soundToggle?.unmute:t.soundToggle?.mute,C=n?t.expandControls?.minimise:t.expandControls?.maximise;return Bs("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,width:"100%",height:"100%",zIndex:9999999,pointerEvents:"none",...c},children:[t.crossButton?.enabled&&Cn(Dt,{config:{enabled:t.crossButton?.enabled??!1,image:t.crossButton?.image??"",color:{cross:t.crossButton?.color?.cross??"#ffffff",fill:t.crossButton?.color?.fill??"",stroke:t.crossButton?.color?.stroke??""},margin:{top:t.crossButton?.margin?.top??0,bottom:t.crossButton?.margin?.bottom??0,left:t.crossButton?.margin?.left??0,right:t.crossButton?.margin?.right??0},size:t.crossButton?.size&&t.crossButton.size>10?t.crossButton.size:20},onPress:i,ignoreSizeAndMargin:d,style:S}),t.soundToggle?.enabled&&u&&Cn(be,{config:u,onPress:s,ignoreSizeAndMargin:d,style:p,enabled:t.soundToggle?.enabled,type:o?"unmute":"mute"}),t.expandControls?.enabled&&C&&Cn(Pi,{config:C,onPress:l,ignoreSizeAndMargin:d,style:y,enabled:t.expandControls?.enabled,type:n?"minimise":"maximise"})]})},Di=Is;import{jsx as wn,jsxs as As}from"react/jsx-runtime";var vn=t=>(t||"").trim().toLowerCase(),Ho=(t,e)=>{let o=Number(t);return Number.isFinite(o)?o:e},Wi=20,$i=20,Ni=20,Oi=(t,e,o)=>{let n=window.innerWidth,i=window.innerHeight,s=Wi,l=Math.max(s,n-o.width-Wi),c=o.topInset,d=Math.max(c,i-o.height-o.bottomInset);return{x:Math.min(Math.max(t,s),l),y:Math.min(Math.max(e,c),d)}},Ls=t=>{if(t===!0||t===1)return!0;if(t===!1||t===0||t==null||t==="")return!1;let e=String(t).trim().toLowerCase();return e==="yes"||e==="true"||e==="1"},Es=()=>{let t=At("PIP"),e=P(K=>K.campaigns),o=P(K=>K.allCampaigns),n=P(K=>K.currentScreen),i=P(K=>K.isVisible),[s,l]=fo(!1),[c,d]=fo(!1),[S,p]=fo(!0),[y,u]=fo(!1),[C,h]=fo(null),g=go({x:0,y:0}),b=go({width:150,height:300,topInset:$i,bottomInset:Ni}),m=go(null),E=go({x:0,y:0}),O=go(!1),D=_i(()=>{if(t)return t;let K=vn(n),it=mt=>mt.find(gt=>{let R=gt,I=R.campaign_type==="PIP",N=!vn(R.screen)||vn(R.screen)===K,Z=!!(R.trigger_event??R.trigger),xt=R.display_trigger!==!1&&!Z;return I&&N&&xt}),lt=it(e)??it(o);return lt?Nt(lt):void 0},[t,e,o,n]),L=_i(()=>D,[D?.id,D?.details?.id]);if(po(()=>{if(!L)return;let K=L.details||{},it=K?.styling?.soundToggle?.defaultSound||K?.styling?.appearance?.defaultSound||"yes";p(String(it).toLowerCase()!=="yes"),l(!1),d(!1),h(null),rt("viewed",L.id)},[L]),po(()=>{let K=m.current;if(!K)return;K.muted=S;let it=K.play();it&&typeof it.catch=="function"&&it.catch(()=>{S||(K.muted=!0,p(!0))})},[S]),po(()=>{if(!c)return;let K=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.body.style.overflow=K}},[c]),po(()=>{if(!y)return;let K=lt=>{let mt=lt.clientX-E.current.x,gt=lt.clientY-E.current.y;(Math.abs(mt)>4||Math.abs(gt)>4)&&(O.current=!0);let R=lt.clientX-g.current.x,I=lt.clientY-g.current.y;h(Oi(R,I,b.current))},it=()=>{u(!1)};return window.addEventListener("pointermove",K),window.addEventListener("pointerup",it),window.addEventListener("pointercancel",it),()=>{window.removeEventListener("pointermove",K),window.removeEventListener("pointerup",it),window.removeEventListener("pointercancel",it)}},[y]),po(()=>{let K=()=>{h(it=>it&&Oi(it.x,it.y,b.current))};return window.addEventListener("resize",K),window.addEventListener("orientationchange",K),()=>{window.removeEventListener("resize",K),window.removeEventListener("orientationchange",K)}},[]),!L||!L.details||s||!i)return null;let v=L.details,w=v.styling||{},_=w.appearance||{},$=Ho(v.width??_.pipWidth,150),V=Ho(v.height??_.pipHeight,300),A=$,T=V,k=w.cta?.container||{},B=w.cta?.text||{},W=w.cta?.cornerRadius,H=w.cta?.margin||{},Y=!!(v.button_text&&v.button_text.trim().length>0),r=Ho(w.pipBottomPadding,20),M=Ho(w.pipTopPadding,0);b.current={width:A,height:T,topInset:$i+M,bottomInset:Ni+r};let a=c?v.large_video||v.small_video:v.small_video||v.large_video,f=(v.position||L.position||"right").toLowerCase(),x=!!w.isMovable,z=w.soundToggle?.enabled!==!1,U=w.crossButton?.enabled!==!1,et=w.expandablePip??v.expandablePip??v.expandable_pip,X=et!=null&&et!==""?Ls(et):w.expandControls?.enabled!==!1,q={...w,crossButton:{...w.crossButton,enabled:U,image:v.crossButtonImage||w.crossButton?.image},soundToggle:{...w.soundToggle,enabled:z,mute:{...w.soundToggle?.mute,image:v.muteImage||w.soundToggle?.mute?.image},unmute:{...w.soundToggle?.unmute,image:v.unmuteImage||w.soundToggle?.unmute?.image}},expandControls:{...w.expandControls,enabled:X,maximise:{...w.expandControls?.maximise,image:v.maximiseImage||w.expandControls?.maximise?.image},minimise:{...w.expandControls?.minimise,image:v.minimiseImage||w.expandControls?.minimise?.image}}},J=()=>{d(K=>{let it=!K;return it&&L?.id&&(rt("viewed",L.id),rt("analyze",L.id)),it})},nt={position:"fixed",zIndex:10020,width:c?"auto":A,height:c?"auto":T,borderRadius:c?0:5,overflow:"hidden",background:"#000",boxShadow:"0 16px 40px rgba(0,0,0,0.35)",cursor:y?"grabbing":x&&!c?"grab":"default",transition:y?"none":"width 180ms ease, height 180ms ease, transform 180ms ease",touchAction:c||x?"none":"auto",WebkitUserSelect:"none",userSelect:"none",WebkitTapHighlightColor:"transparent"};C&&!c?(nt.left=C.x,nt.top=C.y):c?(nt.left=0,nt.top=0,nt.right=0,nt.bottom=0):(f==="left"?nt.left=24:nt.right=24,M>0?nt.top=M:nt.bottom=r+20);let ht=K=>{if(!x||c||K.pointerType==="mouse"&&K.button!==0||K.target.closest("[data-control-button='true']"))return;let lt=K.currentTarget.getBoundingClientRect();g.current={x:K.clientX-lt.left,y:K.clientY-lt.top},E.current={x:K.clientX,y:K.clientY},O.current=!1,h({x:lt.left,y:lt.top}),u(!0)},dt=()=>{if(!v.link)return;rt("clicked",L.id);let K=String(v.link).trim();try{let it=P.getState(),lt=it.allCampaigns||[],mt=it.campaigns||[],gt=lt.find(R=>R.id===K);if(console.log("[Pip] clicked link=",K,"allCount=",lt.length,"visibleCount=",mt.length,"referenced=",!!gt),gt){let R={...gt};delete R.trigger_event,delete R.trigger,R.display_trigger=!0;let I=mt.findIndex(N=>N.id===R.id);if(I===-1)it.saveCampaigns([R,...mt]);else{let N=mt[I];if(!!(N.trigger_event??N.trigger)){let xt=[...mt];xt[I]=R,it.saveCampaigns(xt)}}return}}catch{}window.open(v.link,"_blank")};return a?As("div",{style:nt,onPointerDown:ht,children:[wn("video",{ref:m,src:a,autoPlay:!0,loop:!0,playsInline:!0,muted:S,style:{width:"100%",height:"100%",objectFit:c?"contain":"cover",cursor:X&&!c||v.link?"pointer":"default"},onClick:()=>{if(O.current){O.current=!1;return}if(X){J();return}dt()},onEnded:()=>{D&&rt("analyze",D.id)}}),wn(Di,{styling:q,mode:c?"LARGE":"SMALL",muted:!S,expanded:c,onClose:()=>l(!0),onToggleMute:()=>p(K=>!K),onToggleExpand:J,containerStyle:c?{paddingTop:"env(safe-area-inset-top, 0px)",paddingLeft:"env(safe-area-inset-left, 0px)",paddingRight:"env(safe-area-inset-right, 0px)"}:void 0}),c&&Y&&wn("button",{"data-control-button":"true",onClick:dt,style:{position:"absolute",left:H.left??12,right:H.right??12,bottom:`calc(${H.bottom??12}px + env(safe-area-inset-bottom, 0px))`,height:k.height||42,width:k.ctaFullWidth?"auto":k.ctaWidth||"auto",maxWidth:`calc(100% - ${(H.left??12)+(H.right??12)}px)`,margin:k.ctaFullWidth?"0":"0 auto",background:k.backgroundColor||"#F7921C",color:B.color||"#fff",border:`${k.borderWidth||0}px solid ${k.borderColor||"transparent"}`,borderTopLeftRadius:typeof W=="number"?W:W?.topLeft??10,borderTopRightRadius:typeof W=="number"?W:W?.topRight??10,borderBottomRightRadius:typeof W=="number"?W:W?.bottomRight??10,borderBottomLeftRadius:typeof W=="number"?W:W?.bottomLeft??10,fontSize:B.fontSize||14,fontFamily:st(B.fontFamily),fontWeight:600,cursor:v.link?"pointer":"default"},children:v.button_text})]}):null};import Ms,{useEffect as kn,useRef as Rn,useState as Vo}from"react";import{LottiePlayer as Ps}from"lottie-react";yt();import{jsx as qe}from"react/jsx-runtime";var Jt=(t,e=0)=>{let o=Number(t);return Number.isFinite(o)?o:e},Fn=t=>(t||"").trim().toLowerCase(),Ds="appstorysmediabucketdev.s3.ap-south-1.amazonaws.com",_s=t=>{try{if(typeof window>"u")return[t];let e=new URL(t);if(e.hostname!==Ds)return[t];let o=!!window.location.port,n=`/appstorys-media${e.pathname}${e.search}`;return o?[n,t]:[t]}catch{return[t]}},Ws=t=>{if(!t||typeof t!="object"||Array.isArray(t))return!1;let e=t;return Array.isArray(e.layers)||Array.isArray(e.assets)||typeof e.v=="string"},Tn=class extends Ms.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(){this.props.onError()}render(){return this.state.hasError?null:this.props.children}},$s=()=>{let[t,e]=Vo(null),[o,n]=Vo([]),[i,s]=Vo(!1),[l,c]=Vo(!1),d=Rn(null),S=Rn(null),p=At("FLT"),y=P(k=>k.campaigns),u=P(k=>k.allCampaigns),C=P(k=>k.currentScreen),h=P(k=>k.isVisible),g=Rn(null),b=p??(()=>{let k=[...y,...u].find(B=>{let W=B;if(W.campaign_type!=="FLT")return!1;let H=!!(W.trigger_event??W.trigger);return W.display_trigger===!1||H?!1:!Fn(W.screen)||Fn(W.screen)===Fn(C)});if(k)try{return Nt(k)}catch{return k}})(),m=b?.id,E=P(k=>m?k.variantMappings[m]:void 0);if(kn(()=>{if(!b?.id||!h||Eo(b)&&!E)return;let B=`${b.id}:${E||""}`;g.current!==B&&(g.current=B,rt("viewed",b.id))},[b?.id,E,h]),kn(()=>{let k=b?.details?.lottie_data;if(e(null),n([]),s(!1),c(!1),!k)return;if(Ws(k)){e(k),c(!0);return}if(typeof k!="string"){s(!0);return}let B=_s(k);n(B),c(!0)},[b?.details?.lottie_data]),kn(()=>{if(!b?.details?.lottie_data||!d.current)return;let k=Ps;if(!k||typeof k.loadAnimation!="function"){s(!0),c(!1);return}let B=!1,W=null,H=()=>{W&&typeof W.destroy=="function"&&W.destroy(),W=null,S.current=null},Y=(r,M)=>{if(B)return;if(M>=r.length){s(!0),c(!1),console.error("[Floater] lottie load failed",{lottieUrls:r});return}H();let a=k.loadAnimation({container:d.current,renderer:"svg",loop:!0,autoplay:!0,path:r[M]});W=a,S.current=a,a.addEventListener("DOMLoaded",()=>{B||c(!1)}),a.addEventListener("data_failed",()=>{B||Y(r,M+1)})};if(t){H();let r=k.loadAnimation({container:d.current,renderer:"svg",loop:!0,autoplay:!0,animationData:t});W=r,S.current=r,r.addEventListener("DOMLoaded",()=>{B||c(!1)}),r.addEventListener("data_failed",()=>{B||(s(!0),c(!1))})}else o.length>0&&Y(o,0);return()=>{B=!0,H()}},[b?.details?.lottie_data,t,o]),!b||!b.details||!h)return null;let{details:O}=b,D=O.styling||{},v=(typeof O.position=="string"?O.position:typeof b.position=="string"?b.position:"right").toLowerCase()==="left"?"left":"right",w={position:"fixed",left:v==="left"?Jt(D.marginLeft,12):void 0,right:v==="left"?void 0:Jt(D.marginRight,12),top:Jt(D.marginTop,0)>0?Jt(D.marginTop,0):void 0,bottom:Jt(D.marginTop,0)>0?void 0:Jt(D.marginBottom,80),zIndex:10040,display:"flex"},_={width:Jt(O.width,60),height:Jt(O.height,60),background:"transparent",overflow:"hidden",borderBottomLeftRadius:Jt(D.bottomLeftRadius,0),borderBottomRightRadius:Jt(D.bottomRightRadius,0),borderTopLeftRadius:Jt(D.topLeftRadius,0),borderTopRightRadius:Jt(D.topRightRadius,0),display:"flex",alignItems:"center",justifyContent:"center",cursor:O.link?"pointer":"default",boxShadow:"0 8px 18px rgba(0,0,0,0.2)"},$=async()=>{if(!O.link)return;await rt("clicked",b.id);let k=String(O.link).trim();try{let B=P.getState(),W=B.allCampaigns||[],H=B.campaigns||[],Y=W.find(r=>{if(!r)return!1;let M=String(r.id||"").trim(),a=r.details||{},f=String(a.campaign||a.id||"").trim();return!!(M&&M===k||f&&f===k||M&&k.includes(M)||f&&k.includes(f))});if(console.log("[Floater] clicked link=",k,"allCampaignsCount=",W.length,"visibleCount=",H.length),console.log("[Floater] all ids=",W.map(r=>r.id).slice(0,50)),console.log("[Floater] referenced found=",!!Y,Y&&(Y.id||Y.details?.campaign||Y.details?.id)),Y){let r={...Y};delete r.trigger_event,delete r.trigger,r.display_trigger=!0;let M=H.findIndex(a=>a.id===r.id);if(M===-1)console.log("[Floater] revealing campaign (prepended)",r.id),B.saveCampaigns([r,...H]);else{let a=H[M];if(!!(a.trigger_event??a.trigger)){let x=[...H];x[M]=r,console.log("[Floater] replacing existing triggered campaign with revealed one",r.id),B.saveCampaigns(x)}else console.log("[Floater] campaign already visible and not trigger-driven",r.id)}return}}catch(B){console.warn("[Floater] error while resolving referenced campaign",B)}try{window.open(O.link,"_blank")}catch{}},V=!!(O.lottie_data&&!i),A=!!O.image,T=!!(O.lottie_data&&l&&!t&&!i);return!V&&!A&&!T?null:qe("div",{style:w,children:qe("div",{style:_,onClick:()=>{$()},children:V?qe(Tn,{onError:()=>s(!0),children:qe("div",{ref:d,style:{width:"100%",height:"100%",display:"block"}})},String(O.lottie_data)):T?qe("div",{style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.08)",color:"#333",fontSize:10,fontWeight:600},children:"..."}):qe("img",{src:O.image,alt:"floater",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}})})})},Ns=$s;yt();function ji(t){return(t||"").trim().toLowerCase()}function zn(t,e){let o=ji(t.screen),n=ji(e);return!o||o===n}async function In(t){try{let e=P.getState(),o=await Et(),n=e.accountId;if(!o||!n)return;e.setCurrentScreen(t),e.setTrackedEvents([]);let i=e.baseUrl||"https://users.appstorys.co",s=await fetch(`${i}/v2/${n}/track-user-res`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o}`},body:JSON.stringify({user_id:ee(),screenName:t})});if(!s.ok)return;let l=await s.json();if(typeof l.screen_capture_enabled<"u"&&e.setScreenCaptureEnabled(!!l.screen_capture_enabled),l.variants&&l.variants.length>0){let m={};l.variants.forEach(E=>{m[E.id]=E.v_id}),e.setVariantMappings(m)}l.personalization_data&&e.setPersonalizationData(l.personalization_data);let c=e.allCampaigns||[],d=l.eligibleCampaignList||[],S=c.filter(m=>d.includes(m.id)&&zn(m,t)),p=S.map(m=>m.id),y=d.filter(m=>!p.includes(m)),u=[];if(y.length>0){let m=await fetch(`${i}/load-campaign-data`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o}`},body:JSON.stringify(y)});m.ok&&(u=(await m.json()).filter(O=>zn(O,t)))}let C=[...S,...u],h=c.filter(m=>{let E=!!(m.trigger_event??m.trigger);return zn(m,t)&&m.display_trigger===!0&&!E}),g=[...C],b=new Set(g.map(m=>m.id));for(let m of h)b.has(m.id)||(g.push(m),b.add(m.id));e.saveCampaigns(g)}catch(e){console.error("Error when tracking screen:",t,e)}}Po();yt();Mo();async function Bn(t){try{let e=await Et(),o=ee(),n=P.getState();if(!e||!o){console.warn("AppStorys: Missing accessToken or userId. Ensure SDK is initialized before setting user properties.");return}let i={...t||{}},s=await Pe();i={...i,...s};let l={user_id:o,attributes:i},c=n.baseUrl||"https://users.appstorys.co";await Wo({url:`${c}/update-user-atr`,method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`},body:l})}catch(e){console.error("AppStorys: Error in setUserProperties:",e)}}yt();function Ce(t){if(!t||t.trim()==="")return t;let e=P.getState().personalizationData;if(!e||Object.keys(e).length===0)return Os(t);let o=/\{\{([^|}\s]+)\s*\|\s*([^}]+)\}\}/g;return t.replace(o,(n,i,s)=>{let l=i.trim(),c=s.trim();return e[l]??c})}function Os(t){let e=/\{\{[^|}\s]+\s*\|\s*([^}]+)\}\}/g;return t.replace(e,(o,n)=>n.trim())}Oe();yt();yt();var Ln="appstorys_campaigns_cache",qi="appstorys_campaigns_etag",En="appstorys_campaigns_version";async function An(t,e){try{let o=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),n=o?`/appstorys-campaigns/clients/${t}/campaigns.json`:`https://dev-cdn-campaign-appstorys.s3.ap-south-1.amazonaws.com/clients/${t}/campaigns.json`,i=await Ct.getItem(Ln),s=await Ct.getItem(qi),l=await Ct.getItem(En),c={Accept:"application/json"};!o&&s&&(c["If-None-Match"]=s);let d=await fetch(n,{method:"GET",headers:c,...o?{cache:"no-store"}:{}});if(d.status===304)return{campaigns:i?JSON.parse(i):[],version:l?parseInt(l):1};let S=d.headers.get("ETag"),p=await d.json(),y=2,u=p,C=e;if(!C)try{let h=await Et(),g=ee(),m=await fetch(`${o?"/appstorys-users":"https://users.appstorys.co"}/v2/${t}/track-user-res`,{method:"POST",headers:{"Content-Type":"application/json",...h?{Authorization:`Bearer ${h}`}:{}},body:JSON.stringify({user_id:g,screenName:typeof window<"u"&&window.location&&window.location.pathname?window.location.pathname:"",silentUpdate:!0})});if(m.ok){let E=await m.json();console.info("AppStorys: fetchAllCampaigns track-user-res returned",E);let O=E?.screenName||E?.screen||E?.currentScreen||E?.screen_name||E?.current_screen;O&&(C=O);try{let D=P.getState();typeof E.screen_capture_enabled<"u"&&D.setScreenCaptureEnabled(!!E.screen_capture_enabled)}catch{}}}catch(h){console.warn("Could not fetch screen name from track-user-res:",h)}if(p.length>0&&p[0].version!==void 0&&(y=p[0].version,u=p.slice(1)),!u||u.length===0)try{let h=await Et(),g=ee(),m=await fetch(`${o?"/appstorys-users":"https://users.appstorys.co"}/v2/${t}/track-user-res`,{method:"POST",headers:{"Content-Type":"application/json",...h?{Authorization:`Bearer ${h}`}:{}},body:JSON.stringify({user_id:g,screenName:typeof window<"u"&&window.location&&window.location.pathname?window.location.pathname:"",silentUpdate:!0})});if(m.ok){let E=await m.json(),O=E?.user_id||E?.id||E?.userId||g;try{let D=P.getState();typeof E.screen_capture_enabled<"u"&&D.setScreenCaptureEnabled(!!E.screen_capture_enabled)}catch{}if(O){let L=await fetch(o?"/appstorys-users/load-campaign-data":"https://users.appstorys.co/load-campaign-data",{method:"POST",headers:{"Content-Type":"application/json",...h?{Authorization:`Bearer ${h}`}:{}},body:JSON.stringify({user_id:O})});if(L.ok){let v=await L.json();console.log(`Fetched ${v.length} missing campaigns from fallback`),console.log("Fallback campaigns:",JSON.stringify(v,null,2)),v&&v.length>0&&(u=v)}else console.error("Failed to fetch missing campaigns:",await L.text())}}}catch(h){console.error("Error fetching missing campaigns via fallback:",h)}if(C&&u&&u.length>0){let h=b=>(b||"").trim().toLowerCase(),g=h(C);u=u.filter(b=>!h(b.screen)||h(b.screen)===g)}return await Ct.setItem(Ln,JSON.stringify(u)),await Ct.setItem(En,y.toString()),S&&await Ct.setItem(qi,S),{campaigns:u,version:y}}catch(o){console.error("Error fetching campaigns:",o);let n=await Ct.getItem(Ln),i=await Ct.getItem(En);return{campaigns:n?JSON.parse(n):[],version:i?parseInt(i):1}}}yt();yt();yt();async function Uo(t,e){try{let o=await Et(),n=P.getState();if(!o)return console.error("AppStorys: Access token not found for reconciliation"),!1;let i={anonymous_user_id:t,identified_user_id:e},s=n.baseUrl||"https://users.appstorys.co",l=await fetch(`${s}/reconcile-anonymous-user`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o}`},body:JSON.stringify(i)});if(l.ok)return!0;{let c=await l.text();return console.error("AppStorys: Failed to reconcile anonymous user:",l.status,c),!1}}catch(o){return console.error("AppStorys: Error in reconcileAnonymousUser:",o),!1}}yt();var Mn=class{isInitialized=!1;setup(){this.isInitialized||typeof window>"u"||(document.addEventListener("mouseleave",this.handleMouseLeave),window.addEventListener("popstate",this.handlePopState),window.history.state!=="appstorys_navigation"&&window.history.pushState("appstorys_navigation",""),this.isInitialized=!0)}destroy(){!this.isInitialized||typeof window>"u"||(document.removeEventListener("mouseleave",this.handleMouseLeave),window.removeEventListener("popstate",this.handlePopState),this.isInitialized=!1)}handleMouseLeave=e=>{e.clientY<=0&&bn()&&this.triggerCampaign()};handlePopState=()=>{bn()&&(window.history.pushState("appstorys_navigation",""),this.triggerCampaign())};triggerCampaign(){let e=P.getState(),{trackedEvents:o}=e;o.includes(Ao)||(console.log("AppStorys: Exit Intent triggered. Displaying campaign."),e.setTrackedEvents([...o,Ao]))}},Hi=new Mn;yt();var Pn=class{isInitialized=!1;setup(){this.isInitialized||typeof document>"u"||(document.addEventListener("visibilitychange",this.handleVisibilityChange),this.updateVisibility(document.visibilityState==="visible"),this.isInitialized=!0)}destroy(){!this.isInitialized||typeof document>"u"||(document.removeEventListener("visibilitychange",this.handleVisibilityChange),this.isInitialized=!1)}handleVisibilityChange=()=>{this.updateVisibility(document.visibilityState==="visible")};updateVisibility(e){let o=P.getState();o.isVisible!==e&&(console.log(`AppStorys: SDK visibility changed to ${e?"visible":"hidden"}`),o.setVisibility(e))}},Dn=new Pn;Oe();var Yo="anonymous_user_id";async function Vi(){let t=Date.now(),e=navigator.userAgent.split(" ")[0].replace(/[^a-zA-Z0-9]/g,"_");return`${t}_${e}`}async function Ui(){try{let t=await Ct.getItem(Yo);if(t)return t;let e=await Vi();return await Ct.setItem(Yo,e),e}catch(t){return console.error("Error managing anonymous user ID:",t),await Vi()}}async function _n(){try{await Ct.removeItem(Yo)}catch(t){console.error("Error clearing anonymous user ID:",t)}}async function Wn(){try{return await Ct.getItem(Yo)}catch(t){return console.error("Error getting stored anonymous user ID:",t),null}}function js(){if(document.getElementById("appstorys-widget-debug-styles"))return;let t=document.createElement("style");t.id="appstorys-widget-debug-styles",t.innerHTML=`
15
15
  .appstorys-widget-debug-pill {
16
16
  position: absolute;
17
17
  top: 8px;
@@ -30,10 +30,45 @@ var Yi=Object.defineProperty;var Nt=(t,e)=>()=>(t&&(e=t(t=0)),e);var Qi=(t,e)=>{
30
30
  outline: 3px dashed rgba(255,122,24,0.85);
31
31
  outline-offset: 6px;
32
32
  }
33
- `,document.head.appendChild(t)}function Ln(t){let e=document.createElement("div");return e.className="appstorys-widget-debug-pill",e.textContent=t,e}function vr(t){let e=t,o=getComputedStyle(e);(o.position==="static"||!o.position)&&(e.style.position="relative")}window.AppStorysShowWidgetElements=function(){try{Cr();let e=Array.from(document.querySelectorAll("[data-as-id], [data-widget], [data-widget-id]"));if(e.length||["#hero_section",".hero_section","#header_container",".header_container"].forEach(i=>{let n=document.querySelector(i);n&&e.push(n)}),!e.length){let o=Ln("Widget");o.style.position="fixed",o.style.top="12px",o.style.left="12px",o.style.pointerEvents="auto",document.body.appendChild(o);return}e.forEach((o,i)=>{let n=o;vr(n),n.classList.add("appstorys-widget-debug-overlay");let r=n.querySelector(".appstorys-widget-debug-pill");r&&r.remove();let s=Ln("Widget "+(i+1));n.appendChild(s)})}catch(e){console.error("AppStorysShowWidgetElements error",e)}};K();import{useState as Ci,useEffect as vi}from"react";import{useEffect as wr,useState as Dn}from"react";import*as ee from"lottie-react";import{jsx as $n}from"react/jsx-runtime";var _n=ee.default?.default??ee.default??ee.Lottie??ee,zt=({src:t,alt:e,style:o,size:i})=>{let[n,r]=Dn(null),[s,a]=Dn(!1);wr(()=>{t&&t.toLowerCase().endsWith(".json")?fetch(t).then(u=>{if(!u.ok)throw new Error("Failed to fetch Lottie");return u.json()}).then(u=>{r(u),a(!1)}).catch(u=>{console.error("AppStorys: Error loading Lottie thumbnail:",u),a(!0)}):(r(null),a(!1))},[t]);let c={width:i?`${i}px`:o?.width||"100%",height:i?`${i}px`:o?.height||"100%",objectFit:"cover",display:"block",...o};if(n&&!s){let u=_n.default||_n;return $n(u,{animationData:n,loop:!0,autoplay:!0,style:c})}return $n("img",{src:t,alt:e||"story thumbnail",style:c,onError:()=>a(!0)})};import{jsx as Eo,jsxs as kr}from"react/jsx-runtime";var Wn=({story:t,isViewed:e,onClick:o})=>{let i=t.styling||{},n=i.size||80,r=i.ringWidth||3,s=e?"#E5E7EB":t.ringColor||"#FF0000",a=t.nameColor||"#333333",c=i.cornerRadius,u=c?`${c.topLeft||0}px ${c.topRight||0}px ${c.bottomRight||0}px ${c.bottomLeft||0}px`:"50%",x=c?`${Math.max(0,(c.topLeft||0)-3)}px ${Math.max(0,(c.topRight||0)-3)}px ${Math.max(0,(c.bottomRight||0)-3)}px ${Math.max(0,(c.bottomLeft||0)-3)}px`:"50%";return kr("div",{onClick:o,style:{display:"flex",flexDirection:"column",alignItems:"center",cursor:"pointer",flexShrink:0},children:[Eo("div",{style:{width:`${n}px`,height:`${n}px`,borderRadius:u,border:`${r}px solid ${s}`,padding:"3px",boxSizing:"border-box",transition:"transform 0.1s ease",overflow:"hidden",backgroundColor:"#f5f5f5"},children:Eo(zt,{src:t.thumbnail,alt:t.name,style:{borderRadius:x}})}),Eo("span",{style:{marginTop:"6px",fontSize:`${i.name?.size||12}px`,fontFamily:ct(i.name?.fontFamily)||"sans-serif",fontWeight:i.name?.font==="Bold"?"bold":"normal",color:a,maxWidth:`${n+10}px`,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.name})]})};import{jsx as Mn}from"react/jsx-runtime";var On=({stories:t,viewedStories:e,onStoryClick:o})=>Mn("div",{style:{display:"flex",gap:"18px",padding:"16px 20px",overflowX:"auto",WebkitOverflowScrolling:"touch",justifyContent:"flex-start"},children:t.sort((i,n)=>i.order-n.order).map((i,n)=>Mn(Wn,{story:i,isViewed:e.includes(i.id),onClick:()=>o(n)},i.id))});import bi,{useState as St,useEffect as he,useRef as Uo}from"react";K();import{jsx as jn,jsxs as Po}from"react/jsx-runtime";var Nn=({data:t,onInteraction:e,isEditing:o=!1})=>{let i=t.layout?.type==="horizontal",n={headerTextColor:"#000000",optionBgColor:"#1A1A1A",optionTextColor:"#FFFFFF",backgroundColor:"#FFFFFF",borderRadius:24,padding:20},r=t.styling||{},s={backgroundColor:r.backgroundColor||n.backgroundColor,borderRadius:`${r.borderRadius??n.borderRadius}px`,overflow:"hidden",boxShadow:r.shadow||"0 12px 24px rgba(0,0,0,0.1)",boxSizing:"border-box",width:"100%",opacity:r.opacity??1,padding:`${r.padding??n.padding}px`,display:"flex",flexDirection:"column",alignItems:"center",gap:"16px"},a={color:r.headerTextColor||n.headerTextColor,textAlign:"center",fontWeight:"800",fontSize:`${r.fontSize?r.fontSize+4:20}px`,lineHeight:"1.2",margin:"0",width:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'},c={display:"flex",flexDirection:i?"row":"column",gap:"4px",width:"100%",backgroundColor:"#1A1A1A",borderRadius:"12px",overflow:"hidden",padding:"2px"},u={backgroundColor:r.optionBgColor||"transparent",color:r.optionTextColor||n.optionTextColor,padding:i?"14px 10px":"16px 20px",fontSize:`${r.fontSize?r.fontSize+1:16}px`,fontWeight:"700",cursor:"pointer",border:"none",width:"100%",textAlign:"center",boxSizing:"border-box",display:"flex",alignItems:"center",justifyContent:"center",transition:"background 0.2s",flex:1,borderRight:i?"1px solid rgba(255,255,255,0.1)":"none",borderBottom:i?"none":"1px solid rgba(255,255,255,0.1)"},x=g=>{o||e?.({type:"poll",pollId:t.id,optionId:g,stickerId:t.id})},m=Array.isArray(t.options)?t.options:[];return Po("div",{style:s,children:[jn("h3",{style:a,children:t.question||"Ask A Question..."}),jn("div",{style:c,children:m.map((g,v)=>Po("button",{style:{...u,borderRight:i&&v===m.length-1?"none":u.borderRight,borderBottom:!i&&v===m.length-1?"none":u.borderBottom},onClick:()=>x(g.id),onMouseOver:f=>{o||(f.currentTarget.style.backgroundColor="rgba(255,255,255,0.1)")},onMouseOut:f=>{o||(f.currentTarget.style.backgroundColor=r.optionBgColor||"transparent")},children:[g.text,g.percentage!==void 0&&Po("span",{style:{fontSize:"11px",opacity:.6,marginLeft:"8px"},children:[g.percentage,"%"]})]},g.id))})]})};import{useState as Rr}from"react";import{jsx as qe,jsxs as qn}from"react/jsx-runtime";var Un=({data:t,onInteraction:e,isEditing:o=!1})=>{let[i,n]=Rr(null),r={backgroundColor:"#FFFFFF",borderRadius:20,padding:16,questionTextColor:"#FFFFFF",questionBgColor:"#000000",optionBgColor:"#FFFFFF",optionTextColor:"#2B2B2B",borderColor:"#E5E7EB",activeColor:"#10b981",incorrectColor:"#ef4444",labelBgColor:"#FFFFFF",labelTextColor:"#111111",labelBorderColor:"#111111"},s=t.styling||{},a=s.padding??r.padding,c=s.fontSize?s.fontSize+6:22,u=s.optionFontSize||17,x=s.optionBorderRadius||14,m=s.borderColor||r.borderColor,g=Math.min(Math.max(Math.round(u*2.1),18),32),v={backgroundColor:s.backgroundColor||r.backgroundColor,borderRadius:`${s.borderRadius??r.borderRadius}px`,padding:`${a}px`,paddingTop:0,boxShadow:s.shadow||"0 10px 30px rgba(0,0,0,0.12)",boxSizing:"border-box",width:"100%",display:"flex",flexDirection:"column",overflow:"hidden",opacity:s.opacity??1},f={color:s.questionTextColor||r.questionTextColor,backgroundColor:s.questionBgColor||r.questionBgColor,fontWeight:"900",fontSize:`${c}px`,lineHeight:1.25,margin:`0 -${a}px 16px -${a}px`,textAlign:"center",padding:`24px ${a}px`,borderTopLeftRadius:`${s.borderRadius??r.borderRadius}px`,borderTopRightRadius:`${s.borderRadius??r.borderRadius}px`,letterSpacing:"-0.01em"},b={backgroundColor:s.optionBgColor||r.optionBgColor,color:s.optionTextColor||r.optionTextColor,padding:`${s.optionPadding||Math.max(a*.7,10)}px ${Math.max(a*.8,12)}px`,borderRadius:`${x}px`,border:`1px solid ${m}`,display:"flex",alignItems:"center",gap:`${Math.max(Math.round(g*.45),8)}px`,cursor:i?"default":"pointer",width:"100%",textAlign:"left",boxSizing:"border-box",transition:"all 0.2s ease",boxShadow:"0 1px 2px rgba(15,23,42,0.03)"},h={width:`${g}px`,height:`${g}px`,minWidth:`${g}px`,borderRadius:"50%",backgroundColor:s.labelBgColor||r.labelBgColor,color:s.labelTextColor||r.labelTextColor,border:`${Math.max(Math.round(g*.08),1)}px solid ${s.labelBorderColor||r.labelBorderColor}`,display:"flex",alignItems:"center",justifyContent:"center",fontWeight:"700",fontSize:`${Math.max(Math.round(g*.46),10)}px`},y={backgroundColor:s.backgroundColor||r.backgroundColor,borderRadius:`0 0 ${s.borderRadius??r.borderRadius}px ${s.borderRadius??r.borderRadius}px`,display:"flex",flexDirection:"column",gap:`${Math.max(a*.55,8)}px`},w=R=>{o||i||(n(R),e?.({type:"quiz",quizId:t.id,optionId:R,stickerId:t.id}))},I=["A","B","C","D","E","F"],z=Array.isArray(t.options)?t.options:[];return z.length===0&&!o&&console.warn("AppStorys: QuizSticker has no options!",t.id),qn("div",{style:{...v,background:s.backgroundColor||r.backgroundColor},children:[t.question&&qe("h3",{style:f,children:t.question}),qe("div",{style:{...y,background:"transparent"},children:z.map((R,d)=>{let T=R.label||I[d]||"\u2022",l=R.id===i,p=R.isCorrect===!0,M={...b},B={...h};return i&&(p?(M.backgroundColor=s.activeColor||r.activeColor,M.borderColor=s.activeColor||r.activeColor,M.color="#FFFFFF"):l&&(M.backgroundColor=s.incorrectColor||r.incorrectColor,M.borderColor=s.incorrectColor||r.incorrectColor,M.color="#FFFFFF")),qn("button",{style:M,onClick:()=>w(R.id),disabled:!!i,children:[qe("div",{style:h,className:"letter-circle",children:T}),qe("span",{style:{fontWeight:"600",fontSize:`${u}px`},children:R.text})]},R.id)})})]})};import{useState as Tr,useEffect as Fr}from"react";import{jsx as $t,jsxs as Hn}from"react/jsx-runtime";var Vn=({data:t})=>{let[e,o]=Tr({days:"00",hours:"00",minutes:"00",seconds:"00"});Fr(()=>{if(!t.targetDate)return;let T=()=>{let p=+new Date(t.targetDate)-+new Date;if(p>0){let M=Math.floor(p/864e5),B=Math.floor(p/(1e3*60*60)%24),L=Math.floor(p/1e3/60%60),C=Math.floor(p/1e3%60);o({days:M.toString().padStart(2,"0"),hours:B.toString().padStart(2,"0"),minutes:L.toString().padStart(2,"0"),seconds:C.toString().padStart(2,"0")})}else o({days:"00",hours:"00",minutes:"00",seconds:"00"})},l=setInterval(T,1e3);return T(),()=>clearInterval(l)},[t.targetDate]);let i=t.styling||{},n=t.display||{showDays:!0,showHours:!0,showMinutes:!0,showSeconds:!0},r=Number(i.digitSize||18),s=!isNaN(r)&&r>0?r:18,a=typeof i.labelFontSize<"u"?Number(i.labelFontSize):Math.max(10,Math.round(s*.55)),c=Math.max(30,Math.round(s*1.8)),u=Math.max(24,Math.round(s*1.3)),x=Math.max(6,Math.round(s*.35)),m=Math.max(6,Math.round(s*.25)),g={backgroundColor:i.backgroundColor||"#FFFFFF",borderRadius:`${i.borderRadius!==void 0?i.borderRadius:16}px`,padding:`${i.padding!==void 0?i.padding:16}px`,boxShadow:i.shadow||"0 10px 30px rgba(0,0,0,0.08)",width:"100%",boxSizing:"border-box",display:"flex",flexDirection:"column",alignItems:"center",gap:"8px",border:i.borderColor?`1px solid ${i.borderColor}`:"none",overflow:"hidden",opacity:i.opacity??1},v={color:i.titleColor||"#000000",fontWeight:"700",fontSize:`${i.fontSize?i.fontSize:14}px`,width:"100%",textAlign:"center",marginBottom:"4px"},f={display:"flex",gap:`${m}px`,width:"100%",justifyContent:"center",alignItems:"center",flexWrap:"nowrap"},b={display:"flex",flexDirection:"column",alignItems:"center",gap:"2px"},h={display:"flex",gap:"2px"},y={backgroundColor:i.digitBackground||"#F1F3F5",borderRadius:`${x}px`,minWidth:`${u}px`,height:`${c}px`,display:"flex",alignItems:"center",justifyContent:"center",fontSize:`${s}px`,fontWeight:"bold",color:i.digitColor||"#1A202C",padding:"0 4px"},w={fontSize:`${Math.max(9,a)}px`,color:i.labelColor||"#A0AEC0",fontWeight:"600",textTransform:"lowercase"},I={fontSize:`${Math.max(14,Math.round(s*.9))}px`,fontWeight:"700",color:i.labelColor||"#A0AEC0",display:"flex",alignItems:"center",lineHeight:1},z=(T,l)=>Hn("div",{style:b,children:[$t("div",{style:h,children:T.split("").map((p,M)=>$t("div",{style:y,children:p},M))}),$t("span",{style:w,children:l})]}),R=[],d=0;return n.showDays!==!1&&(R.push(z(e.days,"days")),d++),n.showHours!==!1&&(d>0&&R.push($t("div",{style:I,children:":"},"sep-h")),R.push(z(e.hours,"hours")),d++),n.showMinutes!==!1&&(d>0&&R.push($t("div",{style:I,children:":"},"sep-m")),R.push(z(e.minutes,"min")),d++),n.showSeconds!==!1&&(d>0&&R.push($t("div",{style:I,children:":"},"sep-s")),R.push(z(e.seconds,"sec")),d++),Hn("div",{style:g,children:[t.title&&$t("div",{style:v,children:t.title}),$t("div",{style:f,children:R})]})};import{useState as Ir}from"react";import{jsx as oe,jsxs as Ue}from"react/jsx-runtime";var Yn=({data:t,onInteraction:e})=>{let[o,i]=Ir(!1),n=()=>{t.code&&(navigator.clipboard.writeText(t.code).catch(()=>{}),i(!0),e?.({type:"promo_code",value:"copied",stickerId:t.id,code:t.code}),setTimeout(()=>i(!1),2e3))},r=t.styling||{},s={backgroundColor:r.backgroundColor||"#FFFFFF",padding:"12px 18px",borderRadius:"12px",display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%",height:"60px",boxSizing:"border-box",position:"relative",filter:"drop-shadow(0 8px 16px rgba(0,0,0,0.1))",cursor:"pointer",clipPath:"polygon(0% 0%, 0% 40%, 4% 50%, 0% 60%, 0% 100%, 100% 100%, 100% 60%, 96% 50%, 100% 40%, 100% 0%)",backgroundImage:`
34
- radial-gradient(circle at 0px 30px, transparent 8px, white 8.5px),
35
- radial-gradient(circle at 100% 30px, transparent 8px, white 8.5px)
36
- `,backgroundPosition:"0 0, 100% 0",backgroundSize:"100% 100%",backgroundRepeat:"no-repeat"},a={width:"36px",height:"36px",borderRadius:"8px",backgroundColor:"#F1F3F5",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"18px",fontWeight:"800",color:"#2D3748",border:"1px solid #E2E8F0"},c={fontSize:`${r.fontSize||18}px`,fontWeight:"800",color:"#1A202C",letterSpacing:"1px",flex:1,textAlign:"center"};return Ue("div",{style:s,onClick:n,children:[Ue("div",{style:{display:"flex",alignItems:"center",gap:"12px",flex:1},children:[oe("div",{style:a,children:"%"}),oe("span",{style:c,children:t.code||"OFFER20"})]}),Ue("div",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[o&&oe("span",{style:{fontSize:"11px",color:"#10B981",fontWeight:"700"},children:"Copied!"}),oe("div",{style:{padding:"8px",display:"flex",alignItems:"center"},children:Ue("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"#4A5568",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[oe("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),oe("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]})]})};import{jsx as Qn}from"react/jsx-runtime";var Gn=({data:t,onInteraction:e,isEditing:o=!1})=>{let i={emojis:["\u{1F60D}","\u{1F44D}"]},n=Array.isArray(t.emojis)?t.emojis:Array.isArray(i.emojis)?i.emojis:[],r=c=>{o||e?.({type:"reaction",reactionId:t.id,emoji:c,stickerId:t.id})},s={display:"flex",gap:"20px",justifyContent:"center",alignItems:"center",width:"100%",padding:"12px"},a={backgroundColor:"#FFFFFF",width:"64px",height:"64px",borderRadius:"100px",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 8px 30px rgba(0,0,0,0.12)",fontSize:"32px",cursor:o?"default":"pointer",transition:"all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275)",border:"none",outline:"none",padding:0,position:"relative",zIndex:1};return Qn("div",{style:s,children:n.map((c,u)=>Qn("button",{style:a,onClick:()=>r(c),onMouseOver:x=>{o||(x.currentTarget.style.transform="scale(1.15) translateY(-4px)")},onMouseOut:x=>{o||(x.currentTarget.style.transform="scale(1) translateY(0)")},children:c},u))})};import{useState as Jn,useRef as zr,useEffect as Br}from"react";import{jsx as Lo,jsxs as Xn}from"react/jsx-runtime";var Kn=({data:t,onInteraction:e,isEditing:o=!1})=>{let i=t.maxRating||5,n=t.currentRating??Math.floor(i/2),[r,s]=Jn(n),a=zr(null),[c,u]=Jn(!1),x={backgroundColor:"#FFFFFF",borderRadius:36,padding:24,titleColor:"#000000",titleFontSize:24,sliderTrackColor:"#F3F4F6",sliderFillColor:"#F97316",emojiSize:42},m=t.styling||{},g={backgroundColor:m.backgroundColor||x.backgroundColor,borderRadius:`${m.borderRadius??x.borderRadius}px`,padding:`${m.padding??x.padding}px`,boxShadow:m.shadow||"0 12px 30px rgba(0,0,0,0.08)",boxSizing:"border-box",width:"100%",display:"flex",flexDirection:"column",alignItems:"center",gap:"20px",cursor:"default",opacity:m.opacity??1},v={color:m.titleColor||x.titleColor,fontWeight:"900",fontSize:`${m.titleFontSize||x.titleFontSize}px`,margin:"0",textAlign:"center",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',width:"100%"},f={width:"100%",height:"18px",backgroundColor:m.sliderTrackColor||x.sliderTrackColor,borderRadius:"100px",position:"relative",cursor:o?"default":"pointer",marginTop:"24px",marginBottom:"8px",userSelect:"none"},b=r/i*100,h={width:`${b}%`,height:"100%",background:m.sliderFillColor||"linear-gradient(90deg, #FF4582, #e11d48)",borderRadius:"100px",transition:c?"none":"width 0.1s ease"},y=m.emojiSize||x.emojiSize,w={position:"absolute",left:`calc(${b}% - ${y/2}px)`,top:`-${y/4}px`,fontSize:`${y}px`,userSelect:"none",cursor:"grab",transition:c?"none":"left 0.1s ease",filter:"drop-shadow(0 4px 8px rgba(0,0,0,0.2))"},I=d=>{if(!a.current||o)return;let T=a.current.getBoundingClientRect(),l=d-T.left;l<0&&(l=0),l>T.width&&(l=T.width);let p=l/T.width,M=Math.round(p*i*10)/10;s(M)},z=d=>{o||(u(!0),I(d.clientX))},R=d=>{o||(u(!0),I(d.touches[0].clientX))};return Br(()=>{let d=p=>{c&&I(p.clientX)},T=()=>{c&&(u(!1),e?.({type:"rating",ratingId:t.id,value:r,stickerId:t.id}))},l=p=>{c&&I(p.touches[0].clientX)};return c&&(window.addEventListener("mousemove",d),window.addEventListener("mouseup",T),window.addEventListener("touchmove",l),window.addEventListener("touchend",T)),()=>{window.removeEventListener("mousemove",d),window.removeEventListener("mouseup",T),window.removeEventListener("touchmove",l),window.removeEventListener("touchend",T)}},[c,r]),Xn("div",{style:g,children:[Lo("h3",{style:v,children:t.title||"Do you like my space?"}),Xn("div",{ref:a,style:f,onMouseDown:z,onTouchStart:R,children:[Lo("div",{style:h}),Lo("div",{style:w,className:"interactive-emoji-thumb",children:t.emoji||"\u{1F60D}"})]})]})};import{useState as Ar}from"react";import{jsx as ue,jsxs as Do}from"react/jsx-runtime";var Zn=({data:t,onInteraction:e,isEditing:o=!1})=>{let[i,n]=Ar(""),r={backgroundColor:"#FFFFFF",borderRadius:16,padding:16,promptColor:"#111111",inputBgColor:"#FFFFFF",borderColor:"#EFEFEF",textColor:"#333333",placeholderColor:"#A0AEC0"},s=t.styling||{},a={backgroundColor:s.backgroundColor||r.backgroundColor,borderRadius:`${s.borderRadius??r.borderRadius}px`,padding:`${s.padding??r.padding}px`,boxShadow:s.shadow||"0 8px 24px rgba(0,0,0,0.06)",boxSizing:"border-box",width:"100%",display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",border:`1px solid ${s.borderColor||"#F0F0F0"}`},c={color:s.promptColor||r.promptColor,fontWeight:"700",fontSize:`${s.fontSize?s.fontSize+2:16}px`,textAlign:"center",marginBottom:"2px",width:"100%"},u={width:"100%",position:"relative",display:"flex",alignItems:"center"},x={backgroundColor:s.inputBgColor||"#F1F3F5",border:"none",borderRadius:"30px",padding:"14px 45px 14px 20px",width:"100%",boxSizing:"border-box",color:s.inputTextColor||"#1A202C",fontSize:`${s.fontSize||14}px`,outline:"none",textAlign:"left",cursor:o?"default":"text",boxShadow:"inset 0 1px 2px rgba(0,0,0,0.05)"},m={position:"absolute",right:"10px",background:s.submitBackground||"#FE6B35",color:"white",border:"none",borderRadius:"50%",width:"32px",height:"32px",display:i.length>0?"flex":"none",alignItems:"center",justifyContent:"center",cursor:"pointer",transition:"transform 0.2s"},g=f=>{o||n(f.target.value)},v=()=>{o||!i.trim()||(e?.({type:"question",questionId:t.id,value:i.trim(),stickerId:t.id}),n(""))};return Do("div",{style:a,children:[ue("div",{style:c,children:t.question||"Ask me anything"}),Do("div",{style:u,children:[ue("input",{type:"text",value:i,placeholder:t.placeholder||"Type your answer...",style:x,disabled:o,onChange:g,onKeyDown:f=>f.key==="Enter"&&v()}),ue("button",{style:m,onClick:v,children:Do("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:[ue("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),ue("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]})})]})]})};import{useState as Er}from"react";import{jsx as ge,jsxs as _o}from"react/jsx-runtime";var ti=({data:t,onInteraction:e,isEditing:o=!1})=>{let[i,n]=Er(null),r={backgroundColor:"#FFFFFF",borderRadius:20,padding:16,questionTextColor:"#111111",optionBgColor:"#F7FAFC",optionTextColor:"#2D3748",borderColor:"#E2E8F0",activeColor:"#10B981",incorrectColor:"#EF4444"},s=t.styling||{},a={backgroundColor:s.backgroundColor||r.backgroundColor,borderRadius:`${s.borderRadius??r.borderRadius}px`,padding:`${s.padding??r.padding}px`,boxShadow:s.shadow||"0 8px 24px rgba(0,0,0,0.06)",boxSizing:"border-box",width:"100%",display:"flex",flexDirection:"column",gap:"12px",border:s.borderColor?`1px solid ${s.borderColor}`:"none"},c={color:s.questionTextColor||r.questionTextColor,fontWeight:"800",fontSize:`${s.fontSize?s.fontSize+2:16}px`,margin:"0 0 4px 0",textAlign:"left"},u={display:"grid",gridTemplateColumns:"repeat(2, 1fr)",gap:"12px",width:"100%"},x={backgroundColor:s.optionBgColor||r.optionBgColor,color:s.optionTextColor||r.optionTextColor,borderRadius:"16px",border:`2px solid ${s.borderColor||r.borderColor}`,cursor:i?"default":"pointer",display:"flex",flexDirection:"column",alignItems:"center",padding:"8px",boxSizing:"border-box",transition:"all 0.2s ease",overflow:"hidden"},m=f=>{o||i||(n(f),e?.({type:"image",quizId:t.id,optionId:f,stickerId:t.id}))},g="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='100' viewBox='0 0 100 100'%3E%3Crect width='100%25' height='100%25' fill='%23EDF2F7'/%3E%3Cpath d='M30 40 L40 30 L50 40 L60 30 L70 40 V60 H30 Z' fill='%23A0AEC0'/%3E%3Ccircle cx='40' cy='45' r='5' fill='%23FFFFFF'/%3E%3C/svg%3E",v=Array.isArray(t.options)?t.options:[];return _o("div",{style:a,children:[t.question&&ge("h3",{style:c,children:t.question}),ge("div",{style:u,children:v.map(f=>{let b=f.id===i,h=f.isCorrect===!0,y={...x};return i&&(h?(y.borderColor=s.activeColor||r.activeColor,y.backgroundColor="rgba(16, 185, 129, 0.05)"):b&&(y.borderColor=s.incorrectColor||r.incorrectColor,y.backgroundColor="rgba(239, 68, 68, 0.05)")),_o("button",{style:y,onClick:()=>m(f.id),disabled:!!i,onMouseOver:w=>{!o&&!i&&(w.currentTarget.style.transform="translateY(-2px)")},onMouseOut:w=>{!o&&!i&&(w.currentTarget.style.transform="translateY(0)")},children:[_o("div",{style:{width:"100%",aspectRatio:"1",borderRadius:"12px",overflow:"hidden",backgroundColor:"#EDF2F7",display:"flex",alignItems:"center",justifyContent:"center",marginBottom:"8px",position:"relative"},children:[ge("img",{src:f.image||g,alt:f.text,style:{width:"100%",height:"100%",objectFit:"cover"}}),i&&ge("div",{style:{position:"absolute",top:"6px",right:"6px",width:"24px",height:"24px",borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:h?r.activeColor:b?r.incorrectColor:"#A0AEC0",color:"#FFFFFF",fontSize:"12px",fontWeight:"bold"},children:h?"\u2713":b?"\u2715":""})]}),ge("span",{style:{fontWeight:"600",fontSize:`${s.optionFontSize||13}px`,color:i&&h?r.activeColor:r.optionTextColor,width:"100%",textAlign:"center",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:f.text})]},f.id)})})]})};import{useState as ai}from"react";import{useState as fe,useEffect as Pr}from"react";import{jsx as U,jsxs as ot}from"react/jsx-runtime";var si=({product:t,styling:e,onClose:o,onAddToCart:i})=>{let[n,r]=fe(""),[s,a]=fe(0),[c,u]=fe(1),[x,m]=fe(!1),[g,v]=fe(!1),f=t.attributes||{},b=f.colors||[],h=f.sizes||[],y=f.imageUrls||[t.image],w=f.description||"";Pr(()=>{h.length>0&&r(h[0]),v(!0)},[h]);let I=()=>{let C={productId:t.productId||t.id,title:t.title,selectedSize:n,selectedColor:b[s]?.name,quantity:c,price:t.price};i(C);let S=t.redirectUrl||t.url;if(S){!S.startsWith("http")&&!S.startsWith("//")&&(S="https://"+S);try{window.open(S,"_blank","noopener,noreferrer")}catch(_){console.error("AppStorys: Redirect failed",_)}}m(!0)},z=()=>{v(!1),setTimeout(o,400)},R=e?.buttonBackground||"#000000",d=e?.buttonTextColor||"#ffffff",T=e?.titleColor||e?.textColor||"#1a1a2e",l=e?.priceColor||e?.textColor||"#1a1a2e",p=e?.mrpColor||"#8b8b98",M=e?.titleFontWeight||"600",B=e?.priceFontWeight||"700",L=e?.mrpFontWeight||"500";return x?ot("div",{className:"appstorys-shopable-success-overlay",style:ei,children:[U("div",{className:"appstorys-shopable-backdrop",style:oi,onClick:z}),ot("div",{className:"appstorys-shopable-sheet",style:{...ni,height:"auto",minHeight:"310px",animation:"appstorys-slide-up 0.4s cubic-bezier(0.2, 0.8, 0.2, 1)"},children:[U("div",{style:ii,onClick:z}),ot("div",{style:{padding:"0 20px 24px",textAlign:"center"},children:[ot("div",{style:{backgroundColor:"#F3F4F6",borderRadius:"20px",padding:"22px",marginTop:"16px",display:"flex",flexDirection:"column",alignItems:"center",gap:"12px"},children:[ot("h3",{style:{margin:0,fontSize:"16px",fontWeight:"600",lineHeight:"1.4"},children:["Added to your bag",U("br",{}),"successfully"]}),U("svg",{width:"44",height:"26",viewBox:"0 0 44 26",fill:"none",children:U("path",{d:"M4 4C4 4 11 22 22 22C33 22 40 4 40 4",stroke:"currentColor",strokeWidth:"2.8",strokeLinecap:"round"})})]}),ot("div",{style:{marginTop:"24px",display:"flex",flexDirection:"column",gap:"8px"},children:[U("button",{onClick:z,style:{...Mo,backgroundColor:"#000000",color:"#ffffff",padding:"17px",fontSize:"16px",fontWeight:"600"},children:ot("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},children:[ot("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[U("path",{d:"M6 2L3 6v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6l-3-4Z"}),U("path",{d:"M3 6h18"}),U("path",{d:"M16 10a4 4 0 0 1-8 0"})]}),"Go to checkout"]})}),U("button",{onClick:z,style:{...Mo,backgroundColor:"transparent",color:"#000000",border:"1px solid rgba(0,0,0,0.1)",padding:"15px",fontSize:"16px"},children:"Continue with stories"})]})]})]})]}):ot("div",{className:`appstorys-shopable-overlay ${g?"visible":""}`,style:ei,children:[U("div",{className:"appstorys-shopable-backdrop",style:oi,onClick:z}),ot("div",{className:"appstorys-shopable-sheet",style:{...ni,transform:g?"translateY(0)":"translateY(100%)",opacity:g?1:0},children:[ot("div",{style:Lr,children:[U("div",{style:ii,onClick:z}),U("button",{style:Dr,onClick:z,children:ot("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:[U("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),U("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),ot("div",{style:_r,children:[U("div",{style:$r,children:y.map((C,S)=>U("div",{style:{minWidth:y.length>1?"85%":"100%",aspectRatio:"1.2 / 1",maxHeight:"240px",borderRadius:"16px",overflow:"hidden",backgroundColor:"#F9FAFB"},children:U("img",{src:C,alt:t.title,style:{width:"100%",height:"100%",objectFit:"contain"}})},S))}),ot("div",{style:{padding:"0 20px 20px"},children:[U("h2",{style:{margin:"16px 0 4px",fontSize:e?.titleFontSize?`${e.titleFontSize}px`:"20px",fontWeight:M,color:T,lineHeight:"1.2"},children:t.title}),ot("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",marginBottom:"16px"},children:[U("span",{style:{fontSize:e?.priceFontSize?`${e.priceFontSize}px`:"18px",fontWeight:B,color:l},children:t.price}),t.oldPrice&&U("span",{style:{fontSize:e?.mrpFontSize?`${e.mrpFontSize}px`:"14px",color:p,textDecoration:"line-through",fontWeight:L},children:t.oldPrice})]}),b.length>0&&ot("div",{style:$o,children:[U("div",{style:Wo,children:"COLOR"}),U("div",{style:{display:"flex",gap:"14px",marginTop:"12px"},children:b.map((C,S)=>ot("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"5px"},children:[U("button",{onClick:()=>a(S),style:{width:"36px",height:"36px",borderRadius:"50%",border:"none",backgroundColor:C.hex||"#gray",position:"relative",cursor:"pointer",boxShadow:s===S?"0 0 0 2px #fff, 0 0 0 4px #000":"none",transition:"all 0.2s ease"}}),U("div",{style:{width:"5px",height:"5px",borderRadius:"50%",backgroundColor:s===S?"#000":"transparent",transition:"all 0.2s ease"}})]},C.id))})]}),h.length>0&&ot("div",{style:$o,children:[U("div",{style:Wo,children:"SIZE"}),U("div",{style:{display:"flex",gap:"10px",marginTop:"12px",flexWrap:"wrap"},children:h.map(C=>ot("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"4px"},children:[U("button",{onClick:()=>r(C),style:{minWidth:"42px",height:"42px",borderRadius:"50%",backgroundColor:"transparent",border:`1px solid ${n===C?"#000":"rgba(0,0,0,0.1)"}`,color:n===C?"#000":"#8b8b98",fontSize:"13px",fontWeight:"500",cursor:"pointer",transition:"all 0.2s ease"},children:C}),U("div",{style:{width:"5px",height:"5px",borderRadius:"50%",backgroundColor:n===C?"#000":"transparent",transition:"all 0.2s ease"}})]},C))})]}),w&&ot("div",{style:$o,children:[U("div",{style:Wo,children:"DESCRIPTION"}),U("p",{style:{margin:"8px 0 0",fontSize:"14px",lineHeight:"1.5",color:"#8b8b98",wordBreak:"break-word"},children:w})]})]})]}),ot("div",{style:Wr,children:[ot("div",{style:{display:"flex",flexDirection:"column",gap:"1px",minWidth:"75px"},children:[U("div",{style:{fontSize:"15px",fontWeight:B,color:l},children:t.price}),t.oldPrice&&U("div",{style:{fontSize:"11px",color:p,textDecoration:"line-through",fontWeight:L},children:t.oldPrice})]}),ot("div",{style:Mr,children:[U("button",{style:ri,onClick:()=>u(C=>Math.max(1,C-1)),children:U("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:U("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})}),U("span",{style:{fontSize:"16px",fontWeight:"700",minWidth:"18px",textAlign:"center",color:"#000000",display:"inline-block"},children:c}),U("button",{style:ri,onClick:()=>u(C=>C+1),children:ot("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[U("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),U("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})})]}),(()=>{let C=f.availability?.toLowerCase()||"",S=C==="out of stock"||C==="out-of-stock";return ot("button",{onClick:S?void 0:I,disabled:S,style:{...Mo,backgroundColor:S?"#F3F4F6":R,color:S?"#9CA3AF":d,flex:"1",padding:"12px 8px",gap:"6px",cursor:S?"not-allowed":"pointer",opacity:S?.8:1},children:[!S&&ot("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[U("path",{d:"M6 2L3 6v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6l-3-4Z"}),U("path",{d:"M3 6h18"}),U("path",{d:"M16 10a4 4 0 0 1-8 0"})]}),U("span",{style:{fontSize:"12px",fontWeight:"700",whiteSpace:"nowrap"},children:S?"Out of Stock":"Add to cart"})]})})()]})]}),U("style",{children:`
33
+ `,document.head.appendChild(t)}function Yi(t){let e=document.createElement("div");return e.className="appstorys-widget-debug-pill",e.textContent=t,e}function qs(t){let e=t,o=getComputedStyle(e);(o.position==="static"||!o.position)&&(e.style.position="relative")}window.AppStorysShowWidgetElements=function(){try{js();let e=Array.from(document.querySelectorAll("[data-as-id], [data-widget], [data-widget-id]"));if(e.length||["#hero_section",".hero_section","#header_container",".header_container"].forEach(n=>{let i=document.querySelector(n);i&&e.push(i)}),!e.length){let o=Yi("Widget");o.style.position="fixed",o.style.top="12px",o.style.left="12px",o.style.pointerEvents="auto",document.body.appendChild(o);return}e.forEach((o,n)=>{let i=o;qs(i),i.classList.add("appstorys-widget-debug-overlay");let s=i.querySelector(".appstorys-widget-debug-pill");s&&s.remove();let l=Yi("Widget "+(n+1));i.appendChild(l)})}catch(e){console.error("AppStorysShowWidgetElements error",e)}};yt();import Fa,{useState as Dr,useEffect as ei}from"react";import{useEffect as Hs,useState as Gi}from"react";import*as He from"lottie-react";import{jsx as Xi}from"react/jsx-runtime";var Qi=He.default?.default??He.default??He.Lottie??He,de=({src:t,alt:e,style:o,size:n})=>{let[i,s]=Gi(null),[l,c]=Gi(!1);Hs(()=>{t&&t.toLowerCase().endsWith(".json")?fetch(t).then(y=>{if(!y.ok)throw new Error("Failed to fetch Lottie");return y.json()}).then(y=>{s(y),c(!1)}).catch(y=>{console.error("AppStorys: Error loading Lottie thumbnail:",y),c(!0)}):(s(null),c(!1))},[t]);let d={width:n?`${n}px`:o?.width||"100%",height:n?`${n}px`:o?.height||"100%",objectFit:"cover",display:"block",...o},S=o?.objectFit||"cover",p=S==="contain"?"xMidYMid meet":S==="fill"?"none":"xMidYMid slice";if(i&&!l){let y=Qi.default||Qi;return Xi(y,{animationData:i,loop:!0,autoplay:!0,style:d,rendererSettings:{preserveAspectRatio:p}})}return Xi("img",{src:t,alt:e||"story thumbnail",style:d,onError:()=>c(!0)})};import{jsx as $n,jsxs as Vs}from"react/jsx-runtime";var Ji=({story:t,isViewed:e,onClick:o})=>{let n=t.styling||{},i=n.size||80,s=n.ringWidth!==void 0?n.ringWidth:3,l=n.ringAndImageSpace!==void 0?n.ringAndImageSpace:3,c=e?"#E5E7EB":t.ringColor||"#FF0000",d=t.nameColor||"#333333",S=n.storyGroupText||t.name,p=n.cornerRadius,y=p?`${p.topLeft||0}px ${p.topRight||0}px ${p.bottomRight||0}px ${p.bottomLeft||0}px`:"50%",u=p?`${Math.max(0,(p.topLeft||0)-s)}px ${Math.max(0,(p.topRight||0)-s)}px ${Math.max(0,(p.bottomRight||0)-s)}px ${Math.max(0,(p.bottomLeft||0)-s)}px`:"50%",h=st(n.name?.fontFamily||n.name?.font)||n.name?.fontFamily||(n.name?.font&&n.name.font!=="Bold"&&n.name.font!=="Normal"?n.name.font:void 0)||"sans-serif",g=n.name?.font==="Bold"||n.name?.font==="bold"||n.name?.font?.toLowerCase()?.includes("bold");return Vs("div",{onClick:o,style:{display:"flex",flexDirection:"column",alignItems:"center",cursor:"pointer",flexShrink:0},children:[$n("div",{style:{width:`${i}px`,height:`${i}px`,borderRadius:y,border:`${s}px solid ${c}`,padding:`${l}px`,boxSizing:"border-box",transition:"transform 0.1s ease",overflow:"hidden",backgroundColor:"#f5f5f5"},children:$n(de,{src:t.thumbnail,alt:S,style:{borderRadius:u}})}),$n("span",{style:{marginTop:"6px",fontSize:`${n.name?.size||12}px`,fontFamily:h,fontWeight:g?"bold":"normal",color:d,maxWidth:`${i+20}px`,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",textAlign:"center"},children:S})]})};import{jsx as Ki}from"react/jsx-runtime";var Zi=({stories:t,viewedStories:e,onStoryClick:o})=>Ki("div",{style:{display:"flex",gap:"18px",padding:"16px 20px",overflowX:"auto",WebkitOverflowScrolling:"touch",justifyContent:"flex-start"},children:t.sort((n,i)=>n.order-i.order).map((n,i)=>Ki(Ji,{story:n,isViewed:e.includes(n.id),onClick:()=>o(i)},n.id))});import Er,{useState as Ot,useEffect as Re,useRef as Co}from"react";yt();yt();var tr=()=>P.getState().trackingUrl||"https://tracking.appstorys.co";import{useState as vr,useEffect as da}from"react";import*as Ye from"lottie-react";var tt=t=>{if(t){if(typeof t=="string")return t;if(typeof t=="object"){if(typeof t.color=="string")return t.color;if(typeof t.color=="object"&&t.color){let e=tt(t.color);if(e)return e}if(typeof t.solid=="string"&&t.solid)return t.solid;if(typeof t.value=="string"&&t.value)return t.value;if(typeof t.hex=="string"&&t.hex)return t.hex}}},St=t=>{if(!t)return;if(typeof t=="string")return t;if(typeof t=="object"){if(typeof t.solid=="string"&&t.solid)return t.solid;if(typeof t.value=="string"&&t.value)return t.value;if(typeof t.color=="string"&&t.color)return t.color}let e=t.color||{};if(typeof e=="object"&&e&&e.type==="gradient"&&e.gradient){let{direction:o="right",from:n,to:i,stops:s=[]}=e.gradient,c={right:"to right",left:"to left",top:"to top",bottom:"to bottom"}[o]||o;if(s.length>0){let d=s.map(S=>{let p=S.offset,y="0%";if(p!=null){let u=String(p).trim();if(u.endsWith("%"))y=u;else{let C=Number(u);isNaN(C)||(y=C>1?`${C}%`:`${Math.round(C*100)}%`)}}return`${S.color} ${y}`}).join(", ");return`linear-gradient(${c}, ${d})`}return`linear-gradient(${c}, ${n}, ${i})`}return tt(t)},mo=t=>{if(!t||t.type==="none")return;let e=String(t.type).toLowerCase(),o=t.duration||.6;if(e==="fade")return`appstorys-fade-in ${o}s ease-out forwards`;if(e==="classic")return`appstorys-classic-in ${o}s cubic-bezier(0.34, 1.56, 0.64, 1) forwards`;if(e==="rotate")return`appstorys-rotate-in ${o}s ease-out forwards`;if(e==="bounce")return`appstorys-bounce-in ${o+.2}s cubic-bezier(0.68, -0.6, 0.32, 1.6) forwards`},ot=(t,e="px")=>{if(t==null||t==="")return"";let o=String(t).trim();return/^[\d.-]+$/.test(o)?`${o}${e}`:o},Ve=t=>{if(!t||typeof t!="string")return"center center";let e=t.trim().toLowerCase().replace(/_/g,"-");switch(e){case"top-left":case"left-top":return"top left";case"top-center":case"center-top":case"top":return"top center";case"top-right":case"right-top":return"top right";case"center-left":case"left-center":case"left":return"center left";case"center":case"center-center":return"center center";case"center-right":case"right-center":case"right":return"center right";case"bottom-left":case"left-bottom":return"bottom left";case"bottom-center":case"center-bottom":case"bottom":return"bottom center";case"bottom-right":case"right-bottom":return"bottom right";default:return e.replace("-"," ")}};import Us from"react";import{jsx as Go,jsxs as Qo}from"react/jsx-runtime";var er=({data:t,onInteraction:e,isEditing:o=!1})=>{let[n,i]=Us.useState(()=>{try{return localStorage.getItem(`appstorys_poll_${t.id}`)}catch{return null}}),s=t.layout?.type==="horizontal",l={headerTextColor:"#000000",optionBgColor:"#1A1A1A",optionTextColor:"#FFFFFF",backgroundColor:"#FFFFFF",borderRadius:20,padding:12},c=t.styling||{},d=st(c.questionFontFamily||c.fontFamily,'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'),S=st(c.optionFontFamily||c.fontFamily,'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'),p=c.optionBorderRadius??c.optionRadius,y=p!==void 0?ot(p):"9999px",u=c.optionBgColor||"#1A1A1A",C={backgroundColor:c.backgroundColor||l.backgroundColor,borderRadius:ot(c.borderRadius??l.borderRadius),overflow:"hidden",boxShadow:c.shadow||"0 12px 24px rgba(0,0,0,0.1)",boxSizing:"border-box",width:"100%",maxWidth:"280px",margin:"0 auto",opacity:c.opacity??1,padding:"14px 16px",display:"flex",flexDirection:"column",alignItems:"center",gap:"10px"},h={color:c.headerTextColor||l.headerTextColor,textAlign:"center",fontWeight:"700",fontSize:ot(c.fontSize||14),lineHeight:"1.25",margin:"0",width:"100%",fontFamily:d},g={display:"flex",flexDirection:s?"row":"column",gap:s?n?"0px":"4px":ot(c.gap??8),width:"100%",backgroundColor:s?u:"transparent",borderRadius:s?ot(y):"0px",overflow:s?"hidden":"visible",padding:"0px"},b={backgroundColor:s?"transparent":u,color:c.optionTextColor||l.optionTextColor,padding:s?"8px 12px":"10px 16px",fontSize:ot(c.optionFontSize||14),fontWeight:"700",fontFamily:S,cursor:n?"default":"pointer",border:"none",borderRadius:s?"0px":ot(y),width:"100%",textAlign:"center",boxSizing:"border-box",display:"flex",alignItems:"center",justifyContent:"center",transition:"all 0.4s cubic-bezier(0.4, 0, 0.2, 1)",flex:s?1:void 0,borderRight:s?"1px solid rgba(255,255,255,0.1)":"none",borderBottom:"none",position:"relative",overflow:"hidden"},m=Array.isArray(t.options)?t.options:[],E=v=>{let w=m.find(_=>_.id===v);if(!w)return 0;if(w.percentage!==void 0)return w.percentage;if(w.votes!==void 0){let _=m.reduce(($,V)=>$+(V.votes||0),0);if(_>0)return Math.round(w.votes/_*100)}return n?v===n?m.length===1?100:60:Math.round(40/(m.length-1)):0},O=(v,w)=>{let _=v.replace("#","");_.length===3&&(_=_.split("").map(T=>T+T).join(""));let $=parseInt(_.substring(0,2),16)||0,V=parseInt(_.substring(2,4),16)||0,A=parseInt(_.substring(4,6),16)||0;return`rgba(${$}, ${V}, ${A}, ${w})`},D=v=>{let w=v===n,_=w?c.activeResultBarColor:c.inactiveResultBarColor,$=_?.color||(w?"#F97316":"#404040"),V=_?.opacity!==void 0?_.opacity/100:1;return $.startsWith("#")&&($.length===7||$.length===4)?O($,V):$},L=v=>{if(!(o||n)){i(v);try{localStorage.setItem(`appstorys_poll_${t.id}`,v)}catch{}e?.({type:"poll",pollId:t.id,optionId:v,stickerId:t.id})}};return Qo("div",{style:C,children:[Go("h3",{style:h,children:t.question||"Ask A Question..."}),Go("div",{style:g,children:m.map((v,w)=>{let _=E(v.id),$=n!==null,V=v.id===n,A=$?s?D(v.id):u:s?"transparent":u;return Qo("button",{style:{...b,flex:$&&s?_:s?1:void 0,backgroundColor:A,borderRight:$||s&&w===m.length-1?"none":b.borderRight},onClick:()=>L(v.id),disabled:$,onMouseOver:T=>{!o&&!$&&!s&&(T.currentTarget.style.opacity="0.9")},onMouseOut:T=>{!o&&!$&&!s&&(T.currentTarget.style.opacity="1")},children:[$&&!s&&Go("div",{style:{position:"absolute",top:0,left:0,bottom:0,width:`${_}%`,backgroundColor:D(v.id),transition:"width 0.6s cubic-bezier(0.4, 0, 0.2, 1)",zIndex:1,borderRadius:"inherit"}}),Qo("div",{style:{display:"flex",flexDirection:s?"column":"row",justifyContent:s?"center":"space-between",alignItems:"center",width:"100%",zIndex:2,position:"relative"},children:[Go("span",{style:{whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:v.text}),$&&Qo("span",{style:{fontWeight:"800",fontSize:s?"12px":"15px",marginTop:s?"4px":"0"},children:[_,"%"]})]})]},v.id)})})]})};import{useState as Ys}from"react";import{jsx as ce,jsxs as Ue}from"react/jsx-runtime";var or=({data:t,onInteraction:e,isEditing:o=!1})=>{let[n,i]=Ys(()=>{try{return localStorage.getItem(`appstorys_quiz_${t.id}`)}catch{return null}}),s={backgroundColor:"#FFFFFF",borderRadius:28,padding:16,questionTextColor:"#FFFFFF",questionBgColor:"#000000",optionBgColor:"#F8FAFC",optionTextColor:"#1E293B",borderColor:"#000000",activeColor:"#10b981",incorrectColor:"#ef4444",labelBgColor:"#FFFFFF",labelTextColor:"#111111",labelBorderColor:"#111111"},l=t.styling||{},c=ot(l.padding??s.padding),d=ot(l.fontSize||16),S=ot(l.optionFontSize||15),p=l.optionBorderRadius!==void 0?ot(l.optionBorderRadius):"9999px",y=l.optionBorderColor||"#CBD5E1",u=st(l.questionFontFamily||l.fontFamily,'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'),C=st(l.optionFontFamily||l.fontFamily,'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'),h={backgroundColor:l.backgroundColor||s.backgroundColor,borderRadius:ot(l.borderRadius??s.borderRadius),padding:0,boxShadow:l.shadow||"0 12px 32px rgba(0,0,0,0.14)",boxSizing:"border-box",width:"100%",maxWidth:"270px",margin:"0 auto",display:"flex",flexDirection:"column",overflow:"hidden",opacity:l.opacity??1},g={color:l.questionTextColor||s.questionTextColor,backgroundColor:l.questionBgColor||s.questionBgColor,fontWeight:"700",fontSize:d,fontFamily:u,lineHeight:1.3,margin:0,textAlign:"center",padding:"14px 16px",minHeight:"48px",display:"flex",alignItems:"center",justifyContent:"center",boxSizing:"border-box",borderTopLeftRadius:ot(l.borderRadius??s.borderRadius),borderTopRightRadius:ot(l.borderRadius??s.borderRadius),letterSpacing:"-0.01em"},b={backgroundColor:l.optionBgColor||s.optionBgColor,color:l.optionTextColor||s.optionTextColor,fontFamily:C,padding:"8px 14px",borderRadius:p,border:`1px solid ${y}`,display:"flex",alignItems:"center",justifyContent:"flex-start",cursor:n?"default":"pointer",width:"100%",textAlign:"left",boxSizing:"border-box",transition:"all 0.2s ease",fontSize:S,fontWeight:"500"},m={backgroundColor:l.backgroundColor||s.backgroundColor,borderRadius:`0 0 ${ot(l.borderRadius??s.borderRadius)} ${ot(l.borderRadius??s.borderRadius)}`,display:"flex",flexDirection:"column",gap:"6px",padding:"10px 14px 12px 14px"},E=_=>{if(!(o||n)){i(_);try{localStorage.setItem(`appstorys_quiz_${t.id}`,_)}catch{}e?.({type:"quiz",quizId:t.id,optionId:_,stickerId:t.id})}},O=["A","B","C","D","E","F"],D=Array.isArray(t.options)?t.options:[];D.length===0&&!o&&console.warn("AppStorys: QuizSticker has no options!",t.id);let L=D.find(_=>_.id===n),v=L?L.isCorrect===!0:!1,w=!!n&&t.showExplanation!==!1&&!!t.explanation;return Ue("div",{style:{...h,background:l.backgroundColor||s.backgroundColor},children:[ce("style",{children:`
34
+ @keyframes appstorys-quiz-fade-in {
35
+ from { opacity: 0; transform: translateY(4px); }
36
+ to { opacity: 1; transform: translateY(0); }
37
+ }
38
+ `}),t.question&&ce("h3",{style:g,children:t.question}),Ue("div",{style:{...m,background:"transparent"},children:[D.map((_,$)=>{let V=_.label||O[$]||"\u2022",A=_.id===n,T=_.isCorrect===!0,k={...b};return n&&(T?(k.backgroundColor=l.activeColor||s.activeColor,k.borderColor=l.activeColor||s.activeColor,k.color="#FFFFFF"):A&&(k.backgroundColor=l.incorrectColor||s.incorrectColor,k.borderColor=l.incorrectColor||s.incorrectColor,k.color="#FFFFFF")),ce("button",{style:k,onClick:()=>E(_.id),disabled:!!n,children:ce("span",{style:{fontWeight:"600",fontSize:S},children:_.text})},_.id)}),w&&Ue("div",{style:{marginTop:"8px",padding:"12px 14px",backgroundColor:v?"#E6F4EA":"#FCE8E6",borderRadius:"12px",border:`1px solid ${v?"rgba(16, 185, 129, 0.3)":"rgba(239, 68, 68, 0.3)"}`,display:"flex",flexDirection:"column",gap:"4px",textAlign:"left",animation:"appstorys-quiz-fade-in 0.3s ease forwards"},children:[Ue("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[v?Ue("svg",{width:"18",height:"18",viewBox:"0 0 20 20",fill:"none",style:{flexShrink:0},children:[ce("circle",{cx:"10",cy:"10",r:"10",fill:"#10B981"}),ce("path",{d:"M6 10L9 13L14 7",stroke:"white",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round"})]}):Ue("svg",{width:"18",height:"18",viewBox:"0 0 20 20",fill:"none",style:{flexShrink:0},children:[ce("circle",{cx:"10",cy:"10",r:"10",fill:"#EF4444"}),ce("path",{d:"M7 7L13 13M13 7L7 13",stroke:"white",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round"})]}),ce("span",{style:{fontWeight:"700",fontSize:"14px",color:v?"#0ABA73":"#EF4444",fontFamily:C},children:v?"Correct":"Incorrect"})]}),ce("div",{style:{fontSize:"13px",color:"#374151",fontFamily:C,lineHeight:"1.4",paddingLeft:"26px",wordBreak:"break-word"},children:t.explanation})]})]})]})};import{useState as Gs,useEffect as Qs}from"react";import{jsx as ve,jsxs as nr}from"react/jsx-runtime";var ir=({data:t})=>{let[e,o]=Gs({days:"00",hours:"00",minutes:"00",seconds:"00"});Qs(()=>{if(!t.targetDate)return;let V=()=>{let T=+new Date(t.targetDate)-+new Date;if(T>0){let k=Math.floor(T/864e5),B=Math.floor(T/(1e3*60*60)%24),W=Math.floor(T/1e3/60%60),H=Math.floor(T/1e3%60);o({days:k.toString().padStart(2,"0"),hours:B.toString().padStart(2,"0"),minutes:W.toString().padStart(2,"0"),seconds:H.toString().padStart(2,"0")})}else o({days:"00",hours:"00",minutes:"00",seconds:"00"})},A=setInterval(V,1e3);return V(),()=>clearInterval(A)},[t.targetDate]);let n=t.styling||{},i=t.display||{showDays:!0,showHours:!0,showMinutes:!0,showSeconds:!0},s=st(n.questionFontFamily||n.fontFamily,'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'),l=n.digitSize||n.fontSize,c=typeof l=="string",d=c?l:`${!isNaN(Number(l))&&Number(l)>0?Number(l):18}px`,S=n.labelFontSize?ot(n.labelFontSize):c?`calc(${d} * 0.45)`:`${Math.max(10,Math.round(Number(l||18)*.45))}px`,p=c?`calc(${d} * 1.65)`:`${Math.max(36,Math.round(Number(l||18)*1.65))}px`,y=c?`calc(${d} * 0.95)`:`${Math.max(26,Math.round(Number(l||18)*.95))}px`,u=c?`calc(${d} * 0.25)`:`${Math.max(6,Math.round(Number(l||18)*.25))}px`,C=c?`calc(${d} * 0.15)`:`${Math.max(6,Math.round(Number(l||18)*.15))}px`,h=c?`calc(${d} * 0.75)`:`${Math.max(14,Math.round(Number(l||18)*.75))}px`,g={backgroundColor:n.backgroundColor||"#FFFFFF",borderRadius:ot(n.borderRadius!==void 0?n.borderRadius:16),padding:n.padding?ot(n.padding):"16px 18px",boxShadow:n.shadow||"0 10px 30px rgba(0,0,0,0.08)",width:"100%",boxSizing:"border-box",display:"flex",flexDirection:"column",alignItems:"center",gap:"10px",border:n.borderColor?`1px solid ${n.borderColor}`:"none",overflow:"hidden",opacity:n.opacity??1},b={color:n.titleColor||"#000000",fontWeight:"700",fontSize:ot(n.fontSize||14),fontFamily:s,width:"100%",textAlign:"center",marginBottom:"4px"},m={display:"flex",gap:C,width:"100%",justifyContent:"center",alignItems:"center",flexWrap:"nowrap"},E={display:"flex",flexDirection:"column",alignItems:"center",gap:"2px"},O={display:"flex",gap:"2px"},D={backgroundColor:n.digitBackground||"#F1F3F5",borderRadius:u,minWidth:y,height:p,display:"flex",alignItems:"center",justifyContent:"center",fontSize:d,fontWeight:"bold",color:n.digitColor||"#1A202C",padding:"0 4px"},L={fontSize:c?S:`${Math.max(9,Number(String(S).replace("px","")))}px`,color:n.labelColor||"#A0AEC0",fontWeight:"600",textTransform:"lowercase"},v={fontSize:h,fontWeight:"700",color:n.labelColor||"#A0AEC0",display:"flex",alignItems:"center",lineHeight:1},w=(V,A)=>nr("div",{style:E,children:[ve("div",{style:O,children:V.split("").map((T,k)=>ve("div",{style:D,children:T},k))}),ve("span",{style:L,children:A})]}),_=[],$=0;return i.showDays!==!1&&(_.push(w(e.days,"days")),$++),i.showHours!==!1&&($>0&&_.push(ve("div",{style:v,children:":"},"sep-h")),_.push(w(e.hours,"hours")),$++),i.showMinutes!==!1&&($>0&&_.push(ve("div",{style:v,children:":"},"sep-m")),_.push(w(e.minutes,"minutes")),$++),i.showSeconds!==!1&&($>0&&_.push(ve("div",{style:v,children:":"},"sep-s")),_.push(w(e.seconds,"seconds")),$++),nr("div",{style:g,children:[t.title&&ve("div",{style:b,children:t.title}),ve("div",{style:m,children:_})]})};import{useState as Xs}from"react";import{jsx as we,jsxs as rr}from"react/jsx-runtime";var sr=({data:t,onInteraction:e})=>{let[o,n]=Xs(!1),i=y=>{y.stopPropagation(),t.code&&(navigator.clipboard.writeText(t.code).catch(()=>{}),n(!0),e?.({type:"promo_code",value:"copied",stickerId:t.id,code:t.code}),setTimeout(()=>n(!1),2e3))},s=t.styling||{},l=s.backgroundColor||"#F4F4F6",c=st(s.fontFamily,'"SF Mono", "Roboto Mono", Menlo, Consolas, "Courier New", monospace'),d={backgroundColor:l,padding:"6px 14px",borderRadius:"12px",display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%",minHeight:"36px",boxSizing:"border-box",position:"relative",boxShadow:s.shadow||"0 4px 16px rgba(0,0,0,0.08)",cursor:"pointer",WebkitMaskImage:"radial-gradient(circle at 0px 50%, transparent 6px, black 6.5px), radial-gradient(circle at 100% 50%, transparent 6px, black 6.5px)",maskImage:"radial-gradient(circle at 0px 50%, transparent 6px, black 6.5px), radial-gradient(circle at 100% 50%, transparent 6px, black 6.5px)",WebkitMaskComposite:"destination-in",maskComposite:"intersect"};return rr("div",{style:d,onClick:i,children:[we("div",{style:{width:"26px",height:"26px",borderRadius:"6px",backgroundColor:"#FFFFFF",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"13px",fontWeight:"900",color:"#000000",border:"1.8px solid #000000",flexShrink:0},children:"%"}),we("div",{style:{flex:1,minWidth:0,padding:"0 8px",display:"flex",alignItems:"center",justifyContent:"center"},children:we("span",{style:{fontSize:"13px",fontWeight:"700",color:o?"#10B981":"#000000",fontFamily:c,letterSpacing:"0.5px",textAlign:"center",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",display:"block",width:"100%",transition:"color 0.2s ease"},children:o?"Copied!":t.code||"OFFER20"})}),we("div",{style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",borderLeft:"1.5px dashed rgba(0,0,0,0.2)",paddingLeft:"10px",marginLeft:"4px",height:"24px"},children:o?we("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"#10B981",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:we("polyline",{points:"20 6 9 17 4 12"})}):rr("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",children:[we("rect",{x:"8",y:"8",width:"12",height:"12",rx:"2.5",stroke:"#000000",strokeWidth:"2",fill:"none"}),we("rect",{x:"4",y:"4",width:"12",height:"12",rx:"2.5",stroke:"#000000",strokeWidth:"2",fill:"none"})]})})]})};import{useState as ar,useEffect as Js}from"react";import{jsx as Nn,jsxs as lr}from"react/jsx-runtime";var dr=({data:t,onInteraction:e,isEditing:o=!1})=>{let n={emojis:["\u{1F60D}","\u{1F44D}"]},i=Array.isArray(t.emojis)?t.emojis:Array.isArray(n.emojis)?n.emojis:[],[s,l]=ar(()=>{try{return localStorage.getItem(`appstorys_reaction_${t.id}`)!==null}catch{return!1}}),[c,d]=ar({});Js(()=>{let g={},b=(()=>{try{return localStorage.getItem(`appstorys_reaction_${t.id}`)}catch{return null}})();i.forEach(m=>{let E=Math.random()>.5?1999:2e3;b&&m===b&&(E+=1),g[m]=E}),d(g)},[t.emojis]);let S=(g,b)=>{if(!(o||s)){d(m=>({...m,[g]:(m[g]||0)+1})),l(!0);try{localStorage.setItem(`appstorys_reaction_${t.id}`,g)}catch{}e?.({type:"reaction",reactionId:t.id,optionId:`option${b+1}`,selected_option:`option${b+1}`,emoji:g,stickerId:t.id})}},p=g=>g>=1e3?(g/1e3).toFixed(0)+"k":String(g),y={display:"flex",gap:"10px",justifyContent:"center",alignItems:"center",width:"100%",padding:"6px",boxSizing:"border-box"},u={backgroundColor:"#FFFFFF",width:"52px",height:s?"72px":"52px",borderRadius:"100px",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:s?"space-between":"center",padding:s?"6px 0":"0",boxShadow:"0 8px 30px rgba(0,0,0,0.12)",cursor:o||s?"default":"pointer",border:"none",outline:"none",position:"relative",zIndex:1,boxSizing:"border-box",flexShrink:0},C={fontSize:"28px",lineHeight:"1",userSelect:"none"},h={fontSize:"13px",fontWeight:"800",color:"#374151",animation:"appstorys-reaction-fade-in 0.3s ease forwards",lineHeight:"1",userSelect:"none",fontFamily:st(t.styling?.fontFamily,'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif')};return lr("div",{style:y,children:[Nn("style",{children:`
39
+ @keyframes appstorys-reaction-fade-in {
40
+ from { opacity: 0; transform: translateY(4px); }
41
+ to { opacity: 1; transform: translateY(0); }
42
+ }
43
+ .appstorys-reaction-btn {
44
+ transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) !important;
45
+ }
46
+ .appstorys-reaction-btn:not(.voted):not(.editing):hover {
47
+ transform: scale(1.15) translateY(-4px) !important;
48
+ }
49
+ .appstorys-reaction-btn.voted {
50
+ transform: scale(1) translateY(0) !important;
51
+ }
52
+ `}),i.map((g,b)=>{let m=c[g]||2e3;return lr("button",{className:`appstorys-reaction-btn ${s?"voted":""} ${o?"editing":""}`,style:u,onClick:()=>S(g,b),children:[Nn("span",{style:C,children:g}),s&&Nn("span",{style:h,children:p(m)})]},b)})]})};import{useState as Xo,useRef as Ks,useEffect as Zs}from"react";import{jsx as Jo,jsxs as On}from"react/jsx-runtime";var cr=({data:t,onInteraction:e,isEditing:o=!1})=>{let n=t.maxRating||5,i=t.currentRating??Math.floor(n/2),[s,l]=Xo(()=>{try{let B=localStorage.getItem(`appstorys_rating_${t.id}`);return B?Number(B):i}catch{return i}}),c=Ks(null),[d,S]=Xo(!1),[p,y]=Xo(()=>{try{return localStorage.getItem(`appstorys_rating_${t.id}`)!==null}catch{return!1}}),[u,C]=Xo([]),h={backgroundColor:"#FFFFFF",borderRadius:20,padding:14,titleColor:"#000000",titleFontSize:15,sliderTrackColor:"#F3F4F6",sliderFillColor:"#F97316",emojiSize:32},g=t.styling||{},b=st(g.questionFontFamily||g.fontFamily,'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'),m={backgroundColor:g.backgroundColor||h.backgroundColor,borderRadius:ot(g.borderRadius??h.borderRadius),padding:g.padding?ot(g.padding):"8px 12px",boxShadow:g.shadow||"0 10px 24px rgba(0,0,0,0.08)",boxSizing:"border-box",width:"100%",display:"flex",flexDirection:"column",alignItems:"center",gap:"4px",cursor:"default",opacity:g.opacity??1},E={color:g.titleColor||h.titleColor,fontWeight:"700",fontSize:typeof g.titleFontSize=="string"?`min(${g.titleFontSize}, 16px)`:`${g.titleFontSize?Math.min(Number(g.titleFontSize),16):15}px`,margin:"0",textAlign:"center",lineHeight:"1.25",fontFamily:b,width:"100%"},O={width:"100%",height:"16px",backgroundColor:g.sliderTrackColor||h.sliderTrackColor,borderRadius:"100px",position:"relative",cursor:o||p?"default":"pointer",marginTop:"4px",marginBottom:"2px",userSelect:"none"},D=s/n*100,L={width:`${D}%`,height:"100%",background:g.sliderFillColor||"linear-gradient(90deg, #FF4582, #e11d48)",borderRadius:"100px",transition:d?"none":"width 0.1s ease"},v=g.emojiSize||h.emojiSize,w=typeof v=="string",_=ot(v),$={position:"absolute",left:w?`calc(${D}% - calc(${_} / 2))`:`calc(${D}% - ${Number(v)/2}px)`,top:w?`calc(50% - calc(${_} / 2))`:`calc(50% - ${Number(v)/2}px)`,fontSize:_,lineHeight:1,display:"flex",alignItems:"center",justifyContent:"center",userSelect:"none",cursor:p||o?"default":"grab",transition:d?"none":"left 0.1s ease",filter:"drop-shadow(0 4px 8px rgba(0,0,0,0.2))",animation:p?"thumbPop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards":"none"},V=B=>{if(!c.current||o||p)return;let W=c.current.getBoundingClientRect(),H=B-W.left;H<0&&(H=0),H>W.width&&(H=W.width);let Y=H/W.width,r=Math.round(Y*n*10)/10;l(r)},A=B=>{o||p||(S(!0),V(B.clientX))},T=B=>{o||p||(S(!0),V(B.touches[0].clientX))},k=()=>{let B=Array.from({length:16}).map((W,H)=>({id:Date.now()+H,scale:.5+Math.random()*.8,angle:H*22.5+(Math.random()*15-7.5),delay:Math.random()*.1}));C(B),setTimeout(()=>{C([])},1200)};return Zs(()=>{let B=Y=>{d&&V(Y.clientX)},W=()=>{if(d){S(!1),y(!0);try{localStorage.setItem(`appstorys_rating_${t.id}`,String(s))}catch{}k(),e?.({type:"rating",ratingId:t.id,value:s,stickerId:t.id})}},H=Y=>{d&&V(Y.touches[0].clientX)};return d&&(window.addEventListener("mousemove",B),window.addEventListener("mouseup",W),window.addEventListener("touchmove",H),window.addEventListener("touchend",W)),()=>{window.removeEventListener("mousemove",B),window.removeEventListener("mouseup",W),window.removeEventListener("touchmove",H),window.removeEventListener("touchend",W)}},[d,s]),On("div",{style:m,children:[Jo("style",{children:`
53
+ @keyframes emojiBurst {
54
+ 0% {
55
+ transform: translate(0, 0) scale(0.3);
56
+ opacity: 1;
57
+ }
58
+ 90% {
59
+ opacity: 0.9;
60
+ }
61
+ 100% {
62
+ transform: translate(var(--tx), var(--ty)) scale(var(--scale));
63
+ opacity: 0;
64
+ }
65
+ }
66
+ @keyframes thumbPop {
67
+ 0% { transform: scale(1); }
68
+ 50% { transform: scale(1.3); }
69
+ 100% { transform: scale(1); }
70
+ }
71
+ `}),Jo("h3",{style:E,children:t.title||"Do you like my space?"}),On("div",{ref:c,style:O,onMouseDown:A,onTouchStart:T,children:[Jo("div",{style:L}),On("div",{style:$,className:"interactive-emoji-thumb",children:[t.emoji||"\u{1F60D}",u.map(B=>{let W=60+Math.random()*80,H=B.angle*Math.PI/180,Y=`${Math.cos(H)*W}px`,r=`${Math.sin(H)*W}px`;return Jo("span",{style:{position:"absolute",left:"50%",top:"50%",width:"30px",height:"30px",marginLeft:"-15px",marginTop:"-15px",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"24px",pointerEvents:"none",zIndex:100,animation:`emojiBurst 1s cubic-bezier(0.15, 0.85, 0.35, 1) ${B.delay}s forwards`,"--tx":Y,"--ty":r,"--scale":B.scale},children:t.emoji||"\u{1F60D}"},B.id)})]})]})]})};import{useState as ur}from"react";import{jsx as yo,jsxs as jn}from"react/jsx-runtime";var pr=({data:t,onInteraction:e,isEditing:o=!1})=>{let[n,i]=ur(()=>{try{return localStorage.getItem(`appstorys_question_${t.id}`)||""}catch{return""}}),[s,l]=ur(()=>{try{return localStorage.getItem(`appstorys_question_${t.id}`)!==null}catch{return!1}}),c={backgroundColor:"#FFFFFF",borderRadius:16,padding:16,promptColor:"#111111",inputBgColor:"#FFFFFF",borderColor:"#EFEFEF",textColor:"#333333",placeholderColor:"#A0AEC0"},d=t.styling||{},S=st(d.questionFontFamily||d.fontFamily,'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'),p=st(d.optionFontFamily||d.fontFamily,'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'),y={backgroundColor:d.backgroundColor||c.backgroundColor,borderRadius:ot(d.borderRadius??c.borderRadius),padding:d.padding?ot(d.padding):"10px 12px",boxShadow:d.shadow||"0 8px 24px rgba(0,0,0,0.06)",boxSizing:"border-box",width:"100%",display:"flex",flexDirection:"column",alignItems:"center",gap:"6px",border:`1px solid ${d.borderColor||"#F0F0F0"}`},u={color:d.promptColor||c.promptColor,fontWeight:"700",fontSize:ot(d.fontSize||16),fontFamily:S,textAlign:"center",marginBottom:"2px",width:"100%"},C={width:"100%",position:"relative",display:"flex",alignItems:"center"},h=d.optionRadius??d.inputBorderRadius??d.optionBorderRadius??d.inputRadius,g=h!==void 0?typeof h=="number"&&h>=5?"9999px":ot(h):"9999px",b={backgroundColor:d.inputBgColor||"#F1F3F5",border:"none",borderRadius:g,padding:"8px 36px 8px 14px",width:"100%",boxSizing:"border-box",color:d.inputTextColor||"#1A202C",fontSize:"13px",fontFamily:p,outline:"none",textAlign:"left",cursor:o?"default":"text",boxShadow:"inset 0 1px 2px rgba(0,0,0,0.05)"},m={position:"absolute",right:"4px",background:d.submitBackground||"#FE6B35",color:"white",border:"none",borderRadius:"50%",width:"24px",height:"24px",display:n.length>0&&!s?"flex":"none",alignItems:"center",justifyContent:"center",cursor:"pointer",transition:"transform 0.2s"},E=D=>{o||s||i(D.target.value)},O=()=>{if(!(o||!n.trim()||s)){l(!0);try{localStorage.setItem(`appstorys_question_${t.id}`,n.trim())}catch{}e?.({type:"question",questionId:t.id,value:n.trim(),stickerId:t.id})}};return jn("div",{style:y,children:[yo("div",{style:u,children:t.question||"Ask me anything"}),jn("div",{style:C,children:[yo("input",{type:"text",value:n,placeholder:s?"Submitted!":t.placeholder||"Type your answer...",style:b,disabled:o||s,onChange:E,onKeyDown:D=>D.key==="Enter"&&O()}),yo("button",{style:m,onClick:O,children:jn("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[yo("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),yo("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]})})]})]})};import{useState as ta}from"react";import{jsx as ho,jsxs as qn}from"react/jsx-runtime";var gr=({data:t,onInteraction:e,isEditing:o=!1})=>{let[n,i]=ta(()=>{try{return localStorage.getItem(`appstorys_image_quiz_${t.id}`)}catch{return null}}),s={backgroundColor:"#FFFFFF",borderRadius:16,padding:10,optionBgColor:"#F8FAFC",optionTextColor:"#0F172A",borderColor:"#E2E8F0",activeColor:"#10B981",incorrectColor:"#EF4444"},l=t.styling||{},c=ot(l.padding??s.padding),d=ot(l.borderRadius??s.borderRadius),S=st(l.questionFontFamily||l.fontFamily,'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'),p=st(l.optionFontFamily||l.fontFamily,'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'),y={backgroundColor:l.backgroundColor||s.backgroundColor,borderRadius:d,padding:c,boxShadow:l.shadow||"0 12px 32px rgba(0,0,0,0.12)",boxSizing:"border-box",width:"100%",maxWidth:"280px",margin:"0 auto",display:"flex",flexDirection:"column",opacity:l.opacity??1,border:l.borderColor?`1px solid ${l.borderColor}`:"none",overflow:"hidden"},u={color:l.questionTextColor||"#FFFFFF",backgroundColor:l.questionBgColor||"#000000",fontWeight:"800",fontSize:ot(l.fontSize||15),fontFamily:S,margin:`calc(-1 * ${c}) calc(-1 * ${c}) 8px calc(-1 * ${c})`,padding:`12px ${c} 10px ${c}`,textAlign:"center",borderTopLeftRadius:d,borderTopRightRadius:d},g={display:"grid",gridTemplateColumns:`repeat(${(v=>{if(typeof v=="number"&&!isNaN(v)&&v>0)return v;if(typeof v=="string"){let w=parseInt(v,10);if(!isNaN(w)&&w>0)return w}if(typeof v=="object"&&v!==null){let w=v.columns||v.cols||v.columnCount;if(typeof w=="number"&&!isNaN(w)&&w>0)return w;if(typeof w=="string"){let _=parseInt(w,10);if(!isNaN(_)&&_>0)return _}}return 2})(t.layout??l.layout??l.columns)}, 1fr)`,gap:"6px",width:"100%"},b=ot(l.optionRadius??l.optionBorderRadius??l.imageRadius??14),m={backgroundColor:l.optionBgColor||s.optionBgColor,color:l.optionTextColor||s.optionTextColor,fontFamily:p,borderRadius:b,border:`2px solid ${l.borderColor||s.borderColor}`,cursor:n?"default":"pointer",display:"flex",flexDirection:"column",alignItems:"center",padding:"6px",boxSizing:"border-box",transition:"all 0.2s ease",overflow:"hidden"},E=v=>{if(!(o||n)){i(v);try{localStorage.setItem(`appstorys_image_quiz_${t.id}`,v)}catch{}e?.({type:"image",quizId:t.id,optionId:v,stickerId:t.id})}},O="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='100' viewBox='0 0 100 100'%3E%3Crect width='100%25' height='100%25' fill='%23EDF2F7'/%3E%3Cpath d='M30 40 L40 30 L50 40 L60 30 L70 40 V60 H30 Z' fill='%23A0AEC0'/%3E%3Ccircle cx='40' cy='45' r='5' fill='%23FFFFFF'/%3E%3C/svg%3E",D=["A","B","C","D","E","F"],L=Array.isArray(t.options)?t.options:[];return L.length===0&&!o&&console.warn("AppStorys: ImageQuizSticker has no options!",t.id),qn("div",{style:{...y,background:l.backgroundColor||s.backgroundColor},children:[t.question&&ho("h3",{style:u,children:t.question}),ho("div",{style:g,children:L.map((v,w)=>{let _=v.id===n,$=v.isCorrect===!0,V=l.borderColor||s.borderColor,A=l.optionBgColor||s.optionBgColor;n&&($?(V=l.activeColor||s.activeColor,A="rgba(16, 185, 129, 0.08)"):_&&(V=l.incorrectColor||s.incorrectColor,A="rgba(239, 68, 68, 0.08)"));let T=n?$?l.activeColor||s.activeColor:_?l.incorrectColor||s.incorrectColor:l.labelColor||l.optionTextColor||s.optionTextColor:l.labelColor||l.optionTextColor||s.optionTextColor;return qn("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",width:"100%",boxSizing:"border-box"},children:[qn("button",{style:{width:"100%",aspectRatio:"1",borderRadius:b,border:`2px solid ${V}`,backgroundColor:A,overflow:"hidden",cursor:n?"default":"pointer",position:"relative",padding:0,margin:0,outline:"none",transition:"transform 0.2s ease, border-color 0.2s ease",boxSizing:"border-box"},onClick:()=>E(v.id),disabled:!!n,onMouseOver:k=>{!o&&!n&&(k.currentTarget.style.transform="scale(1.02)")},onMouseOut:k=>{!o&&!n&&(k.currentTarget.style.transform="scale(1)")},children:[ho("img",{src:v.image||O,alt:v.text,style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}}),n&&ho("div",{style:{position:"absolute",top:"6px",right:"6px",width:"24px",height:"24px",borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:$?l.activeColor||s.activeColor:_?l.incorrectColor||s.incorrectColor:"#A0AEC0",color:"#FFFFFF",fontSize:"12px",fontWeight:"bold",boxShadow:"0 2px 6px rgba(0,0,0,0.2)"},children:$?"\u2713":_?"\u2715":""})]}),ho("span",{style:{marginTop:"6px",fontWeight:"600",fontSize:ot(l.optionFontSize||13),color:T,fontFamily:p,width:"100%",textAlign:"center",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:v.text})]},v.id)})})]})};import{useState as Sr}from"react";import{useState as bo,useEffect as ea}from"react";import{jsx as at,jsxs as wt}from"react/jsx-runtime";var xr=({product:t,styling:e,onClose:o,onAddToCart:n})=>{let[i,s]=bo(""),[l,c]=bo(0),[d,S]=bo(1),[p,y]=bo(!1),[u,C]=bo(!1),h=t.attributes||{},g=h.colors||[],b=h.sizes||[],m=h.imageUrls||[t.image],E=h.description||"";ea(()=>{b.length>0&&s(b[0]),C(!0)},[b]);let O=()=>{let k={productId:t.productId||t.id,title:t.title,selectedSize:i,selectedColor:g[l]?.name,quantity:d,price:t.price};n(k);let B=t.redirectUrl||t.url;if(B){!B.startsWith("http")&&!B.startsWith("//")&&(B="https://"+B);try{window.open(B,"_blank","noopener,noreferrer")}catch(W){console.error("AppStorys: Redirect failed",W)}}y(!0)},D=()=>{C(!1),setTimeout(o,400)},L=e?.buttonBackground||"#000000",v=e?.buttonTextColor||"#ffffff",w=e?.titleColor||e?.textColor||"#1a1a2e",_=e?.priceColor||e?.textColor||"#1a1a2e",$=e?.mrpColor||"#8b8b98",V=e?.titleFontWeight||"600",A=e?.priceFontWeight||"700",T=e?.mrpFontWeight||"500";return p?wt("div",{className:"appstorys-shopable-success-overlay",style:fr,children:[at("div",{className:"appstorys-shopable-backdrop",style:mr,onClick:D}),wt("div",{className:"appstorys-shopable-sheet",style:{...yr,height:"auto",minHeight:"310px",animation:"appstorys-slide-up 0.4s cubic-bezier(0.2, 0.8, 0.2, 1)"},children:[at("div",{style:hr,onClick:D}),wt("div",{style:{padding:"0 20px 24px",textAlign:"center"},children:[wt("div",{style:{backgroundColor:"#F3F4F6",borderRadius:"20px",padding:"22px",marginTop:"16px",display:"flex",flexDirection:"column",alignItems:"center",gap:"12px"},children:[wt("h3",{style:{margin:0,fontSize:"16px",fontWeight:"600",lineHeight:"1.4"},children:["Added to your bag",at("br",{}),"successfully"]}),at("svg",{width:"44",height:"26",viewBox:"0 0 44 26",fill:"none",children:at("path",{d:"M4 4C4 4 11 22 22 22C33 22 40 4 40 4",stroke:"currentColor",strokeWidth:"2.8",strokeLinecap:"round"})})]}),wt("div",{style:{marginTop:"24px",display:"flex",flexDirection:"column",gap:"8px"},children:[at("button",{onClick:D,style:{...Un,backgroundColor:"#000000",color:"#ffffff",padding:"17px",fontSize:"16px",fontWeight:"600"},children:wt("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},children:[wt("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[at("path",{d:"M6 2L3 6v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6l-3-4Z"}),at("path",{d:"M3 6h18"}),at("path",{d:"M16 10a4 4 0 0 1-8 0"})]}),"Go to checkout"]})}),at("button",{onClick:D,style:{...Un,backgroundColor:"transparent",color:"#000000",border:"1px solid rgba(0,0,0,0.1)",padding:"15px",fontSize:"16px"},children:"Continue with stories"})]})]})]})]}):wt("div",{className:`appstorys-shopable-overlay ${u?"visible":""}`,style:fr,children:[at("div",{className:"appstorys-shopable-backdrop",style:mr,onClick:D}),wt("div",{className:"appstorys-shopable-sheet",style:{...yr,transform:u?"translateY(0)":"translateY(100%)",opacity:u?1:0},children:[wt("div",{style:oa,children:[at("div",{style:hr,onClick:D}),at("button",{style:na,onClick:D,children:wt("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:[at("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),at("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),wt("div",{style:ia,children:[at("div",{style:ra,children:m.map((k,B)=>at("div",{style:{minWidth:m.length>1?"85%":"100%",aspectRatio:"1.2 / 1",maxHeight:"240px",borderRadius:"16px",overflow:"hidden",backgroundColor:"#F9FAFB"},children:at("img",{src:k,alt:t.title,style:{width:"100%",height:"100%",objectFit:"contain"}})},B))}),wt("div",{style:{padding:"0 20px 20px"},children:[at("h2",{style:{margin:"16px 0 4px",fontSize:e?.titleFontSize?ot(e.titleFontSize):"20px",fontWeight:V,color:w,lineHeight:"1.2"},children:t.title}),wt("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",marginBottom:"16px"},children:[at("span",{style:{fontSize:e?.priceFontSize?ot(e.priceFontSize):"18px",fontWeight:A,color:_},children:t.price}),t.oldPrice&&at("span",{style:{fontSize:e?.mrpFontSize?ot(e.mrpFontSize):"14px",color:$,textDecoration:"line-through",fontWeight:T},children:t.oldPrice})]}),g.length>0&&wt("div",{style:Hn,children:[at("div",{style:Vn,children:"COLOR"}),at("div",{style:{display:"flex",gap:"14px",marginTop:"12px"},children:g.map((k,B)=>wt("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"5px"},children:[at("button",{onClick:()=>c(B),style:{width:"36px",height:"36px",borderRadius:"50%",border:"none",backgroundColor:k.hex||"#gray",position:"relative",cursor:"pointer",boxShadow:l===B?"0 0 0 2px #fff, 0 0 0 4px #000":"none",transition:"all 0.2s ease"}}),at("div",{style:{width:"5px",height:"5px",borderRadius:"50%",backgroundColor:l===B?"#000":"transparent",transition:"all 0.2s ease"}})]},k.id))})]}),b.length>0&&wt("div",{style:Hn,children:[at("div",{style:Vn,children:"SIZE"}),at("div",{style:{display:"flex",gap:"10px",marginTop:"12px",flexWrap:"wrap"},children:b.map(k=>wt("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"4px"},children:[at("button",{onClick:()=>s(k),style:{minWidth:"42px",height:"42px",borderRadius:"50%",backgroundColor:"transparent",border:`1px solid ${i===k?"#000":"rgba(0,0,0,0.1)"}`,color:i===k?"#000":"#8b8b98",fontSize:"13px",fontWeight:"500",cursor:"pointer",transition:"all 0.2s ease"},children:k}),at("div",{style:{width:"5px",height:"5px",borderRadius:"50%",backgroundColor:i===k?"#000":"transparent",transition:"all 0.2s ease"}})]},k))})]}),E&&wt("div",{style:Hn,children:[at("div",{style:Vn,children:"DESCRIPTION"}),at("p",{style:{margin:"8px 0 0",fontSize:"14px",lineHeight:"1.5",color:"#8b8b98",wordBreak:"break-word"},children:E})]})]})]}),wt("div",{style:sa,children:[wt("div",{style:{display:"flex",flexDirection:"column",gap:"1px",minWidth:"75px"},children:[at("div",{style:{fontSize:"15px",fontWeight:A,color:_},children:t.price}),t.oldPrice&&at("div",{style:{fontSize:"11px",color:$,textDecoration:"line-through",fontWeight:T},children:t.oldPrice})]}),wt("div",{style:aa,children:[at("button",{style:br,onClick:()=>S(k=>Math.max(1,k-1)),children:at("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:at("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})}),at("span",{style:{fontSize:"16px",fontWeight:"700",minWidth:"18px",textAlign:"center",color:"#000000",display:"inline-block"},children:d}),at("button",{style:br,onClick:()=>S(k=>k+1),children:wt("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[at("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),at("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})})]}),(()=>{let k=h.availability?.toLowerCase()||"",B=k==="out of stock"||k==="out-of-stock";return wt("button",{onClick:B?void 0:O,disabled:B,style:{...Un,backgroundColor:B?"#F3F4F6":L,color:B?"#9CA3AF":v,flex:"1",padding:"12px 8px",gap:"6px",cursor:B?"not-allowed":"pointer",opacity:B?.8:1},children:[!B&&wt("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[at("path",{d:"M6 2L3 6v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6l-3-4Z"}),at("path",{d:"M3 6h18"}),at("path",{d:"M16 10a4 4 0 0 1-8 0"})]}),at("span",{style:{fontSize:"12px",fontWeight:"700",whiteSpace:"nowrap"},children:B?"Out of Stock":"Add to cart"})]})})()]})]}),at("style",{children:`
37
72
  @keyframes appstorys-slide-up {
38
73
  from { transform: translateY(100%); }
39
74
  to { transform: translateY(0); }
@@ -46,10 +81,22 @@ var Yi=Object.defineProperty;var Nt=(t,e)=>()=>(t&&(e=t(t=0)),e);var Qi=(t,e)=>{
46
81
  .appstorys-shopable-overlay.visible {
47
82
  visibility: visible;
48
83
  }
49
- `})]})},ei={position:"fixed",top:0,left:0,right:0,bottom:0,zIndex:1e4,display:"flex",alignItems:"flex-end",justifyContent:"center",pointerEvents:"auto",fontFamily:"'Inter', system-ui, -apple-system, sans-serif",width:"100%",height:"100%",boxSizing:"border-box"},oi={position:"absolute",top:0,left:0,right:0,bottom:0,backgroundColor:"rgba(0,0,0,0.45)",cursor:"pointer"},ni={position:"relative",width:"100%",maxWidth:"500px",backgroundColor:"#fff",borderTopLeftRadius:"28px",borderTopRightRadius:"28px",borderBottomLeftRadius:0,borderBottomRightRadius:0,maxHeight:"60vh",display:"flex",flexDirection:"column",margin:0,transition:"transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.4s ease",boxShadow:"0 -8px 24px rgba(0,0,0,0.15)",overflow:"hidden",boxSizing:"border-box"},Lr={height:"48px",display:"flex",alignItems:"center",justifyContent:"center",position:"relative",flexShrink:0},ii={width:"36px",height:"5px",backgroundColor:"rgba(0,0,0,0.1)",borderRadius:"3px",cursor:"pointer"},Dr={position:"absolute",right:"18px",top:"16px",border:"none",width:"28px",height:"28px",borderRadius:"50%",backgroundColor:"#F3F4F6",display:"flex",alignItems:"center",justifyContent:"center",color:"#666",cursor:"pointer"},_r={flex:1,overflowY:"auto",WebkitOverflowScrolling:"touch"},$r={padding:"0 16px 20px",display:"flex",gap:"8px",overflowX:"auto",scrollSnapType:"x mandatory"},$o={marginTop:"20px"},Wo={fontSize:"11px",fontWeight:"600",color:"rgba(0,0,0,0.5)",letterSpacing:"1.4px"},Wr={padding:"12px 16px calc(20px + env(safe-area-inset-bottom, 0px))",borderTop:"1px solid rgba(0,0,0,0.05)",display:"flex",alignItems:"center",gap:"8px",backgroundColor:"#fff",boxShadow:"0 -4px 12px rgba(0,0,0,0.06)",zIndex:10,boxSizing:"border-box"},Mr={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"100px",border:"1px solid rgba(0,0,0,0.1)"},ri={border:"none",backgroundColor:"transparent",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"},Mo={border:"none",borderRadius:"100px",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",transition:"all 0.2s ease"};import{Fragment as Or,jsx as Wt,jsxs as me}from"react/jsx-runtime";var li=({data:t,onInteraction:e,isEditing:o})=>{let{products:i,styling:n}=t,[r,s]=ai(!1),[a,c]=ai(null),u=(b,h)=>{if(b.stopPropagation(),o)return;if(t.shopableType==="product"){c(h),s(!0),e&&e({type:"product_view",stickerId:t.id,productId:h.productId||h.id,value:h.title});return}let y=h.redirectUrl||h.url;if(y&&!y.startsWith("http")&&!y.startsWith("//")&&(y="https://"+y),e&&e({type:"buy",stickerId:t.id,productId:h.id,value:h.title,selected_option:y}),y)try{window.open(y,"_blank","noopener,noreferrer")}catch(w){console.error("AppStorys: Redirect failed",w),window.location.href=y}},x=b=>{e&&e({type:"add_to_cart",stickerId:t.id,productId:b.productId,value:b.title,selected_option:JSON.stringify({size:b.selectedSize,color:b.selectedColor,quantity:b.quantity})})},m={width:"100%",height:"100%",display:"flex",gap:"12px",overflowX:"auto",padding:"0 1px",scrollSnapType:"x mandatory",scrollbarWidth:"none",msOverflowStyle:"none",WebkitOverflowScrolling:"touch",pointerEvents:"auto"},g={flex:"0 0 auto",width:"100%",backgroundColor:n?.cardBackground||"#ffffff",borderRadius:n?.cardBorderRadius!==void 0?`${n.cardBorderRadius}px`:n?.cardRadiusPercent!==void 0?`${n.cardRadiusPercent}%`:"12px",overflow:"hidden",boxShadow:n?.shadow||"0 -2px 12px rgba(0,0,0,0.12)",display:"flex",flexDirection:"row",alignItems:"center",padding:"8px 12px",position:"relative",scrollSnapAlign:"center",transition:"transform 0.2s ease",cursor:"pointer",boxSizing:"border-box",pointerEvents:"auto",opacity:n?.opacity??1,marginBottom:0},v={width:"64px",height:"64px",borderRadius:n?.imageRadius!==void 0?`${n.imageRadius}px`:"12px",overflow:"hidden",backgroundColor:"#f5f5f5",flexShrink:0},f={flex:1,display:"flex",flexDirection:"column",justifyContent:"center",padding:"0 12px",minWidth:0};return me(Or,{children:[me("div",{style:m,className:"shopable-container",children:[Wt("style",{children:`
84
+ `})]})},fr={position:"fixed",top:0,left:0,right:0,bottom:0,zIndex:1e4,display:"flex",alignItems:"flex-end",justifyContent:"center",pointerEvents:"auto",fontFamily:"'Inter', system-ui, -apple-system, sans-serif",width:"100%",height:"100%",boxSizing:"border-box"},mr={position:"absolute",top:0,left:0,right:0,bottom:0,backgroundColor:"rgba(0,0,0,0.45)",cursor:"pointer"},yr={position:"relative",width:"100%",maxWidth:"500px",backgroundColor:"#fff",borderTopLeftRadius:"28px",borderTopRightRadius:"28px",borderBottomLeftRadius:0,borderBottomRightRadius:0,maxHeight:"60vh",display:"flex",flexDirection:"column",margin:0,transition:"transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.4s ease",boxShadow:"0 -8px 24px rgba(0,0,0,0.15)",overflow:"hidden",boxSizing:"border-box"},oa={height:"48px",display:"flex",alignItems:"center",justifyContent:"center",position:"relative",flexShrink:0},hr={width:"36px",height:"5px",backgroundColor:"rgba(0,0,0,0.1)",borderRadius:"3px",cursor:"pointer"},na={position:"absolute",right:"18px",top:"16px",border:"none",width:"28px",height:"28px",borderRadius:"50%",backgroundColor:"#F3F4F6",display:"flex",alignItems:"center",justifyContent:"center",color:"#666",cursor:"pointer"},ia={flex:1,overflowY:"auto",WebkitOverflowScrolling:"touch"},ra={padding:"0 16px 20px",display:"flex",gap:"8px",overflowX:"auto",scrollSnapType:"x mandatory"},Hn={marginTop:"20px"},Vn={fontSize:"11px",fontWeight:"600",color:"rgba(0,0,0,0.5)",letterSpacing:"1.4px"},sa={padding:"12px 16px calc(20px + env(safe-area-inset-bottom, 0px))",borderTop:"1px solid rgba(0,0,0,0.05)",display:"flex",alignItems:"center",gap:"8px",backgroundColor:"#fff",boxShadow:"0 -4px 12px rgba(0,0,0,0.06)",zIndex:10,boxSizing:"border-box"},aa={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"100px",border:"1px solid rgba(0,0,0,0.1)"},br={border:"none",backgroundColor:"transparent",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"},Un={border:"none",borderRadius:"100px",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",transition:"all 0.2s ease"};import{Fragment as la,jsx as ke,jsxs as xo}from"react/jsx-runtime";var Cr=({data:t,onInteraction:e,isEditing:o})=>{let{products:n,styling:i}=t,[s,l]=Sr(!1),[c,d]=Sr(null),S=(g,b)=>{if(g.stopPropagation(),o)return;if(t.shopableType==="product"){d(b),l(!0),e&&e({type:"product_view",stickerId:t.id,productId:b.productId||b.id,value:b.title});return}let m=b.redirectUrl||b.url;if(m&&!m.startsWith("http")&&!m.startsWith("//")&&(m="https://"+m),e&&e({type:"buy",stickerId:t.id,productId:b.id,value:b.title,selected_option:m}),m)try{window.open(m,"_blank","noopener,noreferrer")}catch(E){console.error("AppStorys: Redirect failed",E),window.location.href=m}},p=g=>{e&&e({type:"add_to_cart",stickerId:t.id,productId:g.productId,value:g.title,selected_option:JSON.stringify({size:g.selectedSize,color:g.selectedColor,quantity:g.quantity})})},y={width:"100%",height:"100%",display:"flex",gap:"12px",overflowX:"auto",padding:"0 1px",scrollSnapType:"x mandatory",scrollbarWidth:"none",msOverflowStyle:"none",WebkitOverflowScrolling:"touch",pointerEvents:"auto"},u={flex:"0 0 auto",width:"100%",backgroundColor:i?.cardBackground||"#ffffff",borderRadius:i?.cardBorderRadius!==void 0?ot(i.cardBorderRadius):i?.cardRadiusPercent!==void 0?`${i.cardRadiusPercent}%`:"12px",overflow:"hidden",boxShadow:i?.shadow||"0 -2px 12px rgba(0,0,0,0.12)",display:"flex",flexDirection:"row",alignItems:"center",padding:"8px 12px",position:"relative",scrollSnapAlign:"center",transition:"transform 0.2s ease",cursor:"pointer",boxSizing:"border-box",pointerEvents:"auto",opacity:i?.opacity??1,marginBottom:0},C={width:"64px",height:"64px",borderRadius:i?.imageRadius!==void 0?ot(i.imageRadius):"12px",overflow:"hidden",backgroundColor:"#f5f5f5",flexShrink:0},h={flex:1,display:"flex",flexDirection:"column",justifyContent:"center",padding:"0 12px",minWidth:0};return xo(la,{children:[xo("div",{style:y,className:"shopable-container",children:[ke("style",{children:`
50
85
  .shopable-container::-webkit-scrollbar { display: none; }
51
86
  .shopable-card:active { transform: scale(0.98); }
52
- `}),i.map(b=>me("div",{style:g,className:"shopable-card",onClick:h=>u(h,b),children:[Wt("div",{style:v,children:Wt("img",{src:b.image,alt:b.title,style:{width:"100%",height:"100%",objectFit:"cover"}})}),me("div",{style:f,children:[Wt("span",{style:{color:n?.titleColor||n?.textColor||"#1a1b2e",fontSize:n?.titleFontSize?`${n.titleFontSize}px`:"15px",fontWeight:n?.titleFontWeight||"700",lineHeight:"1.2",display:"block",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",marginBottom:"1px"},children:b.title}),me("div",{style:{display:"flex",alignItems:"baseline",gap:"6px",flexWrap:"wrap"},children:[Wt("span",{style:{color:n?.priceColor||n?.textColor||"#1a1b2e",fontSize:n?.priceFontSize?`${n.priceFontSize}px`:"18px",fontWeight:n?.priceFontWeight||"800",display:"block"},children:b.price}),b.oldPrice&&Wt("span",{style:{color:n?.mrpColor||"#8b8b98",fontSize:n?.mrpFontSize?`${n.mrpFontSize}px`:"12px",fontWeight:n?.mrpFontWeight||"500",textDecoration:"line-through"},children:b.oldPrice})]})]}),Wt("div",{style:{backgroundColor:n?.buttonBackground||"#000000",color:n?.buttonTextColor||"#ffffff",fontSize:n?.buttonFontSize?`${n.buttonFontSize}px`:"14px",fontWeight:"700",padding:"10px 18px",borderRadius:n?.buttonBorderRadius!==void 0?`${n.buttonBorderRadius}px`:"100px",textAlign:"center",flexShrink:0,whiteSpace:"nowrap"},children:"Buy Now"})]},b.id))]}),r&&a&&Wt(si,{product:a,styling:n,onClose:()=>s(!1),onAddToCart:x})]})};import{jsx as bt,jsxs as jr}from"react/jsx-runtime";var di=({data:t,onInteraction:e,isEditing:o=!1})=>{let i={x:10,y:15,width:80,rotation:0},n=t.x??i.x,r=t.y??i.y,s=t.width??i.width,a=t.rotation??i.rotation,c={position:"absolute",top:`${r}%`,left:`${n}%`,width:`${s}%`,height:t.height?`${t.height}%`:"auto",transform:`rotate(${a}deg)`,zIndex:10,transformOrigin:"center center",boxSizing:"border-box",cursor:o?"move":"default",pointerEvents:"auto"},u={width:"100%",height:"100%",animation:t.styling?.animation,animationFillMode:"forwards"},x=()=>{switch(t.type){case"poll":return bt(Nn,{data:t,onInteraction:e,isEditing:o});case"quiz":return bt(Un,{data:t,onInteraction:e,isEditing:o});case"rating":return bt(Kn,{data:t,onInteraction:e,isEditing:o});case"question":case"input":return bt(Zn,{data:t,onInteraction:e,isEditing:o});case"image_quiz":return bt(ti,{data:t,onInteraction:e,isEditing:o});case"countdown":return bt(Vn,{data:t,onInteraction:e,isEditing:o});case"promo_code":case"promo":return bt(Yn,{data:t,onInteraction:e,isEditing:o});case"reaction":return bt(Gn,{data:t,onInteraction:e,isEditing:o});case"buy":case"shopable":return bt(li,{data:t,onInteraction:e,isEditing:o});case"image":return bt("img",{src:t.url,alt:"static overlay",style:{width:"100%",height:"100%",objectFit:"fill"}});case"text":{let g=t.styling||{};return bt("span",{style:{color:g.color||"#000000",fontSize:`${g.fontSize||14}px`,fontFamily:ct(g.fontFamily)||"Arial",fontStyle:g.fontStyle||"normal",fontWeight:g.fontWeight||"normal",wordBreak:"break-word",display:"inline-block"},children:t.text})}default:return jr("div",{style:{padding:"10px",background:"white",color:"black",borderRadius:"4px"},children:["Unsupported interactive element: ",t.type]})}};return bt("div",{style:c,className:`interactive-item-z${t.z??0}`,children:bt("div",{style:u,children:x()})})};var Pt=t=>{if(!t)return;if(typeof t=="string")return t;if(typeof t=="object"){if(typeof t.solid=="string"&&t.solid)return t.solid;if(typeof t.value=="string"&&t.value)return t.value}let e=t.color||{};if(e.type==="gradient"&&e.gradient){let{direction:o="right",from:i,to:n,stops:r=[]}=e.gradient,a={right:"to right",left:"to left",top:"to top",bottom:"to bottom"}[o]||o;if(r.length>0){let c=r.map(u=>`${u.color} ${Math.round((u.offset||0)*100)}%`).join(", ");return`linear-gradient(${a}, ${c})`}return`linear-gradient(${a}, ${i}, ${n})`}return e.solid||e.value||void 0},He=t=>{if(!t||t.type==="none")return;let e=String(t.type).toLowerCase(),o=t.duration||.6;if(e==="fade")return`appstorys-fade-in ${o}s ease-out forwards`;if(e==="classic")return`appstorys-classic-in ${o}s cubic-bezier(0.34, 1.56, 0.64, 1) forwards`;if(e==="rotate")return`appstorys-rotate-in ${o}s ease-out forwards`;if(e==="bounce")return`appstorys-bounce-in ${o+.2}s cubic-bezier(0.68, -0.6, 0.32, 1.6) forwards`};import{jsx as fi,jsxs as Nr}from"react/jsx-runtime";var ci=(t,e)=>{let o=t?.styling?.editorSource||t?.styling?.meta?.editorSource||t?.style?.editorSource||e?.editorSource||e?.meta?.editorSource;return o==="studio"||o==="editor"?"studio":"dashboard"},Ht=(t,e)=>Array.isArray(t)?t.map((o,i)=>{let n=o?.id||o?.key||o?.value||`option_${i+1}`,r=o?.label||o?.optionLabel,s=typeof o=="string"?o:o?.text||o?.title||r||"";return{id:String(n),text:s,image:o?.image||o?.imageUrl||"",label:r,isCorrect:o?.isCorrect===!0||String(n)===String(e)}}):t&&typeof t=="object"?Object.entries(t).map(([o,i])=>{let n=typeof i=="string"?{text:i}:i||{};return{id:o,text:n.text||n.title||n.label||"",image:n.image||n.imageUrl||"",label:n.label,isCorrect:o===String(e)}}):[],pi=t=>Array.isArray(t?.emojis)?t.emojis.map(e=>String(e)):Ht(t?.options).map(e=>e.text).filter(Boolean),ui=t=>{let e=String(t||"").toLowerCase();return e==="quizz"?"quiz":e==="rate"?"rating":e==="input"||e==="ask_question"||e==="askquestion"?"question":e==="promo"||e==="promocode"?"promo_code":e},gi=t=>{if(t.targetDate)return t.targetDate;if(!t.endDate)return new Date(Date.now()+864e5).toISOString();try{let e=`${t.endDate}${t.endTime?`T${t.endTime}`:""}`;return new Date(e).toISOString()}catch{return t.endDate||new Date(Date.now()+864e5).toISOString()}},Oo=({content:t={},onInteraction:e,isEditing:o=!1,elapsedTime:i=0})=>{let n=t?.canva||{height:1920,width:1080},r=n?.width||1080,s=n?.height||1920,a=.352,c=t?.elements||[],u=t?.image||[],x=t?.text||[],m=t?.interactions||[],g=Array.isArray(t?.shopable)&&t.shopable.length>0?t.shopable:Array.isArray(t?.styling?.shopable)?t.styling.shopable:[],v=new Set(g.map(d=>d.id)),f=(t?.styling?.shopable||[]).concat(g.map(d=>d.styling).filter(Boolean));if(c.length===0&&u.length===0&&x.length===0&&m.length===0&&g.length===0)return null;let b=c.filter(d=>!v.has(d.id)).map(d=>{let T=d.custom||{},l=T.data||{},p=T.style||d.styling||{},M=ci(d,t),B=d.position||d.postion||{},L=d.size||{},C=d.x!==void 0?d.x:B.x,S=d.y!==void 0?d.y:B.y,_=d.width!==void 0?d.width:L.width,E=C!==void 0&&!isNaN(Number(C))?Number(C)/r*100:10,$=S!==void 0&&!isNaN(Number(S))?Number(S)/s*100:15,D=_!==void 0&&!isNaN(Number(_))?Number(_)/r*100:80,k={id:d.id||Math.random().toString(),type:ui(T.interactiveType||d.widgetType||d.type||"unknown"),x:E,y:$,width:D,rotation:p.rotation??d.rotation??0,z:d.z??d.position?.z??p.z??10,duration:l.duration||p.duration,styling:{backgroundColor:Pt(p.background||p.containerBgColor||p.backgroundColor),borderRadius:p.borderRadius!==void 0?p.borderRadius>=100?999:p.borderRadius*a:p.radius!==void 0?p.radius>=100?999:p.radius*a:0,padding:(p.containerPadding!==void 0?p.containerPadding:p.padding!==void 0?p.padding:0)*a,shadow:p.shadow,fontSize:p.questionFontSize?p.questionFontSize*a:void 0,opacity:p.opacity??1,animation:He(p.animation)}};if(k.type==="poll"){let P=Ht(l.options);return{...k,type:"poll",question:l.question||l.title||"Poll Question",options:P,layout:l.layout||{type:"vertical",columns:1},styling:{...k.styling,headerColor:p.headerBgColor||p.background,headerTextColor:p.questionColor||p.questionTextColor||p.question?.color,optionBgColor:p.optionBgColor||p.options?.background||"#1A1A1A",optionTextColor:p.optionTextColor||p.options?.textColor||"#ffffff",optionBorderRadius:p.optionBorderRadius!==void 0?p.optionBorderRadius*a:p.options?.radius!==void 0?p.options?.radius*a:0}}}if(k.type==="quiz"){let P=p.colors||{},O=Ht(l.options,l.isCorrect);return{...k,type:"quiz",question:l.question||l.title||"Quiz Question",options:O,showExplanation:l.showExplanation,url:l.url,styling:{...k.styling,backgroundColor:p.background||p.containerBgColor||p.backgroundColor||"transparent",questionTextColor:p.questionColor||P.questionColor||p.question?.color||p.colors?.questionText||"#FF0000",questionBgColor:p.questionBgColor||P.questionBackground||p.question?.background||p.colors?.questionBg||"#3BFF00",optionBgColor:p.optionBgColor||P.optionBackground||p.options?.background||p.colors?.optionBg||"#C100FF",optionTextColor:p.optionTextColor||P.optionTextColor||p.options?.textColor||p.colors?.optionText||"#ffffff",borderColor:p.borderColor||"transparent",activeColor:p.correctColor||P.correctColor||p.correctBorderColor||"#00D9FF",incorrectColor:p.incorrectColor||P.incorrectColor||"#ef4444",optionBorderRadius:p.optionRadius!==void 0?p.optionRadius>=100?999:p.optionRadius*a:p.optionBorderRadius!==void 0?p.optionBorderRadius>=100?999:p.optionBorderRadius*a:100,optionFontSize:(p.optionFontSize?p.optionFontSize:p.typography?.optionSize?p.typography?.optionSize:p.options?.fontSize?p.options?.fontSize:16)*a*1.25}}}if(k.type==="rating")return{...k,type:"rating",title:l.title||"Do you like my space?",emoji:l.emoji||"\u{1F60D}",currentRating:l.currentRating,maxRating:l.maxRating,styling:{...k.styling,sliderTrackColor:p.colors?.sliderTrack||p.sliderTrack,sliderFillColor:p.colors?.sliderFill||p.sliderFill,emojiSize:p.emojiSize?p.emojiSize*.45:void 0,titleColor:p.colors?.titleColor||p.titleColor,titleFontSize:p.titleFontSize?p.titleFontSize*.4:void 0}};if(k.type==="question")return{...k,type:"question",question:l.question||l.title||"Ask me a question",placeholder:l.placeholder||"Type your answer...",styling:{...k.styling,promptColor:p.questionColor||p.textColor,inputBgColor:p.inputBgColor,inputTextColor:p.inputTextColor,submitBackground:p.submitBackground}};if(k.type==="image_quiz"||k.type==="imageQuiz"||(T.interactiveType||"").toLowerCase()==="media_quiz")return{...k,type:"image_quiz",question:l.question||l.title||"Image Quiz",options:Ht(l.options||[]),styling:{...k.styling,questionTextColor:p.questionColor,activeColor:p.correctColor||p.correctBorderColor,incorrectColor:p.incorrectColor,imageRadius:p.imageRadius?p.imageRadius*a:void 0}};if(k.type==="countdown")return{...k,type:"countdown",title:l.title||"Ends in...",targetDate:gi(l),styling:{...k.styling,borderColor:p.borderColor,digitBackground:p.digitBackground,digitColor:p.digitColor,digitSize:p.digitSize?p.digitSize*a:void 0,labelColor:p.labelColor,titleColor:p.titleColor},display:l.display};if(k.type==="promo_code")return{...k,type:"promo_code",code:l.code||"CODE20",styling:{...k.styling,borderColor:p.borderColor}};if(k.type==="reaction"||k.type==="emoji_reaction"){let P=pi(l);return{...k,type:"reaction",emojis:P.length>0?P:["\u{1F60D}","\u{1F44D}"],source:M}}return k}),h=(t?.interactions||[]).filter(d=>!v.has(d.id)).map(d=>{let T=d.config||{},l=d.styling||d.style||{},p=ci(d,t),M=ui(d.interaction_type||d.type),B=l.position||d.position||{},L=l.size||d.size||{},C=B.x??d.x,S=B.y??d.y,_=L.width??d.width,E=L.height??d.height,$=C!==void 0&&!isNaN(Number(C))?Number(C)/r*100:10,D=S!==void 0&&!isNaN(Number(S))?Number(S)/s*100:15,k=_!==void 0&&!isNaN(Number(_))?Number(_)/r*100:80,P=E!==void 0&&!isNaN(Number(E))?Number(E)/s*100:void 0,O={id:d.id||Math.random().toString(),type:M,x:$,y:D,width:k,height:P,rotation:l.rotation??d.rotation??0,z:d.z??d.position?.z??l.z??10,source:p,duration:T.duration||l.duration,styling:{backgroundColor:Pt(l.background||l.containerBgColor||l.backgroundColor),borderRadius:l.borderRadius!==void 0?l.borderRadius>=100?999:l.borderRadius*a:l.radius!==void 0?l.radius>=100?999:l.radius*a:0,padding:(l.containerPadding!==void 0?l.containerPadding:l.padding!==void 0?l.padding:0)*a,shadow:l.shadow,fontSize:l.questionSize?l.questionSize*a:l.questionFontSize?l.questionFontSize*a:void 0,opacity:l.opacity??1,animation:He(l.animation)}};if(O.type==="rating"||O.type==="rate"){let G=l.colors||{};return{...O,type:"rating",title:T.title||"Do you like my space?",emoji:T.emoji||"\u{1F60D}",currentRating:T.currentRating,maxRating:T.maxRating,styling:{...O.styling,sliderTrackColor:G.sliderTrack||l.colors?.sliderTrack||l.colors?.sliderTrack,sliderFillColor:G.sliderFill||l.colors?.sliderFill||l.sliderFill,emojiSize:l.emojiSize?l.emojiSize*.45:void 0,titleColor:G.titleColor||l.colors?.titleColor||l.titleColor,titleFontSize:l.titleFontSize?l.titleFontSize*.4:void 0}}}if(O.type==="poll"){let G=Ht(T.options);return{...O,type:"poll",question:T.question||T.title||"Poll Question",options:G,layout:T.layout||{type:"vertical",columns:1},styling:{...O.styling,headerColor:l.headerBgColor||l.background,headerTextColor:l.questionColor||l.questionTextColor||l.question?.color,optionBgColor:l.optionBgColor||l.options?.background||"#1A1A1A",optionTextColor:l.optionTextColor||l.options?.textColor||"#ffffff",optionBorderRadius:l.optionBorderRadius!==void 0?l.optionBorderRadius*a:l.options?.radius!==void 0?l.options?.radius*a:0}}}if(O.type==="quiz"){let G=l.colors||{},ut=Ht(T.options,T.isCorrect);return{...O,type:"quiz",question:T.question||T.title||"Quiz Question",options:ut,showExplanation:T.showExplanation,url:T.url,styling:{...O.styling,backgroundColor:l.background||l.containerBgColor||l.backgroundColor||"transparent",questionTextColor:l.questionColor||G.questionColor||l.question?.color||l.colors?.questionText||"#FF0000",questionBgColor:l.questionBgColor||G.questionBackground||l.question?.background||l.colors?.questionBg||"#3BFF00",optionBgColor:l.optionBgColor||G.optionBackground||l.options?.background||l.colors?.optionBg||"#C100FF",optionTextColor:l.optionTextColor||G.optionTextColor||l.options?.textColor||l.colors?.optionText||"#ffffff",borderColor:l.borderColor||"transparent",activeColor:l.correctColor||G.correctColor||l.correctBorderColor||"#00D9FF",incorrectColor:l.incorrectColor||G.incorrectColor||"#ef4444",optionBorderRadius:l.optionRadius!==void 0?l.optionRadius>=100?999:l.optionRadius*a:l.optionBorderRadius!==void 0?l.optionBorderRadius>=100?999:l.optionBorderRadius*a:100,optionFontSize:(l.optionFontSize?l.optionFontSize:l.typography?.optionSize?l.typography?.optionSize:l.options?.fontSize?l.options?.fontSize:16)*a*1.25}}}if(O.type==="question")return{...O,type:"question",question:T.question||T.title||"Ask me a question",placeholder:T.placeholder||"Type your answer...",styling:{...O.styling,promptColor:l.questionColor||l.promptColor||l.textColor,inputBgColor:l.inputBackground||l.inputBgColor,inputTextColor:l.inputTextColor,submitBackground:l.submitBackground}};if(O.type==="image_quiz"||O.type==="imageQuiz"||M==="media_quiz")return{...O,type:"image_quiz",question:T.question||T.title||"Image Quiz",options:Ht(T.options||[]),styling:{...O.styling,questionTextColor:l.questionColor,activeColor:l.correctColor||l.correctBorderColor,incorrectColor:l.incorrectColor,imageRadius:l.imageRadius?l.imageRadius*a:void 0}};if(O.type==="countdown")return{...O,type:"countdown",title:T.title||"Ends in...",targetDate:gi(T),styling:{...O.styling,borderColor:l.borderColor,digitBackground:l.digitBackground,digitColor:l.digitColor,digitSize:l.digitSize||l.fontSize?Number(l.digitSize||l.fontSize):void 0,labelColor:l.labelColor,titleColor:l.titleColor,labelFontSize:l.labelFontSize?Number(l.labelFontSize):void 0},display:T.display||d.display};if(O.type==="promo_code")return{...O,type:"promo_code",code:T.code||"CODE20",styling:{...O.styling,borderColor:l.borderColor}};if(O.type==="reaction"||O.type==="emoji_reaction"){let G=pi(T);return{...O,type:"reaction",emojis:G.length>0?G:["\u{1F60D}","\u{1F44D}"]}}return O}),y=g.map(d=>{let T=f.find(j=>String(j?.id)===String(d?.id))||f.find(j=>j?.id===void 0)||{},l={position:d?.position,size:d?.size,rotation:d?.rotation,z:d?.z,background:d?.background,cardBackground:d?.cardBackground,cardBorderRadius:d?.cardBorderRadius,cardRadiusPercent:d?.cardRadiusPercent,transparent:d?.transparent,textColor:d?.textColor,buttonBackground:d?.buttonBackground,buttonTextColor:d?.buttonTextColor,buttonFontSize:d?.buttonFontSize,buttonBorderRadius:d?.buttonBorderRadius,titleColor:d?.titleColor,titleFontSize:d?.titleFontSize,titleFontWeight:d?.titleFontWeight,priceColor:d?.priceColor,priceFontSize:d?.priceFontSize,priceFontWeight:d?.priceFontWeight,mrpColor:d?.mrpColor,mrpFontSize:d?.mrpFontSize,mrpFontWeight:d?.mrpFontWeight,imageRadius:d?.imageRadius,opacity:d?.opacity,animation:d?.animation},p={...T,...d?.styling||{},...Object.fromEntries(Object.entries(l).filter(([,j])=>j!==void 0))},M=p.position||{},B=p.size||{},L=p.cardBorderRadius!==void 0?Number(p.cardBorderRadius):void 0,C=p.cardRadiusPercent!==void 0?Number(p.cardRadiusPercent):void 0,S=B.height!==void 0?Number(B.height):void 0,_=L===void 0&&C!==void 0&&S!==void 0?Math.max(0,Math.min(100,C))/100*(S/2):void 0,E=L??_,$=E!==void 0&&!isNaN(E)?E*a:void 0,D=M.x!==void 0?Number(M.x)/r*100:0,k=B.width!==void 0?Number(B.width)/r*100:100,P=B.height!==void 0?Number(B.height)/s*100:void 0,O=M.y!==void 0?Number(M.y)/s*100:P?100-P-2.5:85;P&&O+P>96?O=Math.max(0,100-P):O>75&&P&&O+P>91&&(O=Math.max(0,100-P-1));let G=Array.isArray(d.product)&&d.product.length>0,ut=G?d.product:d.static||[];return{id:d.id||Math.random().toString(),type:"buy",shopableType:G?"product":"static",x:D,y:O,width:k,height:P,rotation:p.rotation??0,z:p.z??10,products:ut.map(j=>{let X=j.productData||j||{},J=X.attributes||j.attributes||{},V=J.sales_price||X.price||J.price||j.price,et=J.sales_price?X.price||J.price||j.price:X.oldPrice||j.oldPrice,q=X.color||J.color||j.color,Q=X.size||J.size||j.size,Y=J.colors||[];Y.length===0&&q&&(Y=[{id:q,hex:q,name:q}]);let lt=J.sizes||[];lt.length===0&&Q&&(lt=typeof Q=="string"?Q.split(",").map(nt=>nt.trim()):[Q]);let mt={description:X.description||J.description||j.description,color:q,size:Q,colors:Y,sizes:lt,imageUrls:J.imageUrls||[J.image_link||X.imageUrl||X.image||j.imageUrl||j.image||j.url].filter(Boolean),availability:X.availability||J.availability||j.availability,tags:X.tags||J.tags||j.tags,...J};return{id:X.productId||X.id||j.productId||j.id||Math.random().toString(),image:J.image_link||X.imageUrl||X.image||j.imageUrl||j.image||j.url,url:X.link||X.url||j.link||j.url||j.redirectUrl,title:X.title||j.title,price:V,oldPrice:et,redirectUrl:j.redirectUrl||X.link||j.link||j.url,svg:X.svg||j.svg,productId:X.productId||j.productId,collectionId:X.collectionId||j.collectionId,feedId:X.feedId||j.feedId,attributes:mt}}),styling:{backgroundColor:Pt(p.background),cardBackground:Pt(p.cardBackground)||Pt(p.background)||"#ffffff",cardBorderRadius:$!==void 0?$:10,cardRadiusPercent:C,transparent:p.transparent===!0,textColor:p.textColor||"#ffffff",buttonBackground:p.buttonBackground||"#000000",buttonTextColor:p.buttonTextColor||"#ffffff",buttonFontSize:p.buttonFontSize||12,buttonBorderRadius:p.buttonBorderRadius!==void 0?p.buttonBorderRadius:100,titleColor:p.titleColor||p.textColor||"#1a1a2e",titleFontSize:p.titleFontSize||14,titleFontWeight:p.titleFontWeight?String(p.titleFontWeight):"600",priceColor:p.priceColor||p.textColor||"#1a1a2e",priceFontSize:p.priceFontSize||16,priceFontWeight:p.priceFontWeight?String(p.priceFontWeight):"700",mrpColor:p.mrpColor||"#8b8b98",mrpFontSize:p.mrpFontSize||12,mrpFontWeight:p.mrpFontWeight?String(p.mrpFontWeight):"500",imageRadius:p.imageRadius!==void 0?Number(p.imageRadius)*a:10,animation:He(p.animation)}}}),w=u.map(d=>{let T=d.position||d.postion||{x:0,y:0};return{id:d.id||Math.random().toString(),type:"image",x:T.x/r*100,y:T.y/s*100,width:d.width/r*100,height:d.height?d.height/s*100:void 0,url:d.link||d.url,z:d.z??0}}),I=x.map(d=>{let T=d.position||{x:0,y:0},l=d.font||{};return{id:d.id||Math.random().toString(),type:"text",x:T.x/r*100,y:T.y/s*100,width:d.size?.width?d.size.width/r*100:void 0,text:d.value,z:d.z??1,styling:{color:d.color||"#000000",fontSize:l.fontSize?l.fontSize*a:void 0,fontFamily:ct(l.fontFamily),fontStyle:l.fontStyle,fontWeight:l.fontWeight}}}),z=[...b,...h,...y,...w,...I].filter(d=>{if(!d.duration)return!0;let{start:T,end:l}=d.duration;return i>=T&&i<=l}).sort((d,T)=>(d.z??0)-(T.z??0));return Nr("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:10,pointerEvents:"none",overflow:"hidden"},children:[fi("style",{children:`
87
+ `}),n.map(g=>xo("div",{style:u,className:"shopable-card",onClick:b=>S(b,g),children:[ke("div",{style:C,children:ke("img",{src:g.image,alt:g.title,style:{width:"100%",height:"100%",objectFit:"cover"}})}),xo("div",{style:h,children:[ke("span",{style:{color:i?.titleColor||i?.textColor||"#1a1b2e",fontSize:i?.titleFontSize?ot(i.titleFontSize):"15px",fontWeight:i?.titleFontWeight||"700",lineHeight:"1.2",display:"block",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",marginBottom:"1px"},children:g.title}),xo("div",{style:{display:"flex",alignItems:"baseline",gap:"6px",flexWrap:"wrap"},children:[ke("span",{style:{color:i?.priceColor||i?.textColor||"#1a1b2e",fontSize:i?.priceFontSize?ot(i.priceFontSize):"18px",fontWeight:i?.priceFontWeight||"800",display:"block"},children:g.price}),g.oldPrice&&ke("span",{style:{color:i?.mrpColor||"#8b8b98",fontSize:i?.mrpFontSize?ot(i.mrpFontSize):"12px",fontWeight:i?.mrpFontWeight||"500",textDecoration:"line-through"},children:g.oldPrice})]})]}),ke("div",{style:{backgroundColor:i?.buttonBackground||"#000000",color:i?.buttonTextColor||"#ffffff",fontSize:i?.buttonFontSize?ot(i.buttonFontSize):"14px",fontWeight:"700",padding:"10px 18px",borderRadius:i?.buttonBorderRadius!==void 0?ot(i.buttonBorderRadius):"100px",textAlign:"center",flexShrink:0,whiteSpace:"nowrap"},children:"Buy Now"})]},g.id))]}),s&&c&&ke(xr,{product:c,styling:i,onClose:()=>l(!1),onAddToCart:p})]})};import{Fragment as ua,jsx as It,jsxs as Yn}from"react/jsx-runtime";var wr=Ye.default?.default??Ye.default??Ye.Lottie??Ye,ca=({url:t,animationData:e,loop:o=!0,autoplay:n=!0,styling:i={}})=>{let[s,l]=vr(e||null),[c,d]=vr(!1);da(()=>{if(e){l(e);return}t&&(d(!1),fetch(t).then(y=>{if(!y.ok)throw new Error(`Failed to fetch Lottie JSON (${y.status})`);return y.json()}).then(y=>{l(y),d(!1)}).catch(y=>{console.error("AppStorys: Error loading Lottie sticker from URL:",t,y),d(!0)}))},[t,e]);let S={width:"100%",height:"100%",display:"block",borderRadius:ot(i.borderRadius||"0px"),border:i.border||"none",boxShadow:i.boxShadow||"none",opacity:i.opacity??1,transform:i.transform||void 0,overflow:"hidden"};if(!s)return It("div",{style:S});let p=wr.default||wr;return It(p,{animationData:s,loop:o,autoplay:n,style:S,rendererSettings:{preserveAspectRatio:"xMidYMid meet"}})},kr=({data:t,onInteraction:e,isEditing:o=!1})=>{let n={x:10,y:15,width:80,rotation:0},i=t.x??n.x,s=t.y??n.y,l=t.width??n.width,c=t.rotation??n.rotation,d={position:"absolute",top:`${s}%`,left:`${i}%`,width:`${l}%`,height:t.height?`${t.height}%`:"auto",transform:`rotate(${c}deg)`,zIndex:10,transformOrigin:"center center",boxSizing:"border-box",cursor:o?"move":"default",pointerEvents:"auto"},S={width:"100%",height:"100%",animation:t.styling?.animation,animationFillMode:"forwards"},p=()=>{switch(t.type){case"poll":return It(er,{data:t,onInteraction:e,isEditing:o});case"quiz":return It(or,{data:t,onInteraction:e,isEditing:o});case"rating":return It(cr,{data:t,onInteraction:e,isEditing:o});case"question":case"input":return It(pr,{data:t,onInteraction:e,isEditing:o});case"image_quiz":return It(gr,{data:t,onInteraction:e,isEditing:o});case"countdown":return It(ir,{data:t,onInteraction:e,isEditing:o});case"promo_code":case"promo":return It(sr,{data:t,onInteraction:e,isEditing:o});case"reaction":return It(dr,{data:t,onInteraction:e,isEditing:o});case"lottie":return It(ca,{url:t.url,loop:t.loop,autoplay:t.autoplay,styling:t.styling});case"buy":case"shopable":return It(Cr,{data:t,onInteraction:e,isEditing:o});case"video":{let u=t.styling||{};return It("video",{src:t.url,autoPlay:!0,loop:t.loop!==!1,muted:t.muted!==!1,playsInline:!0,style:{width:"100%",height:"100%",objectFit:u.objectFit||"cover",objectPosition:u.objectPosition||"center center",borderRadius:ot(u.borderRadius||"0px"),border:u.border||"none",boxShadow:u.boxShadow||"none",opacity:u.opacity??1,display:"block",overflow:"hidden",WebkitMaskImage:"-webkit-radial-gradient(white, black)",transform:"translateZ(0)"}})}case"shape":case"gif":case"svg":case"sticker":case"image":{let u=t.styling||{};return It("img",{src:t.url,alt:"static overlay",style:{width:"100%",height:"100%",objectFit:u.objectFit||"cover",objectPosition:u.objectPosition||"center center",borderRadius:u.borderRadius||"0px",border:u.border||"none",boxShadow:u.boxShadow||"none",opacity:u.opacity??1,display:"block",overflow:"hidden",WebkitMaskImage:"-webkit-radial-gradient(white, black)",transform:"translateZ(0)"}})}case"text":{let u=t.styling||{},C=u.verticalAlignment,h=u.textAlign,g=u.lineHeight,b="1.25";if(g!=null&&g!==""){let m=Number(g);isNaN(m)?b=String(g):b=m<=5?String(m):"1.25"}return It("div",{style:{color:u.color||"#000000",fontSize:ot(u.fontSize||14),fontFamily:st(u.fontFamily)||"Arial",fontStyle:u.fontStyle||"normal",fontWeight:u.fontWeight||"normal",textDecoration:u.textDecoration||"none",lineHeight:b,letterSpacing:u.letterSpacing||"normal",opacity:u.opacity??1,wordBreak:"break-word",whiteSpace:"pre-wrap",width:"100%",height:"100%",display:"flex",alignItems:C==="middle"||C==="center"?"center":C==="bottom"?"flex-end":"flex-start",justifyContent:h==="center"?"center":h==="right"?"flex-end":"flex-start",textAlign:h||"left"},children:t.text})}case"cta":{let u=t.styling||{};if(t.ctaType==="image")return It("button",{onClick:v=>{v.stopPropagation(),e&&e({type:"cta",stickerId:t.id,redirectUrl:t.redirectUrl})},style:{background:"none",border:u.borderWidth&&u.borderWidth!=="0px"&&u.borderWidth!=="0cqh"?`${ot(u.borderWidth)} solid ${u.borderColor||"#FFFFFF"}`:"none",padding:0,width:"100%",height:"100%",cursor:"pointer",display:"block",outline:"none",borderRadius:u.borderRadius||"0px",overflow:"hidden",WebkitMaskImage:"-webkit-radial-gradient(white, black)",transform:"translateZ(0)"},children:It("img",{src:t.url,alt:t.text,style:{width:"100%",height:"100%",objectFit:u.objectFit||"cover",objectPosition:u.objectPosition||"center center",display:"block",borderRadius:u.borderRadius||"0px"}})});let h=u.borderRadius,g=(t.text||"").trim(),b=g.toLowerCase().includes("swipe")||String(t.ctaType).toLowerCase().includes("swipe")||String(t.type).toLowerCase().includes("swipe")||String(t.id).toLowerCase().includes("swipe"),m={width:"100%",height:u.pillH?`${u.pillH}cqh`:"100%",backgroundColor:u.transparent?"transparent":u.backgroundColor||"#3B82F6",color:u.textColor||"#FFFFFF",border:u.borderWidth&&u.borderWidth!=="0px"&&u.borderWidth!=="0cqh"?`${ot(u.borderWidth)} solid ${u.borderColor||"#FFFFFF"}`:"none",borderRadius:h||"4px",fontSize:ot(u.fontSize||14),fontFamily:st(u.fontFamily)||"Arial",fontStyle:u.fontStyle||"normal",fontWeight:u.fontWeight||"normal",textDecoration:u.textDecoration||"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxSizing:"border-box",outline:"none",padding:"0 12px",wordBreak:"break-word",flexShrink:0},E={position:"relative",width:"100%",height:"100%",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"flex-end",boxSizing:"border-box",animation:b&&u.arrowAnimation!==!1?"appstorys-swipe-bounce 2.2s ease-in-out infinite":"none",transformOrigin:"bottom center"},O={display:"flex",alignItems:"center",justifyContent:"center",flexGrow:1,width:"100%",color:u.arrowColor||u.textColor||"#FFFFFF",pointerEvents:"none",boxSizing:"border-box"},D=u.arrowSize?`${u.arrowSize}cqh`:"1.5cqh";return Yn("div",{style:E,children:[b&&Yn(ua,{children:[It("style",{children:`
88
+ @keyframes appstorys-swipe-bounce {
89
+ 0%, 100% {
90
+ transform: translateY(0) scaleY(1) scaleX(1);
91
+ }
92
+ 40% {
93
+ transform: translateY(-3px) scaleY(1.04) scaleX(0.98);
94
+ }
95
+ 75% {
96
+ transform: translateY(1px) scaleY(0.97) scaleX(1.02);
97
+ }
98
+ }
99
+ `}),It("div",{style:O,children:It("svg",{style:{height:D,width:"auto"},viewBox:"0 0 28 18",fill:"none",stroke:"currentColor",strokeWidth:"4",strokeLinecap:"round",strokeLinejoin:"round",children:It("polyline",{points:"4 14 14 4 24 14"})})})]}),It("button",{onClick:v=>{v.stopPropagation(),e&&e({type:"cta",stickerId:t.id,redirectUrl:t.redirectUrl})},style:m,children:g||t.text})]})}default:return Yn("div",{style:{padding:"10px",background:"white",color:"black",borderRadius:"4px"},children:["Unsupported interactive element: ",t.type]})}};return It("div",{style:d,className:`interactive-item-z${t.z??0}`,children:It("div",{style:S,children:p()})})};import{jsx as Br,jsxs as pa}from"react/jsx-runtime";var Ko=(t,e)=>{let o=t?.styling?.editorSource||t?.styling?.meta?.editorSource||t?.style?.editorSource||e?.editorSource||e?.meta?.editorSource||e?.styling?.editorSource||e?.styling?.meta?.editorSource;return o==="studio"||o==="editor"?"studio":"dashboard"},Rr=t=>{if(!t)return!1;let e=t.trim();return e.startsWith("http://")||e.startsWith("https://")},Ge=(...t)=>{for(let e of t)if(e){if(typeof e=="object"){let o=e.fontFamily||e.font_family||e.font?.fontFamily||e.font?.font_family;if(typeof o=="string"&&o.trim()){let n=o.trim();if(Rr(n)||n.length<50&&!/[?!.,;:\n]/.test(n))return n}}if(typeof e=="string"){let o=e.trim();if(!o)continue;if(Rr(o)||o.length<35&&!/[?!.,;:\n]/.test(o)&&o.split(/\s+/).length<=3)return o}}},De=(t,e)=>Array.isArray(t)?t.map((o,n)=>{let i=o?.id||o?.key||o?.value||`option_${n+1}`,s=o?.label||o?.optionLabel,l=typeof o=="string"?o:o?.text||o?.title||s||"";return{id:String(i),text:l,image:o?.image||o?.imageUrl||"",label:s,isCorrect:o?.isCorrect===!0||String(i)===String(e)}}):t&&typeof t=="object"?Object.entries(t).map(([o,n])=>{let i=typeof n=="string"?{text:n}:n||{};return{id:o,text:i.text||i.title||i.label||"",image:i.image||i.imageUrl||"",label:i.label,isCorrect:o===String(e)}}):[],Fr=t=>Array.isArray(t?.emojis)?t.emojis.map(e=>String(e)):De(t?.options).map(e=>e.text).filter(Boolean),Tr=t=>{let e=String(t||"").toLowerCase();return e==="quizz"?"quiz":e==="rate"?"rating":e==="input"||e==="ask_question"||e==="askquestion"?"question":e==="promo"||e==="promocode"?"promo_code":e},zr=(t,e,o)=>{let n=e?.couponCode||e?.code||e?.coupon_code||e?.promoCode||e?.promocode||e?.coupon||e?.value||t?.couponCode||t?.code||t?.coupon_code||o?.couponCode||o?.code||o?.data?.couponCode||o?.data?.code;return typeof n=="string"&&n.trim()!==""?n.trim():"OFFER20"},Ir=t=>{if(t.targetDate)return t.targetDate;if(!t.endDate)return new Date(Date.now()+864e5).toISOString();try{let e=`${t.endDate}${t.endTime?`T${t.endTime}`:""}`;return new Date(e).toISOString()}catch{return t.endDate||new Date(Date.now()+864e5).toISOString()}},Gn=({content:t={},onInteraction:e,isEditing:o=!1,elapsedTime:n=0})=>{let i=t?.canva||t?.styling?.canva||t?.meta?.canva||{height:1920,width:1080},s=Number(i?.width)||1080,l=Number(i?.height)||1920,c=.352,d=t?.elements||[],S=t?.image||[],p=t?.video||t?.styling?.video||[],y=Array.isArray(p)?p:typeof p=="object"&&p!==null?[p]:[],u=t?.lottie||t?.styling?.lottie||t?.styling?.lotties||t?.meta?.lottie||[],C=Array.isArray(u)?u:typeof u=="object"&&u!==null?[u]:[],h=t?.text||[],g=t?.ctas||[],b=t?.interactions||[],m=Array.isArray(t?.shopable)&&t.shopable.length>0?t.shopable:Array.isArray(t?.styling?.shopable)?t.styling.shopable:[],E=new Set(m.map(r=>r.id)),O=(t?.styling?.shopable||[]).concat(m.map(r=>r.styling).filter(Boolean)),L=Ko(null,t)==="studio",v=(r,M=L)=>{if(r==null||r==="")return;if(typeof r=="string"&&(r.endsWith("cqh")||r.endsWith("px")||r.endsWith("%")||r.endsWith("em")||r.endsWith("rem")))return r;let a=Number(r);return isNaN(a)?String(r):a>=1e3?"999px":M||a<=100?`${a}cqh`:`${a/l*100}cqh`},w=(r,M=L)=>{if(r==null||r==="")return;if(typeof r=="string"&&(r.endsWith("cqh")||r.endsWith("px")||r.endsWith("%")||r.endsWith("em")||r.endsWith("rem")))return r;let a=Number(r);if(isNaN(a))return String(r);let f;return a<10?f=a:f=a/l*100,f<1.4?`clamp(11px, ${(f*1.25).toFixed(3)}cqh, 22px)`:f<2.5?`clamp(14px, ${(f*1.15).toFixed(3)}cqh, 32px)`:`clamp(16px, ${(f*1.05).toFixed(3)}cqh, 48px)`};if(d.length===0&&S.length===0&&y.length===0&&C.length===0&&h.length===0&&b.length===0&&m.length===0&&g.length===0)return null;let _=d.filter(r=>!E.has(r.id)).map(r=>{let M=r.custom||{},a=M.data||{},f=M.style||r.styling||{},x=Ko(r,t),z=x==="studio",U=r.position||r.postion||{},et=r.size||{},X=r.x!==void 0?r.x:U.x,q=r.y!==void 0?r.y:U.y,J=r.width!==void 0?r.width:et.width,nt=r.height!==void 0?r.height:et.height,ht=X!==void 0&&!isNaN(Number(X))?z?Number(X):Number(X)/s*100:10,dt=q!==void 0&&!isNaN(Number(q))?z?Number(q):Number(q)/l*100:15,K=J!==void 0&&!isNaN(Number(J))?z?Number(J):Number(J)/s*100:80,it=nt!==void 0&&!isNaN(Number(nt))?z?Number(nt):Number(nt)/l*100:void 0,lt=Ge(a.question,a.prompt,a.title,f.question,r.question,f.prompt,r.font,f.font,a.font,a.fontFamily,r.fontFamily,f.fontFamily),mt=Ge(a.options,f.options,r.options,a.font,f.font,r.font,a.fontFamily,r.fontFamily,f.fontFamily),gt=Ge(a.font,f.font,r.font,a.fontFamily,r.fontFamily,f.fontFamily),R={id:r.id||Math.random().toString(),type:Tr(M.interactiveType||r.widgetType||r.type||"unknown"),x:ht,y:dt,width:K,height:it,url:r.url||a.url||r.link||a.link,rotation:f.rotation??r.rotation??0,z:r.z??r.position?.z??f.z??10,duration:a.duration||f.duration,styling:{backgroundColor:St(f.background||f.containerBgColor||f.backgroundColor),borderRadius:f.borderRadius!==void 0?f.borderRadius>=100?"999px":v(f.borderRadius,z):f.radius!==void 0?f.radius>=100?"999px":v(f.radius,z):"0px",padding:v(f.containerPadding!==void 0?f.containerPadding:f.padding!==void 0?f.padding:0,z),shadow:f.shadow,fontSize:w(f.questionFontSize??f.questionFont?.fontSize??f.questionSize??f.fontSize,z),opacity:f.opacity??1,animation:mo(f.animation),fontFamily:gt,questionFontFamily:lt||gt,optionFontFamily:mt||gt}};if(R.type==="poll"){let I=De(a.options);return{...R,type:"poll",question:a.question||a.title||"Poll Question",options:I,layout:a.layout||{type:"vertical",columns:1},styling:{...R.styling,headerColor:St(f.headerBgColor||f.background),headerTextColor:tt(f.questionColor||f.questionTextColor||f.question?.color),optionBgColor:St(f.optionBgColor||f.options?.background)||"#1A1A1A",optionTextColor:tt(f.optionTextColor||f.options?.textColor)||"#ffffff",optionBorderRadius:f.optionBorderRadius!==void 0?v(f.optionBorderRadius,z):f.options?.radius!==void 0?v(f.options?.radius,z):"0px"}}}if(R.type==="quiz"){let I=f.colors||{},N=De(a.options,a.isCorrect),Z=f.optionFontSize??f.optionFont?.fontSize??f.typography?.optionSize??f.options?.fontSize??16;return{...R,type:"quiz",question:a.question||a.title||"Quiz Question",options:N,showExplanation:a.showExplanation??r.showExplanation??f.showExplanation??M.showExplanation??!0,explanation:a.explanation||r.explanation||f.explanation||M.explanation,url:a.url,styling:{...R.styling,backgroundColor:St(f.background||f.containerBgColor||f.backgroundColor)||"transparent",questionTextColor:tt(f.questionColor||I.questionColor||f.question?.color||f.colors?.questionText)||"#FFFFFF",questionBgColor:St(f.questionBgColor||I.questionBackground||f.question?.background||f.colors?.questionBg)||"#000000",optionBgColor:St(f.optionBgColor||I.optionBackground||f.options?.background||f.colors?.optionBg)||"#FFFFFF",optionTextColor:tt(f.optionTextColor||I.optionTextColor||f.options?.textColor||f.colors?.optionText)||"#2B2B2B",borderColor:tt(f.borderColor)||"transparent",activeColor:tt(f.correctColor||I.correctColor||f.correctBorderColor)||"#10b981",incorrectColor:tt(f.incorrectColor||I.incorrectColor)||"#ef4444",optionBorderRadius:f.optionRadius!==void 0?f.optionRadius>=100?"999px":v(f.optionRadius,z):f.optionBorderRadius!==void 0?f.optionBorderRadius>=100?"999px":v(f.optionBorderRadius,z):"100px",optionFontSize:w(Z,z)}}}if(R.type==="rating")return{...R,type:"rating",title:a.title||"Do you like my space?",emoji:a.emoji||"\u{1F60D}",currentRating:a.currentRating,maxRating:a.maxRating,styling:{...R.styling,sliderTrackColor:tt(f.colors?.sliderTrack||f.sliderTrack),sliderFillColor:tt(f.colors?.sliderFill||f.sliderFill),emojiSize:f.emojiSize?z?`${Math.min(Number(f.emojiSize),32)}px`:`${Math.min(f.emojiSize*.45,32)}px`:void 0,titleColor:tt(f.colors?.titleColor||f.titleColor),titleFontSize:f.titleFontSize?z?`${Math.min(Number(f.titleFontSize),16)}px`:`${Math.min(f.titleFontSize*.4,16)}px`:void 0}};if(R.type==="question"){let I=f.optionRadius??f.optionBorderRadius??f.inputRadius??f.inputBorderRadius,N=f.borderRadius??f.radius??f.containerBorderRadius;return{...R,type:"question",question:a.question||a.title||"Ask me a question",placeholder:a.placeholder||"Type your answer...",styling:{...R.styling,borderRadius:N!==void 0?N>=100?"999px":v(N,z):"16px",promptColor:tt(f.questionColor||f.promptColor||f.textColor),inputBgColor:St(f.inputBackground||f.inputBgColor),inputTextColor:tt(f.inputTextColor),submitBackground:St(f.submitBackground),optionRadius:I!==void 0?I>=5?"9999px":v(I,z):"9999px",inputBorderRadius:I!==void 0?I>=5?"9999px":v(I,z):"9999px"}}}if(R.type==="image_quiz"||R.type==="imageQuiz"||(M.interactiveType||"").toLowerCase()==="media_quiz"){let I=f.optionFontSize??f.optionFont?.fontSize??f.typography?.optionSize??f.options?.fontSize??13,N=f.borderRadius??f.radius??f.containerBorderRadius,Z=f.optionRadius??f.optionBorderRadius??f.imageRadius;return{...R,type:"image_quiz",question:a.question||a.title||"Image Quiz",options:De(a.options||[]),layout:a.layout??f.layout??r.layout,styling:{...R.styling,borderRadius:N!==void 0?N>=100?"999px":v(N,z):void 0,optionRadius:Z!==void 0?Z>=100?"999px":v(Z,z):void 0,questionBgColor:St(f.questionBgColor||f.questionBackground),questionTextColor:tt(f.questionColor||f.questionTextColor),optionBgColor:St(f.optionBgColor||f.optionBackground),optionTextColor:tt(f.optionTextColor||f.textColor),labelColor:tt(f.labelColor),borderColor:tt(f.borderColor),activeColor:tt(f.correctBorderColor||f.correctColor||f.activeColor),incorrectColor:tt(f.incorrectColor),imageRadius:Z!==void 0?v(Z,z):void 0,optionFontSize:w(I,z)}}}if(R.type==="countdown")return{...R,type:"countdown",title:a.title||"Ends in...",targetDate:Ir(a),styling:{...R.styling,borderColor:tt(f.borderColor),digitBackground:St(f.digitBackground),digitColor:tt(f.digitColor),digitSize:f.digitSize||f.fontSize?w(f.digitSize||f.fontSize,z):void 0,labelColor:tt(f.labelColor),titleColor:tt(f.titleColor)},display:a.display};if(R.type==="promo_code")return{...R,width:R.width?Math.max(R.width,65):75,type:"promo_code",code:zr(r,a,M),styling:{...R.styling,borderColor:tt(f.borderColor)}};if(R.type==="reaction"||R.type==="emoji_reaction"){let I=Fr(a);return{...R,type:"reaction",emojis:I.length>0?I:["\u{1F60D}","\u{1F44D}"],source:x}}return R}),$=(t?.interactions||[]).filter(r=>!E.has(r.id)).map(r=>{let M=r.config||{},a=r.styling||r.style||{},f=Ko(r,t),x=f==="studio",z=Tr(r.interaction_type||r.type),U=a.position||r.position||{},et=a.size||r.size||{},X=U.x??r.x,q=U.y??r.y,J=et.width??r.width,nt=et.height??r.height,ht=X!==void 0&&!isNaN(Number(X))?x?Number(X):Number(X)/s*100:10,dt=q!==void 0&&!isNaN(Number(q))?x?Number(q):Number(q)/l*100:15,K=J!==void 0&&!isNaN(Number(J))?x?Number(J):Number(J)/s*100:80,it=nt!==void 0&&!isNaN(Number(nt))?x?Number(nt):Number(nt)/l*100:void 0,lt=Ge(a.question,r.question,a.prompt,M.question,M.prompt,M.title,a.font,r.font,M.font,a.fontFamily,M.fontFamily,r.fontFamily),mt=Ge(a.options,r.options,M.options,a.font,r.font,M.font,a.fontFamily,M.fontFamily,r.fontFamily),gt=Ge(a.font,r.font,M.font,a.fontFamily,M.fontFamily,r.fontFamily),R={id:r.id||Math.random().toString(),type:z,x:ht,y:dt,width:K,height:it,rotation:a.rotation??r.rotation??0,z:r.z??r.position?.z??a.z??10,source:f,duration:M.duration||a.duration,styling:{backgroundColor:St(a.background||a.containerBgColor||a.backgroundColor),borderRadius:a.borderRadius!==void 0?a.borderRadius>=100?"999px":v(a.borderRadius,x):a.radius!==void 0?a.radius>=100?"999px":v(a.radius,x):"0px",padding:v(a.containerPadding!==void 0?a.containerPadding:a.padding!==void 0?a.padding:0,x),shadow:a.shadow,fontSize:w(a.questionFontSize??a.questionFont?.fontSize??a.questionSize??a.fontSize,x),opacity:a.opacity??1,animation:mo(a.animation),fontFamily:gt,questionFontFamily:lt||gt,optionFontFamily:mt||gt}};if(R.type==="rating"||R.type==="rate"){let I=a.colors||{};return{...R,type:"rating",title:M.title||"Do you like my space?",emoji:M.emoji||"\u{1F60D}",currentRating:M.currentRating,maxRating:M.maxRating,styling:{...R.styling,sliderTrackColor:tt(I.sliderTrack||a.colors?.sliderTrack||a.colors?.sliderTrack),sliderFillColor:tt(I.sliderFill||a.colors?.sliderFill||a.colors?.sliderFill),emojiSize:a.emojiSize?x?`${Math.min(Number(a.emojiSize),32)}px`:`${Math.min(a.emojiSize*.45,32)}px`:void 0,titleColor:tt(I.titleColor||a.colors?.titleColor||a.titleColor),titleFontSize:a.titleFontSize?x?`${Math.min(Number(a.titleFontSize),16)}px`:`${Math.min(a.titleFontSize*.4,16)}px`:void 0}}}if(R.type==="poll"){let I=De(M.options);return{...R,type:"poll",question:M.question||M.title||"Poll Question",options:I,layout:M.layout||{type:"vertical",columns:1},styling:{...R.styling,headerColor:St(a.headerBgColor||a.background),headerTextColor:tt(a.questionColor||a.questionTextColor||a.question?.color),optionBgColor:St(a.optionBgColor||a.options?.background)||"#1A1A1A",optionTextColor:tt(a.optionTextColor||a.options?.textColor)||"#ffffff",optionBorderRadius:a.optionBorderRadius!==void 0?v(a.optionBorderRadius,x):a.options?.radius!==void 0?v(a.options?.radius,x):"0px"}}}if(R.type==="quiz"){let I=a.colors||{},N=De(M.options,M.isCorrect),Z=a.optionFontSize??a.optionFont?.fontSize??a.typography?.optionSize??a.options?.fontSize??16;return{...R,type:"quiz",question:M.question||M.title||"Quiz Question",options:N,showExplanation:M.showExplanation??r.showExplanation??a.showExplanation??!0,explanation:M.explanation||r.explanation||a.explanation,url:M.url,styling:{...R.styling,backgroundColor:St(a.background||a.containerBgColor||a.backgroundColor)||"transparent",questionTextColor:tt(a.questionColor||I.questionColor||a.question?.color||a.colors?.questionText)||"#FFFFFF",questionBgColor:St(a.questionBgColor||I.questionBackground||a.question?.background||a.colors?.questionBg)||"#000000",optionBgColor:St(a.optionBgColor||I.optionBackground||a.options?.background||a.colors?.optionBg)||"#FFFFFF",optionTextColor:tt(a.optionTextColor||I.optionTextColor||a.options?.textColor||a.colors?.optionText)||"#2B2B2B",borderColor:tt(a.borderColor)||"transparent",activeColor:tt(a.correctColor||I.correctColor||a.correctBorderColor)||"#10b981",incorrectColor:tt(a.incorrectColor||I.incorrectColor)||"#ef4444",optionBorderRadius:a.optionRadius!==void 0?a.optionRadius>=100?"999px":v(a.optionRadius,x):a.optionBorderRadius!==void 0?a.optionBorderRadius>=100?"999px":v(a.optionBorderRadius,x):"100px",optionFontSize:w(Z,x)}}}if(R.type==="question"){let I=a.optionRadius??a.optionBorderRadius??a.inputRadius??a.inputBorderRadius,N=a.borderRadius??a.radius??a.containerBorderRadius;return{...R,type:"question",question:M.question||M.title||"Ask me a question",placeholder:M.placeholder||"Type your answer...",styling:{...R.styling,borderRadius:N!==void 0?N>=100?"999px":v(N,x):"16px",promptColor:tt(a.questionColor||a.promptColor||a.textColor),inputBgColor:St(a.inputBackground||a.inputBgColor),inputTextColor:tt(a.inputTextColor),submitBackground:St(a.submitBackground),optionRadius:I!==void 0?I>=5?"9999px":v(I,x):"9999px",inputBorderRadius:I!==void 0?I>=5?"9999px":v(I,x):"9999px"}}}if(R.type==="image_quiz"||R.type==="imageQuiz"||z==="media_quiz"){let I=a.optionFontSize??a.optionFont?.fontSize??a.typography?.optionSize??a.options?.fontSize??13,N=a.borderRadius??a.radius??a.containerBorderRadius,Z=a.optionRadius??a.optionBorderRadius??a.imageRadius;return{...R,type:"image_quiz",question:M.question||M.title||"Image Quiz",options:De(M.options||[]),layout:M.layout??a.layout??r.layout,styling:{...R.styling,borderRadius:N!==void 0?N>=100?"999px":v(N,x):void 0,optionRadius:Z!==void 0?Z>=100?"999px":v(Z,x):void 0,questionBgColor:St(a.questionBgColor||a.questionBackground),questionTextColor:tt(a.questionColor||a.questionTextColor),optionBgColor:St(a.optionBgColor||a.optionBackground),optionTextColor:tt(a.optionTextColor||a.textColor),labelColor:tt(a.labelColor),borderColor:tt(a.borderColor),activeColor:tt(a.correctBorderColor||a.correctColor||a.activeColor),incorrectColor:tt(a.incorrectColor),imageRadius:Z!==void 0?v(Z,x):void 0,optionFontSize:w(I,x)}}}if(R.type==="countdown")return{...R,type:"countdown",title:M.title||"Ends in...",targetDate:Ir(M),styling:{...R.styling,borderColor:tt(a.borderColor),digitBackground:St(a.digitBackground),digitColor:tt(a.digitColor),digitSize:a.digitSize||a.fontSize?w(a.digitSize||a.fontSize,x):void 0,labelColor:tt(a.labelColor),titleColor:tt(a.titleColor),labelFontSize:a.labelFontSize?w(a.labelFontSize,x):void 0},display:M.display||r.display};if(R.type==="promo_code")return{...R,width:R.width?Math.max(R.width,65):75,type:"promo_code",code:zr(r,M,a),styling:{...R.styling,borderColor:tt(a.borderColor)}};if(R.type==="reaction"||R.type==="emoji_reaction"){let I=Fr(M);return{...R,type:"reaction",emojis:I.length>0?I:["\u{1F60D}","\u{1F44D}"]}}return R}),V=m.map(r=>{let M=O.find(I=>String(I?.id)===String(r?.id))||O.find(I=>I?.id===void 0)||{},f=Ko(r,t)==="studio",x={position:r?.position,size:r?.size,rotation:r?.rotation,z:r?.z,background:r?.background,cardBackground:r?.cardBackground,cardBorderRadius:r?.cardBorderRadius,cardRadiusPercent:r?.cardRadiusPercent,transparent:r?.transparent,textColor:r?.textColor,buttonBackground:r?.buttonBackground,buttonTextColor:r?.buttonTextColor,buttonFontSize:r?.buttonFontSize,buttonBorderRadius:r?.buttonBorderRadius,titleColor:r?.titleColor,titleFontSize:r?.titleFontSize,titleFontWeight:r?.titleFontWeight,priceColor:r?.priceColor,priceFontSize:r?.priceFontSize,priceFontWeight:r?.priceFontWeight,mrpColor:r?.mrpColor,mrpFontSize:r?.mrpFontSize,mrpFontWeight:r?.mrpFontWeight,imageRadius:r?.imageRadius,opacity:r?.opacity,animation:r?.animation},z={...M,...r?.styling||{},...Object.fromEntries(Object.entries(x).filter(([,I])=>I!==void 0))},U=z.position||{},et=z.size||{},X=z.cardBorderRadius!==void 0?Number(z.cardBorderRadius):void 0,q=z.cardRadiusPercent!==void 0?Number(z.cardRadiusPercent):void 0,J=et.height!==void 0?Number(et.height):void 0,nt=X===void 0&&q!==void 0&&J!==void 0?Math.max(0,Math.min(100,q))/100*(J/2):void 0,ht=X??nt,dt=ht!==void 0&&!isNaN(ht)?ht*c:void 0,K=U.x!==void 0?f?Number(U.x):Number(U.x)/s*100:0,it=et.width!==void 0?f?Number(et.width):Number(et.width)/s*100:100,lt=et.height!==void 0?f?Number(et.height):Number(et.height)/l*100:void 0,mt=U.y!==void 0?f?Number(U.y):Number(U.y)/l*100:lt?100-lt-2.5:85;lt&&mt+lt>96?mt=Math.max(0,100-lt):mt>75&&lt&&mt+lt>91&&(mt=Math.max(0,100-lt-1));let gt=Array.isArray(r.product)&&r.product.length>0,R=gt?r.product:r.static||[];return{id:r.id||Math.random().toString(),type:"buy",shopableType:gt?"product":"static",x:K,y:mt,width:it,height:lt,rotation:z.rotation??0,z:z.z??10,products:R.map(I=>{let N=I.productData||I||{},Z=N.attributes||I.attributes||{},xt=Z.sales_price||N.price||Z.price||I.price,Ft=Z.sales_price?N.price||Z.price||I.price:N.oldPrice||I.oldPrice,kt=N.color||Z.color||I.color,Wt=N.size||Z.size||I.size,Bt=Z.colors||[];Bt.length===0&&kt&&(Bt=[{id:kt,hex:kt,name:kt}]);let Ht=Z.sizes||[];Ht.length===0&&Wt&&(Ht=typeof Wt=="string"?Wt.split(",").map(Kt=>Kt.trim()):[Wt]);let Tt={description:N.description||Z.description||I.description,color:kt,size:Wt,colors:Bt,sizes:Ht,imageUrls:Z.imageUrls||[Z.image_link||N.imageUrl||N.image||I.imageUrl||I.image||I.url].filter(Boolean),availability:N.availability||Z.availability||I.availability,tags:N.tags||Z.tags||I.tags,...Z};return{id:N.productId||N.id||I.productId||I.id||Math.random().toString(),image:Z.image_link||N.imageUrl||N.image||I.imageUrl||I.image||I.url,url:N.link||N.url||I.link||I.url||I.redirectUrl,title:N.title||I.title,price:xt,oldPrice:Ft,redirectUrl:I.redirectUrl||N.link||I.link||I.url,svg:N.svg||I.svg,productId:N.productId||I.productId,collectionId:N.collectionId||I.collectionId,feedId:N.feedId||I.feedId,attributes:Tt}}),styling:{backgroundColor:St(z.background),cardBackground:St(z.cardBackground)||St(z.background)||"#ffffff",cardBorderRadius:ht!==void 0&&!isNaN(ht)?f?`${ht}cqh`:`${dt}px`:f?"1cqh":"10px",cardRadiusPercent:q,transparent:z.transparent===!0,textColor:tt(z.textColor)||"#ffffff",buttonBackground:St(z.buttonBackground)||"#000000",buttonTextColor:tt(z.buttonTextColor)||"#ffffff",buttonFontSize:w(z.buttonFontSize||12,f),buttonBorderRadius:z.buttonBorderRadius!==void 0?f?`${z.buttonBorderRadius}cqh`:`${z.buttonBorderRadius}px`:f?"10cqh":"100px",titleColor:tt(z.titleColor||z.textColor)||"#1a1a2e",titleFontSize:w(z.titleFontSize||14,f),titleFontWeight:z.titleFontWeight?String(z.titleFontWeight):"600",priceColor:tt(z.priceColor||z.textColor)||"#1a1a2e",priceFontSize:w(z.priceFontSize||16,f),priceFontWeight:z.priceFontWeight?String(z.priceFontWeight):"700",mrpColor:tt(z.mrpColor)||"#8b8b98",mrpFontSize:w(z.mrpFontSize||12,f),mrpFontWeight:z.mrpFontWeight?String(z.mrpFontWeight):"500",imageRadius:z.imageRadius!==void 0?f?`${z.imageRadius}cqh`:`${Number(z.imageRadius)*c}px`:f?"1cqh":"10px",animation:mo(z.animation)}}}),A=S.map(r=>{let a=(t?.styling?.image||t?.styling?.images||[]).find(z=>z.id===r.id)||{},f=r.position||a.position||r.postion||{x:0,y:0},x=r.borderRadius??r.styling?.borderRadius??a.borderRadius??a.styling?.borderRadius??r.imageRadius??r.radius;return{id:r.id||Math.random().toString(),type:"image",x:L?Number(f.x):f.x/s*100,y:L?Number(f.y):f.y/l*100,width:L?Number(r.width):r.width/s*100,height:r.height?L?Number(r.height):r.height/l*100:void 0,url:r.link||r.url,z:r.z??a.z??0,styling:{borderRadius:x!==void 0?v(x,L):void 0,objectFit:r.objectFit||a.objectFit||r.sizing||a.sizing||"fill",objectPosition:Ve(r.objectPosition||a.objectPosition||r.positionStr),border:r.border||r.styling?.border||a.border,boxShadow:r.shadow||r.styling?.shadow||a.shadow,opacity:(r.opacity!==void 0?r.opacity:a.opacity)!==void 0?Number(r.opacity!==void 0?r.opacity:a.opacity)/100:void 0}}}),T=y.map(r=>{let a=(t?.styling?.video||t?.styling?.videos||[]).find(J=>J.id===r.id)||{},f=r.position||a.position||{x:r.x,y:r.y},x=f.x??r.x,z=f.y??r.y,U=r.width??a.width,et=r.height??a.height,X=r.cornerRadius??r.borderRadius??a.cornerRadius??a.borderRadius??r.radius,q=r.rotation!==void 0?r.rotation:a.rotation;return{id:r.id||Math.random().toString(),type:"video",x:x!==void 0&&!isNaN(Number(x))?L?Number(x):Number(x)/s*100:0,y:z!==void 0&&!isNaN(Number(z))?L?Number(z):Number(z)/l*100:0,width:U!==void 0&&!isNaN(Number(U))?L?Number(U):Number(U)/s*100:100,height:et!==void 0&&!isNaN(Number(et))?L?Number(et):Number(et)/l*100:void 0,url:r.link||r.url||r.src||a.link||a.url,rotation:q??0,z:r.z??a.z??2,loop:r.loop??a.loop??!0,muted:r.muted??a.muted??!1,styling:{borderRadius:X!==void 0?v(X,L):void 0,objectFit:r.objectFit||a.objectFit||r.sizing||a.sizing||"cover",objectPosition:Ve(r.objectPosition||a.objectPosition),border:r.border||r.styling?.border||a.border,boxShadow:r.shadow||r.styling?.shadow||a.shadow,opacity:(r.opacity!==void 0?r.opacity:a.opacity)!==void 0?Number(r.opacity!==void 0?r.opacity:a.opacity)/100:void 0}}}),k=C.map(r=>{let a=(t?.styling?.lottie||t?.styling?.lotties||[]).find(dt=>dt.id===r.id)||{},f=r.position||a.position||{x:r.x,y:r.y},x=f.x??r.x,z=f.y??r.y,U=r.width??a.width,et=r.height??a.height,X=r.cornerRadius??r.borderRadius??a.cornerRadius??a.borderRadius??r.radius,q=r.rotation!==void 0?r.rotation:a.rotation,J=r.flip||a.flip||{},nt="";J.horizontal&&J.vertical?nt="scale(-1, -1)":J.horizontal?nt="scaleX(-1)":J.vertical&&(nt="scaleY(-1)");let ht=r.duration||a.duration;return{id:r.id||Math.random().toString(),type:"lottie",x:x!==void 0&&!isNaN(Number(x))?L?Number(x):Number(x)/s*100:0,y:z!==void 0&&!isNaN(Number(z))?L?Number(z):Number(z)/l*100:0,width:U!==void 0&&!isNaN(Number(U))?L?Number(U):Number(U)/s*100:100,height:et!==void 0&&!isNaN(Number(et))?L?Number(et):Number(et)/l*100:void 0,url:r.link||r.url||r.src||r.lottie_url||a.link||a.url,rotation:q??0,z:r.z??a.z??3,duration:ht?.start!==void 0?ht:void 0,loop:r.loop??a.loop??!0,autoplay:r.autoplay??a.autoplay??!0,styling:{borderRadius:X!==void 0?v(X,L):void 0,border:r.border||r.styling?.border||a.border,boxShadow:r.shadow||r.styling?.shadow||a.shadow,opacity:(r.opacity!==void 0?r.opacity:a.opacity)!==void 0?Number(r.opacity!==void 0?r.opacity:a.opacity)/100:void 0,transform:nt||void 0,animation:mo(r.animation||a.animation)}}}),B=h.map(r=>{let a=(t?.styling?.text||[]).find(ht=>ht.id===r.id)||{},f=r.position||a.position||{x:0,y:0},x=r.font||a.font||{},z=r.size||a.size||{},U=r.alignment||a.alignment||{},et=r.color||a.color,X=x.fontDecoration||[],q=X.includes("underline")?"underline":X.includes("line-through")?"line-through":void 0,J=r.rotation!==void 0?r.rotation:a.rotation,nt=x.fontSize??r.fontSize??a.fontSize??a.font?.fontSize;return{id:r.id||Math.random().toString(),type:"text",x:L?Number(f.x):f.x/s*100,y:L?Number(f.y):f.y/l*100,width:z.width?L?Number(z.width):z.width/s*100:void 0,height:z.height?L?Number(z.height):z.height/l*100:void 0,rotation:J??0,text:r.text||r.value||a.text||a.value||"",z:r.z??a.z??1,styling:{color:tt(et)||"#000000",fontSize:nt?w(nt,L):void 0,fontFamily:x.fontFamily,fontStyle:x.fontStyle||(X.includes("italic")?"italic":"normal"),fontWeight:x.fontWeight||(X.includes("bold")?"bold":"normal"),textDecoration:q,lineHeight:r.lineHeight!==void 0?r.lineHeight:a.lineHeight,letterSpacing:(r.letterSpacing!==void 0?r.letterSpacing:a.letterSpacing)!==void 0?`${r.letterSpacing!==void 0?r.letterSpacing:a.letterSpacing}px`:void 0,opacity:(r.opacity!==void 0?r.opacity:a.opacity)!==void 0?Number(r.opacity!==void 0?r.opacity:a.opacity)/100:void 0,textAlign:U.horizontalAlignment||"left",verticalAlignment:U.verticalAlignment||"top"}}}),W=g.map(r=>{let a=(t?.styling?.ctas||t?.styling?.cta||[]).find(ht=>ht.id===r.id)||{},f=r.position||a.position||{x:0,y:0},x=r.size||a.size||{},z=r.font||a.font||{},U=z.fontDecoration||[],et=U.includes("underline")?"underline":U.includes("line-through")?"line-through":void 0,X=r.rotation!==void 0?r.rotation:a.rotation,q=z.fontSize??r.fontSize??a.fontSize??a.font?.fontSize,J=r.borderRadius??r.styling?.borderRadius??a.borderRadius??a.styling?.borderRadius,nt=r.borderWidth??r.styling?.borderWidth??a.borderWidth??a.styling?.borderWidth;return{id:r.id||Math.random().toString(),type:"cta",x:L?Number(f.x):f.x/s*100,y:L?Number(f.y):f.y/l*100,width:x.width?L?Number(x.width):x.width/s*100:void 0,height:x.height?L?Number(x.height):x.height/l*100:void 0,rotation:X??0,text:r.text||a.text||"Learn More",redirectUrl:r.redirectUrl||a.redirectUrl||r.link||a.link,ctaType:r.type||a.type||"classic",url:r.url||a.url,z:r.z??a.z??10,source:L?"studio":"dashboard",styling:{backgroundColor:St(r.background||a.background),textColor:tt(r.textColor||a.textColor)||"#FFFFFF",borderColor:tt(r.borderColor||a.borderColor||r.styling?.borderColor||a.styling?.borderColor)||"#FFFFFF",borderWidth:nt!==void 0&&Number(nt)>0?v(nt,L):void 0,borderRadius:J!==void 0?v(J,L):void 0,fontSize:q?w(q,L):void 0,fontFamily:z.fontFamily,fontStyle:z.fontStyle||(U.includes("italic")?"italic":"normal"),fontWeight:z.fontWeight||(U.includes("bold")?"bold":"normal"),textDecoration:et,pillH:r.pillH??a.pillH,arrowAnimation:r.arrowAnimation??a.arrowAnimation,arrowColor:tt(r.arrowColor||a.arrowColor),arrowSize:r.arrowSize??a.arrowSize,transparent:r.transparent??a.transparent}}}),H=[..._,...$,...V,...A,...T,...k,...B,...W].filter(r=>{if(!r.duration)return!0;let{start:M,end:a}=r.duration;return n>=M&&n<=a}).sort((r,M)=>(r.z??0)-(M.z??0));return console.log("InteractiveOverlay Debug - content.ctas:",g,"displayCtas:",W,"displayItems:",H),pa("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:10,pointerEvents:"none",overflow:"hidden",containerType:"size"},children:[Br("style",{children:`
53
100
  @keyframes appstorys-fade-in {
54
101
  from { opacity: 0; transform: translateY(10px); }
55
102
  to { opacity: 1; transform: translateY(0); }
@@ -69,16 +116,16 @@ var Yi=Object.defineProperty;var Nt=(t,e)=>()=>(t&&(e=t(t=0)),e);var Qi=(t,e)=>{
69
116
  70% { opacity: 1; transform: scale(0.95); }
70
117
  100% { opacity: 1; transform: scale(1); }
71
118
  }
72
- `}),z.map(d=>!d||typeof d!="object"||!(d.type||"").toLowerCase()?null:fi(di,{data:d,onInteraction:e,isEditing:o},d.id))]})};import{useState as qr}from"react";import{jsx as ye,jsxs as Hr}from"react/jsx-runtime";var Ur=({isPaused:t,onPress:e,style:o,size:i=36})=>{let[n,r]=qr(!1);return ye("button",{onClick:e,onMouseEnter:()=>r(!0),onMouseLeave:()=>r(!1),style:{width:`${i}px`,height:`${i}px`,background:n?"rgba(255, 255, 255, 0.15)":"rgba(255, 255, 255, 0.08)",border:n?"1px solid white":"1px solid rgba(255, 255, 255, 0.1)",display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"10px",cursor:"pointer",transition:"all 0.2s ease",padding:0,outline:"none",...o},children:t?ye("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"white",children:ye("path",{d:"M5 3.867v16.266c0 .54.58.88 1.05.61l14.133-8.133c.46-.27.46-.94 0-1.21L6.05 3.257C5.58 2.987 5 3.327 5 3.867z"})}):Hr("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"white",children:[ye("rect",{x:"6",y:"4",width:"4",height:"16",rx:"1"}),ye("rect",{x:"14",y:"4",width:"4",height:"16",rx:"1"})]})})},mi=Ur;import{jsx as jo}from"react/jsx-runtime";var Vr=t=>{switch(t){case"left":return"flex-start";case"right":return"flex-end";default:return"center"}},Yr=({cta:t,buttonText:e,onPress:o})=>!t||!e||e.trim()===""?null:jo("div",{style:{position:"absolute",bottom:t?.margin?.bottom,left:t?.margin?.left,right:t?.margin?.right,display:"flex",justifyContent:Vr(t?.container?.alignment),width:"100%",pointerEvents:"none",boxSizing:"border-box",zIndex:10},children:jo("button",{style:{backgroundColor:t?.container?.backgroundColor||"#F7921C",borderColor:t?.container?.borderColor||"transparent",borderWidth:t?.container?.borderWidth??0,borderStyle:t?.container?.borderWidth?"solid":"none",borderTopRightRadius:t?.cornerRadius?.topRight,borderTopLeftRadius:t?.cornerRadius?.topLeft,borderBottomRightRadius:t?.cornerRadius?.bottomRight,borderBottomLeftRadius:t?.cornerRadius?.bottomLeft,height:t?.container?.height||42,width:t?.container?.ctaFullWidth?"100%":t?.container?.ctaWidth||"auto",justifyContent:"center",alignItems:"center",display:"flex",cursor:"pointer",outline:"none",pointerEvents:"auto",padding:"0 12px",boxSizing:"border-box"},onClick:o,children:jo("span",{style:{color:t?.text?.color||"#ffffff",fontSize:t?.text?.fontSize||14,fontFamily:ct(t?.text?.fontFamily),fontWeight:t?.text?.fontDecoration?.includes("bold")?"bold":"normal",fontStyle:t?.text?.fontDecoration?.includes("italic")?"italic":"normal",textDecorationLine:t?.text?.fontDecoration?.includes("underline")?"underline":"none",textAlign:"center"},children:Oe(e)})})}),No=Yr;import{jsx as Ve,jsxs as Gr}from"react/jsx-runtime";var Qr=({config:t,onPress:e,style:o,ignoreSizeAndMargin:i=!1})=>{if(!t||!t.enabled)return null;let{size:n=18,margin:r,color:s,image:a,selectedStyle:c}=t,u=i?40:n,x={marginTop:i?0:r?.top??0,marginBottom:i?0:r?.bottom??0,marginLeft:i?0:r?.left??0,marginRight:i?0:r?.right??0,width:u,height:u,backgroundColor:s?.fill||"transparent",borderColor:s?.stroke||"transparent",borderWidth:u*.05,borderRadius:"50%",justifyContent:"center",alignItems:"center",zIndex:1e6,position:"absolute",display:"flex",padding:0,cursor:"pointer",outline:"none",borderStyle:s?.stroke?"solid":"none",...o},m=()=>{let g=s?.cross||"#ffffff";return Gr("svg",{viewBox:"0 0 24 24",width:"70%",height:"70%","aria-hidden":!0,children:[Ve("line",{x1:"6",y1:"6",x2:"18",y2:"18",stroke:g,strokeWidth:"2.2",strokeLinecap:"round"}),Ve("line",{x1:"18",y1:"6",x2:"6",y2:"18",stroke:g,strokeWidth:"2.2",strokeLinecap:"round"})]})};return Ve("button",{onClick:e,style:x,title:c||"",children:a&&a.trim()!==""?Ve("img",{src:a,style:{width:u,height:u,objectFit:"contain"},alt:"close"}):m()})},Lt=Qr;import{jsx as Mt,jsxs as yi}from"react/jsx-runtime";var qo=({config:t,onPress:e,ignoreSizeAndMargin:o=!1,enabled:i,style:n,type:r})=>{if(!t||!i)return null;let{size:s=18,margin:a,color:c,image:u,selectedStyle:x}=t,m=o?40:s,g=o?0:a?.top??0,v=o?0:a?.bottom??0,f=o?0:a?.left??0,b=o?0:a?.right??0,h={marginTop:g,marginBottom:v,marginLeft:f,marginRight:b,width:m,height:m,backgroundColor:c?.fill||"transparent",borderColor:c?.stroke||"transparent",borderWidth:m*.05,borderRadius:"50%",justifyContent:"center",alignItems:"center",zIndex:1e6,display:"flex",...o?{}:{marginTop:t.margin?.top??0,marginRight:t.margin?.right??0,marginBottom:t.margin?.bottom??0,marginLeft:t.margin?.left??0},...n},y=()=>{let w=c?.cross||"#ffffff";return r==="mute"?yi("svg",{viewBox:"0 0 24 24",width:"70%",height:"70%","aria-hidden":!0,children:[Mt("polygon",{points:"4,10 8,10 13,6 13,18 8,14 4,14",fill:"none",stroke:w,strokeWidth:"2.2",strokeLinejoin:"round"}),Mt("line",{x1:"16",y1:"8",x2:"21",y2:"16",stroke:w,strokeWidth:"2.2",strokeLinecap:"round"}),Mt("line",{x1:"21",y1:"8",x2:"16",y2:"16",stroke:w,strokeWidth:"2.2",strokeLinecap:"round"})]}):yi("svg",{viewBox:"0 0 24 24",width:"70%",height:"70%","aria-hidden":!0,children:[Mt("polygon",{points:"4,10 8,10 13,6 13,18 8,14 4,14",fill:"none",stroke:w,strokeWidth:"2.2",strokeLinejoin:"round"}),Mt("path",{d:"M16 10 Q18 12 16 14",fill:"none",stroke:w,strokeWidth:"2.2",strokeLinecap:"round"}),Mt("path",{d:"M18 8 Q22 12 18 16",fill:"none",stroke:w,strokeWidth:"2.2",strokeLinecap:"round"})]})};return Mt("button",{onClick:e,style:{...h,border:h.borderColor?`${h.borderWidth}px solid ${h.borderColor}`:"none",padding:0,cursor:"pointer",outline:"none"},title:x||"",children:u&&u.trim()!==""?Mt("img",{src:u,style:{width:m,height:m,objectFit:"contain"},alt:r}):y()})};import{jsx as Vt,jsxs as Xr}from"react/jsx-runtime";var Jr=({config:t,onPress:e,ignoreSizeAndMargin:o=!1,style:i})=>{if(!t||t.enabled===!1)return null;let{size:n=18,margin:r,color:s,image:a,selectedStyle:c}=t,u=o?40:n,x={marginTop:o?0:r?.top??0,marginBottom:o?0:r?.bottom??0,marginLeft:o?0:r?.left??0,marginRight:o?0:r?.right??0,width:u,height:u,backgroundColor:s?.fill||"transparent",borderColor:s?.stroke||"transparent",borderWidth:u*.05,borderRadius:"50%",justifyContent:"center",alignItems:"center",zIndex:1e6,position:"absolute",display:"flex",padding:0,cursor:"pointer",outline:"none",borderStyle:s?.stroke?"solid":"none",...i},m=()=>{let g=s?.cross||"#ffffff";return Xr("svg",{viewBox:"0 0 24 24",width:"60%",height:"60%",fill:"none",stroke:g,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[Vt("circle",{cx:"18",cy:"5",r:"3"}),Vt("circle",{cx:"6",cy:"12",r:"3"}),Vt("circle",{cx:"18",cy:"19",r:"3"}),Vt("line",{x1:"8.59",y1:"13.51",x2:"15.42",y2:"17.49"}),Vt("line",{x1:"15.41",y1:"6.51",x2:"8.59",y2:"10.49"})]})};return Vt("button",{onClick:e,style:x,title:c||"",children:a&&a.trim()!==""?Vt("img",{src:a,style:{width:u,height:u,objectFit:"contain"},alt:"share"}):m()})},hi=Jr;import{Fragment as Zr,jsx as W,jsxs as it}from"react/jsx-runtime";var be=.63,Ho=420,Dt=580,Vo="cubic-bezier(0.65, 0, 0.35, 1)",Yo="cubic-bezier(0.45, 0, 0.25, 1)";function Kr(t,e){let o=Ho+e*be+27;switch(t){case"center":return{transform:"translateX(0px) scale(1)",opacity:1,zIndex:10,pointerEvents:"auto",boxShadow:"0 32px 64px -12px rgba(0,0,0,0.9)",filter:"brightness(1)"};case"left":return{transform:`translateX(-${Ho}px) scale(${be})`,opacity:1,filter:"brightness(0.55)",zIndex:5,pointerEvents:"auto",boxShadow:"0 8px 24px rgba(0,0,0,0.5)"};case"right":return{transform:`translateX(${Ho}px) scale(${be})`,opacity:1,filter:"brightness(0.55)",zIndex:5,pointerEvents:"auto",boxShadow:"0 8px 24px rgba(0,0,0,0.5)"};case"far-left":return{transform:`translateX(-${o}px) scale(${be})`,opacity:1,filter:"brightness(0.3)",zIndex:2,pointerEvents:"none"};case"far-right":return{transform:`translateX(${o}px) scale(${be})`,opacity:1,filter:"brightness(0.3)",zIndex:2,pointerEvents:"none"};default:return{opacity:0,zIndex:1,pointerEvents:"none",transform:"translateX(0px) scale(1)",filter:"brightness(1)"}}}var xi=({src:t,isActive:e,isAnimating:o,isMuted:i,onLoadedData:n,activeVideoRef:r})=>{let s=bi.useRef(null);return bi.useEffect(()=>{e&&!o?(r.current=s.current,s.current?.play().catch(()=>{}),s.current&&s.current.readyState>=2&&n?.()):(s.current?.pause(),r.current===s.current&&(r.current=null))},[e,o,t,r]),W("video",{ref:s,src:t,playsInline:!0,muted:i,onLoadedData:e&&!o?n:void 0,style:{width:"100%",height:"100%",objectFit:"cover"}})},Si=({stories:t,activeStoryIndex:e,dataId:o,viewedStories:i,setViewedStories:n,onNextStory:r,onPrevStory:s,onClose:a})=>{let[c,u]=St(0),[x,m]=St(0),[g,v]=St(!1),[f,b]=St(!1),[h,y]=St(!1),[w,I]=St(!1),[z,R]=St(null),[d,T]=St(typeof window<"u"?window.innerWidth>=1024:!1),[l,p]=St(!1),[M,B]=St(null),[L,C]=St(null),[S,_]=St(null);he(()=>{let A=()=>{T(window.innerWidth>=1024)};return window.addEventListener("resize",A),()=>window.removeEventListener("resize",A)},[]);let E=Uo(null),$=Uo(null),D=Uo(0),k=t[e],P=k?.slides[c],O=P?.styling,G=O?.editorSource||O?.meta?.editorSource,ut=G==="studio"||G==="editor",j=ut?O?.background?.media?.mediaUrl:P?.image,X=ut?P?.content?.button_text:P?.button_text,J=ut?P?.content?.link:P?.link,V=P?.video||(ut?P?.content?.video?.[0]?.link:void 0),et=P?.content?.canva,q=et&&et.width&&et.height?et.width/et.height:400/700,Q=700,Y=Math.round(Q*q),lt=async()=>{let A={title:k.name,text:`Check out this story: ${k.name}`,url:window.location.href};if(P?.id&&H("shared",o,{story_slide:P.id}),navigator.share)try{await navigator.share(A)}catch{}else if(navigator.clipboard)try{await navigator.clipboard.writeText(window.location.href),R("Story link copied to clipboard!"),setTimeout(()=>R(null),2500)}catch{}};if(he(()=>{u(0),m(0),b(!1),y(!1),p(!1),B(null),C(null),_(null)},[e]),he(()=>{let A=N=>{if(!(document.activeElement?.tagName==="INPUT"||document.activeElement?.tagName==="TEXTAREA"))switch(N.key){case"ArrowRight":nt();break;case"ArrowLeft":Ct();break;case" ":N.preventDefault(),y(st=>!st);break;case"Escape":a();break;case"s":case"S":N.preventDefault(),lt();break}};return window.addEventListener("keydown",A),()=>window.removeEventListener("keydown",A)},[c,e,h,k,a]),he(()=>{k&&P&&H("viewed",o,{story_slide:P.id})},[c,k?.id,o]),he(()=>{if(k&&P){let A=k.styling?.slideShowTime||5,N=!!V;if(E.current&&clearInterval(E.current),h){$.current&&$.current.pause();return}else $.current&&$.current.play().catch(()=>{});return N&&!f||l?void 0:(E.current=setInterval(()=>{m(st=>st>=100?(nt(),100):st+100/(A*10))},100),()=>{E.current&&clearInterval(E.current)})}},[e,c,h,f,l]),!P)return null;let mt=(A,N)=>{l||(_(A),B(c),C(N),p(!0),setTimeout(()=>{u(N),m(0),b(!1),p(!1),B(null),C(null),_(null)},Dt+20))},nt=()=>{if(!l)if(c<k.slides.length-1)mt("next",c+1);else{if(!i.includes(k.id)){let A=[...i,k.id];n(A),localStorage.setItem("app_storys_viewed_stories",JSON.stringify(A))}r()}},Ct=()=>{l||(c>0?mt("prev",c-1):s())},gt=()=>{D.current=Date.now(),y(!0)},vt=A=>{y(!1),Date.now()-D.current<300&&(A==="next"?nt():Ct())},jt=()=>b(!0),sn=A=>{let N=A?.styling,st=N?.editorSource||N?.meta?.editorSource,ft=st==="studio"||st==="editor"?A.content?.link:A.link;ft&&(H("clicked",o,{story_slide:A.id}),ft.startsWith("http")?window.open(ft,"_blank"):window.location.href=ft)},an=A=>{A.stopPropagation(),v(!g)},ln=k?.styling?.crossButton,dn=k?.styling?.soundToggle,js=P?.styling?.cta,cn=A=>l?S==="next"?A===M?"left":A===L?"center":A===(M??0)-1?"far-left":A===(M??0)-2?"hidden":A===(L??0)+1?"right":A===(L??0)+2?"far-right":"hidden":A===M?"right":A===L?"center":A===(M??0)+1?"far-right":A===(M??0)+2?"hidden":A===(L??0)-1?"left":A===(L??0)-2?"far-left":"hidden":A===c?"center":A===c-1?"left":A===c-2?"far-left":A===c+1?"right":A===c+2?"far-right":"hidden",Ni=d?{position:"fixed",top:0,left:0,width:"100vw",height:"100vh",background:"radial-gradient(circle at center, #0B1424 0%, #03070E 100%)",zIndex:1e5,display:"flex",flexDirection:"column",alignItems:"center",overflow:"hidden",color:"white"}:{position:"fixed",top:0,left:0,width:"100vw",height:"100vh",backgroundColor:"rgba(0,0,0,0.95)",zIndex:1e5,display:"flex",justifyContent:"center",alignItems:"center"},pn=d?{position:"absolute",width:`${Y}px`,height:`${Q}px`,backgroundColor:"#000",borderRadius:"20px",overflow:"hidden",display:"flex",flexDirection:"column",boxShadow:"0 25px 50px -12px rgba(0, 0, 0, 0.8)",border:"1px solid rgba(255, 255, 255, 0.1)"}:{position:"relative",width:"100%",maxWidth:"450px",height:"100%",maxHeight:"850px",backgroundColor:"#000",borderRadius:"0px",overflow:"hidden",display:"flex",flexDirection:"column"},Ns={width:"240px",height:"420px",backgroundColor:"#000",borderRadius:"16px",overflow:"hidden",opacity:1,filter:"brightness(0.6)",display:"flex",flexDirection:"column",boxShadow:"0 10px 20px rgba(0,0,0,0.5)",border:"1px solid rgba(255, 255, 255, 0.05)",transform:"scale(0.9)",transition:"all 0.3s ease",cursor:"pointer"},qi=k.slides.reduce((A,N,st)=>(cn(st)!=="hidden"&&A.push(st),A),[]),Gt=new Set(qi);return Gt.add(c),c>0&&Gt.add(c-1),c>1&&Gt.add(c-2),c<k.slides.length-1&&Gt.add(c+1),c<k.slides.length-2&&Gt.add(c+2),it("div",{style:Ni,onClick:()=>!d&&nt(),children:[it("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:0,overflow:"hidden",pointerEvents:"none",transition:"all 0.6s ease-in-out"},children:[V?W("video",{src:V,style:{width:"100%",height:"100%",objectFit:"cover",filter:"blur(120px) saturate(1.8) opacity(0.35)"},muted:!0}):W(zt,{src:j||k.thumbnail,style:{width:"100%",height:"100%",filter:"blur(120px) saturate(1.8) opacity(0.35)"}}),W("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,background:"rgba(5, 5, 8, 0.4)"}})]},`${e}-${l?L:c}`),d&&it("div",{style:{width:"100%",display:"flex",flexDirection:"column",paddingTop:"20px",zIndex:10},children:[W("div",{style:{width:"100%",display:"flex",gap:"8px",padding:"0 20px",boxSizing:"border-box"},children:k.slides.map((A,N)=>{let st=l&&L!==null?L:c,Rt="0%";return N<st?Rt="100%":N===st&&(Rt=`${x}%`),W("div",{style:{flex:1,height:"3px",backgroundColor:"rgba(255,255,255,0.15)",borderRadius:"2px",overflow:"hidden"},children:W("div",{style:{width:Rt,height:"100%",backgroundColor:"white",transition:N===st?"width 0.1s linear":"none"}})},N)})}),it("div",{style:{width:"100%",maxWidth:"1400px",margin:"0 auto",display:"grid",gridTemplateColumns:`minmax(0, 1fr) ${Y}px minmax(0, 1fr)`,gap:"12px",alignItems:"center",marginTop:"16px",padding:"0 20px",boxSizing:"border-box",zIndex:w?2e3:10},children:[W("div",{style:{paddingLeft:"0px"}}),it("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%"},children:[it("div",{style:{display:"flex",alignItems:"center",gap:"12px"},children:[W(zt,{src:k.thumbnail,alt:k.name,style:{width:"44px",height:"44px",borderRadius:"50%",border:"2px solid white",margin:0}}),W("span",{style:{color:"white",fontWeight:"bold",fontSize:"16px",whiteSpace:"nowrap"},children:k.name})]}),it("div",{style:{display:"flex",gap:"8px"},children:[W(hi,{config:{enabled:k?.styling?.share?.enabled??!0,image:k?.styling?.share?.image??"",color:{cross:k?.styling?.share?.color?.cross??"#ffffff",fill:k?.styling?.share?.color?.fill??"rgba(255,255,255,0.08)",stroke:k?.styling?.share?.color?.stroke??"transparent"},margin:{top:0,bottom:0,left:0,right:0},size:k?.styling?.share?.size??44},onPress:lt,style:{position:"relative",borderRadius:"12px"}}),W(qo,{config:{size:44,color:{cross:"#ffffff",fill:"rgba(255,255,255,0.08)",stroke:"transparent"},margin:{top:0,bottom:0,left:0,right:0},image:""},onPress:an,type:g?"mute":"unmute",enabled:!!dn?.enabled&&!!V,style:{position:"relative",borderRadius:"12px"}}),W(mi,{isPaused:h,onPress:()=>y(!h),size:44,style:{borderRadius:"12px"}})]})]}),it("div",{style:{display:"flex",gap:"10px",flex:1,justifyContent:"flex-end",paddingRight:"0px"},children:[it("div",{style:{position:"relative"},children:[W("button",{onClick:()=>{I(!w),y(!w)},style:{width:"44px",height:"44px",background:w?"rgba(255,255,255,0.15)":"rgba(255,255,255,0.08)",border:w?"1px solid white":"1px solid rgba(255,255,255,0.1)",display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"12px",cursor:"pointer",transition:"all 0.2s",padding:0,outline:"none"},children:it("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[W("rect",{x:"3",y:"3",width:"7",height:"7"}),W("rect",{x:"14",y:"3",width:"7",height:"7"}),W("rect",{x:"14",y:"14",width:"7",height:"7"}),W("rect",{x:"3",y:"14",width:"7",height:"7"})]})}),w&&it(Zr,{children:[W("style",{children:`
119
+ `}),H.map(r=>!r||typeof r!="object"||!(r.type||"").toLowerCase()?null:Br(kr,{data:r,onInteraction:e,isEditing:o},r.id))]})};import{useState as ga}from"react";import{jsx as So,jsxs as ma}from"react/jsx-runtime";var fa=({isPaused:t,onPress:e,style:o,size:n=36})=>{let[i,s]=ga(!1);return So("button",{onClick:e,onMouseEnter:()=>s(!0),onMouseLeave:()=>s(!1),style:{width:`${n}px`,height:`${n}px`,background:i?"rgba(255, 255, 255, 0.15)":"rgba(255, 255, 255, 0.08)",border:i?"1px solid white":"1px solid rgba(255, 255, 255, 0.1)",display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"10px",cursor:"pointer",transition:"all 0.2s ease",padding:0,outline:"none",...o},children:t?So("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"white",children:So("path",{d:"M5 3.867v16.266c0 .54.58.88 1.05.61l14.133-8.133c.46-.27.46-.94 0-1.21L6.05 3.257C5.58 2.987 5 3.327 5 3.867z"})}):ma("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"white",children:[So("rect",{x:"6",y:"4",width:"4",height:"16",rx:"1"}),So("rect",{x:"14",y:"4",width:"4",height:"16",rx:"1"})]})})},Lr=fa;import{jsx as Qn}from"react/jsx-runtime";var ya=t=>{switch(t){case"left":return"flex-start";case"right":return"flex-end";default:return"center"}},ha=({cta:t,buttonText:e,onPress:o})=>!t||!e||e.trim()===""?null:Qn("div",{style:{position:"absolute",bottom:t?.margin?.bottom,left:t?.margin?.left,right:t?.margin?.right,display:"flex",justifyContent:ya(t?.container?.alignment),width:"100%",pointerEvents:"none",boxSizing:"border-box",zIndex:10},children:Qn("button",{style:{backgroundColor:t?.container?.backgroundColor||"#F7921C",borderColor:t?.container?.borderColor||"transparent",borderWidth:t?.container?.borderWidth??0,borderStyle:t?.container?.borderWidth?"solid":"none",borderTopRightRadius:t?.cornerRadius?.topRight,borderTopLeftRadius:t?.cornerRadius?.topLeft,borderBottomRightRadius:t?.cornerRadius?.bottomRight,borderBottomLeftRadius:t?.cornerRadius?.bottomLeft,height:t?.container?.height||42,width:t?.container?.ctaFullWidth?"100%":t?.container?.ctaWidth||"auto",justifyContent:"center",alignItems:"center",display:"flex",cursor:"pointer",outline:"none",pointerEvents:"auto",padding:"0 12px",boxSizing:"border-box"},onClick:o,children:Qn("span",{style:{color:t?.text?.color||"#ffffff",fontSize:t?.text?.fontSize||14,fontFamily:st(t?.text?.fontFamily),fontWeight:t?.text?.fontDecoration?.includes("bold")?"bold":"normal",fontStyle:t?.text?.fontDecoration?.includes("italic")?"italic":"normal",textDecorationLine:t?.text?.fontDecoration?.includes("underline")?"underline":"none",textAlign:"center"},children:Ce(e)})})}),Xn=ha;import{jsx as _e,jsxs as xa}from"react/jsx-runtime";var ba=({config:t,onPress:e,ignoreSizeAndMargin:o=!1,style:n})=>{if(!t||t.enabled===!1)return null;let{size:i=18,margin:s,color:l,image:c,selectedStyle:d}=t,S=o?40:i,p={marginTop:o?0:s?.top??0,marginBottom:o?0:s?.bottom??0,marginLeft:o?0:s?.left??0,marginRight:o?0:s?.right??0,width:S,height:S,backgroundColor:l?.fill||"transparent",borderColor:l?.stroke||"transparent",borderWidth:S*.05,borderRadius:"50%",justifyContent:"center",alignItems:"center",zIndex:1e6,position:"relative",display:"flex",padding:0,cursor:"pointer",outline:"none",borderStyle:l?.stroke?"solid":"none",...n},y=()=>{let u=l?.cross||"#ffffff";return xa("svg",{viewBox:"0 0 24 24",width:"60%",height:"60%",fill:"none",stroke:u,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[_e("circle",{cx:"18",cy:"5",r:"3"}),_e("circle",{cx:"6",cy:"12",r:"3"}),_e("circle",{cx:"18",cy:"19",r:"3"}),_e("line",{x1:"8.59",y1:"13.51",x2:"15.42",y2:"17.49"}),_e("line",{x1:"15.41",y1:"6.51",x2:"8.59",y2:"10.49"})]})};return _e("button",{onClick:e,style:p,children:c&&c.trim()!==""?_e("img",{src:c,style:{width:S,height:S,objectFit:"contain"},alt:"share"}):y()})},Jn=ba;import{Fragment as Ra,jsx as Q,jsxs as Rt}from"react/jsx-runtime";var Zo=t=>{if(t)return t.content?.canva||t.canva||t.styling?.canva||t.meta?.canva||t.content?.styling?.canva||t.content?.meta?.canva},Sa=t=>{let e=Zo(t),o=Number(e?.width),n=Number(e?.height);return o>0&&n>0?o/n:9/16},vo=.63;var xe=580,Kn="cubic-bezier(0.65, 0, 0.35, 1)",Zn="cubic-bezier(0.45, 0, 0.25, 1)";function Ca(t,e){let o=Math.round(e*1.08),n=o+Math.round(e*vo)+20;switch(t){case"center":return{transform:"translateX(0px) scale(1)",opacity:1,zIndex:10,pointerEvents:"auto",boxShadow:"0 32px 64px -12px rgba(0,0,0,0.9)",filter:"brightness(1)"};case"left":return{transform:`translateX(-${o}px) scale(${vo})`,opacity:1,filter:"brightness(0.55)",zIndex:5,pointerEvents:"auto",boxShadow:"0 8px 24px rgba(0,0,0,0.5)"};case"right":return{transform:`translateX(${o}px) scale(${vo})`,opacity:1,filter:"brightness(0.55)",zIndex:5,pointerEvents:"auto",boxShadow:"0 8px 24px rgba(0,0,0,0.5)"};case"far-left":return{transform:`translateX(-${n}px) scale(${vo})`,opacity:1,filter:"brightness(0.3)",zIndex:2,pointerEvents:"none"};case"far-right":return{transform:`translateX(${n}px) scale(${vo})`,opacity:1,filter:"brightness(0.3)",zIndex:2,pointerEvents:"none"};default:return{opacity:0,zIndex:1,pointerEvents:"none",transform:"translateX(0px) scale(1)",filter:"brightness(1)"}}}var Ar=({src:t,isActive:e,isAnimating:o,isMuted:n,onLoadedData:i,activeVideoRef:s,objectFit:l="cover",objectPosition:c="center center"})=>{let d=Er.useRef(null);return Er.useEffect(()=>{e&&!o?(s.current=d.current,d.current?.play().catch(()=>{}),d.current&&d.current.readyState>=1&&i?.()):(d.current?.pause(),s.current===d.current&&(s.current=null))},[e,o,t,s,i]),Q("video",{ref:d,src:t,playsInline:!0,muted:n,onLoadedData:i,onCanPlay:i,onLoadedMetadata:i,style:{width:"100%",height:"100%",objectFit:l,objectPosition:c}})},Mr="appstorys_viewed_slide_ids",ti="appstorys_clicked_interaction_ids";var va=t=>{try{let e=localStorage.getItem(Mr),o=e?JSON.parse(e):[];Array.isArray(o)&&!o.includes(t)&&(o.push(t),localStorage.setItem(Mr,JSON.stringify(o)))}catch{}},wa=t=>{try{let e=localStorage.getItem(ti);if(!e)return!1;let o=JSON.parse(e);return Array.isArray(o)&&o.includes(t)}catch{return!1}},ka=t=>{try{let e=localStorage.getItem(ti),o=e?JSON.parse(e):[];Array.isArray(o)&&!o.includes(t)&&(o.push(t),localStorage.setItem(ti,JSON.stringify(o)))}catch{}},Pr=({stories:t,activeStoryIndex:e,dataId:o,viewedStories:n,setViewedStories:i,onNextStory:s,onPrevStory:l,onClose:c})=>{let d=t[e],S=F=>{if(!F?.id)return 0;try{let j=`appstorys_cta_redirect_${F.id}`,pt=sessionStorage.getItem(j);if(pt){let Mt=JSON.parse(pt),vt=Date.now()-(Mt.timestamp||0),ye=F.slides?.length||1;if(sessionStorage.removeItem(j),vt<=300*1e3&&typeof Mt.slideIndex=="number"&&Mt.slideIndex>=0&&Mt.slideIndex<ye)return Mt.slideIndex}}catch{}return 0},[p,y]=Ot(()=>S(t[e])),[u,C]=Ot(0),[h,g]=Ot(t[e]?.styling?.soundToggle?.defaultSound==="no"),[b,m]=Ot(!1),[E,O]=Ot(!1),[D,L]=Ot(!1),[v,w]=Ot(null),[_,$]=Ot({width:typeof window<"u"?window.innerWidth:1280,height:typeof window<"u"?window.innerHeight:800}),[V,A]=Ot(typeof window<"u"?window.innerWidth>=1024:!1),[T,k]=Ot(!1),[B,W]=Ot(null),[H,Y]=Ot(null),[r,M]=Ot(null),[a,f]=Ot(!1),[x,z]=Ot("none"),[U,et]=Ot(null),X=Co(null),q=Co(null),J=Co(0),nt=Co(null),ht=Co(!1),dt=d?.slides[p],K=dt?.styling,it=K?.editorSource||K?.meta?.editorSource,lt=it==="studio"||it==="editor",mt=lt?K?.background?.media?.mediaUrl:dt?.image,gt=lt?dt?.content?.button_text:dt?.button_text,R=lt?dt?.content?.link:dt?.link,I=F=>{if(!F)return;if(F.video&&typeof F.video=="string")return F.video;let j=F.styling?.background?.media||F.content?.styling?.background?.media||F.content?.background?.media;if(j&&(j.mediaType==="video"||j.type==="video"||j.isVideo))return j.mediaUrl||j.url||j.link},N=I(dt),Z=Zo(dt),xt=Sa(dt),Ft=V?160:80,kt=Math.max(350,_.height-Ft),Wt=V?_.width*.75:_.width*.95,Bt=Math.min(kt,Wt/xt),Ht=Math.round(V?Math.max(450,Math.min(Bt,850)):Math.min(kt,850)),Tt=Math.round(Ht*xt),Kt=(F,j)=>{T||(C(0),M(F),W(p),Y(j),k(!0),setTimeout(()=>{y(j),C(0),m(!1),k(!1),W(null),Y(null),M(null)},xe+20))},ne=F=>{if(!(a||T)){if(C(0),F==="next"){if(e>=t.length-1){s();return}}else if(e<=0){l();return}f(!0),et(F),z("out"),setTimeout(()=>{F==="next"?s():l(),z("prepare-in"),setTimeout(()=>{z("in"),setTimeout(()=>{f(!1),z("none"),et(null)},320)},35)},280)}},ge=()=>{if(!(T||a))if(p<(d?.slides?.length||0)-1)Kt("next",p+1);else{if(d&&!n.includes(d.id)){let F=[...n,d.id];i(F),localStorage.setItem("app_storys_viewed_stories",JSON.stringify(F))}ne("next")}},so=()=>{T||a||(p>0?Kt("prev",p-1):ne("prev"))},Lo=async()=>{if(!d)return;let F={title:d.name,text:`Check out this story: ${d.name}`,url:window.location.href};if(dt?.id&&rt("shared",o,{story_slide:dt.id}),navigator.share)try{await navigator.share(F)}catch{}else if(navigator.clipboard)try{await navigator.clipboard.writeText(window.location.href),w("Story link copied to clipboard!"),setTimeout(()=>w(null),2500)}catch{}};if(Re(()=>{let F=()=>{$({width:window.innerWidth,height:window.innerHeight}),A(window.innerWidth>=1024)};return window.addEventListener("resize",F),()=>window.removeEventListener("resize",F)},[]),Re(()=>{let F=document.body.style.overflow,j=document.body.style.touchAction;return document.body.style.overflow="hidden",document.body.style.touchAction="none",()=>{document.body.style.overflow=F,document.body.style.touchAction=j}},[]),Re(()=>{let F=S(d);y(F),C(0),m(!1),O(!1),k(!1),f(!1),z("none"),et(null),W(null),Y(null),M(null),g(d?.styling?.soundToggle?.defaultSound==="no")},[e]),Re(()=>{let F=()=>{document.hidden?(ht.current=E,O(!0),q.current&&q.current.pause()):ht.current||(O(!1),q.current&&q.current.play().catch(()=>{}))};return document.addEventListener("visibilitychange",F),()=>document.removeEventListener("visibilitychange",F)},[E]),Re(()=>{let F=j=>{if(!(document.activeElement?.tagName==="INPUT"||document.activeElement?.tagName==="TEXTAREA"))switch(j.key){case"ArrowRight":ge();break;case"ArrowLeft":so();break;case" ":j.preventDefault(),O(pt=>!pt);break;case"Escape":c();break;case"s":case"S":j.preventDefault(),Lo();break}};return window.addEventListener("keydown",F),()=>window.removeEventListener("keydown",F)},[p,e,E,d,c]),Re(()=>{if(d&&dt){let F=dt.id?String(dt.id):`${d.id||o}_slide_${p}`,j=`${e}_${p}_${F}`;nt.current!==j&&(nt.current=j,va(F),rt("viewed",o,{story_slide:F}))}},[e,p,d?.id,o,dt?.id]),Re(()=>{if(d&&dt&&!!N&&!b){let j=setTimeout(()=>{m(!0)},2e3);return()=>clearTimeout(j)}},[e,p,N,b]),Re(()=>{if(d&&dt){let F=d.styling?.slideShowTime||5,j=!!N;if(X.current&&clearInterval(X.current),E){q.current&&q.current.pause();return}else q.current&&q.current.play().catch(()=>{});return j&&!b||T||a?void 0:(X.current=setInterval(()=>{C(pt=>pt>=100?(ge(),100):pt+100/(F*10))},100),()=>{X.current&&clearInterval(X.current)})}},[e,p,E,b,T,a,N]),!dt)return null;let ao=()=>x==="out"?{transform:`translateX(${U==="next"?-120:120}px) scale(0.92)`,opacity:0,filter:"blur(6px)",transition:"transform 280ms cubic-bezier(0.4, 0, 0.2, 1), opacity 280ms cubic-bezier(0.4, 0, 0.2, 1), filter 280ms cubic-bezier(0.4, 0, 0.2, 1)",willChange:"transform, opacity, filter"}:x==="prepare-in"?{transform:`translateX(${U==="next"?120:-120}px) scale(0.92)`,opacity:0,filter:"blur(6px)",transition:"none",willChange:"transform, opacity, filter"}:x==="in"?{transform:"translateX(0px) scale(1)",opacity:1,filter:"blur(0px)",transition:"transform 320ms cubic-bezier(0.16, 1, 0.3, 1), opacity 320ms cubic-bezier(0.16, 1, 0.3, 1), filter 320ms cubic-bezier(0.16, 1, 0.3, 1)",willChange:"transform, opacity, filter"}:{transition:"transform 320ms cubic-bezier(0.16, 1, 0.3, 1), opacity 320ms cubic-bezier(0.16, 1, 0.3, 1), filter 320ms cubic-bezier(0.16, 1, 0.3, 1)"},Qt=()=>{J.current=Date.now(),O(!0)},ie=F=>{O(!1),Date.now()-J.current<300&&(F==="next"?ge():so())},fe=()=>m(!0),me=()=>{if(d?.id)try{sessionStorage.setItem(`appstorys_cta_redirect_${d.id}`,JSON.stringify({slideIndex:p,timestamp:Date.now()}))}catch{}},G=F=>{let j=F?.styling,pt=j?.editorSource||j?.meta?.editorSource,vt=pt==="studio"||pt==="editor"?F.content?.link:F.link;vt&&(me(),rt("clicked",o,{story_slide:F.id}),vt.startsWith("http")?window.open(vt,"_blank"):window.location.href=vt)},ut=async(F,j)=>{let{type:pt,questionId:Mt,pollId:vt,quizId:ye,ratingId:Zt,reactionId:Ne,productId:Be,optionId:lo,value:Xt,stickerId:Le,redirectUrl:se,code:Ee}=F;if(pt==="cta"){se&&(me(),rt("clicked",o,{story_slide:j.id,cta_id:Le}),se.startsWith("http")?window.open(se,"_blank"):window.location.href=se);return}O(!0);let te=pt||"interaction";te==="quizz"&&(te="quiz"),(te==="image"||pt?.startsWith("image_quiz"))&&(te="quiz"),pt?.startsWith("promo")&&(te="promo_code");let qt=Le||Mt||vt||ye||Zt||Ne||Be||j.id;if(wa(qt))return;ka(qt);let Ae=lo||F.selected_option||F.emoji||Xt||Ee||"",co=P.getState().userId||"anonymous",yn=tr(),ae=await Et(),mi={interaction_type:te,interaction_id:qt,story_slide:j.id,selected_option:String(Ae)};Xt!=null&&Xt!==""&&(mi.value=String(Xt)),fetch(`${yn}/capture-event`,{method:"POST",headers:{"Content-Type":"application/json",...ae?{Authorization:`Bearer ${ae}`}:{}},body:JSON.stringify({user_id:co,campaign_id:o,event:"clicked",metadata:mi})}).catch(as=>console.error("AppStorys: Instant Tracking Failed",as))},zt=F=>{F.stopPropagation(),g(!h)},Vt=d?.styling?.crossButton,ct=d?.styling?.soundToggle,re=dt?.styling?.cta,$e=F=>T?r==="next"?F===B?"left":F===H?"center":F===(B??0)-1?"far-left":F===(B??0)-2?"hidden":F===(H??0)+1?"right":F===(H??0)+2?"far-right":"hidden":F===B?"right":F===H?"center":F===(B??0)+1?"far-right":F===(B??0)+2?"hidden":F===(H??0)-1?"left":F===(H??0)-2?"far-left":"hidden":F===p?"center":F===p-1?"left":F===p-2?"far-left":F===p+1?"right":F===p+2?"far-right":"hidden",Ie=V?{position:"fixed",top:0,left:0,width:"100vw",height:"100vh",background:"radial-gradient(circle at center, #0B1424 0%, #03070E 100%)",zIndex:1e5,display:"flex",flexDirection:"column",alignItems:"center",overflow:"hidden",color:"white"}:{position:"fixed",top:0,left:0,width:"100vw",height:"100dvh",backgroundColor:"#000000",zIndex:1e5,display:"flex",justifyContent:"center",alignItems:"center",overflow:"hidden",touchAction:"none"},_t=V?{position:"absolute",width:`${Tt}px`,height:`${Ht}px`,backgroundColor:"#000",borderRadius:"20px",overflow:"hidden",display:"flex",flexDirection:"column",boxShadow:"0 25px 50px -12px rgba(0, 0, 0, 0.8)",border:"1px solid rgba(255, 255, 255, 0.1)"}:{position:"relative",width:`min(100vw, calc(100dvh * ${xt}))`,height:`min(100dvh, calc(100vw / ${xt}))`,aspectRatio:`${xt}`,backgroundColor:"#000",borderRadius:"0px",overflow:"hidden",display:"flex",flexDirection:"column"},$t={width:"240px",height:"420px",backgroundColor:"#000",borderRadius:"16px",overflow:"hidden",opacity:1,filter:"brightness(0.6)",display:"flex",flexDirection:"column",boxShadow:"0 10px 20px rgba(0,0,0,0.5)",border:"1px solid rgba(255, 255, 255, 0.05)",transform:"scale(0.9)",transition:"all 0.3s ease",cursor:"pointer"},jt=d.slides.reduce((F,j,pt)=>($e(pt)!=="hidden"&&F.push(pt),F),[]),Lt=new Set(jt);return Lt.add(p),p>0&&Lt.add(p-1),p>1&&Lt.add(p-2),p<d.slides.length-1&&Lt.add(p+1),p<d.slides.length-2&&Lt.add(p+2),Rt("div",{style:Ie,onClick:()=>!V&&ge(),children:[Rt("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:0,overflow:"hidden",pointerEvents:"none",transition:"all 0.6s ease-in-out"},children:[N?Q("video",{src:N,style:{width:"100%",height:"100%",objectFit:"cover",filter:"blur(120px) saturate(1.8) opacity(0.35)"},muted:!0}):mt||!lt&&d.thumbnail?Q(de,{src:mt||d.thumbnail,style:{width:"100%",height:"100%",filter:"blur(120px) saturate(1.8) opacity(0.35)"}}):null,Q("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,background:"rgba(5, 5, 8, 0.4)"}})]},`${e}-${T?H:p}`),V&&Rt("div",{style:{width:"100%",display:"flex",flexDirection:"column",paddingTop:"20px",zIndex:10,...ao()},children:[Q("div",{style:{width:"100%",display:"flex",gap:"8px",padding:"0 20px",boxSizing:"border-box"},children:d.slides.map((F,j)=>{let pt=T&&H!==null?H:p,Mt="0%";return j<pt?Mt="100%":j===pt&&(Mt=`${u}%`),Q("div",{style:{flex:1,height:"3px",backgroundColor:"rgba(255,255,255,0.15)",borderRadius:"2px",overflow:"hidden"},children:Q("div",{style:{width:Mt,height:"100%",backgroundColor:"white",transition:j===pt&&u>0&&!T?"width 0.1s linear":"none"}})},j)})}),Rt("div",{style:{width:"100%",margin:"0 auto",display:"grid",gridTemplateColumns:`minmax(0, 1fr) ${Tt}px minmax(0, 1fr)`,gap:"12px",alignItems:"center",marginTop:"16px",padding:"0 20px",boxSizing:"border-box",zIndex:D?2e3:10},children:[Q("div",{style:{paddingLeft:"0px"}}),Rt("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%"},children:[Rt("div",{style:{display:"flex",alignItems:"center",gap:"12px"},children:[Q(de,{src:d.thumbnail,alt:d.name,style:{width:"44px",height:"44px",borderRadius:"50%",border:"2px solid white",margin:0}}),Q("span",{style:{color:"white",fontWeight:"bold",fontSize:"16px",whiteSpace:"nowrap"},children:d.name})]}),Rt("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[Q(Jn,{config:{enabled:d?.styling?.share?.enabled??!0,image:d?.styling?.share?.image??"",color:{cross:d?.styling?.share?.color?.cross??"#ffffff",fill:d?.styling?.share?.color?.fill??"rgba(255,255,255,0.08)",stroke:d?.styling?.share?.color?.stroke??"transparent"},margin:{top:0,bottom:0,left:0,right:0},size:d?.styling?.share?.size??44},onPress:Lo,ignoreSizeAndMargin:!0,style:{position:"relative",margin:0,borderRadius:"12px",width:"44px",height:"44px"}}),Q(be,{config:{size:(h?ct?.mute?.size:ct?.unmute?.size)||44,color:{cross:(h?ct?.mute?.color?.cross:ct?.unmute?.color?.cross)||"#ffffff",fill:(h?ct?.mute?.color?.fill:ct?.unmute?.color?.fill)||"rgba(255,255,255,0.08)",stroke:(h?ct?.mute?.color?.stroke:ct?.unmute?.color?.stroke)||"transparent"},margin:{top:0,bottom:0,left:0,right:0},image:(h?ct?.mute?.image:ct?.unmute?.image)||""},onPress:zt,type:h?"mute":"unmute",enabled:!!ct?.enabled&&!!N,ignoreSizeAndMargin:!0,style:{position:"relative",margin:0,borderRadius:"12px",width:"44px",height:"44px"}}),Q(Lr,{isPaused:E,onPress:()=>O(!E),size:44,style:{borderRadius:"12px",margin:0}})]})]}),Rt("div",{style:{display:"flex",gap:"10px",flex:1,justifyContent:"flex-end",paddingRight:"0px"},children:[Rt("div",{style:{position:"relative"},children:[Q("button",{onClick:()=>{L(!D),O(!D)},style:{width:"44px",height:"44px",background:D?"rgba(255,255,255,0.15)":"rgba(255,255,255,0.08)",border:D?"1px solid white":"1px solid rgba(255,255,255,0.1)",display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"12px",cursor:"pointer",transition:"all 0.2s",padding:0,outline:"none"},children:Rt("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[Q("rect",{x:"3",y:"3",width:"7",height:"7"}),Q("rect",{x:"14",y:"3",width:"7",height:"7"}),Q("rect",{x:"14",y:"14",width:"7",height:"7"}),Q("rect",{x:"3",y:"14",width:"7",height:"7"})]})}),D&&Rt(Ra,{children:[Q("style",{children:`
73
120
  @keyframes fadeUp {
74
121
  from { opacity: 0; transform: translateY(10px) scale(0.95); }
75
122
  to { opacity: 1; transform: translateY(0) scale(1); }
76
123
  }
77
- `}),it("div",{style:{position:"absolute",top:"46px",right:0,width:"260px",background:"rgba(25, 25, 25, 0.98)",border:"1px solid rgba(255,255,255,0.08)",borderRadius:"16px",padding:"18px",boxShadow:"0 20px 25px -5px rgba(0,0,0,0.4), 0 10px 10px -5px rgba(0,0,0,0.4)",zIndex:1001,animation:"fadeUp 0.25s cubic-bezier(0.4, 0, 0.2, 1) forwards"},children:[W("div",{style:{fontSize:"11px",fontWeight:"bold",color:"#9CA3AF",letterSpacing:"1px",textTransform:"uppercase",marginBottom:"16px",paddingBottom:"10px",borderBottom:"1px solid rgba(255,255,255,0.06)"},children:"Keyboard Shortcuts"}),W("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[{key:"\u2192",label:"Next slide"},{key:"\u2190",label:"Previous slide"},{key:"space",label:"Play/Pause"},{key:"esc",label:"Close story"},{key:"S",label:"Share story link"}].map(({key:A,label:N})=>it("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[W("span",{style:{background:"rgba(255,255,255,0.08)",padding:"5px 8px",borderRadius:"5px",fontSize:"12px",color:"white",border:"1px solid rgba(255,255,255,0.1)"},children:A}),W("span",{style:{fontSize:"13px",color:"#E5E7EB",fontWeight:"500"},children:N})]},A))})]})]})]}),W(Lt,{config:{enabled:ln?.enabled??!0,image:"",color:{cross:"#ffffff",fill:"rgba(255,255,255,0.08)",stroke:"transparent"},margin:{top:0,bottom:0,left:0,right:0},size:44},onPress:a,style:{position:"relative",borderRadius:"12px"}})]})]})]}),W("div",{style:{flex:1,width:"100%",display:"flex",flexDirection:"column",justifyContent:"center",alignItems:"center",gap:"20px"},children:it("div",{style:{display:d?"grid":"flex",gridTemplateColumns:d?`minmax(0, 1fr) ${Y}px minmax(0, 1fr)`:"none",alignItems:"center",justifyContent:"center",gap:"12px",width:"100%",maxWidth:"1400px",position:"relative"},onClick:A=>d&&A.stopPropagation(),children:[d&&W("div",{style:{display:"flex",justifyContent:"flex-end",alignItems:"center",gap:"12px",width:"100%",boxSizing:"border-box"},children:(c>0||e>0)&&W("button",{onClick:Ct,style:{background:"rgba(0,0,0,0.5)",border:"none",color:"white",borderRadius:"50%",width:"40px",height:"40px",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",fontSize:"18px",backdropFilter:"blur(5px)",transition:"background 0.2s"},onMouseEnter:A=>A.currentTarget.style.background="rgba(0,0,0,0.7)",onMouseLeave:A=>A.currentTarget.style.background="rgba(0,0,0,0.5)",children:"\u2039"})}),d?W("div",{style:{width:`${Y}px`,height:`${Q}px`,position:"relative",zIndex:5,overflow:"visible"},children:Array.from(Gt).sort((A,N)=>A-N).map(A=>{let N=k.slides[A];if(!N)return null;let st=cn(A),Rt=Kr(st,Y),ft=N?.styling,ae=ft?.editorSource||ft?.meta?.editorSource,Tt=ae==="studio"||ae==="editor",Re=ft?.background?.media?.mediaUrl||N?.image,le=N?.video||(Tt?N?.content?.video?.[0]?.link:void 0),eo=Pt(ft?.background)||"#000000",de=Tt?N?.content?.button_text:N?.button_text,wt=Tt?N?.content?.link:N?.link,ce=A===c&&!l||l&&A===L,oo={display:"flex",justifyContent:"center",alignItems:"center",background:Tt?eo:"#000",position:"relative",width:"100%",height:"100%",overflow:"hidden",borderRadius:"16px"};return it("div",{style:{...pn,position:"absolute",top:0,left:0,width:`${Y}px`,height:`${Q}px`,...Rt,transition:st==="hidden"||st==="far-left"||st==="far-right"?`opacity ${Dt}ms ease, transform ${Dt}ms ease`:A===M?`transform ${Dt}ms ${Vo}, opacity ${Dt}ms ${Vo}, filter ${Dt}ms ${Vo}`:`transform ${Dt}ms ${Yo}, opacity ${Dt}ms ${Yo}, filter ${Dt}ms ${Yo}`,transformOrigin:"center center",willChange:"transform, opacity, filter"},onClick:Ft=>Ft.stopPropagation(),children:[W("div",{style:{position:"absolute",top:0,bottom:0,left:0,width:"30%",zIndex:5,cursor:"pointer"},onMouseDown:gt,onMouseUp:()=>vt("prev"),onTouchStart:gt,onTouchEnd:()=>vt("prev")}),W("div",{style:{position:"absolute",top:0,bottom:0,right:0,width:"70%",zIndex:4,cursor:"pointer"},onMouseDown:gt,onMouseUp:()=>vt("next"),onTouchStart:gt,onTouchEnd:()=>vt("next")}),it("div",{style:oo,children:[le?W(xi,{src:le,isActive:ce,isAnimating:l,isMuted:g,onLoadedData:jt,activeVideoRef:$}):(Re||!Tt&&k?.thumbnail)&&W(zt,{src:Re||k?.thumbnail,alt:"Story content",style:{width:"100%",height:"100%",objectFit:Tt?"contain":"cover"}}),W(Oo,{content:{...N.content,styling:{...N.content?.styling,...N?.styling},interactions:N.interactions},elapsedTime:ce?x/100*(k.styling?.slideShowTime||5):0,onInteraction:async Ft=>{if(!ce)return;y(!0);let{type:Fe,questionId:no,pollId:Jt,quizId:io,optionId:ro,value:Ie,stickerId:so}=Ft,Xt=Fe?.split("_")[0]||"interaction";Xt==="quizz"&&(Xt="quiz"),Fe?.startsWith("image_quiz")&&(Xt="quiz");let ze=so||no||Jt||io||N.id,ao=ro||Ft.selected_option||"",un=F.getState(),Ui=un.userId||"anonymous",Hi=un.trackingUrl||"https://tracking.appstorys.co",gn=await dt();fetch(`${Hi}/capture-event`,{method:"POST",headers:{"Content-Type":"application/json",...gn?{Authorization:`Bearer ${gn}`}:{}},body:JSON.stringify({user_id:Ui,campaign_id:o,event:"interaction",metadata:{interaction_type:Xt,interaction_id:ze,slide_id:N.id,selected_option:String(ao),value:String(Ie||"")}})}).catch(Vi=>console.error("AppStorys: Instant Tracking Failed",Vi))}})]}),(de||wt)&&W(No,{cta:N?.styling?.cta,buttonText:de||"Learn More",onPress:Ft=>{Ft&&Ft.stopPropagation&&Ft.stopPropagation(),sn(N)}})]},N.id||A)})}):W("div",{style:{width:"100%",maxWidth:"450px",height:"100%",maxHeight:"850px",overflow:"hidden",position:"relative",zIndex:5,display:"flex",flexDirection:"column"},children:k.slides.map((A,N)=>{if(Math.abs(N-c)>1)return W("div",{style:{display:"none"}},A.id||N);let st=A?.styling,Rt=st?.editorSource||st?.meta?.editorSource,ft=Rt==="studio"||Rt==="editor",ae=st?.background?.media?.mediaUrl||A?.image,Tt=A?.video||(ft?A?.content?.video?.[0]?.link:void 0),Re=Pt(st?.background)||"#000000",le=ft?A?.content?.button_text:A?.button_text,eo=ft?A?.content?.link:A?.link,de=N===c;return de?W("div",{style:{width:"100%",height:"100%",display:"flex",justifyContent:"center",alignItems:"center"},children:it("div",{style:{...pn},onClick:wt=>wt.stopPropagation(),children:[W("div",{style:{position:"absolute",top:0,left:0,right:0,display:"flex",gap:"4px",padding:"10px",zIndex:10},children:k.slides.map((wt,_t)=>{let Te=_t<c?"100%":_t===c?`${x}%`:"0%";return W("div",{style:{flex:1,height:"3px",backgroundColor:"rgba(255,255,255,0.3)",borderRadius:"2px",overflow:"hidden"},children:W("div",{style:{width:Te,height:"100%",backgroundColor:"white",transition:_t===c?"width 0.1s linear":"none"}})},_t)})}),it("div",{style:{position:"absolute",top:"20px",left:"10px",right:"10px",display:"flex",alignItems:"center",justifyContent:"space-between",zIndex:10,padding:"5px"},children:[it("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[W(zt,{src:k.thumbnail,alt:k.name,style:{width:"32px",height:"32px",borderRadius:"50%"}}),W("span",{style:{color:"white",fontWeight:"bold",fontSize:"14px",textShadow:"0 1px 3px rgba(0,0,0,0.8)"},children:k.name})]}),it("div",{style:{display:"flex",alignItems:"center",gap:"12px"},children:[W(qo,{config:{size:32,color:{cross:"#ffffff",fill:"rgba(255,255,255,0.08)",stroke:"transparent"},margin:{top:0,bottom:0,left:0,right:0},image:""},onPress:an,type:g?"mute":"unmute",enabled:!!dn?.enabled&&!!Tt,style:{position:"relative",borderRadius:"10px"}}),W(Lt,{config:{enabled:ln?.enabled!==!1,image:"",color:{cross:"#ffffff",fill:"rgba(255,255,255,0.08)",stroke:"transparent"},margin:{top:0,bottom:0,left:0,right:0},size:32},onPress:a,style:{position:"relative",borderRadius:"10px"}})]})]}),W("div",{style:{position:"absolute",top:0,bottom:0,left:0,width:"30%",zIndex:5,cursor:"pointer"},onMouseDown:gt,onMouseUp:()=>vt("prev"),onTouchStart:gt,onTouchEnd:()=>vt("prev")}),W("div",{style:{position:"absolute",top:0,bottom:0,right:0,width:"70%",zIndex:4,cursor:"pointer"},onMouseDown:gt,onMouseUp:()=>vt("next"),onTouchStart:gt,onTouchEnd:()=>vt("next")}),it("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",background:ft?Re:"#000",position:"relative",width:"100%",height:"100%",overflow:"hidden",borderRadius:"0px"},children:[Tt?W(xi,{src:Tt,isActive:de,isAnimating:l,isMuted:g,onLoadedData:jt,activeVideoRef:$}):(ae||k?.thumbnail)&&W(zt,{src:ae||k?.thumbnail,alt:"Story content",style:{width:"100%",height:"100%",objectFit:ft?"contain":"cover"}}),W(Oo,{content:{...A.content,styling:{...A.content?.styling,...A?.styling},interactions:A.interactions},elapsedTime:x/100*(k.styling?.slideShowTime||5),onInteraction:async wt=>{y(!0);let{type:_t,questionId:Te,pollId:ce,quizId:oo,optionId:Ft,value:Fe,stickerId:no}=wt,Jt=_t?.split("_")[0]||"interaction";Jt==="quizz"&&(Jt="quiz"),_t?.startsWith("image_quiz")&&(Jt="quiz");let io=no||Te||ce||oo||A.id,ro=Ft||wt.selected_option||"",Ie=F.getState(),so=Ie.userId||"anonymous",Xt=Ie.trackingUrl||"https://tracking.appstorys.co",ze=await dt();fetch(`${Xt}/capture-event`,{method:"POST",headers:{"Content-Type":"application/json",...ze?{Authorization:`Bearer ${ze}`}:{}},body:JSON.stringify({user_id:so,campaign_id:o,event:"interaction",metadata:{interaction_type:Jt,interaction_id:io,slide_id:A.id,selected_option:String(ro),value:String(Fe||"")}})}).catch(ao=>console.error("AppStorys: Instant Tracking Failed",ao))}})]}),(le||eo)&&W(No,{cta:A?.styling?.cta,buttonText:le||"Learn More",onPress:wt=>{wt&&wt.stopPropagation&&wt.stopPropagation(),sn(A)}})]})},A.id||N):null})}),d&&W("div",{style:{display:"flex",justifyContent:"flex-start",alignItems:"center",gap:"12px",width:"100%",boxSizing:"border-box"},children:W("button",{onClick:nt,style:{background:"rgba(0,0,0,0.5)",border:"none",color:"white",borderRadius:"50%",width:"40px",height:"40px",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",fontSize:"18px",backdropFilter:"blur(5px)",transition:"background 0.2s"},onMouseEnter:A=>A.currentTarget.style.background="rgba(0,0,0,0.7)",onMouseLeave:A=>A.currentTarget.style.background="rgba(0,0,0,0.5)",children:"\u203A"})}),d&&e>0&&it("div",{style:{position:"absolute",bottom:"40px",left:"40px",display:"flex",flexDirection:"column",alignItems:"flex-start",gap:"5px",zIndex:20},children:[W("span",{style:{fontSize:"11px",fontWeight:"bold",color:"rgba(255,255,255,0.75)",letterSpacing:"0.4px",paddingLeft:"2px"},children:"Previous Stories"}),it("div",{style:{background:"rgba(255, 255, 255, 0.06)",padding:"8px 14px",borderRadius:"14px",display:"flex",alignItems:"center",gap:"12px",backdropFilter:"blur(16px)",cursor:"pointer",boxShadow:"0 8px 16px rgba(0, 0, 0, 0.25)",transition:"all 0.2s",maxWidth:"280px"},onClick:s,children:[W("span",{style:{color:"white",fontSize:"15px"},children:"\u2190"}),W("div",{style:{width:"40px",height:"40px",borderRadius:"50%",border:"2px solid white",display:"flex",alignItems:"center",justifyContent:"center",background:"white",flexShrink:0},children:W(zt,{src:t[e-1].thumbnail,style:{width:"36px",height:"36px",borderRadius:"50%"}})}),W("span",{style:{fontSize:"14px",color:"white",fontWeight:"500",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",minWidth:0},children:t[e-1].name})]})]}),d&&e<t.length-1&&it("div",{style:{position:"absolute",bottom:"40px",right:"40px",display:"flex",flexDirection:"column",alignItems:"flex-start",gap:"5px",zIndex:20},children:[W("span",{style:{fontSize:"11px",fontWeight:"bold",color:"rgba(255,255,255,0.75)",letterSpacing:"0.4px",paddingLeft:"2px"},children:"Next Stories"}),it("div",{style:{background:"rgba(255, 255, 255, 0.06)",padding:"8px 14px",borderRadius:"14px",display:"flex",alignItems:"center",gap:"12px",backdropFilter:"blur(16px)",cursor:"pointer",boxShadow:"0 8px 16px rgba(0, 0, 0, 0.25)",transition:"all 0.2s",maxWidth:"280px"},onClick:r,children:[W("div",{style:{width:"40px",height:"40px",borderRadius:"50%",border:"2px solid white",display:"flex",alignItems:"center",justifyContent:"center",background:"white",flexShrink:0},children:W(zt,{src:t[e+1].thumbnail,style:{width:"36px",height:"36px",borderRadius:"50%"}})}),W("span",{style:{fontSize:"14px",color:"white",fontWeight:"500",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",minWidth:0},children:t[e+1].name}),W("span",{style:{color:"white",fontSize:"15px"},children:"\u2192"})]})]}),z&&W("div",{style:{position:"absolute",bottom:"40px",left:"50%",transform:"translateX(-50%)",background:"rgba(20, 20, 20, 0.96)",border:"1px solid rgba(255,255,255,0.08)",padding:"12px 24px",borderRadius:"12px",color:"white",fontSize:"13px",fontWeight:"500",boxShadow:"0 10px 20px rgba(0,0,0,0.5)",backdropFilter:"blur(10px)",zIndex:1e3},children:z})]})})]})};import{jsx as wi,jsxs as es}from"react/jsx-runtime";var ts=()=>{let t=pt("STR"),e=F(u=>u.isVisible),[o,i]=Ci(null),[n,r]=Ci([]);if(vi(()=>{try{let u=localStorage.getItem("app_storys_viewed_stories");u&&r(JSON.parse(u))}catch(u){console.error("Failed to load viewed stories:",u)}},[]),vi(()=>{t&&t.details&&H("story_module_viewed",t.id)},[t]),!t||!t.details||t.details.length===0||!e)return null;let s=u=>{i(u);let x=t.details[u];H("story_opened",t.id,{story_id:x.id,story_name:x.name})},a=()=>{o!==null&&(o<t.details.length-1?i(o+1):i(null))},c=()=>{o!==null&&o>0&&i(o-1)};return es("div",{className:"story-group-container",style:{width:"100vw",position:"relative",left:"50%",right:"50%",marginLeft:"-50vw",marginRight:"-50vw",boxSizing:"border-box"},children:[wi(On,{stories:t.details,viewedStories:n,onStoryClick:s}),o!==null&&wi(Si,{stories:t.details,activeStoryIndex:o,dataId:t.id,viewedStories:n,setViewedStories:r,onNextStory:a,onPrevStory:c,onClose:()=>i(null)})]})};import{useState as os,useRef as Qe,useEffect as Qo,useCallback as ns}from"react";import{createPortal as is}from"react-dom";K();import{useEffect as ki,useRef as Ye}from"react";function xe(t,e=.5){let o=Ye(t),i=Ye(!1),n=Ye(null),r=Ye(null);ki(()=>{o.current=t},[t]);let s=a=>{if(r.current&&(r.current.disconnect(),r.current=null),n.current=a,i.current=!1,!a)return;if(typeof IntersectionObserver>"u"){o.current();return}let c=null;r.current=new IntersectionObserver(u=>{u[0].isIntersecting&&!i.current?c||(c=setTimeout(()=>{i.current=!0,o.current(),r.current?.disconnect(),c=null},500)):c&&(clearTimeout(c),c=null)},{threshold:e}),r.current.observe(a)};return ki(()=>()=>{r.current?.disconnect()},[]),s}import{jsx as Ot,jsxs as ss}from"react/jsx-runtime";var rs=({position:t})=>{let e=pt("WID",{position:t}),o=F(B=>B.campaigns),i=F(B=>B.allCampaigns),n=F(B=>B.currentScreen),r=B=>(B||"").trim().toLowerCase(),s=e??(()=>{let B=r(n),L=[...o||[],...i||[]].find(C=>{let S=C;if(S.campaign_type!=="WID"||t&&S.position!==t)return!1;let _=!!(S.trigger_event??S.trigger),E=S.display_trigger!==!1&&!_,$=!r(S.screen)||r(S.screen)===B;return E&&$});if(L)try{return yt(L)}catch{return L}})(),[a,c]=os(0),u=Qe(null),x=Qe(null),m=s?.details||{},g=m.widget_images||[],v=m.styling||{},f=m.type||"full",b=f==="half",h=Qe([]),y=Qe(!1),w=ns(()=>{y.current=!0;let B=g[a];B?.id&&z(B.id)},[g,a]),I=xe(w),z=B=>{!s?.id||!B||y.current&&(h.current.includes(B)||(h.current.push(B),H("viewed",s.id,{widget_image:B})))};Qo(()=>{if(f==="full"&&g.length>1)return x.current=setInterval(()=>{c(B=>{let L=B+1;return L>=g.length?0:L})},5e3),()=>{x.current&&clearInterval(x.current)}},[f,g.length]);let R=(B,L)=>{if(s?.id&&H("clicked",s.id,{widget_image:B}),L){if(!L.startsWith("http")){try{if(ht(L))return}catch(C){console.warn("[Widget] revealCampaignFromLink error",C)}console.log("[Widget] Internal link:",L);return}window.open(L,"_blank")}},d=()=>{if(u.current&&b){let{scrollLeft:B,offsetWidth:L}=u.current,C=L/2+12,S=Math.round(B/C);c(S)}};Qo(()=>{if(!s?.id||f!=="full"||g.length===0)return;let B=g[a];B&&B.id&&z(B.id)},[a,s?.id,g,f]),Qo(()=>{if(!s?.id||!u.current||!b)return;let B=u.current,L=()=>{let{scrollLeft:C,offsetWidth:S}=B,_=S/2+12;g.forEach((E,$)=>{let D=$*_,k=D+_,P=C,O=C+S;Math.max(0,Math.min(k,O)-Math.max(D,P))/_>=.5&&z(E.id)})};return L(),B.addEventListener("scroll",L),()=>B.removeEventListener("scroll",L)},[s?.id,b,g]);let T={display:"flex",flexDirection:"row",flexWrap:b?"nowrap":"wrap",gap:"12px",width:"100%",height:b&&m.height?`${m.height}px`:"auto",marginTop:v.topMargin?`${v.topMargin}px`:"0px",marginBottom:v.bottomMargin?`${v.bottomMargin}px`:"0px",marginLeft:v.leftMargin?`${v.leftMargin}px`:"0px",marginRight:v.rightMargin?`${v.rightMargin}px`:"0px",boxSizing:"border-box",overflowX:b?"auto":"hidden",overflowY:"hidden",scrollSnapType:b?"x mandatory":void 0,msOverflowStyle:"none",scrollbarWidth:"none"},l=B=>({flex:b?"0 0 calc(50% - 6px)":"0 0 100%",height:b&&m.height?`${m.height}px`:"auto",cursor:"pointer",position:"relative",overflow:"hidden",borderRadius:v.borderRadius?`${v.borderRadius}px`:"0px",borderTopLeftRadius:v.topLeftRadius?`${v.topLeftRadius}px`:void 0,borderTopRightRadius:v.topRightRadius?`${v.topRightRadius}px`:void 0,borderBottomLeftRadius:v.bottomLeftRadius?`${v.bottomLeftRadius}px`:void 0,borderBottomRightRadius:v.bottomRightRadius?`${v.bottomRightRadius}px`:void 0,boxShadow:"0 4px 12px rgba(0,0,0,0.08)",scrollSnapAlign:"start"}),p=ss("div",{style:{width:"100%",position:"relative"},children:[Ot("style",{children:`
124
+ `}),Rt("div",{style:{position:"absolute",top:"46px",right:0,width:"260px",background:"rgba(25, 25, 25, 0.98)",border:"1px solid rgba(255,255,255,0.08)",borderRadius:"16px",padding:"18px",boxShadow:"0 20px 25px -5px rgba(0,0,0,0.4), 0 10px 10px -5px rgba(0,0,0,0.4)",zIndex:1001,animation:"fadeUp 0.25s cubic-bezier(0.4, 0, 0.2, 1) forwards"},children:[Q("div",{style:{fontSize:"11px",fontWeight:"bold",color:"#9CA3AF",letterSpacing:"1px",textTransform:"uppercase",marginBottom:"16px",paddingBottom:"10px",borderBottom:"1px solid rgba(255,255,255,0.06)"},children:"Keyboard Shortcuts"}),Q("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[{key:"\u2192",label:"Next slide"},{key:"\u2190",label:"Previous slide"},{key:"space",label:"Play/Pause"},{key:"esc",label:"Close story"},{key:"S",label:"Share story link"}].map(({key:F,label:j})=>Rt("div",{style:{display:"flex",alignItems:"center",gap:"14px",justifyContent:"flex-start"},children:[Q("span",{style:{minWidth:"54px",display:"inline-flex",alignItems:"center",justifyContent:"center",background:"rgba(255,255,255,0.08)",padding:"5px 8px",borderRadius:"5px",fontSize:"12px",color:"white",border:"1px solid rgba(255,255,255,0.1)",boxSizing:"border-box"},children:F}),Q("span",{style:{fontSize:"13px",color:"#E5E7EB",fontWeight:"500",textAlign:"left"},children:j})]},F))})]})]})]}),Q(Dt,{config:{enabled:Vt?.enabled??!0,image:"",color:{cross:"#ffffff",fill:"rgba(255,255,255,0.08)",stroke:"transparent"},margin:{top:0,bottom:0,left:0,right:0},size:44},onPress:c,style:{position:"relative",borderRadius:"12px"}})]})]})]}),Q("div",{style:{flex:1,width:"100%",display:"flex",flexDirection:"column",justifyContent:V?"flex-start":"center",alignItems:"center",paddingTop:V?"14px":"0px",...ao()},children:Rt("div",{style:{display:V?"grid":"flex",gridTemplateColumns:V?`minmax(0, 1fr) ${Tt}px minmax(0, 1fr)`:"none",alignItems:"center",justifyContent:"center",gap:"12px",width:"100%",maxWidth:"1400px",position:"relative"},onClick:F=>V&&F.stopPropagation(),children:[V&&Q("div",{style:{display:"flex",justifyContent:"flex-end",alignItems:"center",gap:"12px",width:"100%",boxSizing:"border-box"},children:(p>0||e>0)&&Q("button",{onClick:so,style:{background:"rgba(0,0,0,0.45)",border:"1px solid rgba(255,255,255,0.1)",color:"white",borderRadius:"50%",width:"44px",height:"44px",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",backdropFilter:"blur(10px)",transition:"all 0.2s cubic-bezier(0.4, 0, 0.2, 1)",boxShadow:"0 8px 16px rgba(0,0,0,0.3)",outline:"none"},onMouseEnter:F=>{F.currentTarget.style.background="rgba(0,0,0,0.75)",F.currentTarget.style.transform="scale(1.1)",F.currentTarget.style.borderColor="rgba(255,255,255,0.25)"},onMouseLeave:F=>{F.currentTarget.style.background="rgba(0,0,0,0.45)",F.currentTarget.style.transform="scale(1)",F.currentTarget.style.borderColor="rgba(255,255,255,0.1)"},children:Q("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:Q("polyline",{points:"15 18 9 12 15 6"})})})}),V?Q("div",{style:{width:`${Tt}px`,height:`${Ht}px`,position:"relative",zIndex:5,overflow:"visible"},children:Array.from(Lt).sort((F,j)=>F-j).map(F=>{let j=d.slides[F];if(!j)return null;let pt=$e(F),Mt=Ca(pt,Tt),vt=j?.styling,ye=vt?.editorSource||vt?.meta?.editorSource,Zt=ye==="studio"||ye==="editor",Ne=vt?.background?.media?.mediaUrl||j?.image,Be=I(j),lo=St(vt?.background)||"#000000",Xt=Zt?j?.content?.button_text:j?.button_text,Le=Zt?j?.content?.link:j?.link,se=vt?.background?.media?.sizing||vt?.background?.sizing||vt?.media?.sizing||j?.sizing,Ee=se==="fill"?"cover":se==="fit"?"contain":se==="stretch"?"fill":Zt?"contain":"cover",te=vt?.background?.media?.position||vt?.background?.position||vt?.media?.position||j?.content?.background?.media?.position||j?.content?.media?.position||j?.position,qt=Ve(te),co=F===p&&!T||T&&F===H,yn={display:"flex",justifyContent:"center",alignItems:"center",background:Zt?lo:"#000",position:"relative",width:"100%",height:"100%",overflow:"hidden",borderRadius:"16px"};return Rt("div",{style:{..._t,position:"absolute",top:0,left:0,width:`${Tt}px`,height:`${Ht}px`,...Mt,transition:pt==="hidden"||pt==="far-left"||pt==="far-right"?`opacity ${xe}ms ease, transform ${xe}ms ease`:F===B?`transform ${xe}ms ${Kn}, opacity ${xe}ms ${Kn}, filter ${xe}ms ${Kn}`:`transform ${xe}ms ${Zn}, opacity ${xe}ms ${Zn}, filter ${xe}ms ${Zn}`,transformOrigin:"center center",willChange:"transform, opacity, filter"},onClick:ae=>ae.stopPropagation(),children:[Q("div",{style:{position:"absolute",top:0,bottom:0,left:0,width:"30%",zIndex:5,cursor:"pointer"},onMouseDown:Qt,onMouseUp:()=>ie("prev"),onTouchStart:Qt,onTouchEnd:()=>ie("prev")}),Q("div",{style:{position:"absolute",top:0,bottom:0,right:0,width:"70%",zIndex:4,cursor:"pointer"},onMouseDown:Qt,onMouseUp:()=>ie("next"),onTouchStart:Qt,onTouchEnd:()=>ie("next")}),Rt("div",{style:yn,children:[Be?Q(Ar,{src:Be,isActive:co,isAnimating:T,isMuted:h,onLoadedData:fe,activeVideoRef:q,objectFit:Ee,objectPosition:qt}):Ne||!Zt&&d?.thumbnail?Q(de,{src:Ne||d?.thumbnail,alt:"Story content",style:{width:"100%",height:"100%",objectFit:Ee,objectPosition:qt}}):null,Q(Gn,{content:{...j.content,lottie:j.content?.lottie||j?.lottie||j.styling?.lottie,video:j.content?.video||j?.videoOverlay||j.styling?.video,image:j.content?.image||j?.imageOverlay||j.styling?.image,canva:Zo(j),editorSource:j.content?.editorSource||j.editorSource||j.styling?.editorSource||j.meta?.editorSource,styling:{...j.content?.styling,...j?.styling},interactions:j.interactions},elapsedTime:co?u/100*(d.styling?.slideShowTime||5):0,onInteraction:async ae=>{co&&ut(ae,j)}})]}),(Xt||Le)&&Q(Xn,{cta:j?.styling?.cta,buttonText:Xt||"Learn More",onPress:ae=>{ae&&ae.stopPropagation&&ae.stopPropagation(),G(j)}})]},j.id||F)})}):Q("div",{style:{width:"100vw",height:"100dvh",maxWidth:"100vw",maxHeight:"100dvh",overflow:"hidden",position:"relative",zIndex:5,display:"flex",flexDirection:"column",justifyContent:"center",alignItems:"center",backgroundColor:"#000000"},children:d.slides.map((F,j)=>{if(Math.abs(j-p)>1)return Q("div",{style:{display:"none"}},F.id||j);let pt=F?.styling,Mt=pt?.editorSource||pt?.meta?.editorSource,vt=Mt==="studio"||Mt==="editor",ye=pt?.background?.media?.mediaUrl||F?.image,Zt=F?.video||(vt?F?.content?.video?.[0]?.link:void 0),Ne=St(pt?.background)||"#000000",Be=vt?F?.content?.button_text:F?.button_text,lo=vt?F?.content?.link:F?.link,Xt=pt?.background?.media?.sizing||pt?.background?.sizing||pt?.media?.sizing||F?.sizing,Le=Xt==="fill"?"cover":Xt==="fit"?"contain":Xt==="stretch"?"fill":vt?"contain":"cover",se=pt?.background?.media?.position||pt?.background?.position||pt?.media?.position||F?.content?.background?.media?.position||F?.content?.media?.position||F?.position,Ee=Ve(se),te=j===p;return te?Q("div",{style:{width:"100%",height:"100%",display:"flex",justifyContent:"center",alignItems:"center"},children:Rt("div",{style:{..._t},onClick:qt=>qt.stopPropagation(),children:[Q("div",{style:{position:"absolute",top:"calc(10px + env(safe-area-inset-top, 0px))",left:"10px",right:"10px",display:"flex",gap:"4px",padding:"0 4px",zIndex:10},children:d.slides.map((qt,Ae)=>{let mn=Ae<p?"100%":Ae===p?`${u}%`:"0%";return Q("div",{style:{flex:1,height:"3px",backgroundColor:"rgba(255,255,255,0.3)",borderRadius:"2px",overflow:"hidden"},children:Q("div",{style:{width:mn,height:"100%",backgroundColor:"white",transition:Ae===p&&u>0&&!T?"width 0.1s linear":"none"}})},Ae)})}),Rt("div",{style:{position:"absolute",top:"calc(22px + env(safe-area-inset-top, 0px))",left:"10px",right:"10px",display:"flex",alignItems:"center",justifyContent:"space-between",zIndex:10,padding:"5px"},children:[Rt("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[Q(de,{src:d.thumbnail,alt:d.name,style:{width:"32px",height:"32px",borderRadius:"50%"}}),Q("span",{style:{color:"white",fontWeight:"bold",fontSize:"14px",textShadow:"0 1px 3px rgba(0,0,0,0.8)"},children:d.name})]}),Rt("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[Q(Jn,{config:{enabled:d?.styling?.share?.enabled??!0,image:d?.styling?.share?.image??"",color:{cross:d?.styling?.share?.color?.cross??"#ffffff",fill:d?.styling?.share?.color?.fill??"rgba(255,255,255,0.08)",stroke:d?.styling?.share?.color?.stroke??"transparent"},margin:{top:0,bottom:0,left:0,right:0},size:d?.styling?.share?.size??32},onPress:Lo,ignoreSizeAndMargin:!0,style:{position:"relative",margin:0,borderRadius:"10px",width:"32px",height:"32px"}}),Q(be,{config:{size:(h?ct?.mute?.size:ct?.unmute?.size)||32,color:{cross:(h?ct?.mute?.color?.cross:ct?.unmute?.color?.cross)||"#ffffff",fill:(h?ct?.mute?.color?.fill:ct?.unmute?.color?.fill)||"rgba(255,255,255,0.08)",stroke:(h?ct?.mute?.color?.stroke:ct?.unmute?.color?.stroke)||"transparent"},margin:(h?ct?.mute?.margin:ct?.unmute?.margin)||{top:0,bottom:0,left:0,right:0},image:(h?ct?.mute?.image:ct?.unmute?.image)||""},onPress:zt,type:h?"mute":"unmute",enabled:!!ct?.enabled&&!!Zt,style:{position:"relative",borderRadius:"10px"}}),Q(Dt,{config:{enabled:Vt?.enabled!==!1,image:"",color:{cross:"#ffffff",fill:"rgba(255,255,255,0.08)",stroke:"transparent"},margin:{top:0,bottom:0,left:0,right:0},size:32},onPress:c,style:{position:"relative",borderRadius:"10px"}})]})]}),Q("div",{style:{position:"absolute",top:0,bottom:0,left:0,width:"30%",zIndex:5,cursor:"pointer"},onMouseDown:Qt,onMouseUp:()=>ie("prev"),onTouchStart:Qt,onTouchEnd:()=>ie("prev")}),Q("div",{style:{position:"absolute",top:0,bottom:0,right:0,width:"70%",zIndex:4,cursor:"pointer"},onMouseDown:Qt,onMouseUp:()=>ie("next"),onTouchStart:Qt,onTouchEnd:()=>ie("next")}),Rt("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",background:vt?Ne:"#000",position:"relative",width:"100%",height:"100%",overflow:"hidden",borderRadius:"0px"},children:[Zt?Q(Ar,{src:Zt,isActive:te,isAnimating:T,isMuted:h,onLoadedData:fe,activeVideoRef:q,objectFit:Le,objectPosition:Ee}):(ye||!vt&&d?.thumbnail)&&Q(de,{src:ye||d?.thumbnail,alt:"Story content",style:{width:"100%",height:"100%",objectFit:Le,objectPosition:Ee}}),Q(Gn,{content:{...F.content,canva:Zo(F),editorSource:F.content?.editorSource||F.editorSource||F.styling?.editorSource||F.meta?.editorSource,styling:{...F.content?.styling,...F?.styling},interactions:F.interactions},elapsedTime:u/100*(d.styling?.slideShowTime||5),onInteraction:async qt=>{ut(qt,F)}})]}),(Be||lo)&&Q(Xn,{cta:F?.styling?.cta,buttonText:Be||"Learn More",onPress:qt=>{qt&&qt.stopPropagation&&qt.stopPropagation(),G(F)}})]})},F.id||j):null})}),V&&Q("div",{style:{display:"flex",justifyContent:"flex-start",alignItems:"center",gap:"12px",width:"100%",boxSizing:"border-box"},children:Q("button",{onClick:ge,style:{background:"rgba(0,0,0,0.45)",border:"1px solid rgba(255,255,255,0.1)",color:"white",borderRadius:"50%",width:"44px",height:"44px",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",backdropFilter:"blur(10px)",transition:"all 0.2s cubic-bezier(0.4, 0, 0.2, 1)",boxShadow:"0 8px 16px rgba(0,0,0,0.3)",outline:"none"},onMouseEnter:F=>{F.currentTarget.style.background="rgba(0,0,0,0.75)",F.currentTarget.style.transform="scale(1.1)",F.currentTarget.style.borderColor="rgba(255,255,255,0.25)"},onMouseLeave:F=>{F.currentTarget.style.background="rgba(0,0,0,0.45)",F.currentTarget.style.transform="scale(1)",F.currentTarget.style.borderColor="rgba(255,255,255,0.1)"},children:Q("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:Q("polyline",{points:"9 18 15 12 9 6"})})})})]})}),V&&e>0&&Rt("div",{style:{position:"absolute",bottom:"36px",left:"24px",display:"flex",flexDirection:"column",alignItems:"flex-start",gap:"6px",zIndex:20},children:[Q("span",{style:{fontSize:"11px",fontWeight:"600",color:"rgba(255,255,255,0.65)",letterSpacing:"0.6px",textTransform:"uppercase",paddingLeft:"2px"},children:"Previous Stories"}),Rt("div",{style:{background:"rgba(255, 255, 255, 0.08)",border:"1px solid rgba(255, 255, 255, 0.12)",padding:"8px 16px",borderRadius:"16px",display:"flex",alignItems:"center",gap:"12px",backdropFilter:"blur(20px)",cursor:"pointer",boxShadow:"0 10px 24px rgba(0, 0, 0, 0.3)",transition:"all 0.25s cubic-bezier(0.4, 0, 0.2, 1)",maxWidth:"280px"},onClick:()=>ne("prev"),onMouseEnter:F=>{F.currentTarget.style.transform="translateY(-2px) scale(1.03)",F.currentTarget.style.background="rgba(255, 255, 255, 0.12)",F.currentTarget.style.borderColor="rgba(255, 255, 255, 0.25)"},onMouseLeave:F=>{F.currentTarget.style.transform="translateY(0px) scale(1)",F.currentTarget.style.background="rgba(255, 255, 255, 0.08)",F.currentTarget.style.borderColor="rgba(255, 255, 255, 0.12)"},children:[Q("span",{style:{color:"white",fontSize:"14px",display:"flex"},children:"\u2190"}),Q("div",{style:{width:"36px",height:"36px",borderRadius:"50%",border:"2px solid rgba(255,255,255,0.8)",display:"flex",alignItems:"center",justifyContent:"center",background:"white",flexShrink:0,overflow:"hidden"},children:Q(de,{src:t[e-1].thumbnail,style:{width:"100%",height:"100%",borderRadius:"50%"}})}),Q("span",{style:{fontSize:"13px",color:"white",fontWeight:"600",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",minWidth:0},children:t[e-1].name})]})]}),V&&e<t.length-1&&Rt("div",{style:{position:"absolute",bottom:"36px",right:"24px",display:"flex",flexDirection:"column",alignItems:"flex-end",gap:"6px",zIndex:20},children:[Q("span",{style:{fontSize:"11px",fontWeight:"600",color:"rgba(255,255,255,0.65)",letterSpacing:"0.6px",textTransform:"uppercase",paddingRight:"2px"},children:"Next Stories"}),Rt("div",{style:{background:"rgba(255, 255, 255, 0.08)",border:"1px solid rgba(255, 255, 255, 0.12)",padding:"8px 16px",borderRadius:"16px",display:"flex",alignItems:"center",gap:"12px",backdropFilter:"blur(20px)",cursor:"pointer",boxShadow:"0 10px 24px rgba(0, 0, 0, 0.3)",transition:"all 0.25s cubic-bezier(0.4, 0, 0.2, 1)",maxWidth:"280px"},onClick:()=>ne("next"),onMouseEnter:F=>{F.currentTarget.style.transform="translateY(-2px) scale(1.03)",F.currentTarget.style.background="rgba(255, 255, 255, 0.12)",F.currentTarget.style.borderColor="rgba(255, 255, 255, 0.25)"},onMouseLeave:F=>{F.currentTarget.style.transform="translateY(0px) scale(1)",F.currentTarget.style.background="rgba(255, 255, 255, 0.08)",F.currentTarget.style.borderColor="rgba(255, 255, 255, 0.12)"},children:[Q("div",{style:{width:"36px",height:"36px",borderRadius:"50%",border:"2px solid rgba(255,255,255,0.8)",display:"flex",alignItems:"center",justifyContent:"center",background:"white",flexShrink:0,overflow:"hidden"},children:Q(de,{src:t[e+1].thumbnail,style:{width:"100%",height:"100%",borderRadius:"50%"}})}),Q("span",{style:{fontSize:"13px",color:"white",fontWeight:"600",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",minWidth:0},children:t[e+1].name}),Q("span",{style:{color:"white",fontSize:"14px",display:"flex"},children:"\u2192"})]})]}),v&&Q("div",{style:{position:"absolute",bottom:"40px",left:"50%",transform:"translateX(-50%)",background:"rgba(20, 20, 20, 0.96)",border:"1px solid rgba(255,255,255,0.08)",padding:"12px 24px",borderRadius:"12px",color:"white",fontSize:"13px",fontWeight:"500",boxShadow:"0 10px 20px rgba(0,0,0,0.5)",backdropFilter:"blur(10px)",zIndex:1e3},children:v})]})};import{jsx as _r,jsxs as za}from"react/jsx-runtime";var Ta=()=>{let t=At("STR"),e=P(p=>p.isVisible),[o,n]=Dr(()=>{try{let p=sessionStorage.getItem("appstorys_active_story_index");if(p!==null){let y=parseInt(p,10);if(!isNaN(y)&&y>=0)return y}}catch{}return null}),[i,s]=Dr([]);ei(()=>{try{o!==null?sessionStorage.setItem("appstorys_active_story_index",String(o)):sessionStorage.removeItem("appstorys_active_story_index")}catch{}},[o]),ei(()=>{try{let p=localStorage.getItem("app_storys_viewed_stories");p&&s(JSON.parse(p))}catch(p){console.error("Failed to load viewed stories:",p)}},[]),ei(()=>{t&&t.details&&rt("story_module_viewed",t.id)},[t]);let l=Fa.useMemo(()=>!t||!t.details?[]:xn(t.details),[t?.details]);if(!t||!l||l.length===0||!e)return null;let c=p=>{n(p)},d=()=>{o!==null&&(o<l.length-1?n(o+1):n(null))},S=()=>{o!==null&&o>0&&n(o-1)};return za("div",{className:"story-group-container",style:{width:"100vw",position:"relative",left:"50%",right:"50%",marginLeft:"-50vw",marginRight:"-50vw",boxSizing:"border-box"},children:[_r(Zi,{stories:l,viewedStories:i,onStoryClick:c}),o!==null&&_r(Pr,{stories:l,activeStoryIndex:o,dataId:t.id,viewedStories:i,setViewedStories:s,onNextStory:d,onPrevStory:S,onClose:()=>n(null)})]})};import{useState as Ba,useRef as on,useEffect as oi,useCallback as La}from"react";import{createPortal as Ea}from"react-dom";yt();import{useEffect as Wr,useRef as tn}from"react";function wo(t,e=.5){let o=tn(t),n=tn(!1),i=tn(null),s=tn(null);Wr(()=>{o.current=t},[t]);let l=c=>{if(s.current&&(s.current.disconnect(),s.current=null),i.current=c,n.current=!1,!c)return;if(typeof IntersectionObserver>"u"){o.current();return}let d=null;s.current=new IntersectionObserver(S=>{S[0].isIntersecting&&!n.current?d||(d=setTimeout(()=>{n.current=!0,o.current(),s.current?.disconnect(),d=null},500)):d&&(clearTimeout(d),d=null)},{threshold:e}),s.current.observe(c)};return Wr(()=>()=>{s.current?.disconnect()},[]),l}var $r=new Set;function Ia(){try{return globalThis?.process?.env?.NODE_ENV!=="production"}catch{return!0}}function Nr(t,e,o){if(!Ia()||o<=1)return;let n=`${e}::${t}`;$r.has(n)||($r.add(n),console.warn(`AppStorys: Found ${o} elements matching target "${t}" (selector "${e}"). The first one in document order will be used. Target identifiers should be unique per screen.`))}function en(t){if(!t)return null;let e=[`[data-as-id="${t}"]`,`[data-id="${t}"]`,`[data-widget="${t}"]`];for(let n of e)try{let i=document.querySelectorAll(n);if(i.length>0)return Nr(t,n,i.length),i[0]}catch{}let o=document.getElementById(t);if(o)return o;try{let n=`.${CSS&&CSS.escape?CSS.escape(t):t}`,i=document.querySelectorAll(n);if(i.length>0)return Nr(t,n,i.length),i[0]}catch{}return null}import{jsx as Fe,jsxs as Ma}from"react/jsx-runtime";var Aa=({position:t})=>{let e=At("WID",{position:t}),o=P(A=>A.campaigns),n=P(A=>A.allCampaigns),i=P(A=>A.currentScreen),s=A=>(A||"").trim().toLowerCase(),l=e??(()=>{let A=s(i),T=[...o||[],...n||[]].find(k=>{let B=k;if(B.campaign_type!=="WID"||t&&B.position!==t)return!1;let W=!!(B.trigger_event??B.trigger),H=B.display_trigger!==!1&&!W,Y=!s(B.screen)||s(B.screen)===A;return H&&Y});if(T)try{return Nt(T)}catch{return T}})(),[c,d]=Ba(0),S=on(null),p=on(null),y=l?.details||{},u=y.widget_images||[],C=y.styling||{},h=y.type||"full",g=h==="half",b=on([]),m=on(!1),E=La(()=>{m.current=!0;let A=u[c];A?.id&&D(A.id)},[u,c]),O=wo(E),D=A=>{!l?.id||!A||m.current&&(b.current.includes(A)||(b.current.push(A),rt("viewed",l.id,{widget_image:A})))};oi(()=>{if(h==="full"&&u.length>1)return p.current=setInterval(()=>{d(A=>{let T=A+1;return T>=u.length?0:T})},5e3),()=>{p.current&&clearInterval(p.current)}},[h,u.length]);let L=(A,T)=>{let k=(T||"").trim();if(k){if(l?.id&&rt("clicked",l.id,{widget_image:A}),!k.startsWith("http")){try{if(Pt(k))return}catch(B){console.warn("[Widget] revealCampaignFromLink error",B)}console.log("[Widget] Internal link:",k);return}window.open(k,"_blank")}},v=()=>{if(S.current&&g){let{scrollLeft:A,offsetWidth:T}=S.current,k=T/2+12,B=Math.round(A/k);d(B)}};oi(()=>{if(!l?.id||h!=="full"||u.length===0)return;let A=u[c];A&&A.id&&D(A.id)},[c,l?.id,u,h]),oi(()=>{if(!l?.id||!S.current||!g)return;let A=S.current,T=()=>{let{scrollLeft:k,offsetWidth:B}=A,W=B/2+12;u.forEach((H,Y)=>{let r=Y*W,M=r+W,a=k,f=k+B;Math.max(0,Math.min(M,f)-Math.max(r,a))/W>=.5&&D(H.id)})};return T(),A.addEventListener("scroll",T),()=>A.removeEventListener("scroll",T)},[l?.id,g,u]);let w={display:"flex",flexDirection:"row",flexWrap:g?"nowrap":"wrap",gap:"12px",width:"100%",height:g&&y.height?`${y.height}px`:"auto",marginTop:C.topMargin?`${C.topMargin}px`:"0px",marginBottom:C.bottomMargin?`${C.bottomMargin}px`:"0px",marginLeft:C.leftMargin?`${C.leftMargin}px`:"0px",marginRight:C.rightMargin?`${C.rightMargin}px`:"0px",boxSizing:"border-box",overflowX:g?"auto":"hidden",overflowY:"hidden",scrollSnapType:g?"x mandatory":void 0,msOverflowStyle:"none",scrollbarWidth:"none"},_=A=>({flex:g?"0 0 calc(50% - 6px)":"0 0 100%",height:g&&y.height?`${y.height}px`:"auto",cursor:"pointer",position:"relative",overflow:"hidden",borderRadius:C.borderRadius?`${C.borderRadius}px`:"0px",borderTopLeftRadius:C.topLeftRadius?`${C.topLeftRadius}px`:void 0,borderTopRightRadius:C.topRightRadius?`${C.topRightRadius}px`:void 0,borderBottomLeftRadius:C.bottomLeftRadius?`${C.bottomLeftRadius}px`:void 0,borderBottomRightRadius:C.bottomRightRadius?`${C.bottomRightRadius}px`:void 0,boxShadow:"0 4px 12px rgba(0,0,0,0.08)",scrollSnapAlign:"start"}),$=Ma("div",{style:{width:"100%",position:"relative"},children:[Fe("style",{children:`
78
125
  .widget-scroll-container::-webkit-scrollbar {
79
126
  display: none;
80
127
  }
81
- `}),Ot("div",{ref:B=>{u.current=B,I(B)},className:"widget-scroll-container",style:T,onScroll:d,children:b?g.map((B,L)=>Ot("div",{style:l(L),children:Ot("img",{src:B.image,alt:"widget",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"},onClick:()=>R(B.id,B.link)})},B.id)):g.length>0&&Ot("div",{style:l(0),children:Ot("img",{src:g[a].image,alt:"widget",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"},onClick:()=>R(g[a].id,g[a].link)})},`slide-${a}`)}),f==="full"&&g.length>1&&Ot("div",{style:{display:"flex",justifyContent:"center",gap:"6px",marginTop:"8px",width:"100%"},children:g.map((B,L)=>Ot("div",{style:{width:"6px",height:"6px",borderRadius:"50%",backgroundColor:L===a?"#333":"#ccc",transition:"background-color 0.2s ease"}},L))})]}),M=null;if(s?.position){let B=String(s.position||"").replace(/^widget_/,""),L=[`[data-as-id="${B}"]`,`#${B}`,`.${B}`,`[data-widget="${B}"]`];for(let C of L)try{let S=document.querySelector(C);if(S){M=S,console.log("[Widget] Portal target found:",C,"for campaign",s?.id);break}}catch{}M||console.log("[Widget] No portal target found for position:",s?.position,"rendering inline for campaign:",s?.id)}return M?is(p,M):p};import{useEffect as Ri,useLayoutEffect as as,useMemo as Ti,useRef as Go,useState as Ge,useCallback as ls}from"react";K();import{Fragment as ps,jsx as ne,jsxs as Fi}from"react/jsx-runtime";var Jo=t=>(t||"").trim().toLowerCase(),ds=()=>{let t=pt("TTP"),e=F(V=>V.campaigns),o=F(V=>V.allCampaigns),i=F(V=>V.currentScreen),n=F(V=>V.isVisible),[r,s]=Ge(0),[a,c]=Ge(!1),[u,x]=Ge(null),[m,g]=Ge({width:0,height:0}),v=Go(null),f=Go(null),b=Ti(()=>{if(t)return t;let V=Jo(i),et=q=>q.find(Q=>{let Y=Q,lt=Y.campaign_type==="TTP"||Y.campaign_type==="TLTP",mt=!Jo(Y.screen)||Jo(Y.screen)===V,nt=!!(Y.trigger_event??Y.trigger),Ct=Y.display_trigger!==!1&&!nt;return lt&&mt&&Ct});return et(e)??et(o)},[t,e,o,i]),h=Ti(()=>b?.details?.tooltips&&Array.isArray(b.details.tooltips)?[...b.details.tooltips].sort((V,et)=>(V.order??0)-(et.order??0)):b?.details?.target||b?.details?.titleText?[{...b.details,_id:b.id}]:[],[b]),y=h[r];Ri(()=>{},[b]);let w=Go(new Set),I=ls(()=>{if(!(!b||!y||a||!n))try{let V=y._id||y.id||void 0,et=String(b.id||"")+"::"+String(V||"");w.current.has(et)||(w.current.add(et),H("viewed",b.id,{tooltip_id:V}))}catch{}},[b,y,a,n]),z=xe(I);if(Ri(()=>{if(!y?.target||a)return;x(null);let V=(Q=!1)=>{let Y=y.target;if(!Y)return null;let lt=document.getElementById(Y)||document.querySelector(`[data-id="${Y}"]`)||document.querySelector(`.${Y}`);return lt?(x(lt.getBoundingClientRect()),Q&&lt.scrollIntoView({behavior:"smooth",block:"center"}),lt):null};V(!0)||(f.current=new MutationObserver(()=>{V(!0)&&f.current?.disconnect()}),f.current.observe(document.body,{childList:!0,subtree:!0}));let q=()=>{let Q=V(!1);Q&&x(Q.getBoundingClientRect())};return window.addEventListener("resize",q),window.addEventListener("scroll",q,{passive:!0}),()=>{f.current?.disconnect(),window.removeEventListener("resize",q),window.removeEventListener("scroll",q)}},[y,a,r]),as(()=>{if(v.current&&u){let{width:V,height:et}=v.current.getBoundingClientRect();g({width:V,height:et})}},[y,u]),!b||!y||a||!n||!u)return null;let R=y.styling||{},d=R.appearance||{},T=d.colors||{},l=R.cta||{},p=l.container||{},M=l.cornerRadius||{},B=l.text||{},L=y.arrowPosition||"left",S=(d.arrowStyle||{width:6,height:12}).width||6,_=u.top+window.scrollY,E=u.left+window.scrollX,$=0,D=0,k=8;L==="left"?($=E+u.width+k,D=_+u.height/2-m.height/2):L==="right"?($=E-m.width-k,D=_+u.height/2-m.height/2):L==="top"?(D=_+u.height+k,$=E+u.width/2-m.width/2):L==="bottom"&&(D=_-m.height-k,$=E+u.width/2-m.width/2);let P=8,O=window.scrollY,G=window.scrollY+window.innerHeight,ut=window.scrollX,j=window.scrollX+window.innerWidth;m.height>0&&(D=Math.max(O+P,Math.min(G-m.height-P,D))),m.width>0&&($=Math.max(ut+P,Math.min(j-m.width-P,$)));let X=()=>{let V=y.clickAction||"nextStep",et=y.link||y.url;try{let q=y._id||y.id||void 0;b?.id&&H("clicked",b.id,{tooltip_id:q})}catch{}if(V==="close"){c(!0),et&&window.open(et,"_blank");return}r<h.length-1?s(q=>q+1):(c(!0),et&&window.open(et,"_blank"))},J=()=>{y.enableBackdrop&&c(!0)};return Fi(ps,{children:[y.enableBackdrop&&ne("div",{style:{position:"fixed",top:0,left:0,right:0,bottom:0,backgroundColor:T.backdrop||"rgba(0, 0, 0, 0.7)",opacity:d.backdropOpacity?d.backdropOpacity/100:.7,zIndex:1e4},onClick:J}),Fi("div",{ref:V=>{v.current=V,z(V)},style:{position:"absolute",top:D,left:$,zIndex:10001,backgroundColor:T.tooltip||"#FE6B35",padding:`${d.padding?.top??8}px ${d.padding?.right??8}px ${d.padding?.bottom??8}px ${d.padding?.left??8}px`,borderRadius:`${d.cornerRadius?.topLeft??12}px ${d.cornerRadius?.topRight??12}px ${d.cornerRadius?.bottomRight??12}px ${d.cornerRadius?.bottomLeft??12}px`,boxShadow:"0 4px 12px rgba(0,0,0,0.15)",maxWidth:300,minWidth:200,transition:"top 0.2s ease, left 0.2s ease"},children:[ne("div",{style:{position:"absolute",width:0,height:0,borderStyle:"solid",...L==="left"&&{left:-k,top:Math.max(12,Math.min(m.height-S*2-12,_+u.height/2-D-S)),borderWidth:`${S}px ${k}px ${S}px 0`,borderColor:`transparent ${T.tooltip||"#FE6B35"} transparent transparent`},...L==="right"&&{right:-k,top:Math.max(12,Math.min(m.height-S*2-12,_+u.height/2-D-S)),borderWidth:`${S}px 0 ${S}px ${k}px`,borderColor:`transparent transparent transparent ${T.tooltip||"#FE6B35"}`},...L==="top"&&{top:-k,left:Math.max(12,Math.min(m.width-S*2-12,E+u.width/2-$-S)),borderWidth:`0 ${S}px ${k}px ${S}px`,borderColor:`transparent transparent ${T.tooltip||"#FE6B35"} transparent`},...L==="bottom"&&{bottom:-k,left:Math.max(12,Math.min(m.width-S*2-12,E+u.width/2-$-S)),borderWidth:`${k}px ${S}px 0 ${S}px`,borderColor:`${T.tooltip||"#FE6B35"} transparent transparent transparent`}}}),y.titleText&&ne("div",{style:{color:R.title?.color||"#ffffff",fontFamily:ct(R.title?.fontFamily)||"Arial",fontSize:R.title?.fontSize||14,textAlign:R.title?.textAlign||"center",marginBottom:R.title?.margin?.bottom??4,marginTop:R.title?.margin?.top??0,marginLeft:R.title?.margin?.left??0,marginRight:R.title?.margin?.right??0,fontWeight:R.title?.fontDecoration?.includes("bold")?"bold":600,fontStyle:R.title?.fontDecoration?.includes("italic")?"italic":"normal",textDecoration:R.title?.fontDecoration?.includes("underline")?"underline":"none"},children:y.titleText}),y.subtitleText&&ne("div",{style:{color:R.subTitle?.color||"#ffffff",fontFamily:ct(R.subTitle?.fontFamily)||"Arial",fontSize:R.subTitle?.fontSize||12,textAlign:R.subTitle?.textAlign||"center",marginBottom:R.subTitle?.margin?.bottom??8,marginTop:R.subTitle?.margin?.top??0,marginLeft:R.subTitle?.margin?.left??0,marginRight:R.subTitle?.margin?.right??0,fontWeight:R.subTitle?.fontDecoration?.includes("bold")?"bold":"normal",fontStyle:R.subTitle?.fontDecoration?.includes("italic")?"italic":"normal",textDecoration:R.subTitle?.fontDecoration?.includes("underline")?"underline":"none"},children:y.subtitleText}),y.ctaText&&ne("div",{style:{display:"flex",justifyContent:p.alignment==="right"?"flex-end":p.alignment==="left"?"flex-start":"center",marginTop:8},children:ne("button",{onClick:X,style:{width:p.ctaFullWidth?"100%":p.ctaWidth||"auto",height:p.height||35,background:p.backgroundColor||"#F7921C",color:B.color||"#ffffff",border:`${p.borderWidth||0}px solid ${p.borderColor||"transparent"}`,borderRadius:`${M.topLeft??7}px ${M.topRight??7}px ${M.bottomRight??7}px ${M.bottomLeft??7}px`,fontSize:B.fontSize||14,fontFamily:ct(B.fontFamily)||"Arial",fontWeight:B.fontDecoration?.includes("bold")?"bold":"normal",fontStyle:B.fontDecoration?.includes("italic")?"italic":"normal",textDecoration:B.fontDecoration?.includes("underline")?"underline":"none",cursor:"pointer",padding:"0 12px",display:"inline-flex",alignItems:"center",justifyContent:"center"},children:y.ctaText})})]})]})},cs=ds;import{useEffect as us,useState as gs}from"react";K();import{Fragment as ms,jsx as Bt,jsxs as Xo}from"react/jsx-runtime";var fs=()=>{let t=pt("BTS"),e=F(f=>f.campaigns),o=F(f=>f.allCampaigns),i=F(f=>f.currentScreen),n=t??(()=>{let f=(i||"").trim().toLowerCase(),b=[...e||[],...o||[]].find(h=>{if(!h||h.campaign_type!=="BTS")return!1;let y=!!(h.trigger_event??h.trigger);if(!(h.display_trigger!==!1&&!y))return!1;let I=(h.screen||"").trim().toLowerCase();return!I||I===f});if(b)try{return yt(b)}catch{return b}})(),r=F(f=>f.isVisible),[s,a]=gs(!1);us(()=>{n&&(a(!1),H("viewed",n.id))},[n]);let c=f=>{try{let b=F.getState(),y=(b.trackedEvents||[]).filter(w=>w!==f);b.setTrackedEvents(y)}catch{}};if(!n||s||!r)return null;let{details:u}=n,m=[...u.elements||[]].sort((f,b)=>(f.order||0)-(b.order||0)),g=u.backdropOpacity??.5;g>1&&(g=g/100);let v=f=>{switch(f.type){case"image":{let b={width:"100%",display:"block",objectFit:"contain",backgroundColor:f.imageBackgroundColor||"transparent",paddingBottom:f.paddingBottom??0,paddingLeft:f.paddingLeft??0,paddingRight:f.paddingRight??0,paddingTop:f.paddingTop??0,cursor:f.imageLink?"pointer":"default"};return Bt("div",{style:{textAlign:f.alignment||"left",width:"100%"},children:f.url&&Bt("img",{src:f.url,alt:"",style:b,onClick:()=>{if(f.imageLink){n?.id&&H("clicked",n.id);try{let h=String(f.imageLink||"").trim();if(h&&!h.startsWith("http")&&ht(h))return}catch(h){console.warn("revealCampaignFromLink error",h)}try{window.open(f.imageLink,"_blank")}catch{}}}})},f.id)}case"cta":{let b=f.cta||{},h=b.container||{},y=b.cornerRadius||{},w=b.margin||{},I=b.text||{};return Bt("div",{style:{display:"flex",justifyContent:h.alignment==="center"?"center":h.alignment==="right"?"flex-end":"flex-start",width:"100%",marginTop:w.top??0,marginBottom:w.bottom??0,marginLeft:w.left??0,marginRight:w.right??0},children:Bt("button",{style:{width:h.ctaFullWidth?"100%":h.ctaWidth||"auto",height:h.height||45,backgroundColor:h.ctaBoxColor||h.backgroundColor||"#FE6B35",color:I.color||"#ffffff",border:`${h.borderWidth||0}px solid ${h.borderColor||"transparent"}`,borderRadius:`${y.topLeft??12}px ${y.topRight??12}px ${y.bottomRight??12}px ${y.bottomLeft??12}px`,fontSize:I.fontSize||14,fontFamily:ct(I.fontFamily)||"Arial",fontWeight:I.fontDecoration?.includes("bold")?"bold":"normal",fontStyle:I.fontDecoration?.includes("italic")?"italic":"normal",textDecoration:I.fontDecoration?.includes("underline")?"underline":"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",padding:"0 16px"},onClick:()=>{let z=f.ctaLink||f.url;if(z){n?.id&&H("clicked",n.id);try{let R=String(z||"").trim();if(R&&!R.startsWith("http")&&ht(R))return}catch(R){console.warn("revealCampaignFromLink error",R)}try{window.open(z,"_blank")}catch{}}},children:f.ctaText||"Button"})},f.id)}case"body":{let b=f.titleFontStyle||{},h=f.descriptionFontStyle||{};return Xo("div",{style:{width:"100%",backgroundColor:f.bodyBackgroundColor||"transparent",marginTop:f.marginTop??0,marginBottom:f.marginBottom??20,marginLeft:f.marginLeft??4,marginRight:f.marginRight??4},children:[f.titleText&&Bt("div",{style:{color:b.colour||"#000000",fontSize:b.fontSize?`${b.fontSize}px`:f.titleFontSize?`${f.titleFontSize}px`:"16px",fontFamily:ct(b.fontFamily)||"inherit",textAlign:b.alignment||"left",lineHeight:f.titleLineHeight||1.2,fontWeight:b.decoration?.includes("bold")?"bold":"600",fontStyle:b.decoration?.includes("italic")?"italic":"normal",textDecoration:b.decoration?.includes("underline")?"underline":"none",marginBottom:f.spacingBetweenTitleDesc??4},children:f.titleText}),f.descriptionText&&Bt("div",{style:{color:h.colour||"#000000",fontSize:h.fontSize?`${h.fontSize}px`:f.descriptionFontSize?`${f.descriptionFontSize}px`:"14px",fontFamily:ct(h.fontFamily)||"inherit",textAlign:h.alignment||"left",lineHeight:f.descriptionLineHeight||1.5,fontWeight:h.decoration?.includes("bold")?"bold":"normal",fontStyle:h.decoration?.includes("italic")?"italic":"normal",textDecoration:h.decoration?.includes("underline")?"underline":"none"},children:f.descriptionText})]},f.id)}default:return null}};return Xo(ms,{children:[Bt("div",{style:{position:"fixed",top:0,left:0,right:0,bottom:0,backgroundColor:u.backdropColor||"rgba(0,0,0,0.5)",opacity:g,zIndex:999998,transition:"opacity 0.3s ease"},onClick:()=>{n?.id&&c(`viaAppStorys${n.id}`),a(!0)}}),Xo("div",{style:{position:"fixed",bottom:0,left:"50%",transform:"translateX(-50%)",width:"100%",maxWidth:"500px",backgroundColor:u.backgroundColor||"#FFFFFF",borderTopLeftRadius:`${u.cornerRadius?.topLeft??16}px`,borderTopRightRadius:`${u.cornerRadius?.topRight??16}px`,borderBottomLeftRadius:`${u.cornerRadius?.bottomLeft??0}px`,borderBottomRightRadius:`${u.cornerRadius?.bottomRight??0}px`,zIndex:999999,padding:"24px 16px",boxShadow:"0 -4px 16px rgba(0,0,0,0.15)",maxHeight:"85vh",overflowY:"auto",display:"flex",flexDirection:"column",alignItems:"center",transition:"transform 0.3s ease-out"},children:[Bt("div",{style:{width:"40px",height:"5px",backgroundColor:"#E0E0E0",borderRadius:"2.5px",marginBottom:"16px",cursor:"pointer"},onClick:()=>a(!0)}),u.crossButton?.enabled&&Bt(Lt,{config:u.crossButton,onPress:()=>{n?.id&&c(`viaAppStorys${n.id}`),a(!0)},style:{top:u.crossButton?.margin?.top??12,right:u.crossButton?.margin?.right??12}}),Bt("div",{style:{width:"100%",display:"flex",flexDirection:"column",gap:"12px"},children:m.map(v)})]})]})};import{useEffect as ys,useMemo as hs,useState as ie}from"react";K();import{Fragment as en,jsx as Z,jsxs as Ce}from"react/jsx-runtime";var Ii=5,Ko=3;function At(t){if(t!=null)return`${t}px`}function Se(t){return{marginTop:At(t?.top),marginRight:At(t?.right),marginBottom:At(t?.bottom),marginLeft:At(t?.left)}}function on(t){return ct(t)}function re(t){return t?{color:t.color,fontSize:t.fontSize,fontFamily:on(t.fontFamily),textAlign:t.textAlign,fontWeight:t.fontDecoration?.includes("bold")?"bold":void 0,fontStyle:t.fontDecoration?.includes("italic")?"italic":void 0,textDecoration:t.fontDecoration?.includes("underline")?"underline":void 0}:{}}function Zo(t){return`${t?.topLeft??8}px ${t?.topRight??8}px ${t?.bottomRight??8}px ${t?.bottomLeft??8}px`}function bs(t){return t==="right"?"flex-end":t==="left"?"flex-start":"center"}function xs(t){let e=t.styling?.rating?.ratingType;return e==="number"||e==="emoji"||e==="star"?e:"star"}function Ss(t){let e=t.styling?.rating?.emoji;if(Array.isArray(e))return e.filter(o=>typeof o=="string"&&o.trim().length>0);if(e&&typeof e=="object"){let o=Object.values(e).filter(i=>typeof i=="string"&&i.trim().length>0);if(o.length>0)return o}if(typeof e=="string"&&e.trim()){if(e.includes(",")){let o=e.split(",").map(i=>i.trim()).filter(Boolean);if(o.length>0)return o}return[e]}return["\u{1F620}","\u{1F615}","\u{1F610}","\u{1F642}","\u{1F60D}"]}function Cs(t){return Array.from({length:5},(e,o)=>o+1)}function tn(t){if(typeof t=="number"&&Number.isFinite(t)&&t>=0)return t;if(typeof t=="string"&&t.trim().length>0){let e=Number(t);if(Number.isFinite(e)&&e>=0)return e}}function vs(t){let e=t.styling?.rating||void 0,o=[e?.numberSpacing,e?.numberGap,e?.number_spacing,e?.number_gap,e?.spacingBetweenNumbers,e?.spaceBetweenNumbers,e?.numberOptionsSpacing];for(let n of o){let r=tn(n);if(r!=null)return r}let i=e?.number;if(i&&typeof i=="object"){let n=i,r=[n.spacing,n.gap,n.optionsSpacing,n.numberSpacing,n.numberGap];for(let s of r){let a=tn(s);if(a!=null)return a}}return 8}var ws=({fill:t,stroke:e})=>Z("svg",{viewBox:"0 0 24 24",width:"22",height:"22","aria-hidden":!0,children:Z("path",{d:"M12 2.25l2.91 5.89 6.5.95-4.7 4.58 1.11 6.46L12 17.03 6.18 20.13l1.11-6.46-4.7-4.58 6.5-.95L12 2.25z",fill:t,stroke:e,strokeWidth:"1.4",strokeLinejoin:"round"})}),ks=({details:t,appearance:e,rating:o,selectedOptions:i,comments:n,isHighRating:r,feedbackOptions:s,onRate:a,onToggleOption:c,onCommentChange:u,onInlineSubmit:x,canSubmit:m})=>{let g=t.styling||{},v=g.feedbackPage||{},f=g.rating||{},b=g.initialFeedback||{},h=v.submitButton?.cta,y=xs(t),w=y==="number"?Cs(t):[],I=y==="emoji"?Ss(t):[],z=y==="number"?vs(t):8,R=r?f.star?.high:f.star?.low;return Ce(en,{children:[Z("div",{style:Se(b.title?.margin),children:Z("div",{style:{...re(b.title?.textStyle),color:b.title?.textStyle?.color||"#101828",fontSize:b.title?.textStyle?.fontSize||20,lineHeight:1.3},children:t.title||"How was your experience?"})}),Z("div",{style:Se(b.subtitle?.margin),children:Z("div",{style:{...re(b.subtitle?.textStyle),color:b.subtitle?.textStyle?.color||"#4b5563",fontSize:b.subtitle?.textStyle?.fontSize||14,lineHeight:1.4},children:t.description_text||"Your feedback helps us improve your experience."})}),Ce("div",{style:{marginTop:8,display:"flex",justifyContent:"center",gap:y==="number"?z:8,flexWrap:"wrap"},children:[y==="star"&&Array.from({length:Ii},(d,T)=>{let l=T+1,p=l<=o,M=p?R?.stylingContainer:f.star?.unselected?.stylingContainer,B=p?R?.stylingStar:f.star?.unselected?.stylingStar;return Z("button",{onClick:()=>a(l),style:{border:`${M?.borderWidth??1}px solid ${M?.border||"#d1d5db"}`,background:M?.background||"#ffffff",borderRadius:10,width:44,height:44,display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0},"aria-label":`Rate ${l} out of ${Ii}`,children:Z(ws,{fill:B?.background||(p?"#f59e0b":"#e5e7eb"),stroke:B?.border||(p?"#d97706":"#9ca3af")})},l)}),y==="number"&&w.map((d,T)=>{let l=d===o;return Z("button",{onClick:()=>a(d),style:{border:`1px solid ${l?"#1d4ed8":"#d1d5db"}`,background:l?"#dbeafe":"#ffffff",color:l?"#1d4ed8":"#111827",borderRadius:8,minWidth:36,height:36,padding:"0 10px",display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:"pointer",fontWeight:600},"aria-label":`Rate ${d}`,children:d},`${d}-${T}`)}),y==="emoji"&&I.map((d,T)=>{let l=T+1,p=l===o;return Z("button",{onClick:()=>a(l),style:{border:`1px solid ${p?"#1d4ed8":"#d1d5db"}`,background:p?"#dbeafe":"#ffffff",borderRadius:"999px",width:44,height:44,display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:"pointer",fontSize:22},"aria-label":`Emoji rating ${T+1}`,children:d},`${d}-${T}`)})]}),o>0&&Z("div",{style:{marginTop:6,textAlign:"center",color:"#374151",fontSize:14},children:r?t.highStarText||f.highRatingSubtitle:t.lowStarText||f.lowRatingSubtitle}),o>0&&o<=Ko&&Ce(en,{children:[s.length>0&&Z("div",{style:{...Se(v.options?.margin),display:"flex",flexDirection:"column",alignItems:"stretch",gap:v.options?.optionsSpacing??8,width:"100%"},children:s.map(d=>{let l=i.includes(d)?v.options?.selectedOptions:v.options?.nonSelectedOptions;return Z("button",{onClick:()=>c(d),style:{border:`${l?.borderWidth??1}px solid ${l?.colors?.border||"#d1d5db"}`,background:l?.colors?.background||"#f9fafb",color:l?.colors?.text||"#111827",width:"100%",height:v.options?.optionsHeight||38,borderRadius:Zo(v.options?.cornerRadius),padding:"0 14px",cursor:"pointer",textAlign:"center",...re(l?.textStyle)},children:d},d)})}),Z("textarea",{value:n,onChange:d=>u(d.target.value),placeholder:v.additionalComments?.placeholder||"Tell us what we can improve",style:{width:"100%",boxSizing:"border-box",minHeight:56,height:56,maxHeight:64,marginTop:8,resize:"none",overflowY:"auto",border:`${v.additionalComments?.borderWidth??1}px solid ${v.additionalComments?.colors?.border||"#d1d5db"}`,background:v.additionalComments?.colors?.background||"#ffffff",color:v.additionalComments?.colors?.text||"#111827",borderRadius:8,padding:"12px",...re(v.additionalComments?.textStyle)}}),Z("div",{style:{position:"sticky",bottom:0,marginTop:8,paddingTop:6,paddingBottom:6,background:e?.backgroundColor||"#2f6ef5",display:"flex",justifyContent:"center"},children:Z("button",{onClick:()=>x(),disabled:!m,style:{width:Math.max(140,Math.min(tn(h?.container?.ctaWidth)??180,220)),maxWidth:"100%",minHeight:30,height:Math.max(30,Math.min(Number(h?.container?.height)||34,34)),border:`${h?.container?.borderWidth??1}px solid ${h?.container?.borderColor||"#ff7a00"}`,background:h?.container?.backgroundColor||"#ff2bc2",color:h?.text?.color||"#ffffff",borderRadius:Zo(h?.cornerRadius),fontFamily:on(h?.text?.fontFamily),fontSize:Math.min(Number(h?.text?.fontSize)||14,14),fontWeight:h?.text?.fontDecoration?.includes("bold")?"bold":600,cursor:m?"pointer":"not-allowed",opacity:m?1:.65,padding:"0 12px"},children:v.submitButton?.text||"Submit"})})]})]})},Rs=({details:t,isHighRating:e,onDone:o})=>{let i=t.styling||{},n=i.thankyouPage||{},r=i.rating||{},s=bs(n.doneButton?.cta?.container?.alignment);return Ce(en,{children:[t.thankyouImage&&Z("div",{style:{display:"flex",justifyContent:"center",marginTop:6},children:Z("img",{src:t.thankyouImage,alt:"thank you",style:{width:n.imageStyle?.width||80,height:n.imageStyle?.height||80,objectFit:"cover",borderRadius:8}})}),Z("div",{style:{...Se(n.title?.margin),textAlign:"center"},children:Z("div",{style:{...re(n.title?.textStyle),color:n.title?.textStyle?.color||"#111827",fontSize:n.title?.textStyle?.fontSize||20,fontWeight:n.title?.textStyle?.fontDecoration?.includes("bold")?"bold":600},children:t.thankyouText||(e?r.highRatingTitle:r.lowRatingTitle)||"Thank you for your feedback"})}),Z("div",{style:{...Se(n.subtitle?.margin),textAlign:"center"},children:Z("div",{style:{...re(n.subtitle?.textStyle),color:n.subtitle?.textStyle?.color||"#4b5563",fontSize:n.subtitle?.textStyle?.fontSize||14},children:t.thankyouDescription||(e?r.highRatingSubtitle:r.lowRatingSubtitle)||"We appreciate your time."})}),Z("div",{style:{marginTop:n.doneButton?.cta?.margin?.top??14,marginBottom:n.doneButton?.cta?.margin?.bottom??0,marginLeft:n.doneButton?.cta?.margin?.left??0,marginRight:n.doneButton?.cta?.margin?.right??0,display:"flex",justifyContent:s},children:Z("button",{onClick:o,style:{width:n.doneButton?.cta?.container?.ctaFullWidth?"100%":n.doneButton?.cta?.container?.ctaWidth||"auto",height:n.doneButton?.cta?.container?.height||45,border:`${n.doneButton?.cta?.container?.borderWidth??0}px solid ${n.doneButton?.cta?.container?.borderColor||"transparent"}`,background:n.doneButton?.cta?.container?.backgroundColor||"#111827",color:n.doneButton?.cta?.text?.color||"#ffffff",borderRadius:Zo(n.doneButton?.cta?.cornerRadius),fontFamily:on(n.doneButton?.cta?.text?.fontFamily),fontSize:n.doneButton?.cta?.text?.fontSize||16,fontWeight:n.doneButton?.cta?.text?.fontDecoration?.includes("bold")?"bold":500,cursor:"pointer",padding:"0 16px"},children:n.doneButton?.text||(e?"Rate Now":"Done")})})]})},Ts=()=>{let t=pt("CSAT"),e=F(C=>C.isVisible),o=F(C=>C.campaigns),i=F(C=>C.allCampaigns),n=F(C=>C.currentScreen),r=t??(()=>{let C=(n||"").trim().toLowerCase(),S=[...o||[],...i||[]].find(_=>{if(!_||_.campaign_type!=="CSAT")return!1;let E=!!(_.trigger_event??_.trigger);if(!(_.display_trigger!==!1&&!E))return!1;let D=(_.screen||"").trim().toLowerCase();return!D||D===C});if(S)try{return yt(S)}catch{return S}})(),[s,a]=ie(!1),[c,u]=ie(!1),[x,m]=ie(0),[g,v]=ie([]),[f,b]=ie(""),[h,y]=ie(!1);ys(()=>{if(!r)return;a(!1),u(!1),m(0),v([]),b(""),y(!1);let C=r.details?.styling?.appearance?.displayDelay??0,S=globalThis.setTimeout(()=>{u(!0),H("viewed",r.id)},Math.max(0,C)*1e3);return()=>globalThis.clearTimeout(S)},[r]);let w=hs(()=>{let C=r?.details?.feedback_option||{};return Object.keys(C).sort((S,_)=>S.localeCompare(_)).map(S=>C[S]).filter(Boolean)},[r]);if(!r||!e||s||!c)return null;let I=r.details,z=I.styling||{},R=z.appearance||{},d=x>Ko,T=Number(I.width??80),l=Math.max(660,Math.min(1080,T*10)),p=C=>{v(S=>S.includes(C)?S.filter(_=>_!==C):[...S,C])},M=async C=>{let S=C?.rating??x;if(S<1)return;y(!0);let _=I.id||r.id,E=(C?.options??g)[0]||"",$=C?.comments??f??"";H("csat captured",_,{starCount:S,selectedOption:E,additionalComments:$})},B=C=>{if(m(C),C>Ko){v([]),b("");let S=I.id||r?.id;setTimeout(()=>{y(!0);try{H("csat captured",S,{starCount:C,selectedOption:"",additionalComments:""})}catch(_){console.warn("Error sending csat captured",_)}},1e3)}},L=()=>{if(d&&I.link){let C=r&&r.id||void 0;try{C&&H("clicked",C)}catch{}try{let S=String(I.link||"").trim();if(S&&!S.startsWith("http")&&ht(S)){a(!0);return}}catch(S){console.warn("revealCampaignFromLink error",S)}try{globalThis.open(I.link,"_blank")}catch{}}a(!0)};return Z("div",{style:{position:"fixed",left:0,right:0,bottom:0,zIndex:999999,display:"flex",justifyContent:"center",alignItems:"flex-end",paddingLeft:"10px",paddingRight:"10px",paddingBottom:"10px",pointerEvents:"none"},children:Ce("div",{style:{position:"relative",width:`min(${l}px, 96vw)`,maxWidth:"96vw",minWidth:"320px",minHeight:"220px",maxHeight:"55vh",overflow:"hidden",backgroundColor:R.backgroundColor||"#2f6ef5",borderRadius:`${R.borderRadius??12}px`,boxSizing:"border-box",paddingTop:"8px",paddingRight:At(R.padding?.right)||"12px",paddingBottom:"4px",paddingLeft:At(R.padding?.left)||"12px",marginTop:At(R.margin?.top),marginRight:At(R.margin?.right),marginBottom:At(R.margin?.bottom),marginLeft:At(R.margin?.left),pointerEvents:"auto",boxShadow:"0 14px 36px rgba(0, 0, 0, 0.25)",display:"flex",flexDirection:"column"},children:[Z("style",{children:`
128
+ `}),Fe("div",{ref:A=>{S.current=A,O(A)},className:"widget-scroll-container",style:w,onScroll:v,children:g?u.map((A,T)=>Fe("div",{style:_(T),children:Fe("img",{src:A.image,alt:"widget",style:{width:"100%",height:"100%",objectFit:"cover",display:"block",cursor:(A.link||"").trim()?"pointer":"default"},onClick:()=>L(A.id,A.link)})},A.id)):u.length>0&&Fe("div",{style:_(0),children:Fe("img",{src:u[c].image,alt:"widget",style:{width:"100%",height:"100%",objectFit:"cover",display:"block",cursor:(u[c].link||"").trim()?"pointer":"default"},onClick:()=>L(u[c].id,u[c].link)})},`slide-${c}`)}),h==="full"&&u.length>1&&Fe("div",{style:{display:"flex",justifyContent:"center",gap:"6px",marginTop:"8px",width:"100%"},children:u.map((A,T)=>Fe("div",{style:{width:"6px",height:"6px",borderRadius:"50%",backgroundColor:T===c?"#333":"#ccc",transition:"background-color 0.2s ease"}},T))})]}),V=null;if(l?.position){let A=String(l.position||"").replace(/^widget_/,"");V=en(A),V?console.log("[Widget] Portal target found for campaign",l?.id):console.log("[Widget] No portal target found for position:",l?.position,"rendering inline for campaign:",l?.id)}return V?Ea($,V):$};import{useEffect as ko,useLayoutEffect as Pa,useMemo as ni,useRef as nn,useState as Qe,useCallback as Or}from"react";yt();import{jsx as Yt,jsxs as Ro}from"react/jsx-runtime";var ii=t=>(t||"").trim().toLowerCase(),Da=t=>{if(t==null)return"8px 8px 8px 8px";if(typeof t=="number")return`${t}px`;if(typeof t=="object"){let e=t.top??8,o=t.right??8,n=t.bottom??8,i=t.left??8;return`${e}px ${o}px ${n}px ${i}px`}return String(t)},_a=(t,e)=>{if(typeof t=="number")return`${t}px`;if(typeof e=="number")return`${e}px`;if(typeof t=="object"&&t!==null){let o=t.topLeft??12,n=t.topRight??12,i=t.bottomRight??12,s=t.bottomLeft??12;return`${o}px ${n}px ${i}px ${s}px`}return"12px"},Wa=()=>{let t=At("TTP"),e=P(G=>G.campaigns),o=P(G=>G.allCampaigns),n=P(G=>G.currentScreen),i=P(G=>G.isVisible),[s,l]=Qe(0),[c,d]=Qe(!1),[S,p]=Qe(null),[y,u]=Qe(null),[C,h]=Qe({width:0,height:0}),[g,b]=Qe(!1),m=nn(null),E=nn(null),O=nn(null),D=Or(G=>{if(G)try{document.body.style.overflow="",document.documentElement.style.overflow="",G.scrollIntoView({behavior:"auto",block:"center",inline:"nearest"})}catch{try{G.scrollIntoView()}catch{}}},[]),L=ni(()=>{if(t)return t;let G=ii(n),ut=zt=>zt.find(Vt=>{let ct=Vt,re=ct.campaign_type==="TTP"||ct.campaign_type==="TLTP",$e=!ii(ct.screen)||ii(ct.screen)===G,Ie=!!(ct.trigger_event??ct.trigger),_t=ct.display_trigger!==!1&&!Ie;return re&&$e&&_t});return ut(e)??ut(o)},[t,e,o,n]);ko(()=>{b(!1)},[s,L?.id]);let v=ni(()=>L?.details?.tooltips&&Array.isArray(L.details.tooltips)?[...L.details.tooltips].sort((G,ut)=>(G.order??0)-(ut.order??0)):L?.details?.target||L?.details?.titleText?[{...L.details,_id:L.id}]:[],[L]),w=v[s];ko(()=>{},[L]);let _=nn(new Set),$=Or(()=>{if(!(!L||!w||c||!i))try{let G=w._id||w.id||void 0,ut=String(L.id||"")+"::"+String(G||"");_.current.has(ut)||(_.current.add(ut),rt("viewed",L.id,{tooltip_id:G}))}catch{}},[L,w,c,i]),V=wo($);ko(()=>{if(!w||c)return;p(null),u(null);let G=null,ut=null,zt=()=>{let $t=typeof window<"u"?document.documentElement.clientWidth||window.innerWidth:1024,jt=typeof window<"u"?document.documentElement.clientHeight||window.innerHeight:768;return new DOMRect($t/2-100,jt/2-50,200,100)},Vt=$t=>{if(!$t||!($t instanceof HTMLElement))return!1;let jt=$t.getBoundingClientRect();if(jt.width===0||jt.height===0)return!1;try{let Lt=window.getComputedStyle($t);if(Lt.display==="none"||Lt.visibility==="hidden"||Lt.opacity==="0")return!1}catch{}return!0},ct=($t=!1)=>{let jt=w.target||w.targetId||w.elementId;if(!jt)return p(zt()),u(null),null;let Lt=en(jt);if(Lt){if(u(Lt),Vt(Lt)){let F=Lt.getBoundingClientRect();$t?(D(Lt),p(F),setTimeout(()=>{D(Lt),p(Lt.getBoundingClientRect())},50),setTimeout(()=>{p(Lt.getBoundingClientRect())},150),setTimeout(()=>{p(Lt.getBoundingClientRect())},350)):p(F)}else p(null);return Lt}return u(null),p(null),null},re=()=>{b(!0)},$e=$t=>{O.current?.disconnect(),O.current=null,!(!$t||typeof ResizeObserver>"u")&&(O.current=new ResizeObserver(()=>{Vt($t)?p($t.getBoundingClientRect()):p(null)}),O.current.observe($t))},Ie=($t=!1)=>{let jt=ct($t);jt&&jt!==G&&(G&&G.removeEventListener("click",re),G=jt,jt.addEventListener("click",re),$e(jt))};Ie(!0),E.current=new MutationObserver(()=>{Ie(!1)}),E.current.observe(document.body,{childList:!0,subtree:!0,attributes:!0});let _t=()=>Ie(!1);return window.addEventListener("resize",_t),window.addEventListener("scroll",_t,{passive:!0,capture:!0}),document.addEventListener("mouseenter",_t,!0),document.addEventListener("mouseover",_t,!0),document.addEventListener("mouseleave",_t,!0),document.addEventListener("click",_t,!0),()=>{ut&&clearTimeout(ut),G&&G.removeEventListener("click",re),E.current?.disconnect(),O.current?.disconnect(),window.removeEventListener("resize",_t),window.removeEventListener("scroll",_t,{capture:!0}),document.removeEventListener("mouseenter",_t,!0),document.removeEventListener("mouseover",_t,!0),document.removeEventListener("mouseleave",_t,!0),document.removeEventListener("click",_t,!0)}},[w,c,s,D]),ko(()=>{if(!w||c||!S)return;let G=w?.enableBackdrop??w?.enable_backdrop??L?.details?.enableBackdrop??L?.details?.enable_backdrop;if(!(G!==!1&&G!=="false"&&G!==0))return;let zt=Vt=>{let ct=Vt.target;ct&&(m.current&&m.current.contains(ct)||y&&(y===ct||y.contains(ct))||(b(!0),s<v.length-1?l(re=>re+1):d(!0)))};return window.addEventListener("click",zt,!0),()=>{window.removeEventListener("click",zt,!0)}},[w,c,S,y,s,v.length,L]),ko(()=>{if(!y||!(y instanceof HTMLElement)||c)return;let G=y,ut=()=>{b(!0)};return G.addEventListener("click",ut),()=>{G.removeEventListener("click",ut)}},[y,s,c]),Pa(()=>{if(m.current&&S){let{width:G,height:ut}=m.current.getBoundingClientRect();h({width:G,height:ut})}},[w,S]);let A=ni(()=>{let G=w?.styling?.appearance?.highlight?.radius;if(G!=null)return`${G}px`;if(y&&typeof window<"u")try{let ut=window.getComputedStyle(y);if(ut.borderRadius&&ut.borderRadius!=="0px")return ut.borderRadius}catch{}return"6px"},[w?.styling?.appearance?.highlight?.radius,y]);if(!L||!w||c||!i||!S)return null;let T=w.styling||{},k=T.appearance||{},B=k.colors||{},W=T.cta||{},H=W.container||{},Y=W.cornerRadius||{},r=W.text||{},M=!!(k.imageDimensions?.width&&k.imageDimensions?.height),a,f;if(M){let G=k.imageDimensions.width,ut=k.imageDimensions.height,zt=typeof window<"u"?window.innerWidth*.9:G;a=Math.min(G,zt),f=a===G?ut:Math.round(ut*(a/G))}let x=w.arrowPosition;!x&&w.position&&(w.position==="left"?x="right":w.position==="right"?x="left":w.position==="top"?x="bottom":w.position==="bottom"&&(x="top")),x||(x="left");let U=(k.arrowStyle||{width:6,height:12}).width||6,et=S.top,X=S.left,q=8,J=8,nt=typeof window<"u"?document.documentElement.clientWidth||window.innerWidth:1024,ht=typeof window<"u"?document.documentElement.clientHeight||window.innerHeight:768,dt=C.width||M&&a||250,K=C.height||(M?f||150:100),it=S.top,lt=ht-(S.top+S.height),mt=S.left,gt=nt-(S.left+S.width),R=dt+q+J,I=K+q+J;x?x==="left"&&gt<R?mt>=R?x="right":it>=I||it>=lt?x="bottom":x="top":x==="right"&&mt<R?gt>=R?x="left":it>=I||it>=lt?x="bottom":x="top":x==="top"&&lt<I?it>=I?x="bottom":gt>=R||gt>=mt?x="left":x="right":x==="bottom"&&it<I&&(lt>=I?x="top":gt>=R||gt>=mt?x="left":x="right"):gt>=R?x="left":mt>=R?x="right":it>=I?x="bottom":x="top";let N=0,Z=0;x==="left"?(N=X+S.width+q,Z=et+S.height/2-K/2):x==="right"?(N=X-dt-q,Z=et+S.height/2-K/2):x==="top"?(Z=et+S.height+q,N=X+S.width/2-dt/2):x==="bottom"&&(Z=et-K-q,N=X+S.width/2-dt/2);let xt=Math.min(dt,Math.max(120,nt-J*2)),Ft=Math.min(K,Math.max(80,ht-J*2)),kt=J,Wt=Math.max(kt,nt-xt-J),Bt=J,Ht=Math.max(Bt,ht-Ft-J),Tt=Math.max(kt,Math.min(Wt,N)),Kt=Math.max(Bt,Math.min(Ht,Z)),ne=w?.enableBackdrop??w?.enable_backdrop??L?.details?.enableBackdrop??L?.details?.enable_backdrop,ge=ne!==!1&&ne!=="false"&&ne!==0,so=k.backdropOpacity!==void 0?k.backdropOpacity>1?k.backdropOpacity/100:k.backdropOpacity:.7,ao=((G,ut)=>{if(!G||G==="transparent")return"transparent";if(G.startsWith("rgba"))return G;if(G.startsWith("rgb"))return G.replace("rgb","rgba").replace(")",`, ${ut})`);if(G.startsWith("#")){let zt=G.slice(1);if(zt.length===3&&(zt=zt.split("").map(Vt=>Vt+Vt).join("")),zt.length===6){let Vt=parseInt(zt.slice(0,2),16),ct=parseInt(zt.slice(2,4),16),re=parseInt(zt.slice(4,6),16);return`rgba(${Vt}, ${ct}, ${re}, ${ut})`}}return G})(B.backdrop||"#000000",so),Qt=()=>{b(!0);let G=w.link;try{let ut=w._id||w.id||void 0;L?.id&&rt("clicked",L.id,{tooltip_id:ut})}catch{}s<v.length-1?(l(ut=>ut+1),G&&window.open(G,"_blank")):(d(!0),G&&window.open(G,"_blank"))},ie=()=>{b(!0),ge&&(s<v.length-1?l(G=>G+1):d(!0))},fe=w?.styling?.appearance?.highlight?.radius??w?.styling?.appearance?.radius,me=0;if(typeof fe=="number"&&fe>0)me=fe;else if(typeof fe=="string"&&fe!=="")me=parseInt(fe,10)||0;else if(y&&typeof window<"u")try{let G=y,ut=window.getComputedStyle(G);if(ut.borderRadius&&ut.borderRadius!=="0px")me=parseFloat(ut.borderRadius)||0;else if(G.firstElementChild){let zt=window.getComputedStyle(G.firstElementChild);zt.borderRadius&&zt.borderRadius!=="0px"&&(me=parseFloat(zt.borderRadius)||0)}}catch{}return Ro("div",{style:{position:"relative",zIndex:99999},children:[ge&&S&&Ro("svg",{style:{position:"fixed",top:0,left:0,width:"100vw",height:"100vh",pointerEvents:"none",zIndex:1e4},children:[Yt("defs",{children:Ro("mask",{id:"as-spotlight-mask",children:[Yt("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:"white"}),Yt("rect",{x:S.left,y:S.top,width:S.width,height:S.height,rx:me,ry:me,fill:"black"})]})}),Yt("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:ao,mask:"url(#as-spotlight-mask)",style:{pointerEvents:"none",cursor:"default"}})]}),ge&&!S&&Yt("div",{style:{position:"fixed",top:0,left:0,right:0,bottom:0,backgroundColor:ao,zIndex:1e4},onClick:ie}),Ro("div",{ref:G=>{m.current=G,V(G)},style:{position:"fixed",top:Kt,left:Tt,zIndex:99999,backgroundColor:B.tooltip||"#FE6B35",padding:M?0:Da(k.padding),borderRadius:_a(k.cornerRadius,k.radius),boxShadow:"0 4px 12px rgba(0,0,0,0.15)",width:M?a:k.width?Math.min(k.width,nt-J*2):"auto",height:M?f:void 0,maxWidth:Math.max(160,nt-J*2),minWidth:M?void 0:Math.min(200,nt-J*2),boxSizing:"border-box",transition:"top 0.2s ease, left 0.2s ease",cursor:"default"},children:[Yt("div",{style:{position:"absolute",width:0,height:0,borderStyle:"solid",...x==="left"&&{left:-q,top:Math.max(12,Math.min(C.height-U*2-12,et+S.height/2-Kt-U)),borderWidth:`${U}px ${q}px ${U}px 0`,borderColor:`transparent ${B.arrow||B.tooltip||"#FE6B35"} transparent transparent`},...x==="right"&&{right:-q,top:Math.max(12,Math.min(C.height-U*2-12,et+S.height/2-Kt-U)),borderWidth:`${U}px 0 ${U}px ${q}px`,borderColor:`transparent transparent transparent ${B.arrow||B.tooltip||"#FE6B35"}`},...x==="top"&&{top:-q,left:Math.max(12,Math.min(C.width-U*2-12,X+S.width/2-Tt-U)),borderWidth:`0 ${U}px ${q}px ${U}px`,borderColor:`transparent transparent ${B.arrow||B.tooltip||"#FE6B35"} transparent`},...x==="bottom"&&{bottom:-q,left:Math.max(12,Math.min(C.width-U*2-12,X+S.width/2-Tt-U)),borderWidth:`${q}px ${U}px 0 ${U}px`,borderColor:`${B.arrow||B.tooltip||"#FE6B35"} transparent transparent transparent`}}}),w.url&&(M?Yt("div",{onClick:Qt,style:{width:"100%",height:"100%",overflow:"hidden",borderRadius:`${k.cornerRadius?.topLeft??12}px ${k.cornerRadius?.topRight??12}px ${k.cornerRadius?.bottomRight??12}px ${k.cornerRadius?.bottomLeft??12}px`,cursor:"pointer"},children:Yt("img",{src:w.url,alt:"tooltip media",style:{width:"100%",height:"100%",display:"block",objectFit:"cover",cursor:"pointer"}})}):Yt("img",{src:w.url,alt:"tooltip media",onClick:Qt,style:{width:"100%",borderRadius:6,marginBottom:8,display:"block",objectFit:"cover",cursor:"pointer"}})),(w.titleText||w.subtitleText||w.ctaText)&&Ro("div",{style:M?{padding:`${k.padding?.top??8}px ${k.padding?.right??8}px ${k.padding?.bottom??8}px ${k.padding?.left??8}px`}:void 0,children:[w.titleText&&Yt("div",{style:{color:T.title?.color||"#ffffff",fontFamily:st(T.title?.fontFamily)||"Arial",fontSize:T.title?.fontSize||14,textAlign:T.title?.textAlign||"center",marginBottom:T.title?.margin?.bottom??4,marginTop:T.title?.margin?.top??0,marginLeft:T.title?.margin?.left??0,marginRight:T.title?.margin?.right??0,fontWeight:T.title?.fontDecoration?.includes("bold")?"bold":600,fontStyle:T.title?.fontDecoration?.includes("italic")?"italic":"normal",textDecoration:T.title?.fontDecoration?.includes("underline")?"underline":"none"},children:w.titleText}),w.subtitleText&&Yt("div",{style:{color:T.subTitle?.color||"#ffffff",fontFamily:st(T.subTitle?.fontFamily)||"Arial",fontSize:T.subTitle?.fontSize||12,textAlign:T.subTitle?.textAlign||"center",marginBottom:T.subTitle?.margin?.bottom??8,marginTop:T.subTitle?.margin?.top??0,marginLeft:T.subTitle?.margin?.left??0,marginRight:T.subTitle?.margin?.right??0,fontWeight:T.subTitle?.fontDecoration?.includes("bold")?"bold":"normal",fontStyle:T.subTitle?.fontDecoration?.includes("italic")?"italic":"normal",textDecoration:T.subTitle?.fontDecoration?.includes("underline")?"underline":"none"},children:w.subtitleText}),w.ctaText&&Yt("div",{style:{display:"flex",justifyContent:H.alignment==="right"?"flex-end":H.alignment==="left"?"flex-start":"center",marginTop:8},children:Yt("button",{onClick:Qt,style:{width:H.ctaFullWidth?"100%":H.ctaWidth||"auto",height:H.height||35,background:H.backgroundColor||"#F7921C",color:r.color||"#ffffff",border:`${H.borderWidth||0}px solid ${H.borderColor||"transparent"}`,borderRadius:`${Y.topLeft??7}px ${Y.topRight??7}px ${Y.bottomRight??7}px ${Y.bottomLeft??7}px`,fontSize:r.fontSize||14,fontFamily:st(r.fontFamily)||"Arial",fontWeight:r.fontDecoration?.includes("bold")?"bold":"normal",fontStyle:r.fontDecoration?.includes("italic")?"italic":"normal",textDecoration:r.fontDecoration?.includes("underline")?"underline":"none",cursor:"pointer",padding:"0 12px",display:"inline-flex",alignItems:"center",justifyContent:"center"},children:w.ctaText})})]})]})]})},$a=Wa;import{useEffect as Na,useState as Oa,useRef as ja}from"react";yt();import{Fragment as Ha,jsx as ue,jsxs as ri}from"react/jsx-runtime";var qa=()=>{let t=At("BTS"),e=P(g=>g.campaigns),o=P(g=>g.allCampaigns),n=P(g=>g.currentScreen),i=t??(()=>{let g=(n||"").trim().toLowerCase(),b=[...e||[],...o||[]].find(m=>{if(!m||m.campaign_type!=="BTS")return!1;let E=!!(m.trigger_event??m.trigger);if(!(m.display_trigger!==!1&&!E))return!1;let D=(m.screen||"").trim().toLowerCase();return!D||D===g});if(b)try{return Nt(b)}catch{return b}})(),s=P(g=>g.isVisible),[l,c]=Oa(!1),d=ja(null);Na(()=>{i?.id&&d.current!==i.id&&(d.current=i.id,c(!1),rt("viewed",i.id))},[i?.id]);let S=g=>{try{let b=P.getState(),E=(b.trackedEvents||[]).filter(O=>O!==g);b.setTrackedEvents(E)}catch{}};if(!i||l||!s)return null;let{details:p}=i,u=[...p.elements||[]].sort((g,b)=>(g.order||0)-(b.order||0)),C=p.backdropOpacity??.5;C>1&&(C=C/100);let h=g=>{switch(g.type){case"image":{let b={width:"100%",display:"block",objectFit:"contain",backgroundColor:g.imageBackgroundColor||"transparent",paddingBottom:g.paddingBottom??0,paddingLeft:g.paddingLeft??0,paddingRight:g.paddingRight??0,paddingTop:g.paddingTop??0,cursor:g.imageLink?"pointer":"default"};return ue("div",{style:{textAlign:g.alignment||"left",width:"100%"},children:g.url&&ue("img",{src:g.url,alt:"",style:b,onClick:()=>{if(g.imageLink){i?.id&&rt("clicked",i.id);try{let m=String(g.imageLink||"").trim();if(m&&!m.startsWith("http")&&Pt(m))return}catch(m){console.warn("revealCampaignFromLink error",m)}try{window.open(g.imageLink,"_blank")}catch{}}}})},g.id)}case"cta":{let b=g.cta||{},m=b.container||{},E=b.cornerRadius||{},O=b.margin||{},D=b.text||{};return ue("div",{style:{display:"flex",justifyContent:m.alignment==="center"?"center":m.alignment==="right"?"flex-end":"flex-start",width:"100%",marginTop:O.top??0,marginBottom:O.bottom??0,marginLeft:O.left??0,marginRight:O.right??0},children:ue("button",{style:{width:m.ctaFullWidth?"100%":m.ctaWidth||"auto",height:m.height||45,backgroundColor:m.ctaBoxColor||m.backgroundColor||"#FE6B35",color:D.color||"#ffffff",border:`${m.borderWidth||0}px solid ${m.borderColor||"transparent"}`,borderRadius:`${E.topLeft??12}px ${E.topRight??12}px ${E.bottomRight??12}px ${E.bottomLeft??12}px`,fontSize:D.fontSize||14,fontFamily:st(D.fontFamily)||"Arial",fontWeight:D.fontDecoration?.includes("bold")?"bold":"normal",fontStyle:D.fontDecoration?.includes("italic")?"italic":"normal",textDecoration:D.fontDecoration?.includes("underline")?"underline":"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",padding:"0 16px"},onClick:()=>{let L=g.ctaLink||g.url;if(L){i?.id&&rt("clicked",i.id);try{let v=String(L||"").trim();if(v&&!v.startsWith("http")&&Pt(v))return}catch(v){console.warn("revealCampaignFromLink error",v)}try{window.open(L,"_blank")}catch{}}},children:g.ctaText||"Button"})},g.id)}case"body":{let b=g.titleFontStyle||{},m=g.descriptionFontStyle||{};return ri("div",{style:{width:"100%",backgroundColor:g.bodyBackgroundColor||"transparent",marginTop:g.marginTop??0,marginBottom:g.marginBottom??20,marginLeft:g.marginLeft??4,marginRight:g.marginRight??4},children:[g.titleText&&ue("div",{style:{color:b.colour||"#000000",fontSize:b.fontSize?`${b.fontSize}px`:g.titleFontSize?`${g.titleFontSize}px`:"16px",fontFamily:st(b.fontFamily)||"inherit",textAlign:b.alignment||"left",lineHeight:g.titleLineHeight||1.2,fontWeight:b.decoration?.includes("bold")?"bold":"600",fontStyle:b.decoration?.includes("italic")?"italic":"normal",textDecoration:b.decoration?.includes("underline")?"underline":"none",marginBottom:g.spacingBetweenTitleDesc??4},children:g.titleText}),g.descriptionText&&ue("div",{style:{color:m.colour||"#000000",fontSize:m.fontSize?`${m.fontSize}px`:g.descriptionFontSize?`${g.descriptionFontSize}px`:"14px",fontFamily:st(m.fontFamily)||"inherit",textAlign:m.alignment||"left",lineHeight:g.descriptionLineHeight||1.5,fontWeight:m.decoration?.includes("bold")?"bold":"normal",fontStyle:m.decoration?.includes("italic")?"italic":"normal",textDecoration:m.decoration?.includes("underline")?"underline":"none"},children:g.descriptionText})]},g.id)}default:return null}};return ri(Ha,{children:[ue("div",{style:{position:"fixed",top:0,left:0,right:0,bottom:0,backgroundColor:p.backdropColor||"rgba(0,0,0,0.5)",opacity:C,zIndex:999998,transition:"opacity 0.3s ease"},onClick:()=>{i?.id&&S(`viaAppStorys${i.id}`),c(!0)}}),ri("div",{style:{position:"fixed",bottom:0,left:"50%",transform:"translateX(-50%)",width:"100%",maxWidth:"500px",backgroundColor:p.backgroundColor||"#FFFFFF",borderTopLeftRadius:`${p.cornerRadius?.topLeft??16}px`,borderTopRightRadius:`${p.cornerRadius?.topRight??16}px`,borderBottomLeftRadius:`${p.cornerRadius?.bottomLeft??0}px`,borderBottomRightRadius:`${p.cornerRadius?.bottomRight??0}px`,zIndex:999999,padding:"24px 16px",boxShadow:"0 -4px 16px rgba(0,0,0,0.15)",maxHeight:"85vh",overflowY:"auto",display:"flex",flexDirection:"column",alignItems:"center",transition:"transform 0.3s ease-out"},children:[ue("div",{style:{width:"40px",height:"5px",backgroundColor:"#E0E0E0",borderRadius:"2.5px",marginBottom:"16px",cursor:"pointer"},onClick:()=>c(!0)}),p.crossButton?.enabled&&ue(Dt,{config:p.crossButton,onPress:()=>{i?.id&&S(`viaAppStorys${i.id}`),c(!0)},style:{top:p.crossButton?.margin?.top??12,right:p.crossButton?.margin?.right??12}}),ue("div",{style:{width:"100%",display:"flex",flexDirection:"column",gap:"12px"},children:u.map(h)})]})]})};import{useEffect as sn,useMemo as Va,useState as pe,useRef as Ua}from"react";yt();import*as Ke from"lottie-react";import{Fragment as di,jsx as bt,jsxs as Fo}from"react/jsx-runtime";var Ya=Ke.default?.default??Ke.default??Ke.Lottie??Ke,jr=5,si=3;function rn(t){if(t!=null)return`${t}px`}function Ut(t,e="0px"){return t==null?e:`${t}px`}function Je(t){return{marginTop:rn(t?.top),marginRight:rn(t?.right),marginBottom:rn(t?.bottom),marginLeft:rn(t?.left)}}function ci(t){return st(t)}function Xe(t){if(!t)return{};let e={};t.color&&(e.color=t.color),t.fontSize&&(e.fontSize=t.fontSize);let o=ci(t.fontFamily);return o&&(e.fontFamily=o),t.textAlign&&(e.textAlign=t.textAlign),t.fontDecoration?.includes("bold")&&(e.fontWeight="bold"),t.fontDecoration?.includes("italic")&&(e.fontStyle="italic"),t.fontDecoration?.includes("underline")&&(e.textDecoration="underline"),e}function an(t){return`${t?.topLeft??8}px ${t?.topRight??8}px ${t?.bottomRight??8}px ${t?.bottomLeft??8}px`}function ai(t){return t==="right"?"flex-end":t==="left"?"flex-start":"center"}function Ga(t){let e=t.styling?.rating?.ratingType;return e==="number"||e==="emoji"||e==="star"?e:"star"}function Qa(t){let e=t.styling?.rating?.emoji,o=[];Array.isArray(e)?o=e:e&&typeof e=="object"?Array.isArray(e.values)?o=e.values:o=Object.values(e):typeof e=="string"&&e.trim()&&(o=e.split(","));let n=o.map(i=>{if(typeof i=="string")return i.trim();if(i&&typeof i=="object"){let s=i.emoji||i.value||i.text||i.icon||i.name||"";if(typeof s=="string")return s.trim()}return""}).filter(Boolean);return n.length>0?n:["\u{1F620}","\u{1F615}","\u{1F610}","\u{1F642}","\u{1F60D}"]}function Xa(t){return Array.from({length:5},(e,o)=>o+1)}function li(t){if(typeof t=="number"&&Number.isFinite(t)&&t>=0)return t;if(typeof t=="string"&&t.trim().length>0){let e=Number(t);if(Number.isFinite(e)&&e>=0)return e}}function Ja(t){let e=t.styling?.rating||void 0,o=[e?.numberSpacing,e?.numberGap,e?.number_spacing,e?.number_gap,e?.spacingBetweenNumbers,e?.spaceBetweenNumbers,e?.numberOptionsSpacing,e?.spacing];for(let i of o){let s=li(i);if(s!=null)return s}let n=e?.number;if(n&&typeof n=="object"){let i=n,s=[i.spacing,i.gap,i.optionsSpacing,i.numberSpacing,i.numberGap];for(let l of s){let c=li(l);if(c!=null)return c}}return 8}var Ka=({fill:t,stroke:e})=>bt("svg",{viewBox:"0 0 24 24",width:"22",height:"22","aria-hidden":!0,children:bt("path",{d:"M12 2.25l2.91 5.89 6.5.95-4.7 4.58 1.11 6.46L12 17.03 6.18 20.13l1.11-6.46-4.7-4.58 6.5-.95L12 2.25z",fill:t,stroke:e,strokeWidth:"1.4",strokeLinejoin:"round"})}),Za=({details:t,appearance:e,rating:o,selectedOptions:n,comments:i,isHighRating:s,feedbackOptions:l,onRate:c,onToggleOption:d,onCommentChange:S,onInlineSubmit:p,canSubmit:y,isMobile:u})=>{let C=t.styling||{},h=C.feedbackPage||{},g=C.rating||{},b=C.initialFeedback||{},m=h.submitButton?.cta,E=Ga(t),O=E==="number"?Xa(t):[],D=E==="emoji"?Qa(t):[],L=E==="number"?Ja(t):8,v=E==="number"?L:g.spacing??8,w=u?"clamp(32px, 11vw, 44px)":"44px",_=u?"clamp(16px, 4.5vw, 22px)":22,$=ai(g.alignment),V=an(g.cornerRadius),A=s?g.star?.high:g.star?.low,T=typeof g.number=="object"&&g.number?g.number:void 0,k=s?T?.high:T?.low,B=m?.container?.ctaFullWidth?"100%":Math.max(140,li(m?.container?.ctaWidth)??180);return Fo(di,{children:[bt("div",{style:Je(b.title?.margin),children:bt("div",{style:{...Xe(b.title?.textStyle),color:b.title?.textStyle?.color||"#101828",fontSize:b.title?.textStyle?.fontSize||20,lineHeight:1.3,wordBreak:"break-word",overflowWrap:"break-word",paddingRight:C.crossButton?.enabled?(C.crossButton.size??30)+(C.crossButton.margin?.right??4)+4:0},children:t.title||"How was your experience?"})}),bt("div",{style:Je(b.subtitle?.margin),children:bt("div",{style:{...Xe(b.subtitle?.textStyle),color:b.subtitle?.textStyle?.color||"#4b5563",fontSize:b.subtitle?.textStyle?.fontSize||14,lineHeight:1.4,wordBreak:"break-word",overflowWrap:"break-word"},children:t.description_text||"Your feedback helps us improve your experience."})}),Fo("div",{style:{marginTop:8,display:"flex",justifyContent:$,gap:v,flexWrap:"wrap"},children:[E==="star"&&Array.from({length:jr},(W,H)=>{let Y=H+1,r=Y<=o,M=r?A?.stylingContainer:g.star?.unselected?.stylingContainer,a=r?A?.stylingStar:g.star?.unselected?.stylingStar;return bt("button",{onClick:()=>c(Y),style:{border:`${M?.borderWidth??1}px solid ${M?.border||"#d1d5db"}`,background:M?.background||"#ffffff",borderRadius:V,width:w,height:w,display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0,flexShrink:0},"aria-label":`Rate ${Y} out of ${jr}`,children:bt(Ka,{fill:a?.background||(r?"#f59e0b":"#e5e7eb"),stroke:a?.border||(r?"#d97706":"#9ca3af")})},Y)}),E==="number"&&O.map((W,H)=>{let Y=W===o,r=Y?k?.stylingContainer:T?.unselected?.stylingContainer,M=Y?T?.stylingNumber:T?.unselected?.stylingNumber;return bt("button",{onClick:()=>c(W),style:{border:`${r?.borderWidth??1}px solid ${r?.border||(Y?"#1d4ed8":"#d1d5db")}`,background:r?.fill||r?.background||(Y?"#dbeafe":"#ffffff"),color:M?.text||(Y?"#1d4ed8":"#111827"),fontSize:M?.textSize||void 0,borderRadius:V,minWidth:w,height:w,padding:"0 10px",display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:"pointer",fontWeight:600,flexShrink:0},"aria-label":`Rate ${W}`,children:W},`${W}-${H}`)}),E==="emoji"&&D.map((W,H)=>{let Y=H+1,r=Y===o,M=g.emoji,f=(r?M?.selected:M?.unselected)?.stylingContainer;return bt("button",{onClick:()=>c(Y),style:{border:`${f?.borderWidth??1}px solid ${f?.border||(r?"#1d4ed8":"#d1d5db")}`,background:f?.fill||f?.background||(r?"#dbeafe":"#ffffff"),borderRadius:V,width:w,height:w,display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:"pointer",fontSize:_,flexShrink:0},"aria-label":`Emoji rating ${H+1}`,children:W},`${W}-${H}`)})]}),o>0&&bt("div",{style:{marginTop:6,textAlign:"center",color:"#374151",fontSize:14},children:s?t.highStarText||g.highRatingSubtitle:t.lowStarText||g.lowRatingSubtitle}),o>0&&o<=si&&Fo(di,{children:[l.length>0&&bt("div",{style:{...Je(h.options?.margin),display:"flex",flexDirection:"column",alignItems:"stretch",gap:h.options?.optionsSpacing??8,width:"100%"},children:l.map(W=>{let Y=n.includes(W)?h.options?.selectedOptions:h.options?.nonSelectedOptions;return bt("button",{onClick:()=>d(W),style:{border:`${Y?.borderWidth??1}px solid ${Y?.colors?.border||"#d1d5db"}`,background:Y?.colors?.background||"#f9fafb",color:Y?.colors?.text||"#111827",width:"100%",height:h.options?.optionsHeight||38,borderRadius:an(h.options?.cornerRadius),padding:"0 14px",cursor:"pointer",textAlign:"center",...Xe(Y?.textStyle)},children:W},W)})}),h.additionalComments?.enabled!==!1&&bt("textarea",{value:i,onChange:W=>S(W.target.value),placeholder:h.additionalComments?.placeholder||"Tell us what we can improve",style:{width:"100%",boxSizing:"border-box",minHeight:56,height:56,maxHeight:64,marginTop:8,resize:"none",overflowY:"auto",border:`${h.additionalComments?.borderWidth??1}px solid ${h.additionalComments?.colors?.border||"#d1d5db"}`,background:h.additionalComments?.colors?.background||"#ffffff",color:h.additionalComments?.colors?.text||"#111827",borderRadius:8,padding:"12px",...Xe(h.additionalComments?.textStyle)}}),bt("div",{style:{position:"sticky",bottom:0,marginTop:m?.margin?.top??8,marginBottom:m?.margin?.bottom??0,marginLeft:m?.margin?.left??0,marginRight:m?.margin?.right??0,paddingTop:6,paddingBottom:6,background:e?.backgroundColor||"#ffffff",display:"flex",justifyContent:ai(m?.container?.alignment)},children:bt("button",{onClick:()=>p(),disabled:!y,style:{width:B,maxWidth:"100%",height:Number(m?.container?.height)||40,border:`${m?.container?.borderWidth??0}px solid ${m?.container?.borderColor||"transparent"}`,background:m?.container?.backgroundColor||"#6848b1",color:m?.text?.color||"#ffffff",borderRadius:an(m?.cornerRadius),fontFamily:ci(m?.text?.fontFamily),fontSize:Number(m?.text?.fontSize)||14,fontWeight:m?.text?.fontDecoration?.includes("bold")?"bold":600,cursor:y?"pointer":"not-allowed",opacity:y?1:.65,padding:"0 12px",boxSizing:"border-box"},children:h.submitButton?.text||"Submit"})})]})]})},tl=({details:t,isHighRating:e,onDone:o})=>{let n=t.styling||{},i=n.thankyouPage||{},s=n.rating||{},l=ai(i.doneButton?.cta?.container?.alignment),[c,d]=pe(null),S=t.thankyouImage?.endsWith(".json");return sn(()=>{S&&t.thankyouImage&&fetch(t.thankyouImage).then(p=>p.json()).then(p=>d(p)).catch(p=>console.error("Error loading Lottie:",p))},[t.thankyouImage,S]),Fo(di,{children:[t.thankyouImage&&bt("div",{style:{display:"flex",justifyContent:"center",...Je(i.imageStyle?.margin)},children:S?c?bt(Ya,{animationData:c,loop:!0,style:{width:i.imageStyle?.width||80,height:i.imageStyle?.height||80}}):bt("div",{style:{width:i.imageStyle?.width||80,height:i.imageStyle?.height||80}}):bt("img",{src:t.thankyouImage,alt:"thank you",style:{width:i.imageStyle?.width||80,height:i.imageStyle?.height||80,objectFit:"cover",borderRadius:8}})}),bt("div",{style:Je(i.title?.margin),children:bt("div",{style:{color:"#111827",fontSize:20,lineHeight:1.3,...Xe(i.title?.textStyle),wordBreak:"break-word",overflowWrap:"break-word"},children:t.thankyouText||(e?s.highRatingTitle:s.lowRatingTitle)||"Thank you for your feedback"})}),bt("div",{style:Je(i.subtitle?.margin),children:bt("div",{style:{color:"#4b5563",fontSize:14,lineHeight:1.4,...Xe(i.subtitle?.textStyle),wordBreak:"break-word",overflowWrap:"break-word"},children:t.thankyouDescription||(e?s.highRatingSubtitle:s.lowRatingSubtitle)||"We appreciate your time."})}),bt("div",{style:{marginTop:i.doneButton?.cta?.margin?.top??14,marginBottom:i.doneButton?.cta?.margin?.bottom??0,marginLeft:i.doneButton?.cta?.margin?.left??0,marginRight:i.doneButton?.cta?.margin?.right??0,display:"flex",justifyContent:l},children:bt("button",{onClick:o,style:{width:i.doneButton?.cta?.container?.ctaFullWidth?"100%":i.doneButton?.cta?.container?.ctaWidth||"auto",height:i.doneButton?.cta?.container?.height||45,border:`${i.doneButton?.cta?.container?.borderWidth??0}px solid ${i.doneButton?.cta?.container?.borderColor||"transparent"}`,background:i.doneButton?.cta?.container?.backgroundColor||"#111827",color:i.doneButton?.cta?.text?.color||"#ffffff",borderRadius:an(i.doneButton?.cta?.cornerRadius),fontFamily:ci(i.doneButton?.cta?.text?.fontFamily),fontSize:i.doneButton?.cta?.text?.fontSize||16,fontWeight:i.doneButton?.cta?.text?.fontDecoration?.includes("bold")?"bold":"normal",cursor:"pointer",padding:"0 16px",boxSizing:"border-box"},children:e?t.highStarText||i.doneButton?.text||"Rate Now":t.lowStarText||i.doneButton?.text||"Done"})})]})},el=()=>{let t=At("CSAT"),e=P(x=>x.isVisible),o=P(x=>x.campaigns),n=P(x=>x.allCampaigns),i=P(x=>x.currentScreen),[s,l]=pe(typeof window<"u"?window.innerWidth:1024);sn(()=>{if(typeof window>"u")return;let x=()=>l(window.innerWidth);return window.addEventListener("resize",x),()=>window.removeEventListener("resize",x)},[]);let c=s<768,d=t??(()=>{let x=(i||"").trim().toLowerCase(),z=[...o||[],...n||[]].find(U=>{if(!U||U.campaign_type!=="CSAT")return!1;let et=!!(U.trigger_event??U.trigger);if(!(U.display_trigger!==!1&&!et))return!1;let q=(U.screen||"").trim().toLowerCase();return!q||q===x});if(z)try{return Nt(z)}catch{return z}})(),[S,p]=pe(!1),[y,u]=pe(!1),[C,h]=pe(!1),[g,b]=pe(!1),[m,E]=pe(0),[O,D]=pe([]),[L,v]=pe(""),[w,_]=pe(!1),$=Ua(null);sn(()=>{if(!d?.id||$.current===d.id)return;$.current=d.id,p(!1),u(!1),h(!1),b(!1),E(0),D([]),v(""),_(!1);let x=d.details?.styling?.appearance?.displayDelay??0,z=globalThis.setTimeout(()=>{u(!0),rt("viewed",d.id)},Math.max(0,x)*1e3);return()=>globalThis.clearTimeout(z)},[d?.id]),sn(()=>{if(y){let x=setTimeout(()=>h(!0),30);return()=>clearTimeout(x)}},[y]);let V=Va(()=>{let x=d?.details?.feedback_option||{};return Object.keys(x).sort((z,U)=>z.localeCompare(U)).map(z=>typeof x[z]=="string"?x[z].trim():x[z]).filter(Boolean)},[d]);if(!d||!e||S||!y)return null;let A=d.details,T=A.styling||{},k=T.appearance||{},B=m>si,W=x=>{D(z=>z.includes(x)?z.filter(U=>U!==x):[...z,x])},H=async x=>{let z=x?.rating??m;if(z<1)return;_(!0);let U=d.id,et=(x?.options??O)[0]||"",X=x?.comments??L??"";rt("csat captured",U,{starCount:z,selectedOption:et,additionalComments:X})},Y=x=>{if(E(x),x>si){D([]),v("");let z=d?.id;setTimeout(()=>{_(!0);try{rt("csat captured",z,{starCount:x,selectedOption:"",additionalComments:""})}catch(U){console.warn("Error sending csat captured",U)}},1e3)}},r=async()=>{b(!0);try{let x=d?.id;await rt("csat closed",x)}catch(x){console.warn("Error sending csat closed",x)}finally{setTimeout(()=>{p(!0)},300)}},M=()=>{if(B&&A.link){let x=d&&d.id||void 0;try{x&&rt("clicked",x)}catch{}try{let z=String(A.link||"").trim();if(z&&!z.startsWith("http")&&Pt(z)){b(!0),setTimeout(()=>{p(!0)},300);return}}catch(z){console.warn("revealCampaignFromLink error",z)}try{globalThis.open(A.link,"_blank")}catch{}}b(!0),setTimeout(()=>{p(!0)},300)},a=c?{position:"fixed",inset:0,zIndex:999999,display:"flex",justifyContent:"center",alignItems:"flex-end",paddingLeft:Ut(k.margin?.left,"0px"),paddingRight:Ut(k.margin?.right,"0px"),pointerEvents:"none"}:{position:"fixed",inset:0,zIndex:999999,display:"flex",justifyContent:"flex-end",alignItems:"flex-end",paddingTop:Ut(k.margin?.top),paddingRight:Ut(k.margin?.right,"20px"),paddingBottom:Ut(k.margin?.bottom,"20px"),paddingLeft:Ut(k.margin?.left,"20px"),pointerEvents:"none"},f=c?{position:"relative",width:"100%",maxWidth:"none",maxHeight:"85vh",overflow:"visible",backgroundColor:k.backgroundColor||"#ffffff",borderTopLeftRadius:`${k.borderRadius??16}px`,borderTopRightRadius:`${k.borderRadius??16}px`,borderBottomLeftRadius:0,borderBottomRightRadius:0,boxSizing:"border-box",paddingTop:Ut(k.padding?.top,"12px"),paddingRight:Ut(k.padding?.right,"16px"),paddingBottom:`max(${Ut(k.padding?.bottom,"16px")}, env(safe-area-inset-bottom, 16px))`,paddingLeft:Ut(k.padding?.left,"16px"),pointerEvents:"auto",boxShadow:"0 -8px 32px rgba(0, 0, 0, 0.20)",display:"flex",flexDirection:"column",transform:g||!C?"translateY(100%)":"translateY(0)",transition:"transform 0.3s cubic-bezier(0.25, 1, 0.5, 1)"}:{position:"relative",width:"min(450px, 92vw)",maxHeight:"85vh",overflow:"visible",backgroundColor:k.backgroundColor||"#ffffff",borderRadius:`${k.borderRadius??12}px`,boxSizing:"border-box",paddingTop:Ut(k.padding?.top,"8px"),paddingRight:Ut(k.padding?.right,"12px"),paddingBottom:Ut(k.padding?.bottom,"8px"),paddingLeft:Ut(k.padding?.left,"12px"),pointerEvents:"auto",boxShadow:"0 14px 36px rgba(0, 0, 0, 0.25)",display:"flex",flexDirection:"column",transform:g||!C?"translateY(100%)":"translateY(0)",transition:"transform 0.3s cubic-bezier(0.25, 1, 0.5, 1)"};return bt("div",{style:a,children:Fo("div",{style:f,children:[bt("style",{children:`
82
129
  .appstorys-csat-scroll {
83
130
  scrollbar-width: none; /* Firefox */
84
131
  -ms-overflow-style: none; /* IE/Edge */
@@ -88,15 +135,31 @@ var Yi=Object.defineProperty;var Nt=(t,e)=>()=>(t&&(e=t(t=0)),e);var Qi=(t,e)=>{
88
135
  height: 0;
89
136
  display: none; /* Chrome/Safari */
90
137
  }
91
- `}),z.crossButton?.enabled&&Z(Lt,{config:z.crossButton,onPress:()=>a(!0),style:{top:z.crossButton?.margin?.top??10,right:z.crossButton?.margin?.right??10}}),Z("div",{className:"appstorys-csat-scroll",style:{flex:1,minHeight:0,overflowY:"auto",paddingBottom:4},children:h?Z(Rs,{details:I,isHighRating:d,onDone:L}):Z(ks,{details:I,rating:x,selectedOptions:g,comments:f,isHighRating:d,feedbackOptions:w,onRate:B,onToggleOption:p,onCommentChange:b,onInlineSubmit:M,canSubmit:x>=1,appearance:R})})]})})},Fs=Ts;import{useEffect as zi,useMemo as Ei,useState as Yt}from"react";K();import{Fragment as Li,jsx as rt,jsxs as we}from"react/jsx-runtime";function Je(t){if(t!=null)return`${t}px`}function nn(t){return ct(t)}function se(t){return t?{color:t.color,fontSize:t.fontSize,fontFamily:nn(t.fontFamily),textAlign:t.textAlign,fontWeight:t.fontDecoration?.includes("bold")?"bold":void 0,fontStyle:t.fontDecoration?.includes("italic")?"italic":void 0,textDecoration:t.fontDecoration?.includes("underline")?"underline":void 0}:{}}function Xe(t){return{marginTop:Je(t?.top),marginRight:Je(t?.right),marginBottom:Je(t?.bottom),marginLeft:Je(t?.left)}}function Ke(t){return`${t?.topLeft??12}px ${t?.topRight??12}px ${t?.bottomRight??t?.topRight??12}px ${t?.bottomLeft??t?.topLeft??12}px`}function Pi(t){return t==="right"?"flex-end":t==="left"?"flex-start":"center"}function ve(t){return Math.max(0,Math.min(1,t))}function Is(t,e){let o=(t||"").trim().replace("#","");if(o.length===3){let i=Number.parseInt(o[0]+o[0],16),n=Number.parseInt(o[1]+o[1],16),r=Number.parseInt(o[2]+o[2],16);return`rgba(${i}, ${n}, ${r}, ${ve(e)})`}if(o.length===6){let i=Number.parseInt(o.slice(0,2),16),n=Number.parseInt(o.slice(2,4),16),r=Number.parseInt(o.slice(4,6),16);return`rgba(${i}, ${n}, ${r}, ${ve(e)})`}return`rgba(0, 0, 0, ${ve(e)})`}function zs(t){if(t==null)return .4;let e=Number(t);return Number.isFinite(e)?e>1?ve(e/100):ve(e):.4}function Bi(t){return[...t.slides||[]].sort((o,i)=>(o.order??0)-(i.order??0))}function Bs(t){let e=t?.options||{},o=Object.keys(e),i=n=>{let r=/(\d+)/.exec(n);if(!r)return;let s=Number(r[1]);return Number.isFinite(s)?s:void 0};return o.sort((n,r)=>{let s=i(n),a=i(r);return s!=null&&a!=null?s-a:s!=null?-1:a!=null?1:n.localeCompare(r)}),o.map(n=>e[n]).filter(n=>typeof n=="string"&&n.trim().length>0)}function As(t,e){if(!t)return null;if(t==="alphabet"){let o="A".codePointAt(0)??65;return String.fromCodePoint(o+e%26)}return t==="number"?String(e+1):null}function Es(t){if(typeof t=="number"&&Number.isFinite(t)&&t>=0)return t;if(typeof t=="string"&&t.trim().length>0){let e=Number(t);if(Number.isFinite(e)&&e>=0)return e}}function Ai(t){return Es(t?.borderwidth)??1}var Ps=({details:t,slide:e,appearance:o,selectedOption:i,comment:n,onSelectOption:r,onCommentChange:s,onSubmit:a,canSubmit:c})=>{let u=t.styling||{},x=u.options||{},m=u.cta,g=Ei(()=>Bs(e),[e]),v=x.optionsSpacing??8,f=x.bulletSpacing??10,b=x.optionsHeight??44,h=Pi(m?.container?.alignment);return we(Li,{children:[rt("div",{style:Xe(u.title?.textStyle?.margin),children:rt("div",{style:{...se(u.title?.textStyle),color:u.title?.textStyle?.color||"#111827",fontSize:u.title?.textStyle?.fontSize||20,lineHeight:1.3,fontWeight:u.title?.textStyle?.fontDecoration?.includes("bold")?"bold":700},children:e.title||e.question||t.name||"Survey"})}),(e.subtitle||u.subtitle?.textStyle)&&rt("div",{style:Xe(u.subtitle?.textStyle?.margin),children:rt("div",{style:{...se(u.subtitle?.textStyle),color:u.subtitle?.textStyle?.color||"#6b7280",fontSize:u.subtitle?.textStyle?.fontSize||14,lineHeight:1.35},children:e.subtitle||""})}),g.length>0&&rt("div",{style:{marginTop:10,display:"flex",flexDirection:"column",gap:v},children:g.map((y,w)=>{let I=i===y,z=I?x.selectedOptions:x.nonSelectedOptions,R=Ai(z?.textStyle),d=As(x.optionListStyle,w);return we("button",{onClick:()=>r(y),style:{width:"100%",boxSizing:"border-box",height:b,borderRadius:Ke(x.cornerRadius),border:`${R}px solid ${z?.colors?.border||"#e5e7eb"}`,background:z?.colors?.background||"#ffffff",color:z?.colors?.text||"#111827",cursor:"pointer",display:"flex",alignItems:"center",gap:f,paddingLeft:14,paddingRight:14,textAlign:"left",...se(z?.textStyle)},"aria-pressed":I,children:[rt("span",{"aria-hidden":!0,style:{width:16,height:16,borderRadius:4,display:"inline-flex",alignItems:"center",justifyContent:"center",border:`1.5px solid ${z?.colors?.border||"#111827"}`,background:"#ffffff",flex:"0 0 auto",fontSize:11,fontWeight:700,color:z?.colors?.text||"#111827"},children:I?"\u2713":d||""}),rt("span",{style:{flex:1,minWidth:0},children:y})]},`${y}-${w}`)})}),e.additionalComment?.enabled&&rt("textarea",{value:n,onChange:y=>s(y.target.value),placeholder:e.additionalComment?.placeholder||"",style:{marginTop:10,width:"100%",boxSizing:"border-box",minHeight:72,resize:"none",overflowY:"auto",border:`${Ai(x.additionalComments?.textStyle)}px solid ${x.additionalComments?.colors?.border||"#e5e7eb"}`,background:x.additionalComments?.colors?.background||"#ffffff",color:x.additionalComments?.colors?.text||"#111827",borderRadius:10,padding:"12px",...se(x.additionalComments?.textStyle)}}),rt("div",{style:{position:"sticky",bottom:0,marginTop:12,paddingTop:10,paddingBottom:6,background:o?.backgroundColor||"#ffffff"},children:rt("div",{style:{marginTop:m?.margin?.top??0,marginBottom:m?.margin?.bottom??0,marginLeft:m?.margin?.left??0,marginRight:m?.margin?.right??0,display:"flex",justifyContent:h},children:rt("button",{onClick:a,disabled:!c,style:{width:m?.container?.ctaFullWidth?"100%":m?.container?.ctaWidth??"100%",height:m?.container?.height??44,border:`${m?.container?.borderWidth??0}px solid ${m?.container?.borderColor||"transparent"}`,background:m?.container?.backgroundColor||"#111827",color:m?.text?.color||"#ffffff",borderRadius:Ke(m?.cornerRadius),fontFamily:nn(m?.text?.fontFamily),fontSize:m?.text?.fontSize||14,fontWeight:m?.text?.fontDecoration?.includes("bold")?"bold":600,cursor:c?"pointer":"not-allowed",opacity:c?1:.6,padding:"0 16px"},children:e.submitButtonText||"Submit"})})})]})},Ls=({details:t,onDone:e})=>{let i=(t.styling||{}).thankyouPage||{},n=i.cta,r=Pi(n?.container?.alignment);return we(Li,{children:[t.thankYouImage&&rt("div",{style:{display:"flex",justifyContent:"center",marginTop:8},children:rt("img",{src:t.thankYouImage,alt:"thank you",style:{width:i.imageStyle?.width||80,height:i.imageStyle?.height||80,objectFit:"cover",borderRadius:10}})}),rt("div",{style:{...Xe(i.title?.textStyle?.margin)},children:rt("div",{style:{...se(i.title?.textStyle),color:i.title?.textStyle?.color||"#111827",fontSize:i.title?.textStyle?.fontSize||20,lineHeight:1.3,fontWeight:i.title?.textStyle?.fontDecoration?.includes("bold")?"bold":700},children:t.thankYouTitle||"Thank you"})}),rt("div",{style:{...Xe(i.subtitle?.textStyle?.margin)},children:rt("div",{style:{...se(i.subtitle?.textStyle),color:i.subtitle?.textStyle?.color||"#6b7280",fontSize:i.subtitle?.textStyle?.fontSize||14,lineHeight:1.35},children:t.thankYouText||""})}),(t.thankYouButtonText||n)&&rt("div",{style:{marginTop:n?.margin?.top??14,marginBottom:n?.margin?.bottom??0,marginLeft:n?.margin?.left??0,marginRight:n?.margin?.right??0,display:"flex",justifyContent:r},children:rt("button",{onClick:e,style:{width:n?.container?.ctaFullWidth?"100%":n?.container?.ctaWidth??"auto",height:n?.container?.height??40,border:`${n?.container?.borderWidth??0}px solid ${n?.container?.borderColor||"transparent"}`,background:n?.container?.backgroundColor||"#111827",color:n?.text?.color||"#ffffff",borderRadius:Ke(n?.cornerRadius),fontFamily:nn(n?.text?.fontFamily),fontSize:n?.text?.fontSize||14,fontWeight:n?.text?.fontDecoration?.includes("bold")?"bold":600,cursor:"pointer",padding:"0 16px"},children:t.thankYouButtonText||"Done"})})]})},Ds=()=>{let t=pt("SUR"),e=F(E=>E.isVisible),o=F(E=>E.campaigns),i=F(E=>E.allCampaigns),n=F(E=>E.currentScreen),r=t??(()=>{let E=(n||"").trim().toLowerCase(),$=[...o||[],...i||[]].find(D=>{if(!D||D.campaign_type!=="SUR")return!1;let k=!!(D.trigger_event??D.trigger);if(!(D.display_trigger!==!1&&!k))return!1;let O=(D.screen||"").trim().toLowerCase();return!O||O===E});if($)try{return yt($)}catch{return $}})(),[s,a]=Yt(!1),[c,u]=Yt(!1),[x,m]=Yt(0),[g,v]=Yt(null),[f,b]=Yt(""),[h,y]=Yt({}),[w,I]=Yt(!1);zi(()=>{if(!r)return;a(!1),u(!1),m(0),v(null),b(""),y({}),I(!1);let E=r.details?.styling?.appearance?.displayDelay??0,$=globalThis.setTimeout(()=>{u(!0);let D=r.details?.id,k=Bi(r.details),P=k.length>0?k[0].id:void 0;H("viewed",r.id,{survey_id:D,slide_id:P})},Math.max(0,E)*1e3);return()=>globalThis.clearTimeout($)},[r]);let z=Ei(()=>r?Bi(r.details):[],[r]),R=z[x];if(zi(()=>{if(!R)return;let E=h[R.id];v(E?.option??null),b(E?.comment??"")},[R?.id]),!r||!e||s||!c)return null;let d=r.details,T=d.styling||{},l=T.appearance||{},p=l.backdropColor||"#000000",M=zs(l.backdropOpacity),B=E=>{v($=>$===E?null:E)},L=async(E,$)=>{let D=z.map(j=>({slide_id:j.id,order:j.order,title:j.title,question:j.question,selected_options:E[j.id]?.option,comment:E[j.id]?.comment})),k=r.id,P=[];for(let j of z){let X=E[j.id]?.option;if(!X)continue;let J=Object.entries(j.options||{}).find(([,V])=>String(V)===String(X));J&&P.push(J[0])}let O=D.map(j=>j.comment).filter(Boolean).join(" || ")||"",G=d.id||k;H("survey captured",G,{survey_id:d.id,slide_id:$,selected_options:P,otherText:O}),T.content?.isThankyouPage!==!1?I(!0):a(!0)},C=async()=>{if(!R||!g)return;let E={...h,[R.id]:{option:g,comment:f}};y(E);try{let P=r.id,O=null;if(g&&R&&R.options){let ut=Object.entries(R.options).find(([,j])=>String(j)===String(g));ut&&(O=ut[0])}let G=d.id||P;H("survey captured",G,{survey_id:d.id,slide_id:R.id,selected_options:O?[O]:[],otherText:f||""})}catch(P){console.warn("Error sending per-slide survey captured",P)}if((R.logic||[]).find(P=>(P.selectOption||[]).includes(g))?.redirectTo==="thank-you"){await L(E,R.id);return}if(x>=z.length-1){await L(E,R.id);return}m(P=>Math.min(P+1,z.length-1))},S=()=>{let E=d.thankYouButtonConfig;if(E?.enabled&&E.redirectUrl){try{let $=String(E.redirectUrl||"").trim();if($&&!$.startsWith("http")&&ht($)){a(!0);return}}catch($){console.warn("revealCampaignFromLink error",$)}try{globalThis.open(E.redirectUrl,"_blank")}catch{}}a(!0)},_=async()=>{try{let E=r?.id,$=d?.id,D=R?.id;await H("SurveyDismissed",E,{survey_id:$,slide_id:D})}catch(E){console.warn("Error sending SurveyDismissed",E)}finally{a(!0)}};return R?we("div",{style:{position:"fixed",inset:0,zIndex:999999,display:"flex",justifyContent:"flex-end",alignItems:"flex-end",padding:12,pointerEvents:"none"},children:[rt("div",{"aria-hidden":!0,style:{position:"absolute",inset:0,background:Is(p,M)}}),we("div",{style:{position:"relative",width:"min(420px, 92vw)",maxWidth:"92vw",minWidth:"320px",maxHeight:"80vh",overflow:"hidden",backgroundColor:l.backgroundColor||"#ffffff",borderRadius:Ke(l.cornerRadius),boxSizing:"border-box",paddingTop:14,paddingRight:16,paddingBottom:10,paddingLeft:16,pointerEvents:"auto",boxShadow:"0 14px 36px rgba(0, 0, 0, 0.25)",display:"flex",flexDirection:"column"},children:[rt("style",{children:`
138
+ `}),T.crossButton?.enabled&&bt(Dt,{config:T.crossButton,onPress:()=>{r()},style:{top:T.crossButton?.margin?.top??10,right:T.crossButton?.margin?.right??10}}),bt("div",{className:"appstorys-csat-scroll",style:{flex:1,minHeight:0,overflowY:"auto",paddingBottom:4},children:w?bt(tl,{details:A,isHighRating:B,onDone:M}):bt(Za,{details:A,rating:m,selectedOptions:O,comments:L,isHighRating:B,feedbackOptions:V,onRate:Y,onToggleOption:W,onCommentChange:v,onInlineSubmit:H,canSubmit:m>=1,appearance:k,isMobile:c})})]})})},ol=el;import{useEffect as to,useMemo as Gr,useState as Gt,useRef as Ze}from"react";yt();import*as oo from"lottie-react";import{Fragment as ui,jsx as ft,jsxs as Te}from"react/jsx-runtime";var nl=oo.default?.default??oo.default??oo.Lottie??oo;function ln(t){if(t!=null)return`${t}px`}function dn(t){return st(t)}function eo(t){if(!t)return{};let e={};t.color&&(e.color=t.color),t.fontSize&&(e.fontSize=t.fontSize);let o=dn(t.fontFamily);return o&&(e.fontFamily=o),t.textAlign&&(e.textAlign=t.textAlign),t.fontDecoration?.includes("bold")&&(e.fontWeight="bold"),t.fontDecoration?.includes("italic")&&(e.fontStyle="italic"),t.fontDecoration?.includes("underline")&&(e.textDecoration="underline"),e}function To(t){return{marginTop:ln(t?.top),marginRight:ln(t?.right),marginBottom:ln(t?.bottom),marginLeft:ln(t?.left)}}function zo(t,e=0){if(!t)return`${e}px`;let o=t.topLeft!==void 0&&t.topLeft!==null?t.topLeft:e,n=t.topRight!==void 0&&t.topRight!==null?t.topRight:e,i=t.bottomRight!==void 0&&t.bottomRight!==null?t.bottomRight:e,s=t.bottomLeft!==void 0&&t.bottomLeft!==null?t.bottomLeft:e;return`${o}px ${n}px ${i}px ${s}px`}function Qr(t){return t==="right"?"flex-end":t==="left"?"flex-start":"center"}function Io(t){return Math.max(0,Math.min(1,t))}function qr(t,e){let o=(t||"").trim().replace("#","");if(o.length===3){let n=Number.parseInt(o[0]+o[0],16),i=Number.parseInt(o[1]+o[1],16),s=Number.parseInt(o[2]+o[2],16);return`rgba(${n}, ${i}, ${s}, ${Io(e)})`}if(o.length===6){let n=Number.parseInt(o.slice(0,2),16),i=Number.parseInt(o.slice(2,4),16),s=Number.parseInt(o.slice(4,6),16);return`rgba(${n}, ${i}, ${s}, ${Io(e)})`}return`rgba(0, 0, 0, ${Io(e)})`}function il(t){if(t==null)return .4;let e=Number(t);return Number.isFinite(e)?e>1?Io(e/100):Io(e):.4}function Hr(t){return[...t.slides||[]].sort((o,n)=>(o.order??0)-(n.order??0))}function rl(t,e){let o=t.trim();if(!o)return{action:"none"};let n=o.toLowerCase().replace(/[\s_-]+/g,"");if(n==="thankyou"||n==="thankyoupage")return{action:"thankyou"};let i=/^question\s+(\d+)$/i.exec(o);if(i){let d=parseInt(i[1],10)-1;return d>=0&&d<e.length?{action:"jump",targetIndex:d}:{action:"none"}}let s=e.findIndex(c=>c.id===o);if(s!==-1)return{action:"jump",targetIndex:s};let l=Number(o);if(Number.isFinite(l)&&l>0){let c=e.findIndex(d=>d.order===l);if(c!==-1)return{action:"jump",targetIndex:c}}return{action:"none"}}function sl(t){let e=t?.options||{},o=Object.keys(e),n=i=>{let s=/(\d+)/.exec(i);if(!s)return;let l=Number(s[1]);return Number.isFinite(l)?l:void 0};return o.sort((i,s)=>{let l=n(i),c=n(s);return l!=null&&c!=null?l-c:l!=null?-1:c!=null?1:i.localeCompare(s)}),o.map(i=>e[i]).filter(i=>typeof i=="string"&&i.trim().length>0)}function al(t,e){if(!t)return null;if(t==="alphabet"){let o="a".codePointAt(0)??97;return String.fromCodePoint(o+e%26)+"."}return t==="number"?String(e+1)+".":t==="roman"?(["i","ii","iii","iv","v","vi","vii","viii","ix","x","xi","xii","xiii","xiv","xv"][e]||String(e+1))+".":null}function ll(t){if(typeof t=="number"&&Number.isFinite(t)&&t>=0)return t;if(typeof t=="string"&&t.trim().length>0){let e=Number(t);if(Number.isFinite(e)&&e>=0)return e}}function Vr(t){return ll(t?.borderwidth)??1}var Ur=({details:t,slide:e,appearance:o,selectedOptions:n,comment:i,onSelectOption:s,onCommentChange:l,onSubmit:c,canSubmit:d})=>{let S=t.styling||{},p=S.options||{},y=S.cta,u=Gr(()=>sl(e),[e]),C=p.optionsSpacing??6,h=p.bulletSpacing??12,g=p.optionsHeight??48,b=Qr(y?.container?.alignment),m=S.title?.textStyle,E=S.subtitle?.textStyle;return Te(ui,{children:[ft("div",{style:{width:"100%",...To(m?.margin)},children:ft("div",{style:{...eo(m),color:m?.color||"#111827",fontSize:m?.fontSize||22,lineHeight:1.3,textAlign:m?.textAlign||"left",fontWeight:m?.fontDecoration?.includes("bold")?"bold":m?.fontDecoration?"normal":600,fontStyle:m?.fontDecoration?.includes("italic")?"italic":"normal",textDecoration:m?.fontDecoration?.includes("underline")?"underline":"none"},children:e.title||e.question||t.name||"Survey"})}),(e.subtitle||E)&&ft("div",{style:{width:"100%",...To(E?.margin)},children:ft("div",{style:{...eo(E),color:E?.color||"#6b7280",fontSize:E?.fontSize||16,lineHeight:1.35,textAlign:E?.textAlign||"left",fontWeight:E?.fontDecoration?.includes("bold")?"bold":"normal",fontStyle:E?.fontDecoration?.includes("italic")?"italic":"normal",textDecoration:E?.fontDecoration?.includes("underline")?"underline":"none"},children:e.subtitle||""})}),u.length>0&&(()=>{let O="__others__",D=e.additionalComment?.placeholder?.trim()||"Others",L=u.map(w=>({value:w,label:w}));e.additionalComment?.enabled&&L.push({value:O,label:D});let v=n.includes(O);return Te(ui,{children:[ft("div",{style:{marginTop:10,display:"flex",flexDirection:"column",gap:C},children:L.map(({value:w,label:_},$)=>{let V=n.includes(w),A=V?p.selectedOptions:p.nonSelectedOptions,T=Vr(A?.textStyle),k=al(p.optionListStyle,$),B=p.optionListStyle,W=B==="bulleted",H=B==="number"||B==="alphabet"||B==="roman",Y=A?.colors?.text||A?.textStyle?.color||(V?"#ffffff":"#111827"),r=A?.colors?.background||(V?"#1f35db":"#ffffff"),M=A?.colors?.border||(V?"#1f35db":"#e5e7eb");return Te("button",{onClick:()=>s(w),style:{width:"100%",boxSizing:"border-box",minHeight:g,height:"auto",borderRadius:zo(p.cornerRadius,7),border:`${T}px solid ${M}`,background:r,color:Y,cursor:"pointer",display:"flex",alignItems:"center",gap:h,paddingTop:8,paddingBottom:8,paddingLeft:14,paddingRight:14,textAlign:A?.textStyle?.textAlign||"left",...eo(A?.textStyle)},"aria-pressed":V,children:[W?ft("span",{"aria-hidden":!0,style:{width:18,height:18,borderRadius:"50%",border:`2px solid ${V?p.selectedOptions?.colors?.border||M:p.nonSelectedOptions?.colors?.border||M}`,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:V&&ft("span",{style:{width:10,height:10,borderRadius:"50%",backgroundColor:Y}})}):H?ft("span",{"aria-hidden":!0,style:{fontSize:A?.textStyle?.fontSize?A.textStyle.fontSize*.85:16,fontWeight:A?.textStyle?.fontDecoration?.includes("bold")?"bold":600,fontFamily:dn(A?.textStyle?.fontFamily),color:Y,marginRight:2,flexShrink:0},children:k}):null,ft("span",{style:{flex:1,minWidth:0,wordBreak:"break-word",lineHeight:1.35,color:Y},children:_})]},`${w}-${$}`)})}),v&&ft("textarea",{value:i,onChange:w=>l(w.target.value),placeholder:e.additionalComment?.placeholder||"Type your response...",style:{marginTop:10,width:"100%",boxSizing:"border-box",minHeight:72,resize:"none",overflowY:"auto",border:`${Vr(p.additionalComments?.textStyle)}px solid ${p.additionalComments?.colors?.border||"#e5e7eb"}`,background:p.additionalComments?.colors?.background||"#ffffff",color:p.additionalComments?.colors?.text||"#111827",borderRadius:zo(p.cornerRadius,7),padding:"12px",...eo(p.additionalComments?.textStyle)}})]})})(),ft("div",{style:{position:"sticky",bottom:0,marginTop:y?.margin?.top??12,marginBottom:y?.margin?.bottom??0,marginLeft:y?.margin?.left??0,marginRight:y?.margin?.right??0,paddingTop:10,paddingBottom:4,background:o?.backgroundColor||"#ffffff",display:"flex",justifyContent:b,width:"100%",boxSizing:"border-box"},children:ft("button",{onClick:c,disabled:!d,style:{width:y?.container?.ctaFullWidth?"100%":y?.container?.ctaWidth?`${y.container.ctaWidth}px`:"140px",maxWidth:"100%",height:y?.container?.height??50,border:`${y?.container?.borderWidth??0}px solid ${y?.container?.borderColor||"transparent"}`,background:y?.container?.backgroundColor||"#1f35db",color:y?.text?.color||"#ffffff",borderRadius:zo(y?.cornerRadius,7),fontFamily:dn(y?.text?.fontFamily)||"Arial",fontSize:y?.text?.fontSize||18,fontWeight:y?.text?.fontDecoration?.includes("bold")?"bold":600,fontStyle:y?.text?.fontDecoration?.includes("italic")?"italic":"normal",textDecoration:y?.text?.fontDecoration?.includes("underline")?"underline":"none",cursor:d?"pointer":"not-allowed",opacity:d?1:.6,display:"flex",alignItems:"center",justifyContent:"center",padding:"0 20px",boxSizing:"border-box"},children:e.submitButtonText||"Submit"})})]})},Yr=({details:t,onDone:e})=>{let o=t.styling||{},n=o.thankyouPage||{},i=n.cta||o.cta,s=Qr(i?.container?.alignment),l=t.thankYouImage?.endsWith(".json"),[c,d]=Gt(null);to(()=>{l&&t.thankYouImage?fetch(t.thankYouImage).then(u=>u.json()).then(u=>d(u)).catch(u=>console.error("AppStorys Survey: Error loading Thank You Lottie:",u)):d(null)},[t.thankYouImage,l]);let S=t.thankYouTitle||t?.thank_you_title||"Thank you",p=t.thankYouText||t?.thank_you_text||"",y=t.thankYouButtonText||t?.thank_you_button_text||"Done";return Te(ui,{children:[t.thankYouImage&&ft("div",{style:{display:"flex",justifyContent:"center",...To(n.imageStyle?.margin)},children:l?c?ft(nl,{animationData:c,loop:!0,style:{width:n.imageStyle?.width||80,height:n.imageStyle?.height||80}}):ft("div",{style:{width:n.imageStyle?.width||80,height:n.imageStyle?.height||80}}):ft("img",{src:t.thankYouImage,alt:"thank you",style:{width:n.imageStyle?.width||80,height:n.imageStyle?.height||80,objectFit:"cover",borderRadius:10}})}),ft("div",{style:{width:"100%",...To(n.title?.textStyle?.margin)},children:ft("div",{style:{...eo(n.title?.textStyle),color:n.title?.textStyle?.color||"#111827",fontSize:n.title?.textStyle?.fontSize||20,lineHeight:1.3,textAlign:n.title?.textStyle?.textAlign||"center",fontWeight:n.title?.textStyle?.fontDecoration?.includes("bold")?"bold":n.title?.textStyle?.fontDecoration?.length?"normal":700},children:S})}),p&&ft("div",{style:{width:"100%",...To(n.subtitle?.textStyle?.margin)},children:ft("div",{style:{...eo(n.subtitle?.textStyle),color:n.subtitle?.textStyle?.color||"#6b7280",fontSize:n.subtitle?.textStyle?.fontSize||14,lineHeight:1.35,textAlign:n.subtitle?.textStyle?.textAlign||"center",fontWeight:n.subtitle?.textStyle?.fontDecoration?.includes("bold")?"bold":"normal"},children:p})}),(y||i)&&ft("div",{style:{marginTop:i?.margin?.top??14,marginBottom:i?.margin?.bottom??0,marginLeft:i?.margin?.left??0,marginRight:i?.margin?.right??0,display:"flex",justifyContent:s,width:"100%",boxSizing:"border-box"},children:ft("button",{onClick:e,style:{width:i?.container?.ctaFullWidth?"100%":i?.container?.ctaWidth?`${i.container.ctaWidth}px`:"auto",maxWidth:"100%",height:i?.container?.height??44,border:`${i?.container?.borderWidth??0}px solid ${i?.container?.borderColor||"transparent"}`,background:i?.container?.backgroundColor||"#1f35db",color:i?.text?.color||"#ffffff",borderRadius:zo(i?.cornerRadius,12),fontFamily:dn(i?.text?.fontFamily)||"Arial",fontSize:i?.text?.fontSize||14,fontWeight:i?.text?.fontDecoration?.includes("bold")?"bold":600,fontStyle:i?.text?.fontDecoration?.includes("italic")?"italic":"normal",textDecoration:i?.text?.fontDecoration?.includes("underline")?"underline":"none",cursor:"pointer",padding:"0 20px",display:"flex",alignItems:"center",justifyContent:"center",boxSizing:"border-box"},children:y})})]})},dl=()=>{let t=At("SUR"),e=P(R=>R.isVisible),o=P(R=>R.campaigns),n=P(R=>R.allCampaigns),i=P(R=>R.currentScreen),[s,l]=Gt(typeof window<"u"?window.innerWidth:1024),[c,d]=Gt(0),[S,p]=Gt(!1),[y,u]=Gt(!1),[C,h]=Gt(!1),g=Ze(0),b=Ze(0),m=Ze(null),E=Ze(0),O=Ze(!1);to(()=>{if(typeof window>"u")return;let R=()=>l(window.innerWidth);return window.addEventListener("resize",R),()=>window.removeEventListener("resize",R)},[]);let D=s<768,L=t??(()=>{let R=(i||"").trim().toLowerCase(),I=[...o||[],...n||[]].find(N=>{if(!N||N.campaign_type!=="SUR")return!1;let Z=!!(N.trigger_event??N.trigger);if(!(N.display_trigger!==!1&&!Z))return!1;let Ft=(N.screen||"").trim().toLowerCase();return!Ft||Ft===R});if(I)try{return Nt(I)}catch{return I}})(),[v,w]=Gt(!1),[_,$]=Gt(!1),[V,A]=Gt(0),[T,k]=Gt([]),[B,W]=Gt(""),[H,Y]=Gt({}),[r,M]=Gt(!1),a=Ze(null);to(()=>{if(!L?.id||a.current===L.id)return;a.current=L.id,w(!1),$(!1),A(0),k([]),W(""),Y({}),M(!1),h(!1),u(!1),d(0);let R=L.details?.styling?.appearance?.displayDelay??0,I=globalThis.setTimeout(()=>{$(!0);let N=L.details?.id,Z=Hr(L.details),xt=Z.length>0?Z[0].id:void 0;rt("viewed",L.id,{survey_id:N,slide_id:xt})},Math.max(0,R)*1e3);return()=>globalThis.clearTimeout(I)},[L?.id]),to(()=>{if(_){let R=setTimeout(()=>h(!0),30);return()=>clearTimeout(R)}},[_]);let f=Gr(()=>L?Hr(L.details):[],[L]),x=f[V];to(()=>{if(typeof window>"u"||!L||!e||v||!_)return;let R=window.scrollY||window.pageYOffset||0,I=document.body.style.position,N=document.body.style.top,Z=document.body.style.left,xt=document.body.style.right,Ft=document.body.style.width,kt=document.body.style.overflow,Wt=document.documentElement.style.overflow;return document.body.style.position="fixed",document.body.style.top=`-${R}px`,document.body.style.left="0",document.body.style.right="0",document.body.style.width="100%",document.body.style.overflow="hidden",document.documentElement.style.overflow="hidden",()=>{document.body.style.position=I,document.body.style.top=N,document.body.style.left=Z,document.body.style.right=xt,document.body.style.width=Ft,document.body.style.overflow=kt,document.documentElement.style.overflow=Wt,window.scrollTo(0,R)}},[L,e,v,_]);let z=(R,I)=>{g.current=R,b.current=0,O.current=I,m.current?E.current=m.current.scrollTop:E.current=0,p(!0)},U=R=>{if(!g.current)return;let I=R-g.current,N=m.current?m.current.scrollTop:0,Z=E.current<=0&&N<=0;(O.current||Z)&&I>0?(b.current=I,d(I)):(b.current=0,d(0))},et=()=>{p(!1),O.current=!1,b.current>80?(u(!0),setTimeout(()=>{gt()},250)):(d(0),b.current=0),g.current=0};if(to(()=>{if(!S)return;let R=xt=>{U(xt.clientY)},I=()=>{et()},N=xt=>{xt.cancelable&&xt.preventDefault(),xt.touches&&xt.touches[0]&&U(xt.touches[0].clientY)},Z=()=>{et()};return window.addEventListener("pointermove",R),window.addEventListener("pointerup",I),window.addEventListener("touchmove",N,{passive:!1}),window.addEventListener("touchend",Z),()=>{window.removeEventListener("pointermove",R),window.removeEventListener("pointerup",I),window.removeEventListener("touchmove",N),window.removeEventListener("touchend",Z)}},[S]),!L||!e||v||!_)return null;let X=L.details,q=X.styling||{},J=q.appearance||{},nt=J.backdropColor||"#000000",ht=il(J.backdropOpacity),dt=x?.multipleSelection!==!1&&x?.isMultiSelect!==!1&&q.options?.multipleSelection!==!1,K=R=>{k(dt?I=>I.includes(R)?I.filter(N=>N!==R):[...I,R]:I=>I[0]===R?[]:[R])},it=async(R,I)=>{let N=f.map(Bt=>({slide_id:Bt.id,order:Bt.order,title:Bt.title,question:Bt.question,selected_options:R[Bt.id]?.options,comment:R[Bt.id]?.comment})),Z=L.id,xt=[];for(let Bt of f){let Ht=R[Bt.id]?.options||[];for(let Tt of Ht){let Kt=Object.entries(Bt.options||{}).find(([,ne])=>String(ne)===String(Tt));Kt&&xt.push(Kt[0])}}let Ft=N.map(Bt=>Bt.comment).filter(Boolean).join(" || ")||"",kt=X.id||Z;rt("survey captured",kt,{survey_id:X.id,slide_id:I,selected_options:xt,otherText:Ft}),q.content?.isThankyouPage!==!1?M(!0):w(!0)},lt=async()=>{if(!x||T.length===0)return;let R={...H,[x.id]:{options:T,comment:B}};Y(R);let I=[];if(x.options)for(let Ft of T){let kt=Object.entries(x.options).find(([,Wt])=>String(Wt)===String(Ft));kt&&I.push(kt[0])}try{let Ft=L.id,kt=X.id||Ft;rt("survey captured",kt,{survey_id:X.id,slide_id:x.id,selected_options:I,otherText:B||""})}catch(Ft){console.warn("Error sending per-slide survey captured",Ft)}let N=T.includes("__others__"),Z={action:"none"};for(let Ft of x.logic||[]){let kt=Ft.selectOption||[];if(kt.length===0)continue;let Wt=kt.some(Tt=>I.includes(Tt)),Bt=kt.some(Tt=>T.includes(Tt)),Ht=N&&kt.some(Tt=>Tt==="others"||Tt==="__others__");if(!(!Wt&&!Bt&&!Ht)&&Ft.redirectTo){let Tt=rl(Ft.redirectTo,f);if(Tt.action!=="none"){Z=Tt;break}}}if(Z.action==="thankyou"){await it(R,x.id);return}if(Z.action==="jump"){A(Z.targetIndex);return}if(V>=f.length-1){await it(R,x.id);return}A(Ft=>Math.min(Ft+1,f.length-1))},mt=()=>{let R=X.thankYouButtonConfig;if(R?.enabled&&R.redirectUrl){try{let I=String(R.redirectUrl||"").trim();if(I&&!I.startsWith("http")&&Pt(I)){w(!0);return}}catch(I){console.warn("revealCampaignFromLink error",I)}try{globalThis.open(R.redirectUrl,"_blank")}catch{}}w(!0)},gt=async()=>{try{let R=L?.id,I=X?.id,N=x?.id;await rt("SurveyDismissed",R,{survey_id:I,slide_id:N})}catch(R){console.warn("Error sending SurveyDismissed",R)}finally{w(!0)}};return x?D?Te("div",{style:{position:"fixed",inset:0,zIndex:999999,display:"flex",justifyContent:"center",alignItems:"flex-end",padding:0,boxSizing:"border-box",pointerEvents:"auto",touchAction:"none",overscrollBehavior:"none"},children:[ft("div",{"aria-hidden":!0,onClick:()=>{u(!0),setTimeout(()=>gt(),250)},onTouchMove:R=>{R.cancelable&&R.preventDefault()},style:{position:"absolute",inset:0,background:qr(nt,y?0:ht),transition:S?"none":"background 0.25s ease-out",zIndex:1,touchAction:"none"}}),Te("div",{onPointerDown:R=>{let I=R.target;I&&I.closest("button, input, textarea, a")||z(R.clientY,!1)},onTouchStart:R=>{let I=R.target;I&&I.closest("button, input, textarea, a")||R.touches&&R.touches[0]&&z(R.touches[0].clientY,!1)},style:{position:"relative",zIndex:2,width:"100%",maxWidth:"520px",maxHeight:"85vh",backgroundColor:J.backgroundColor||"#ffffff",borderTopLeftRadius:`${J.cornerRadius?.topLeft??16}px`,borderTopRightRadius:`${J.cornerRadius?.topRight??16}px`,borderBottomLeftRadius:0,borderBottomRightRadius:0,boxSizing:"border-box",paddingTop:10,paddingRight:16,paddingBottom:"max(14px, env(safe-area-inset-bottom, 14px))",paddingLeft:16,boxShadow:"0 -8px 32px rgba(0, 0, 0, 0.25)",display:"flex",flexDirection:"column",overflow:"hidden",touchAction:"none",overscrollBehavior:"contain",transform:y?"translateY(100%)":C?`translateY(${c}px)`:"translateY(100%)",transition:S?"none":"transform 0.28s cubic-bezier(0.25, 1, 0.5, 1)"},children:[ft("style",{children:`
92
139
  .appstorys-survey-scroll {
93
- scrollbar-width: none; /* Firefox */
94
- -ms-overflow-style: none; /* IE/Edge */
140
+ scrollbar-width: none;
141
+ -ms-overflow-style: none;
95
142
  }
96
143
  .appstorys-survey-scroll::-webkit-scrollbar {
97
144
  width: 0;
98
145
  height: 0;
99
- display: none; /* Chrome/Safari */
146
+ display: none;
100
147
  }
101
- `}),T.crossButton?.enabled&&rt(Lt,{config:T.crossButton,onPress:_,style:{top:T.crossButton?.margin?.top??10,right:T.crossButton?.margin?.right??10}}),rt("div",{className:"appstorys-survey-scroll",style:{flex:1,minHeight:0,overflowY:"auto",paddingRight:2},children:w?rt(Ls,{details:d,onDone:S}):rt(Ps,{details:d,slide:R,appearance:l,selectedOption:g,comment:f,onSelectOption:B,onCommentChange:b,onSubmit:C,canSubmit:g!=null})})]})]}):null},_s=Ds;var rn=class{state="uninitialized";navigateToScreen;async initialize(e){let{appId:o,accountId:i,userId:n}=e;if(this.navigateToScreen=e.navigateToScreen,this.state!=="initializing"){if(this.state==="initialized"){let r=F.getState();if(r.isAnonymousUser&&n&&n.trim()!==""){console.log("AppStorys: Reconciling anonymous user with identified user..."),await this.reconcileUser(r.userId,n,o,i);return}if(r.appId===o&&r.accountId===i&&r.userId===n)return}this.state="initializing";try{let r,s;if(!n||n.trim()==="")r=await Pn(),s=!0;else{let m=await Ao();m&&m!==n&&console.log("AppStorys: Found previous anonymous user, will reconcile after verification."),r=n,s=!1}if(!await Et(i,o,r)){this.state="error";return}if(!s){let m=await Ao();m&&m!==r&&(await je(m,r),await Bo())}try{let m=await dt(),g=e.baseUrl||"https://users.appstorys.co";fetch(`${g}/v2/${i}/track-user-res`,{method:"POST",headers:{"Content-Type":"application/json",...m?{Authorization:`Bearer ${m}`}:{}},body:JSON.stringify({user_id:r,screenName:typeof window<"u"&&window.location&&window.location.pathname?window.location.pathname:"",silentUpdate:!0})}).then(async v=>{if(v.ok)try{let f=await v.json(),b=F.getState();if(typeof f.screen_capture_enabled<"u"){let h=!!f.screen_capture_enabled;console.info("AppStorys: track-user-res returned screen_capture_enabled=",h),b.setScreenCaptureEnabled(h)}}catch{}}).catch(v=>console.warn("track-user-res (init) failed",v))}catch(m){console.warn("track-user-res (init) setup failed",m)}let{campaigns:c,version:u}=await To(i);try{Tn(c)}catch(m){console.warn("Failed to preload campaign fonts",m)}let x=F.getState();x.setAppId(o),x.setAccountId(i),x.setUserId(r),x.setIsAnonymousUser(s),x.setBaseUrl(e.baseUrl),x.setTrackingUrl(e.trackingUrl),x.saveAllCampaigns(c),x.setCampaignVersion(u);try{F.getState().screenCaptureEnabled&&(await Promise.resolve().then(()=>(ji(),Oi))).mountScreenCaptureButton()}catch(m){console.warn("Failed to mount screen capture button",m)}An.setup(),zo.setup(),this.state="initialized"}catch(r){this.state="error",console.error("AppStorys initialization failed:",r)}}}async reconcileUser(e,o,i,n){try{if(!await Et(n,i,o)){console.error("AppStorys: Failed to verify identified user account during reconciliation.");return}if(!await je(e,o)){console.error("AppStorys: Failed to reconcile anonymous and identified users.");return}await Bo();let a=F.getState();a.setUserId(o),a.setIsAnonymousUser(!1)}catch(r){console.error("AppStorys: Error during user reconciliation:",r)}}async trackScreen(e){return await this.ensureInitialized(),vo(e)}async trackEvent(e,o,i){return await this.ensureInitialized(),H(e,o,i)}async setUserProperties(e){return await this.ensureInitialized(),wo(e)}handleLink(e){if(e){if(typeof e=="string"){try{if(!e.startsWith("http")&&ht(e))return}catch(o){console.warn("revealCampaignFromLink error",o)}e.startsWith("http")?window.open(e,"_blank"):this.navigateToScreen?.(e)}else if(typeof e=="object"&&e.value){try{if(ht(e.value))return}catch{}this.navigateToScreen?.(e.value)}}}get visibility(){return F.getState().isVisible}set visibility(e){zo.updateVisibility(e)}async ensureInitialized(){if(this.state==="initialized")return;let e=Date.now();for(;this.state!=="initialized";){if(this.state==="error")throw new Error("AppStorys SDK error");if(Date.now()-e>1e4)throw new Error("AppStorys SDK initialization timeout");await new Promise(o=>setTimeout(o,100))}}personalizeText(e){return Oe(e)}},jp=new rn;export{jp as AppStorys,ar as Banner,fs as BottomSheet,Fs as Csat,xr as Floater,ur as Pip,fn as SdkState,ts as Story,_s as Survey,cs as Tooltip,rs as Widget,Oe as personalizeText};
148
+ `}),ft("div",{onPointerDown:R=>{R.stopPropagation(),z(R.clientY,!0)},onTouchStart:R=>{R.stopPropagation(),R.touches&&R.touches[0]&&z(R.touches[0].clientY,!0)},style:{width:"40px",height:"4px",backgroundColor:"#D1D5DB",borderRadius:"2px",margin:"0 auto 8px auto",flexShrink:0,cursor:"grab",touchAction:"none",userSelect:"none"}}),q.crossButton?.enabled&&ft(Dt,{config:q.crossButton,onPress:()=>{u(!0),setTimeout(()=>gt(),250)},style:{top:q.crossButton?.margin?.top!==void 0&&q.crossButton.margin.top>=0?q.crossButton.margin.top:10,right:q.crossButton?.margin?.right!==void 0&&q.crossButton.margin.right>=0?q.crossButton.margin.right:10,marginTop:0,marginRight:0,marginBottom:0,marginLeft:0}}),ft("div",{ref:m,className:"appstorys-survey-scroll",style:{flex:1,minHeight:0,overflowY:"auto",overscrollBehavior:"contain",touchAction:"pan-y",paddingRight:2,WebkitOverflowScrolling:"touch"},children:r?ft(Yr,{details:X,onDone:mt}):ft(Ur,{details:X,slide:x,appearance:J,selectedOptions:T,comment:B,onSelectOption:K,onCommentChange:W,onSubmit:lt,canSubmit:T.length>0})})]})]}):Te("div",{style:{position:"fixed",inset:0,zIndex:999999,display:"flex",justifyContent:"flex-end",alignItems:"flex-end",padding:16,boxSizing:"border-box",pointerEvents:"none"},children:[ft("div",{"aria-hidden":!0,onClick:gt,style:{position:"absolute",inset:0,background:qr(nt,ht),pointerEvents:ht>0?"auto":"none",zIndex:1}}),Te("div",{style:{position:"relative",zIndex:2,width:"min(420px, 92vw)",maxWidth:"92vw",minWidth:"320px",maxHeight:"80vh",overflow:"hidden",backgroundColor:J.backgroundColor||"#ffffff",borderRadius:zo(J.cornerRadius,12),boxSizing:"border-box",paddingTop:14,paddingRight:16,paddingBottom:10,paddingLeft:16,pointerEvents:"auto",boxShadow:"0 14px 36px rgba(0, 0, 0, 0.25)",display:"flex",flexDirection:"column"},children:[ft("style",{children:`
149
+ .appstorys-survey-scroll {
150
+ scrollbar-width: none;
151
+ -ms-overflow-style: none;
152
+ }
153
+ .appstorys-survey-scroll::-webkit-scrollbar {
154
+ width: 0;
155
+ height: 0;
156
+ display: none;
157
+ }
158
+ `}),q.crossButton?.enabled&&ft(Dt,{config:q.crossButton,onPress:gt,style:{top:q.crossButton?.margin?.top!==void 0&&q.crossButton.margin.top>=0?q.crossButton.margin.top:10,right:q.crossButton?.margin?.right!==void 0&&q.crossButton.margin.right>=0?q.crossButton.margin.right:10,marginTop:0,marginRight:0,marginBottom:0,marginLeft:0}}),ft("div",{className:"appstorys-survey-scroll",style:{flex:1,minHeight:0,overflowY:"auto",paddingRight:2},children:r?ft(Yr,{details:X,onDone:mt}):ft(Ur,{details:X,slide:x,appearance:J,selectedOptions:T,comment:B,onSelectOption:K,onCommentChange:W,onSubmit:lt,canSubmit:T.length>0})})]})]}):null},cl=dl;import{useEffect as Sl,useState as Cl,useRef as vl}from"react";yt();import{useEffect as cn,useState as pi,useRef as ul}from"react";import*as io from"lottie-react";import{Fragment as ml,jsx as oe,jsxs as no}from"react/jsx-runtime";var pl=io.default?.default??io.default??io.Lottie??io,Xr=t=>{if(!t)return;let e=t.trim().toLowerCase();if(e==="middle")return"center";if(e==="left"||e==="right"||e==="center"||e==="justify")return e},gl=t=>{if(!t)return null;if(typeof t=="string"){let e=t.trim();return e.length>0?e:null}if(typeof t=="object"){let e=typeof t.url=="string"?t.url.trim():"";if(e)return e;let o=typeof t.value=="string"?t.value.trim():"";if(o)return o;let n=typeof t.pageName=="string"?t.pageName.trim():"";if(n)return n;let i=typeof t.key=="string"?t.key.trim():"";if(i)return i}return null},fl=(t,e,o)=>{let n=gl(t);if(n){if(e){let i=o?._variantId||o?.details?.id;rt("clicked",e,i?{variant_id:i}:void 0)}if(!n.startsWith("http"))try{if(Pt(n))return}catch{}try{window.open(n,"_blank")}catch{}}},Jr=({campaign:t,onDismiss:e})=>{let[o,n]=pi(typeof window<"u"?window.innerWidth:1024),[i,s]=pi(null),[l,c]=pi(!0),d=ul(null);cn(()=>{if(typeof window>"u")return;let x=()=>n(window.innerWidth);window.addEventListener("resize",x);let z=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{window.removeEventListener("resize",x),document.body.style.overflow=z}},[]);let{details:S}=t,p=S?.modals?.[0],y=p?.content||{},u=p?.styling||{},C=y?.chooseMediaType||p?.chooseMediaType,h=C?.type,g=C?.url;if(cn(()=>{h==="lottie"&&g?(s(null),fetch(g).then(x=>x.json()).then(x=>s(x)).catch(x=>console.error("Error fetching Lottie in ModalWithCta:",x))):s(null)},[h,g]),cn(()=>{d.current&&(d.current.muted=l)},[l]),cn(()=>{let x=d.current;if(!x||h!=="video")return;x.muted=!1;let z=x.play();z!==void 0&&z.then(()=>{c(!1)}).catch(()=>{x.muted=!0,c(!0),x.play().catch(()=>{})})},[g,h]),!p)return null;let b=u.appearance||{},m=u.crossButton,E=b.backdrop?.color||"rgba(0, 0, 0, 0.4)",O=b.backdrop?.opacity!==void 0&&b.backdrop?.opacity!==null?b.backdrop.opacity>1?b.backdrop.opacity/100:b.backdrop.opacity:0,D=b.enableBackdrop!==!1,L=b.dimension?.width!==void 0&&b.dimension?.width!==null&&b.dimension.width>0?b.dimension.width:300,v=o>=768,w=v?L*1.4:L,_=Math.min(w,o*.9),$=b.cornerRadius||{},V=b.backgroundColor||"#FFFFFF",A=y.titleText||"",T=y.subtitleText||"",k=y.primaryCtaText||"",B=y.secondaryCtaText||"",W=y.primaryCtaRedirection,H=y.secondaryCtaRedirection,Y=u.title||{},r=u.subTitle||{},M=u.primaryCta||{},a=u.secondaryCta||{},f=(x,z,U,et=!1)=>{if(!x||x.trim()==="")return null;let X=z?.container||{},q=z?.cornerRadius||{},J=z?.margin||{},nt=z?.text||{},ht=N=>N==="left"?"flex-start":N==="right"?"flex-end":"center",dt=X.ctaWidth,K=v&&dt?dt*1.4:dt,it=X.height||40,lt=v?it*1.2:it,mt=q.topLeft!==void 0&&q.topLeft>=0?q.topLeft:8,gt=q.topRight!==void 0&&q.topRight>=0?q.topRight:8,R=q.bottomRight!==void 0&&q.bottomRight>=0?q.bottomRight:8,I=q.bottomLeft!==void 0&&q.bottomLeft>=0?q.bottomLeft:8;return oe("div",{style:{display:"flex",justifyContent:ht(X.alignment),width:et?"auto":"100%",flex:et?1:void 0,marginTop:J.top!==void 0&&J.top>=0?J.top:0,marginBottom:J.bottom!==void 0&&J.bottom>=0?J.bottom:0,marginLeft:J.left!==void 0&&J.left>=0?J.left:0,marginRight:J.right!==void 0&&J.right>=0?J.right:0,boxSizing:"border-box"},children:oe("button",{style:{width:et||X.ctaFullWidth?"100%":K?`${K}px`:"auto",height:lt,backgroundColor:X.backgroundColor||"#FE6B35",color:nt.color||"#FFFFFF",border:`${X.borderWidth||0}px solid ${X.borderColor||"transparent"}`,borderRadius:`${mt}px ${gt}px ${R}px ${I}px`,fontSize:nt.fontSize||14,fontFamily:st(nt.fontFamily)||"Arial",fontWeight:nt.fontDecoration?.includes("bold")?"bold":"normal",fontStyle:nt.fontDecoration?.includes("italic")?"italic":"normal",textDecoration:nt.fontDecoration?.includes("underline")?"underline":"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",padding:"0 16px",outline:"none",boxSizing:"border-box"},onClick:()=>fl(U,t?.id,t),children:Ce(x)})})};return no(ml,{children:[oe("style",{children:`
159
+ .appstorys-modal-scroll::-webkit-scrollbar { display: none; }
160
+ .appstorys-modal-scroll { scrollbar-width: none; }
161
+ `}),oe("div",{style:{position:"fixed",top:0,left:0,right:0,bottom:0,backgroundColor:D?E:"transparent",opacity:D?O:1,zIndex:999998,transition:"opacity 0.3s ease"}}),no("div",{style:{position:"fixed",top:"50%",left:"50%",transform:"translate(-50%, -50%)",width:_,maxWidth:"95vw",zIndex:999999,overflow:"visible"},children:[(m?.enabled??!0)&&oe(Dt,{config:m||{enabled:!0},onPress:x=>{x&&typeof x.stopPropagation=="function"&&x.stopPropagation(),e()},style:{position:"absolute",zIndex:1e7,top:m?.margin?.top!==void 0&&m.margin?.top>=0?m.margin.top:8,right:m?.margin?.right!==void 0&&m.margin?.right>=0?m.margin.right:8}}),no("div",{style:{width:"100%",backgroundColor:V,borderTopLeftRadius:$.topLeft!==void 0&&$.topLeft>=0?$.topLeft:0,borderTopRightRadius:$.topRight!==void 0&&$.topRight>=0?$.topRight:0,borderBottomLeftRadius:$.bottomLeft!==void 0&&$.bottomLeft>=0?$.bottomLeft:0,borderBottomRightRadius:$.bottomRight!==void 0&&$.bottomRight>=0?$.bottomRight:0,overflow:"hidden",boxShadow:"0 8px 32px rgba(0,0,0,0.25)",display:"flex",flexDirection:"column",maxHeight:"90vh"},children:[no("div",{className:"appstorys-modal-scroll",style:{flex:1,overflowY:"auto",display:"flex",flexDirection:"column",alignItems:"center",minHeight:0},children:[g&&(h==="image"||!h)&&oe("img",{src:g,alt:"",style:{width:"100%",display:"block"}}),g&&h==="video"&&no("div",{style:{position:"relative",width:"100%"},children:[oe("video",{ref:d,src:g,autoPlay:!0,loop:!0,muted:l,playsInline:!0,controls:!1,style:{width:"100%",display:"block"}}),oe(be,{config:{size:32,color:{cross:"#ffffff",fill:"rgba(0,0,0,0.45)",stroke:"transparent"},margin:{top:0,bottom:0,left:0,right:0},image:""},onPress:x=>{x.stopPropagation(),c(z=>!z)},type:l?"mute":"unmute",enabled:!0,style:{position:"absolute",zIndex:1e7,bottom:12,left:12,borderRadius:"50%"}})]}),g&&h==="lottie"&&i&&(()=>{let x=i.w,z=i.h,U=x&&z&&x>0?z/x:void 0,et=_,X=U?Math.round(et*U):void 0;return oe(pl,{animationData:i,loop:!0,autoplay:!0,style:{width:et,height:X,display:"block"}})})(),A.trim()!==""&&oe("div",{style:{width:"100%",padding:"12px 16px 0 16px",color:Y.color||"#000000",fontSize:Y.fontSize||26,fontFamily:st(Y.fontFamily)||"Helvetica",fontWeight:Y.fontDecoration?.includes("bold")?"bold":"600",fontStyle:Y.fontDecoration?.includes("italic")?"italic":"normal",textDecoration:Y.fontDecoration?.includes("underline")?"underline":"none",textAlign:Xr(Y.textAlign)||"center",boxSizing:"border-box"},children:Ce(A)}),T.trim()!==""&&oe("div",{style:{width:"100%",padding:"4px 16px 0 16px",color:r.color||"#000000",fontSize:r.fontSize||20,fontFamily:st(r.fontFamily)||"Helvetica",fontWeight:r.fontDecoration?.includes("bold")?"bold":"normal",fontStyle:r.fontDecoration?.includes("italic")?"italic":"normal",textDecoration:r.fontDecoration?.includes("underline")?"underline":"none",textAlign:Xr(r.textAlign)||"center",boxSizing:"border-box"},children:Ce(T)})]}),(k.trim()!==""||B.trim()!=="")&&no("div",{style:{flexShrink:0,width:"100%",padding:"0 12px 12px 12px",boxSizing:"border-box",display:"flex",flexDirection:k.trim()!==""&&B.trim()!==""?"row":"column",gap:"8px",justifyContent:"center"},children:[f(k,M,W,k.trim()!==""&&B.trim()!==""),f(B,a,H,k.trim()!==""&&B.trim()!=="")]})]})]})]})};import{useEffect as un,useState as gi,useRef as yl}from"react";import*as ro from"lottie-react";import{Fragment as xl,jsx as ze,jsxs as pn}from"react/jsx-runtime";var hl=ro.default?.default??ro.default??ro.Lottie??ro,Kr=t=>{if(!t)return null;if(typeof t=="string"){let e=t.trim();return e.length>0?e:null}if(typeof t=="object"){let e=typeof t.url=="string"?t.url.trim():"";if(e)return e;let o=typeof t.value=="string"?t.value.trim():"";if(o)return o;let n=typeof t.pageName=="string"?t.pageName.trim():"";if(n)return n;let i=typeof t.key=="string"?t.key.trim():"";if(i)return i}return null},bl=(t,e,o)=>{let n=Kr(t);if(n){if(e){let i=o?._variantId||o?.details?.id;rt("clicked",e,i?{variant_id:i}:void 0)}if(!n.startsWith("http"))try{if(Pt(n))return}catch{}try{window.open(n,"_blank")}catch{}}},Zr=({campaign:t,onDismiss:e})=>{let[o,n]=gi(typeof window<"u"?window.innerWidth:1024),[i,s]=gi(null),[l,c]=gi(!0),d=yl(null);un(()=>{if(typeof window>"u")return;let A=()=>n(window.innerWidth);window.addEventListener("resize",A);let T=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{window.removeEventListener("resize",A),document.body.style.overflow=T}},[]);let{details:S}=t,p=S?.modals?.[0],y=p?.chooseMediaType,u=p?.styling||{},C=p?.redirection,h=y?.type,g=y?.url;if(un(()=>{h==="lottie"&&g?(s(null),fetch(g).then(A=>A.json()).then(A=>s(A)).catch(A=>console.error("Error fetching Lottie in MediaOnlyModal:",A))):s(null)},[h,g]),un(()=>{d.current&&(d.current.muted=l)},[l]),un(()=>{let A=d.current;if(!A||h!=="video")return;A.muted=!1;let T=A.play();T!==void 0&&T.then(()=>{c(!1)}).catch(()=>{A.muted=!0,c(!0),A.play().catch(()=>{})})},[g,h]),!p||!y||!g)return null;let b=u.appearance||{},m=u.crossButton,E=b.backdrop?.color||"rgba(0, 0, 0, 0.4)",O=b.backdrop?.opacity!==void 0&&b.backdrop?.opacity!==null?b.backdrop.opacity>1?b.backdrop.opacity/100:b.backdrop.opacity:0,D=b.enableBackdrop!==!1,L=b.dimension?.width!==void 0&&b.dimension?.width!==null&&b.dimension.width>0?b.dimension.width:300,w=o>=768?L*1.4:L,_=Math.min(w,o*.9),$=b.cornerRadius||{},V=b.backgroundColor||(h==="lottie"?"transparent":"#FFFFFF");return pn(xl,{children:[ze("style",{children:`
162
+ .appstorys-media-modal-scroll::-webkit-scrollbar { display: none; }
163
+ .appstorys-media-modal-scroll { scrollbar-width: none; }
164
+ `}),ze("div",{style:{position:"fixed",top:0,left:0,right:0,bottom:0,backgroundColor:D?E:"transparent",opacity:D?O:1,zIndex:999998,transition:"opacity 0.3s ease"}}),pn("div",{style:{position:"fixed",top:"50%",left:"50%",transform:"translate(-50%, -50%)",width:_,maxWidth:"95vw",zIndex:999999,overflow:"visible"},children:[(m?.enabled??!0)&&ze(Dt,{config:m||{enabled:!0},onPress:A=>{A&&typeof A.stopPropagation=="function"&&A.stopPropagation(),e()},style:{position:"absolute",zIndex:1e7,top:m?.margin?.top!==void 0&&m.margin?.top>=0?m.margin.top:8,right:m?.margin?.right!==void 0&&m.margin?.right>=0?m.margin.right:8}}),ze("div",{className:"appstorys-media-modal-scroll",style:{width:"100%",backgroundColor:V,borderTopLeftRadius:$.topLeft!==void 0&&$.topLeft>=0?$.topLeft:0,borderTopRightRadius:$.topRight!==void 0&&$.topRight>=0?$.topRight:0,borderBottomLeftRadius:$.bottomLeft!==void 0&&$.bottomLeft>=0?$.bottomLeft:0,borderBottomRightRadius:$.bottomRight!==void 0&&$.bottomRight>=0?$.bottomRight:0,overflow:"hidden",boxShadow:V==="transparent"?"none":"0 8px 32px rgba(0,0,0,0.25)",display:"flex",flexDirection:"column",alignItems:"center",maxHeight:"90vh",overflowY:"auto"},children:(()=>{let A=!!Kr(C);return pn("div",{onClick:A?()=>bl(C,t?.id,t):void 0,style:{width:"100%",cursor:A?"pointer":"default",minHeight:0},children:[g&&(h==="image"||!h)&&ze("img",{src:g,alt:"",style:{width:"100%",display:"block"}}),g&&h==="video"&&pn("div",{style:{position:"relative",width:"100%"},children:[ze("video",{ref:d,src:g,autoPlay:!0,loop:!0,muted:l,playsInline:!0,controls:!1,style:{width:"100%",display:"block"}}),ze(be,{config:{size:32,color:{cross:"#ffffff",fill:"rgba(0,0,0,0.45)",stroke:"transparent"},margin:{top:0,bottom:0,left:0,right:0},image:""},onPress:T=>{T.stopPropagation(),c(k=>!k)},type:l?"mute":"unmute",enabled:!0,style:{position:"absolute",zIndex:1e7,bottom:12,left:12,borderRadius:"50%"}})]}),g&&h==="lottie"&&i&&(()=>{let T=i.w,k=i.h,B=T&&k&&T>0?k/T:void 0,W=_,H=B?Math.round(W*B):void 0;return ze(hl,{animationData:i,loop:!0,autoplay:!0,style:{width:W,height:H,display:"block"}})})()]})})()})]})]})};import{jsx as ts}from"react/jsx-runtime";var wl=()=>{let t=At("MOD"),e=P(C=>C.campaigns),o=P(C=>C.allCampaigns),n=P(C=>C.currentScreen),i=t??(()=>{let C=(n||"").trim().toLowerCase(),h=[...e||[],...o||[]].find(g=>{if(!g||g.campaign_type!=="MOD")return!1;let b=!!(g.trigger_event??g.trigger);if(!(g.display_trigger!==!1&&!b))return!1;let E=(g.screen||"").trim().toLowerCase();return!E||E===C});if(h)try{return Nt(h)}catch{return h}})(),s=P(C=>C.isVisible),[l,c]=Cl(!1),d=vl(null);Sl(()=>{if(i?.id&&d.current!==i.id){d.current=i.id,c(!1);let C=i._variantId||i.details?.id,h=C?{variant_id:C}:void 0;rt("viewed",i.id,h)}},[i?.id]);let S=C=>{try{let h=P.getState(),b=(h.trackedEvents||[]).filter(m=>m!==C);h.setTrackedEvents(b)}catch{}};if(!i||l||!s)return null;let p=()=>{i?.id&&S(`viaAppStorys${i.id}`),c(!0)},y=i.details?.modal_type||i.details?.modals?.[0]?.modal_type||"";return y==="full-page-modal"||y==="media-only-modal"?ts(Zr,{campaign:i,onDismiss:p}):ts(Jr,{campaign:i,onDismiss:p})};import{jsx as Rl}from"react/jsx-runtime";var kl=({id:t,children:e})=>Rl("div",{"data-as-id":t,style:{display:"contents"},children:e});var fi=class{state="uninitialized";navigateToScreen;async initialize(e){let{appId:o,accountId:n,userId:i}=e;if(this.navigateToScreen=e.navigateToScreen,this.state!=="initializing"){if(this.state==="initialized"){let s=P.getState();if(s.isAnonymousUser&&i&&i.trim()!==""){console.log("AppStorys: Reconciling anonymous user with identified user..."),await this.reconcileUser(s.userId,i,o,n);return}if(s.appId===o&&s.accountId===n&&s.userId===i)return}this.state="initializing";try{let s,l;if(!i||i.trim()==="")s=await Ui(),l=!0;else{let y=await Wn();y&&y!==i&&console.log("AppStorys: Found previous anonymous user, will reconcile after verification."),s=i,l=!1}if(!await he(n,o,s)){this.state="error";return}if(!l){let y=await Wn();y&&y!==s&&(await Uo(y,s),await _n())}try{let y=await Et(),u=e.baseUrl||"https://users.appstorys.co";fetch(`${u}/v2/${n}/track-user-res`,{method:"POST",headers:{"Content-Type":"application/json",...y?{Authorization:`Bearer ${y}`}:{}},body:JSON.stringify({user_id:s,screenName:typeof window<"u"&&window.location&&window.location.pathname?window.location.pathname:"",silentUpdate:!0})}).then(async C=>{if(C.ok)try{let h=await C.json(),g=P.getState();if(typeof h.screen_capture_enabled<"u"){let b=!!h.screen_capture_enabled;console.info("AppStorys: track-user-res returned screen_capture_enabled=",b),g.setScreenCaptureEnabled(b)}}catch{}}).catch(C=>console.warn("track-user-res (init) failed",C))}catch(y){console.warn("track-user-res (init) setup failed",y)}let{campaigns:d,version:S}=await An(n);try{Ei(d)}catch(y){console.warn("Failed to preload campaign fonts",y)}let p=P.getState();p.setAppId(o),p.setAccountId(n),p.setUserId(s),p.setIsAnonymousUser(l),p.setBaseUrl(e.baseUrl),p.setTrackingUrl(e.trackingUrl),p.saveAllCampaigns(d),p.setCampaignVersion(S);try{P.getState().screenCaptureEnabled&&(await Promise.resolve().then(()=>(ss(),rs))).mountScreenCaptureButton()}catch(y){console.warn("Failed to mount screen capture button",y)}Hi.setup(),Dn.setup(),this.state="initialized"}catch(s){this.state="error",console.error("AppStorys initialization failed:",s)}}}async reconcileUser(e,o,n,i){try{if(!await he(i,n,o)){console.error("AppStorys: Failed to verify identified user account during reconciliation.");return}if(!await Uo(e,o)){console.error("AppStorys: Failed to reconcile anonymous and identified users.");return}await _n();let c=P.getState();c.setUserId(o),c.setIsAnonymousUser(!1)}catch(s){console.error("AppStorys: Error during user reconciliation:",s)}}async trackScreen(e){return await this.ensureInitialized(),In(e)}async trackEvent(e,o,n){return await this.ensureInitialized(),rt(e,o,n)}async setUserProperties(e){return await this.ensureInitialized(),Bn(e)}handleLink(e){if(e){if(typeof e=="string"){try{if(!e.startsWith("http")&&Pt(e))return}catch(o){console.warn("revealCampaignFromLink error",o)}e.startsWith("http")?window.open(e,"_blank"):this.navigateToScreen?.(e)}else if(typeof e=="object"&&e.value){try{if(Pt(e.value))return}catch{}this.navigateToScreen?.(e.value)}}}get visibility(){return P.getState().isVisible}set visibility(e){Dn.updateVisibility(e)}async ensureInitialized(){if(this.state==="initialized")return;let e=Date.now();for(;this.state!=="initialized";){if(this.state==="error")throw new Error("AppStorys SDK error");if(Date.now()-e>1e4)throw new Error("AppStorys SDK initialization timeout");await new Promise(o=>setTimeout(o,100))}}personalizeText(e){return Ce(e)}},Gf=new fi;export{Gf as AppStorys,Rs as Banner,qa as BottomSheet,ol as Csat,Ns as Floater,wl as Modal,Es as Pip,yi as SdkState,Ta as Story,cl as Survey,$a as Tooltip,kl as Trackable,Aa as Widget,Wl as getCampaignVariantId,Si as getVariantId,Eo as hasVariants,Ce as personalizeText,Nt as resolveCampaignVariant,gs as selectVariantByWeight};
102
165
  //# sourceMappingURL=index.mjs.map