@appstorys/react-web 1.0.0 → 1.0.1

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 si=Object.defineProperty;var Et=(t,e)=>()=>(t&&(e=t(t=0)),e);var ai=(t,e)=>{for(var o in e)si(t,o,{get:e[o],enumerable:!0})};var tt,Ot=Et(()=>{"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 li}from"zustand";function ht(){return Ie.getState().userId}async function it(){return tt.getItem("access_token")}function Ro(t){if(!t)return;let e=String(t||"").trim();if(e)return Ie.getState().variantMappings?.[e]}var Ie,z,K=Et(()=>{"use strict";Ot();Ie=li(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})}));z=Ie});async function Lt(){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 de=Et(()=>{"use strict"});async function Rt(t,e,o){try{let i={account_id:t,app_id:e,user_id:o};if(await tt.getItem(zo))console.log("Device info already sent previously - skipping");else{let g=await Lt();i.attributes={...g},console.log("First time verification - including device info in attributes")}let a=z.getState().baseUrl||"https://users.appstorys.co",l=await fetch(`${a}/${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",l.status,l.statusText),l.ok){let g=await l.json();console.log("Account verified",g);let{access_token:p,refresh_token:x}=g;if(p&&x)return await tt.setItem("access_token",p),await tt.setItem("refresh_token",x),i.attributes&&(await tt.setItem(zo,"true"),console.log("Device info sent flag set")),!0}return!1}catch(i){return console.error("Error when verifying AppStorys account",i),!1}}var zo,ce=Et(()=>{"use strict";Ot();de();K();zo="device_info_sent"});async function Te(t,e){if(!e||e.length===0){console.info("AppStorys: identifyWidgetPositions called with empty positionList; skipping");return}let o=await it();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 qn=Et(()=>{"use strict";K()});function ze(t){return t&&(t.startsWith("widget_")?t:`widget_${t}`)}function Hn(){try{let t=z.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=>ze(String(o))).filter(o=>!!o)}catch{return[]}}function Ur(t){try{let e=Hn();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}"]`],a=null;for(let l of r)if(a=document.querySelector(l),a)break;if(a){let l=a.getBoundingClientRect(),g={x:Math.round(l.left),y:Math.round(l.top),width:Math.round(l.width),height:Math.round(l.height),screenWidth:window.innerWidth,screenHeight:window.innerHeight};Mt.addLayoutInfo(t,n,g),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 Hr(t){return se[t]||(se[t]=[]),se[t]}function Un(t,e,o,i){let n=new FormData,r=t.replace(/[^a-z0-9]/gi,"_"),a=`screenshot_${e}_${r}_${Date.now()}.png`,l=new File([i],a,{type:"image/png"});n.append("screenName",t),n.append("user_id",e),n.append("children",o),n.append("screenshot",l);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:",l.name,`(${l.size} bytes)`),console.groupEnd()}catch(g){console.warn("AppStorys: Could not run FormData diagnostics",g)}return n}var se,Mt,Vn=Et(()=>{"use strict";K();ce();qn();K();se={};Mt=class{static setup(e,o){let i=z.getState();i.setScreenCaptureEnabled(o),i.setCurrentScreen(e)}static addLayoutInfo(e,o,i){let n=Hr(e),r=n.findIndex(g=>g.id===o),a={...i,screenWidth:i.screenWidth||window.innerWidth,screenHeight:i.screenHeight||window.innerHeight},l={id:o,frame:a};r>=0?n[r]=l:n.push(l)}static collectElements(e){this.clearLayoutData(e);let o=document.querySelectorAll("[data-as-id]"),i=window.innerWidth,n=window.innerHeight,r=[];o.forEach(a=>{let l=a.getAttribute("data-as-id");if(l){r.push(l);let g=a.getBoundingClientRect();this.addLayoutInfo(e,l,{x:Math.round(g.left),y:Math.round(g.top),width:Math.round(g.width),height:Math.round(g.height),screenWidth:i,screenHeight:n})}}),console.info(`AppStorys: Identified ${o.length} elements:`,r)}static clearLayoutData(e){se[e]=[]}static getLayoutData(e){return se[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),z.getState().setCurrentScreen(e),this.collectElements(e);try{let u=Ur(e);u&&u.length>0&&console.info("AppStorys: mapServerPositionsToDOM added",u.length,"elements")}catch{}await new Promise(u=>setTimeout(u,100));let n=window,r=null;if(typeof n.html2canvas!="function")try{await new Promise((u,v)=>{let f=document.createElement("script");f.src="https://html2canvas.hertzen.com/dist/html2canvas.min.js",f.onload=()=>u(),f.onerror=()=>v(new Error("Failed to load html2canvas")),document.head.appendChild(f)})}catch(u){console.warn("AppStorys: html2canvas load error",u)}if(typeof n.html2canvas=="function")try{let u=await n.html2canvas(document.documentElement,{useCORS:!0,allowTaint:!0,logging:!1,scale:window.devicePixelRatio||1});r=await new Promise(v=>u.toBlob(f=>v(f),"image/png"))}catch(u){console.warn("AppStorys: html2canvas capture failed (falling back to getDisplayMedia)",u),r=null}if(!r&&navigator.mediaDevices&&navigator.mediaDevices.getDisplayMedia)try{let u=await navigator.mediaDevices.getDisplayMedia({video:!0}),v=document.createElement("video");v.srcObject=u,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(),u.getTracks().forEach(h=>h.stop())}catch(u){console.warn("AppStorys: getDisplayMedia capture failed",u)}if(!r)return console.warn("AppStorys: Capture failed \u2014 no blob generated"),!1;let a=await it(),l=ht();if(!l)return console.warn("AppStorys: No userId"),!1;if(!a){let u=z.getState();u.accountId&&u.appId&&u.userId&&await Rt(u.accountId,u.appId,u.userId)&&(a=await it())}if(!a)return console.warn("AppStorys: No token available"),!1;let g="https://backend.appstorys.co/api/v1/appinfo/identify-elements/",p=JSON.stringify(this.getLayoutData(e)||[]),x=Un(e,l,p,r);console.info("AppStorys: Sending identify-elements with payload size:",p.length);let m=await fetch(g,{method:"POST",headers:{Authorization:`Bearer ${a}`,Accept:"application/json"},body:x});if(m.status===401){console.warn("AppStorys: 401 response \u2014 retrying once");let u=z.getState();if(u.accountId&&u.appId&&u.userId&&await Rt(u.accountId,u.appId,u.userId)){let f=await it();f&&(m=await fetch(g,{method:"POST",headers:{Authorization:`Bearer ${f}`,Accept:"application/json"},body:Un(e,l,p,r)}))}}if(!m.ok){let u=await m.text();return console.error("AppStorys: identify-elements failed",m.status,u),!1}console.info("AppStorys: identify-elements success \u2713");try{let u=o,v=[];!u||u.length===0?v=(this.getLayoutData(e)||[]).map(y=>ze(y.id)).filter(y=>!!y):v=u.map(h=>ze(h)).filter(h=>!!h);let f=Hn(),b=Array.from(new Set([...v,...f]));console.info("AppStorys: identifyWidgetPositions will send",b.length,"positions (collected + server)",b),await Te(e,b)}catch(u){console.warn("AppStorys: identifyWidgetPositions failed",u)}return!0}catch(i){return console.error("AppStorys: takeScreenshot error",i),!1}}};(function(){try{let e=window;e.AppStorysForceIdentifyPositions=async o=>{let i=z.getState(),n=o||i.currentScreen;if(!n){console.warn("AppStorys: AppStorysForceIdentifyPositions - no screen name available");return}let a=(Mt.getLayoutData(n)||[]).map(l=>ze(l.id)).filter(l=>!!l);console.info("AppStorys: AppStorysForceIdentifyPositions sending",a.length,"positions for",n,a);try{await Te(n,a),console.info("AppStorys: AppStorysForceIdentifyPositions completed")}catch(l){console.error("AppStorys: AppStorysForceIdentifyPositions error",l)}}}catch{}})()});var Qn={};ai(Qn,{mountScreenCaptureButton:()=>Yn});function Vr(){if(document.getElementById("appstorys-capture-styles"))return;let t=document.createElement("style");t.id="appstorys-capture-styles",t.innerHTML=`
1
+ var Vi=Object.defineProperty;var jt=(t,e)=>()=>(t&&(e=t(t=0)),e);var Yi=(t,e)=>{for(var o in e)Vi(t,o,{get:e[o],enumerable:!0})};var et,Xt=jt(()=>{"use strict";et=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 Qi}from"zustand";function Ct(){return co.getState().userId}async function dt(){return et.getItem("access_token")}function gn(t){if(!t)return;let e=String(t||"").trim();if(e)return co.getState().variantMappings?.[e]}var co,F,K=jt(()=>{"use strict";Xt();co=Qi(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=co});async function Nt(){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 Ee=jt(()=>{"use strict"});async function At(t,e,o){try{let i={account_id:t,app_id:e,user_id:o};if(await et.getItem(mn))console.log("Device info already sent previously - skipping");else{let c=await Nt();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 et.setItem("access_token",u),await et.setItem("refresh_token",x),i.attributes&&(await et.setItem(mn,"true"),console.log("Device info sent flag set")),!0}return!1}catch(i){return console.error("Error when verifying AppStorys account",i),!1}}var mn,Pe=jt(()=>{"use strict";Xt();Ee();K();mn="device_info_sent"});async function to(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 Li=jt(()=>{"use strict";K()});function eo(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=>eo(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};Yt.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 $s(t){return Re[t]||(Re[t]=[]),Re[t]}function Di(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 Re,Yt,$i=jt(()=>{"use strict";K();Pe();Li();K();Re={};Yt=class{static setup(e,o){let i=F.getState();i.setScreenCaptureEnabled(o),i.setCurrentScreen(e)}static addLayoutInfo(e,o,i){let n=$s(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){Re[e]=[]}static getLayoutData(e){return Re[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=Ct();if(!a)return console.warn("AppStorys: No userId"),!1;if(!s){let g=F.getState();g.accountId&&g.appId&&g.userId&&await At(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=Di(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 At(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:Di(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=>eo(y.id)).filter(y=>!!y):v=g.map(h=>eo(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 to(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=(Yt.getLayoutData(n)||[]).map(a=>eo(a.id)).filter(a=>!!a);console.info("AppStorys: AppStorysForceIdentifyPositions sending",s.length,"positions for",n,s);try{await to(n,s),console.info("AppStorys: AppStorysForceIdentifyPositions completed")}catch(a){console.error("AppStorys: AppStorysForceIdentifyPositions error",a)}}}catch{}})()});var Mi={};Yi(Mi,{mountScreenCaptureButton:()=>Wi});function Ws(){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 si=Object.defineProperty;var Et=(t,e)=>()=>(t&&(e=t(t=0)),e);var ai=(t,e)=>{
11
11
  border-radius: 50%;
12
12
  animation: appstorys-spin 0.8s linear infinite;
13
13
  }
14
- `,document.head.appendChild(t)}function Yr(){Vr();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 Yn(){try{let t=z.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=Yr();return i.addEventListener("click",async()=>{i.disabled=!0;let n=i.innerText;i.innerHTML='<div class="appstorys-spinner"></div>';let a=z.getState().currentScreen||(typeof window<"u"?window.location.pathname:"");try{await Mt.takeScreenshot(a)}catch(l){console.error("CaptureService error",l)}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 Gn=Et(()=>{"use strict";K();Vn();try{window.AppStorysMountCapture=function(){try{return Yn()}catch(t){return console.error("AppStorysMountCapture failed",t),null}}}catch{}try{window.AppStorysDebugState=function(){try{let t=z.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),a=new Date;console.info("Token expires:",r.toISOString(),"Expired:",a>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 wo=(n=>(n.uninitialized="uninitialized",n.initializing="initializing",n.initialized="initialized",n.error="error",n))(wo||{});K();import{useState as fe,useEffect as Po,useRef as xi}from"react";import*as jt from"lottie-react";K();import{useMemo as ci}from"react";K();var di=t=>z.getState().variantMappings[t];function Be(t){return!!(t.details&&typeof t.details=="object"&&"variants"in t.details)}function ut(t){if(!Be(t))return t;let e=di(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(([a])=>a!=="variants")):{};return{...t,details:{...n,...i},_variantId:e}}var le="__back_press_triggered__";function To(t){return(t||"").trim().toLowerCase()}function pi(t,e){let o=To(t),i=To(e);return!o||o===i}function ui(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 gi(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:ui(String(r),n.operator,n.value)}))}function fi(t,e,o){let i=t,n=i.trigger_event??i.trigger,r=t.id;return!n}function Ae(){let{campaigns:t,trackedEvents:e,trackedEventMetadata:o,currentScreen:i}=z.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:a,event_config:l}=r;if(!(l??[]).some(x=>x.back_press===!0)||e.includes(le)||!e.includes(a))return!1;let g=(l??[]).filter(x=>x.back_press==null);if(g.length===0)return!0;let p=o[a]||[];return gi(g,p)})}function lt(t,e){let o=z(g=>g.currentScreen),i=z(g=>g.campaigns),n=z(g=>g.allCampaigns),r=z(g=>g.trackedEvents),a=z(g=>g.trackedEventMetadata),l=z(g=>g.variantMappings);return ci(()=>{let g=m=>m.find(u=>pi(u.screen,o)&&u.campaign_type===t&&(e?.position?u.position===e.position:!0)&&fi(u,r,a)),x=(i&&i.length>0?g(i):void 0)??g(n||[]);if(x)return ut(x)},[i,n,r,a,l,t,e,o])}K();de();Ot();K();ce();var Fo="appstorys_offline_queue";async function Io(){let t=await tt.getItem(Fo);return t?JSON.parse(t):[]}async function Bo(t){await tt.setItem(Fo,JSON.stringify(t))}function mi(t){return Math.min(3e4*Math.pow(2,t),12e4)}function yi(t){let o=t.retryCount||0,i=t.lastAttempt||0,n=mi(o);return o<3&&Date.now()-i>=n}async function hi(){let t=z.getState();return!t.accountId||!t.appId?!1:await Rt(t.accountId,t.appId,t.userId)}async function Ao(t,e){if(await hi()){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 ue(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 Io();e.push(t),await Bo(e)}async function bi(){let t=await Io();if(t.length===0)return;let e=[];for(let o of t){if(!yi(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 Ao(o,n=>e.push(n)):i.status>=500&&await ue(o,n=>e.push(n))}catch{await ue(o,n=>e.push(n))}}await Bo(e)}async function ge(t){if(!navigator.onLine){await pe(t);return}await bi();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 Ao(t,pe):e.status>=500&&await ue(t,pe)),e}catch{await ue(t,pe);return}}async function V(t,e,o){try{if(!t)return;let i=await it(),n=z.getState(),r=["viewed","clicked","csat captured","survey captured","shared"];if(!r.includes(t)){let p=n.trackedEvents;if(!p.includes(t))n.setTrackedEvents([...p,t]);else{let x=p.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 a={...o||{}};if(!r.includes(t)){let p=await Lt();a={...a,...p}}if(e&&String(e).trim()!==""){let p=Ro(e);p&&(a.variant_id=p)}let l={user_id:ht(),event:t,metadata:a};e&&(l.campaign_id=e);let g=n.trackingUrl||"https://tracking.appstorys.co";i&&await ge({url:`${g}/capture-event`,method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${i}`},body:l})}catch(i){console.error("Error in trackEvent",i)}}K();function gt(t){if(!t)return!1;let e=z.getState(),o=e.allCampaigns||[],i=e.campaigns||[],n=String(t).trim(),r=o.find(g=>{if(!g)return!1;let p=String(g.id||"").trim(),x=g.details||{},m=String(x.campaign||x.id||"").trim();return!!(p&&p===n||m&&m===n||p&&n.includes(p)||m&&n.includes(m))});if(!r)return!1;let a={...r};delete a.trigger_event,delete a.trigger,a.display_trigger=!0;let l=i.findIndex(g=>String(g.id||"")===String(a.id||""));if(l===-1)e.saveCampaigns([a,...i]);else{let g=i[l];if(!!(g.trigger_event??g.trigger)){let x=[...i];x[l]=a,e.saveCampaigns(x)}}return!0}import{jsx as Pe,jsxs as Ci}from"react/jsx-runtime";var Eo=jt.default?.default??jt.default??jt.Lottie??jt,Si=()=>{let t=lt("BAN"),e=z(k=>k.isVisible),[o,i]=fe(!1),[n,r]=fe(null),[a,l]=fe(null),g=xi(null),[p,x]=fe(0);if(Po(()=>{t&&(i(!1),V("viewed",t.id),t.details.lottie_data&&fetch(t.details.lottie_data).then(k=>k.json()).then(k=>{r(k),k.w&&k.h&&l(k.h/k.w)}).catch(k=>console.error("Error loading Lottie:",k)))},[t]),Po(()=>{let k=()=>{g.current&&x(g.current.offsetWidth)};return k(),window.addEventListener("resize",k),()=>window.removeEventListener("resize",k)},[t,o]),!t||o||!e)return null;let{details:m}=t,u=m.styling||{},v=m.height||"auto";a&&p&&(v=p*a);let f={position:"fixed",left:u.marginLeft?`${u.marginLeft}px`:"10px",right:u.marginRight?`${u.marginRight}px`:"10px",bottom:u.marginBottom?`${u.marginBottom}px`:"10px",backgroundColor:"transparent",borderRadius:`${u.topRightRadius||0}px ${u.topLeftRadius||0}px ${u.bottomRightRadius||0}px ${u.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=k=>{k.stopPropagation(),i(!0),V("banner_closed",t.id)};return Ci("div",{ref:g,style:f,onClick:()=>{if(m.link)if(V("clicked",t.id),m.link.startsWith("http"))window.open(m.link,"_blank");else{try{if(gt(m.link))return}catch(k){console.warn("revealCampaignFromLink error",k)}console.log("Internal link:",m.link)}},children:[n?(()=>{let k=Eo.default||Eo;return Pe(k,{animationData:n,loop:!0,autoplay:e,style:b})})():m.image?Pe("img",{src:m.image,alt:"Campaign Banner",style:b}):null,u.crossButton?.enabled&&Pe("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 Ee,useMemo as Lo,useRef as Do,useState as Gt}from"react";K();import{jsx as nt,jsxs as Dt}from"react/jsx-runtime";var Le=t=>(t||"").trim().toLowerCase(),xt=(t,e)=>{let o=Number(t);return Number.isFinite(o)?o:e};function vi({iconType:t,color:e}){let o=e||"#FFFFFF";return t==="close"?Dt("svg",{viewBox:"0 0 24 24",width:"70%",height:"70%","aria-hidden":!0,children:[nt("line",{x1:"6",y1:"6",x2:"18",y2:"18",stroke:o,strokeWidth:"2.2",strokeLinecap:"round"}),nt("line",{x1:"18",y1:"6",x2:"6",y2:"18",stroke:o,strokeWidth:"2.2",strokeLinecap:"round"})]}):t==="expand"?Dt("svg",{viewBox:"0 0 24 24",width:"70%",height:"70%","aria-hidden":!0,children:[nt("polyline",{points:"8,3 3,3 3,8",fill:"none",stroke:o,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),nt("line",{x1:"3",y1:"3",x2:"9",y2:"9",stroke:o,strokeWidth:"2",strokeLinecap:"round"}),nt("polyline",{points:"16,21 21,21 21,16",fill:"none",stroke:o,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),nt("line",{x1:"15",y1:"15",x2:"21",y2:"21",stroke:o,strokeWidth:"2",strokeLinecap:"round"})]}):t==="minimize"?Dt("svg",{viewBox:"0 0 24 24",width:"70%",height:"70%","aria-hidden":!0,children:[nt("polyline",{points:"9,9 3,9 3,3",fill:"none",stroke:o,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),nt("line",{x1:"3",y1:"9",x2:"9",y2:"3",stroke:o,strokeWidth:"2",strokeLinecap:"round"}),nt("polyline",{points:"15,15 21,15 21,21",fill:"none",stroke:o,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),nt("line",{x1:"15",y1:"21",x2:"21",y2:"15",stroke:o,strokeWidth:"2",strokeLinecap:"round"})]}):t==="mute"?Dt("svg",{viewBox:"0 0 24 24",width:"70%",height:"70%","aria-hidden":!0,children:[nt("polygon",{points:"4,10 8,10 13,6 13,18 8,14 4,14",fill:"none",stroke:o,strokeWidth:"2",strokeLinejoin:"round"}),nt("line",{x1:"16",y1:"8",x2:"21",y2:"16",stroke:o,strokeWidth:"2",strokeLinecap:"round"}),nt("line",{x1:"21",y1:"8",x2:"16",y2:"16",stroke:o,strokeWidth:"2",strokeLinecap:"round"})]}):Dt("svg",{viewBox:"0 0 24 24",width:"70%",height:"70%","aria-hidden":!0,children:[nt("polygon",{points:"4,10 8,10 13,6 13,18 8,14 4,14",fill:"none",stroke:o,strokeWidth:"2",strokeLinejoin:"round"}),nt("path",{d:"M16 10 Q18 12 16 14",fill:"none",stroke:o,strokeWidth:"2",strokeLinecap:"round"}),nt("path",{d:"M18 8 Q22 12 18 16",fill:"none",stroke:o,strokeWidth:"2",strokeLinecap:"round"})]})}function De({iconType:t,config:e,imageOverride:o,onClick:i}){let n=xt(e?.size,18),r=Math.max(24,n+10),a=e?.margin||{},l=o||e?.image,g=e?.color?.cross||"#FFFFFF",p=e?.color?.fill||"rgba(0,0,0,0.55)",x=e?.color?.stroke||"rgba(255,255,255,0.35)";return nt("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:p,color:g,display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0,marginTop:xt(a.top,0),marginRight:xt(a.right,0),marginBottom:xt(a.bottom,0),marginLeft:xt(a.left,0)},children:l?nt("img",{src:l,alt:t,style:{width:n,height:n,objectFit:"contain"}}):nt(vi,{iconType:t,color:g})})}var ki=()=>{let t=lt("PIP"),e=z(q=>q.campaigns),o=z(q=>q.allCampaigns),i=z(q=>q.currentScreen),n=z(q=>q.isVisible),[r,a]=Gt(!1),[l,g]=Gt(!1),[p,x]=Gt(!0),[m,u]=Gt(!1),[v,f]=Gt(null),b=Do({x:0,y:0}),h=Do(null),y=Lo(()=>{if(t)return t;let q=Le(i),Q=pt=>pt.find(ft=>{let at=ft,wt=at.campaign_type==="PIP",j=!Le(at.screen)||Le(at.screen)===q,G=!!(at.trigger_event??at.trigger),X=at.display_trigger!==!1&&!G;return wt&&j&&X}),st=Q(e)??Q(o);return st?ut(st):void 0},[t,e,o,i]),k=Lo(()=>y,[y?.id,y?.details?.id]);if(Ee(()=>{if(!k)return;let q=k.details||{},Q=q?.styling?.soundToggle?.defaultSound||q?.styling?.appearance?.defaultSound||"yes";x(String(Q).toLowerCase()!=="yes"),a(!1),g(!1),f(null),V("viewed",k.id)},[k]),Ee(()=>{h.current&&(h.current.muted=p)},[p]),Ee(()=>{if(!m)return;let q=st=>{let pt=st.clientX-b.current.x,ft=st.clientY-b.current.y;f({x:Math.max(0,pt),y:Math.max(0,ft)})},Q=()=>{u(!1)};return window.addEventListener("mousemove",q),window.addEventListener("mouseup",Q),()=>{window.removeEventListener("mousemove",q),window.removeEventListener("mouseup",Q)}},[m]),!k||!k.details||r||!n)return null;let S=k.details,T=S.styling||{},I=T.appearance||{},c=xt(S.width??I.pipWidth,150),w=xt(S.height??I.pipHeight,300),s=Math.max(c,w),d=Math.min(c,w),E=T.cta?.container||{},F=T.cta?.text||{},A=!!(S.button_text&&S.button_text.trim().length>0),C=xt(T.cta?.container?.height,42),R=A?C+24:0,P=xt(T.pipBottomPadding,20),B=xt(T.pipTopPadding,0),_=l?S.large_video||S.small_video:S.small_video||S.large_video,$=(S.position||k.position||"right").toLowerCase(),D=!!T.isMovable,O=T.soundToggle?.enabled!==!1,W=T.crossButton?.enabled!==!1,Y=T.expandControls?.enabled!==!1&&String(T.expandablePip||"yes").toLowerCase()==="yes",dt=T.crossButton,M=l?T.expandControls?.minimise:T.expandControls?.maximise,N=p?T.soundToggle?.mute:T.soundToggle?.unmute,U={position:"fixed",zIndex:10020,width:l?"100vw":s,height:l?"100vh":d,borderRadius:0,overflow:"hidden",background:"#000",boxShadow:"0 16px 40px rgba(0,0,0,0.35)",cursor:m?"grabbing":D&&!l?"grab":"default",transition:m?"none":"width 180ms ease, height 180ms ease, transform 180ms ease"};v&&!l?(U.left=v.x,U.top=v.y):l?(U.left=0,U.top=0,U.right=0,U.bottom=0):($==="left"?U.left=24:U.right=24,B>0?U.top=B:U.bottom=P+20);let rt=q=>{if(!D||l||q.target.closest("[data-control-button='true']"))return;let st=q.currentTarget.getBoundingClientRect();b.current={x:q.clientX-st.left,y:q.clientY-st.top},f({x:st.left,y:st.top}),u(!0)},ct=()=>{if(!S.link)return;V("clicked",k.id);let q=String(S.link).trim();try{let Q=z.getState(),st=Q.allCampaigns||[],pt=Q.campaigns||[],ft=st.find(at=>at.id===q);if(console.log("[Pip] clicked link=",q,"allCount=",st.length,"visibleCount=",pt.length,"referenced=",!!ft),ft){let at={...ft};delete at.trigger_event,delete at.trigger,at.display_trigger=!0;let wt=pt.findIndex(j=>j.id===at.id);if(wt===-1)Q.saveCampaigns([at,...pt]);else{let j=pt[wt];if(!!(j.trigger_event??j.trigger)){let X=[...pt];X[wt]=at,Q.saveCampaigns(X)}}return}}catch{}window.open(S.link,"_blank")};return _?Dt("div",{style:U,onMouseDown:rt,children:[nt("video",{ref:h,src:_,autoPlay:!0,loop:!0,playsInline:!0,muted:p,style:{width:"100%",height:l&&A?`calc(100% - ${R}px)`:"100%",objectFit:l?"contain":"cover"},onClick:ct,onEnded:()=>{y&&V("analyze",y.id)}}),Dt("div",{style:{position:"absolute",top:8,right:8,display:"flex",gap:8,zIndex:2},children:[O&&nt(De,{iconType:p?"mute":"unmute",config:N,imageOverride:p?S.muteImage:S.unmuteImage,onClick:()=>x(q=>!q)}),Y&&nt(De,{iconType:l?"minimize":"expand",config:M,imageOverride:l?S.minimiseImage:S.maximiseImage,onClick:()=>{console.log("[Pip] expand button clicked - isExpanded before:",l),g(q=>{let Q=!q;return Q&&k?.id&&(V("viewed",k.id),V("analyze",k.id)),Q})}}),W&&nt(De,{iconType:"close",config:dt,imageOverride:S.crossButtonImage,onClick:()=>a(!0)})]}),l&&A&&nt("button",{"data-control-button":"true",onClick:ct,style:{position:"absolute",left:12,right:12,bottom:12,height:E.height||42,width:E.ctaFullWidth?"auto":E.ctaWidth||"auto",margin:E.ctaFullWidth?"0":"0 auto",background:E.backgroundColor||"#F7921C",color:F.color||"#fff",border:`${E.borderWidth||0}px solid ${E.borderColor||"transparent"}`,borderRadius:10,fontSize:F.fontSize||14,fontWeight:600,cursor:S.link?"pointer":"default"},children:S.button_text})]}):null};import wi,{useEffect as We,useRef as _e,useState as me}from"react";import{LottiePlayer as Ri}from"lottie-react";K();import{jsx as Nt}from"react/jsx-runtime";var yt=(t,e=0)=>{let o=Number(t);return Number.isFinite(o)?o:e},$e=t=>(t||"").trim().toLowerCase(),Ti="appstorysmediabucketdev.s3.ap-south-1.amazonaws.com",zi=t=>{try{if(typeof window>"u")return[t];let e=new URL(t);if(e.hostname!==Ti)return[t];let o=!!window.location.port,i=`/appstorys-media${e.pathname}${e.search}`;return o?[i,t]:[t]}catch{return[t]}},Fi=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"},Me=class extends wi.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}},Ii=()=>{let[t,e]=me(null),[o,i]=me([]),[n,r]=me(!1),[a,l]=me(!1),g=_e(null),p=_e(null),x=lt("FLT"),m=z(C=>C.campaigns),u=z(C=>C.allCampaigns),v=z(C=>C.currentScreen),f=z(C=>C.isVisible),b=_e(null),h=x??(()=>{let C=[...m,...u].find(R=>{let P=R;if(P.campaign_type!=="FLT")return!1;let B=!!(P.trigger_event??P.trigger);return P.display_trigger===!1||B?!1:!$e(P.screen)||$e(P.screen)===$e(v)});if(C)try{return ut(C)}catch{return C}})(),y=h?.id,k=z(C=>y?C.variantMappings[y]:void 0);if(We(()=>{if(!h?.id||!f||Be(h)&&!k)return;let R=`${h.id}:${k||""}`;b.current!==R&&(b.current=R,V("viewed",h.id))},[h?.id,k,f]),We(()=>{let C=h?.details?.lottie_data;if(e(null),i([]),r(!1),l(!1),!C)return;if(Fi(C)){e(C),l(!0);return}if(typeof C!="string"){r(!0);return}let R=zi(C);i(R),l(!0)},[h?.details?.lottie_data]),We(()=>{if(!h?.details?.lottie_data||!g.current)return;let C=Ri;if(!C||typeof C.loadAnimation!="function"){r(!0),l(!1);return}let R=!1,P=null,B=()=>{P&&typeof P.destroy=="function"&&P.destroy(),P=null,p.current=null},_=($,D)=>{if(R)return;if(D>=$.length){r(!0),l(!1),console.error("[Floater] lottie load failed",{lottieUrls:$});return}B();let O=C.loadAnimation({container:g.current,renderer:"svg",loop:!0,autoplay:!0,path:$[D]});P=O,p.current=O,O.addEventListener("DOMLoaded",()=>{R||l(!1)}),O.addEventListener("data_failed",()=>{R||_($,D+1)})};if(t){B();let $=C.loadAnimation({container:g.current,renderer:"svg",loop:!0,autoplay:!0,animationData:t});P=$,p.current=$,$.addEventListener("DOMLoaded",()=>{R||l(!1)}),$.addEventListener("data_failed",()=>{R||(r(!0),l(!1))})}else o.length>0&&_(o,0);return()=>{R=!0,B()}},[h?.details?.lottie_data,t,o]),!h||!h.details||!f)return null;let{details:S}=h,T=S.styling||{},c=(typeof S.position=="string"?S.position:typeof h.position=="string"?h.position:"right").toLowerCase()==="left"?"left":"right",w={position:"fixed",left:c==="left"?yt(T.marginLeft,12):void 0,right:c==="left"?void 0:yt(T.marginRight,12),top:yt(T.marginTop,0)>0?yt(T.marginTop,0):void 0,bottom:yt(T.marginTop,0)>0?void 0:yt(T.marginBottom,80),zIndex:10040,display:"flex"},s={width:yt(S.width,60),height:yt(S.height,60),background:"transparent",overflow:"hidden",borderBottomLeftRadius:yt(T.bottomLeftRadius,0),borderBottomRightRadius:yt(T.bottomRightRadius,0),borderTopLeftRadius:yt(T.topLeftRadius,0),borderTopRightRadius:yt(T.topRightRadius,0),display:"flex",alignItems:"center",justifyContent:"center",cursor:S.link?"pointer":"default",boxShadow:"0 8px 18px rgba(0,0,0,0.2)"},d=async()=>{if(!S.link)return;await V("clicked",h.id);let C=String(S.link).trim();try{let R=z.getState(),P=R.allCampaigns||[],B=R.campaigns||[],_=P.find($=>{if(!$)return!1;let D=String($.id||"").trim(),O=$.details||{},W=String(O.campaign||O.id||"").trim();return!!(D&&D===C||W&&W===C||D&&C.includes(D)||W&&C.includes(W))});if(console.log("[Floater] clicked link=",C,"allCampaignsCount=",P.length,"visibleCount=",B.length),console.log("[Floater] all ids=",P.map($=>$.id).slice(0,50)),console.log("[Floater] referenced found=",!!_,_&&(_.id||_.details?.campaign||_.details?.id)),_){let $={..._};delete $.trigger_event,delete $.trigger,$.display_trigger=!0;let D=B.findIndex(O=>O.id===$.id);if(D===-1)console.log("[Floater] revealing campaign (prepended)",$.id),R.saveCampaigns([$,...B]);else{let O=B[D];if(!!(O.trigger_event??O.trigger)){let Y=[...B];Y[D]=$,console.log("[Floater] replacing existing triggered campaign with revealed one",$.id),R.saveCampaigns(Y)}else console.log("[Floater] campaign already visible and not trigger-driven",$.id)}return}}catch(R){console.warn("[Floater] error while resolving referenced campaign",R)}try{window.open(S.link,"_blank")}catch{}},E=!!(S.lottie_data&&!n),F=!!S.image,A=!!(S.lottie_data&&a&&!t&&!n);return!E&&!F&&!A?null:Nt("div",{style:w,children:Nt("div",{style:s,onClick:()=>{d()},children:E?Nt(Me,{onError:()=>r(!0),children:Nt("div",{ref:g,style:{width:"100%",height:"100%",display:"block"}})},String(S.lottie_data)):A?Nt("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:"..."}):Nt("img",{src:S.image,alt:"floater",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}})})})},Bi=Ii;K();function Wo(t){return(t||"").trim().toLowerCase()}function Oe(t,e){let o=Wo(t.screen),i=Wo(e);return!o||o===i}async function je(t){try{let e=z.getState(),o=await it(),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:ht(),screenName:t})});if(!r.ok)return;let a=await r.json();if(typeof a.screen_capture_enabled<"u"&&e.setScreenCaptureEnabled(!!a.screen_capture_enabled),a.variants&&a.variants.length>0){let y={};a.variants.forEach(k=>{y[k.id]=k.v_id}),e.setVariantMappings(y)}a.personalization_data&&e.setPersonalizationData(a.personalization_data);let l=e.allCampaigns||[],g=a.eligibleCampaignList||[],p=l.filter(y=>g.includes(y.id)&&Oe(y,t)),x=p.map(y=>y.id),m=g.filter(y=>!x.includes(y)),u=[];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&&(u=(await y.json()).filter(S=>Oe(S,t)))}let v=[...p,...u],f=l.filter(y=>{let k=!!(y.trigger_event??y.trigger);return Oe(y,t)&&y.display_trigger===!0&&!k}),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)}}ce();K();de();async function Ne(t){try{let e=await it(),o=ht(),i=z.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 Lt();n={...n,...r};let a={user_id:o,attributes:n},l=i.baseUrl||"https://users.appstorys.co";await ge({url:`${l}/update-user-atr`,method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`},body:a})}catch(e){console.error("AppStorys: Error in setUserProperties:",e)}}K();function ye(t){if(!t||t.trim()==="")return t;let e=z.getState().personalizationData;if(!e||Object.keys(e).length===0)return Ai(t);let o=/\{\{([^|}\s]+)\s*\|\s*([^}]+)\}\}/g;return t.replace(o,(i,n,r)=>{let a=n.trim(),l=r.trim();return e[a]??l})}function Ai(t){let e=/\{\{[^|}\s]+\s*\|\s*([^}]+)\}\}/g;return t.replace(e,(o,i)=>i.trim())}Ot();K();K();var qe="appstorys_campaigns_cache",_o="appstorys_campaigns_etag",Ue="appstorys_campaigns_version";async function He(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(qe),r=await tt.getItem(_o),a=await tt.getItem(Ue),l={Accept:"application/json"};!o&&r&&(l["If-None-Match"]=r);let g=await fetch(i,{method:"GET",headers:l,...o?{cache:"no-store"}:{}});if(g.status===304)return{campaigns:n?JSON.parse(n):[],version:a?parseInt(a):1};let p=g.headers.get("ETag"),x=await g.json(),m=2,u=x,v=e;if(!v)try{let f=await it(),b=ht(),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 k=await y.json();console.info("AppStorys: fetchAllCampaigns track-user-res returned",k);let S=k?.screenName||k?.screen||k?.currentScreen||k?.screen_name||k?.current_screen;S&&(v=S);try{let T=z.getState();typeof k.screen_capture_enabled<"u"&&T.setScreenCaptureEnabled(!!k.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,u=x.slice(1)),!u||u.length===0)try{let f=await it(),b=ht(),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 k=await y.json(),S=k?.user_id||k?.id||k?.userId||b;try{let T=z.getState();typeof k.screen_capture_enabled<"u"&&T.setScreenCaptureEnabled(!!k.screen_capture_enabled)}catch{}if(S){let I=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:S})});if(I.ok){let c=await I.json();console.log(`Fetched ${c.length} missing campaigns from fallback`),console.log("Fallback campaigns:",JSON.stringify(c,null,2)),c&&c.length>0&&(u=c)}else console.error("Failed to fetch missing campaigns:",await I.text())}}}catch(f){console.error("Error fetching missing campaigns via fallback:",f)}if(v&&u&&u.length>0){let f=h=>(h||"").trim().toLowerCase(),b=f(v);u=u.filter(h=>!f(h.screen)||f(h.screen)===b)}return await tt.setItem(qe,JSON.stringify(u)),await tt.setItem(Ue,m.toString()),p&&await tt.setItem(_o,p),{campaigns:u,version:m}}catch(o){console.error("Error fetching campaigns:",o);let i=await tt.getItem(qe),n=await tt.getItem(Ue);return{campaigns:i?JSON.parse(i):[],version:n?parseInt(n):1}}}K();K();K();async function Ve(t,e){try{let o=await it(),i=z.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",a=await fetch(`${r}/reconcile-anonymous-user`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o}`},body:JSON.stringify(n)});if(a.ok)return!0;{let l=await a.text();return console.error("AppStorys: Failed to reconcile anonymous user:",a.status,l),!1}}catch(o){return console.error("AppStorys: Error in reconcileAnonymousUser:",o),!1}}K();var Ye=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&&Ae()&&this.triggerCampaign()};handlePopState=()=>{Ae()&&(window.history.pushState("appstorys_navigation",""),this.triggerCampaign())};triggerCampaign(){let e=z.getState(),{trackedEvents:o}=e;o.includes(le)||(console.log("AppStorys: Exit Intent triggered. Displaying campaign."),e.setTrackedEvents([...o,le]))}},$o=new Ye;K();var Qe=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=z.getState();o.isVisible!==e&&(console.log(`AppStorys: SDK visibility changed to ${e?"visible":"hidden"}`),o.setVisibility(e))}},Ge=new Qe;Ot();var he="anonymous_user_id";async function Mo(){let t=Date.now(),e=navigator.userAgent.split(" ")[0].replace(/[^a-zA-Z0-9]/g,"_");return`${t}_${e}`}async function Oo(){try{let t=await tt.getItem(he);if(t)return t;let e=await Mo();return await tt.setItem(he,e),e}catch(t){return console.error("Error managing anonymous user ID:",t),await Mo()}}async function jo(){try{await tt.removeItem(he)}catch(t){console.error("Error clearing anonymous user ID:",t)}}async function Je(){try{return await tt.getItem(he)}catch(t){return console.error("Error getting stored anonymous user ID:",t),null}}function Pi(){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 Ms(){Ws();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 Wi(){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=Ms();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 Yt.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 Oi=jt(()=>{"use strict";K();$i();try{window.AppStorysMountCapture=function(){try{return Wi()}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 un=(n=>(n.uninitialized="uninitialized",n.initializing="initializing",n.initialized="initialized",n.error="error",n))(un||{});K();import{useState as $e,useEffect as Sn,useRef as rr}from"react";import*as Kt from"lottie-react";K();import{useMemo as Ji}from"react";K();var Gi=t=>F.getState().variantMappings[t];function po(t){return!!(t.details&&typeof t.details=="object"&&"variants"in t.details)}function mt(t){if(!po(t))return t;let e=Gi(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 Ae="__back_press_triggered__";function fn(t){return(t||"").trim().toLowerCase()}function Xi(t,e){let o=fn(t),i=fn(e);return!o||o===i}function Ki(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 Zi(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:Ki(String(r),n.operator,n.value)}))}function tr(t,e,o){let i=t,n=i.trigger_event??i.trigger,r=t.id;return!n}function uo(){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(Ae)||!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 Zi(c,u)})}function ut(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 Ji(()=>{let c=m=>m.find(g=>Xi(g.screen,o)&&g.campaign_type===t&&(e?.position?g.position===e.position:!0)&&tr(g,r,s)),x=(i&&i.length>0?c(i):void 0)??c(n||[]);if(x)return mt(x)},[i,n,r,s,a,t,e,o])}K();Ee();Xt();K();Pe();var yn="appstorys_offline_queue";async function hn(){let t=await et.getItem(yn);return t?JSON.parse(t):[]}async function bn(t){await et.setItem(yn,JSON.stringify(t))}function er(t){return Math.min(3e4*Math.pow(2,t),12e4)}function or(t){let o=t.retryCount||0,i=t.lastAttempt||0,n=er(o);return o<3&&Date.now()-i>=n}async function nr(){let t=F.getState();return!t.accountId||!t.appId?!1:await At(t.accountId,t.appId,t.userId)}async function xn(t,e){if(await nr()){let i=await et.getItem("access_token");i&&(t.headers={...t.headers,Authorization:`Bearer ${i}`}),t.authRetried=!0,t.lastAttempt=Date.now(),e(t)}}async function De(t,e){let o=(t.retryCount||0)+1;o<=3&&(t.retryCount=o,t.lastAttempt=Date.now(),e(t))}async function Le(t){let e=await hn();e.push(t),await bn(e)}async function ir(){let t=await hn();if(t.length===0)return;let e=[];for(let o of t){if(!or(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 xn(o,n=>e.push(n)):i.status>=500&&await De(o,n=>e.push(n))}catch{await De(o,n=>e.push(n))}}await bn(e)}async function _e(t){if(!navigator.onLine){await Le(t);return}await ir();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 xn(t,Le):e.status>=500&&await De(t,Le)),e}catch{await De(t,Le);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 Nt();s={...s,...u}}if(e&&String(e).trim()!==""){let u=gn(e);u&&(s.variant_id=u)}let a={user_id:Ct(),event:t,metadata:s};e&&(a.campaign_id=e);let c=n.trackingUrl||"https://tracking.appstorys.co";i&&await _e({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 yt(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 go,jsxs as ar}from"react/jsx-runtime";var Cn=Kt.default?.default??Kt.default??Kt.Lottie??Kt,sr=()=>{let t=ut("BAN"),e=F(w=>w.isVisible),[o,i]=$e(!1),[n,r]=$e(null),[s,a]=$e(null),c=rr(null),[u,x]=$e(0);if(Sn(()=>{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]),Sn(()=>{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 ar("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(yt(m.link))return}catch(w){console.warn("revealCampaignFromLink error",w)}console.log("Internal link:",m.link)}},children:[n?(()=>{let w=Cn.default||Cn;return go(w,{animationData:n,loop:!0,autoplay:e,style:b})})():m.image?go("img",{src:m.image,alt:"Campaign Banner",style:b}):null,g.crossButton?.enabled&&go("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 mo,useMemo as Rn,useRef as Tn,useState as ue}from"react";K();function Me(t){let e=t.trim();return e.startsWith("http://")||e.startsWith("https://")}function vn(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 wn(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 We=new Map;async function lr(t,e){try{wn(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 fo={async load(t){if(!t||!Me(t))return;let e=We.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:vn(t),listeners:[]};We.set(t,i);let n=new Promise(r=>i.listeners.push(r));return lr(t,i),n},ensure(t){if(!t||!Me(t))return;let e=vn(t);return wn(e,t),fo.load(t),e},getSync(t){if(!t)return;let e=We.get(t);return e?.status==="loaded"?e.name:void 0},_clearCache(){We.clear()}};function ct(t){if(t)return Me(t)?fo.ensure(t):t}function dr(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"&&Me(s)&&e.add(s),i(s)}}};return i(t),Array.from(e)}async function kn(t){let e=new Set;for(let o of t)dr(o).forEach(i=>e.add(i));await Promise.all(Array.from(e).map(o=>fo.load(o)))}import{jsx as st,jsxs as qt}from"react/jsx-runtime";var yo=t=>(t||"").trim().toLowerCase(),Tt=(t,e)=>{let o=Number(t);return Number.isFinite(o)?o:e};function cr({iconType:t,color:e}){let o=e||"#FFFFFF";return t==="close"?qt("svg",{viewBox:"0 0 24 24",width:"70%",height:"70%","aria-hidden":!0,children:[st("line",{x1:"6",y1:"6",x2:"18",y2:"18",stroke:o,strokeWidth:"2.2",strokeLinecap:"round"}),st("line",{x1:"18",y1:"6",x2:"6",y2:"18",stroke:o,strokeWidth:"2.2",strokeLinecap:"round"})]}):t==="expand"?qt("svg",{viewBox:"0 0 24 24",width:"70%",height:"70%","aria-hidden":!0,children:[st("polyline",{points:"8,3 3,3 3,8",fill:"none",stroke:o,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),st("line",{x1:"3",y1:"3",x2:"9",y2:"9",stroke:o,strokeWidth:"2",strokeLinecap:"round"}),st("polyline",{points:"16,21 21,21 21,16",fill:"none",stroke:o,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),st("line",{x1:"15",y1:"15",x2:"21",y2:"21",stroke:o,strokeWidth:"2",strokeLinecap:"round"})]}):t==="minimize"?qt("svg",{viewBox:"0 0 24 24",width:"70%",height:"70%","aria-hidden":!0,children:[st("polyline",{points:"9,9 3,9 3,3",fill:"none",stroke:o,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),st("line",{x1:"3",y1:"9",x2:"9",y2:"3",stroke:o,strokeWidth:"2",strokeLinecap:"round"}),st("polyline",{points:"15,15 21,15 21,21",fill:"none",stroke:o,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),st("line",{x1:"15",y1:"21",x2:"21",y2:"15",stroke:o,strokeWidth:"2",strokeLinecap:"round"})]}):t==="mute"?qt("svg",{viewBox:"0 0 24 24",width:"70%",height:"70%","aria-hidden":!0,children:[st("polygon",{points:"4,10 8,10 13,6 13,18 8,14 4,14",fill:"none",stroke:o,strokeWidth:"2",strokeLinejoin:"round"}),st("line",{x1:"16",y1:"8",x2:"21",y2:"16",stroke:o,strokeWidth:"2",strokeLinecap:"round"}),st("line",{x1:"21",y1:"8",x2:"16",y2:"16",stroke:o,strokeWidth:"2",strokeLinecap:"round"})]}):qt("svg",{viewBox:"0 0 24 24",width:"70%",height:"70%","aria-hidden":!0,children:[st("polygon",{points:"4,10 8,10 13,6 13,18 8,14 4,14",fill:"none",stroke:o,strokeWidth:"2",strokeLinejoin:"round"}),st("path",{d:"M16 10 Q18 12 16 14",fill:"none",stroke:o,strokeWidth:"2",strokeLinecap:"round"}),st("path",{d:"M18 8 Q22 12 18 16",fill:"none",stroke:o,strokeWidth:"2",strokeLinecap:"round"})]})}function ho({iconType:t,config:e,imageOverride:o,onClick:i}){let n=Tt(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 st("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:Tt(s.top,0),marginRight:Tt(s.right,0),marginBottom:Tt(s.bottom,0),marginLeft:Tt(s.left,0)},children:a?st("img",{src:a,alt:t,style:{width:n,height:n,objectFit:"contain"}}):st(cr,{iconType:t,color:c})})}var pr=()=>{let t=ut("PIP"),e=F(N=>N.campaigns),o=F(N=>N.allCampaigns),i=F(N=>N.currentScreen),n=F(N=>N.isVisible),[r,s]=ue(!1),[a,c]=ue(!1),[u,x]=ue(!0),[m,g]=ue(!1),[v,f]=ue(null),b=Tn({x:0,y:0}),h=Tn(null),y=Rn(()=>{if(t)return t;let N=yo(i),Y=tt=>tt.find(pt=>{let lt=pt,vt=lt.campaign_type==="PIP",Bt=!yo(lt.screen)||yo(lt.screen)===N,ae=!!(lt.trigger_event??lt.trigger),Ot=lt.display_trigger!==!1&&!ae;return vt&&Bt&&Ot}),Q=Y(e)??Y(o);return Q?mt(Q):void 0},[t,e,o,i]),w=Rn(()=>y,[y?.id,y?.details?.id]);if(mo(()=>{if(!w)return;let N=w.details||{},Y=N?.styling?.soundToggle?.defaultSound||N?.styling?.appearance?.defaultSound||"yes";x(String(Y).toLowerCase()!=="yes"),s(!1),c(!1),f(null),H("viewed",w.id)},[w]),mo(()=>{h.current&&(h.current.muted=u)},[u]),mo(()=>{if(!m)return;let N=Q=>{let tt=Q.clientX-b.current.x,pt=Q.clientY-b.current.y;f({x:Math.max(0,tt),y:Math.max(0,pt)})},Y=()=>{g(!1)};return window.addEventListener("mousemove",N),window.addEventListener("mouseup",Y),()=>{window.removeEventListener("mousemove",N),window.removeEventListener("mouseup",Y)}},[m]),!w||!w.details||r||!n)return null;let I=w.details,z=I.styling||{},R=z.appearance||{},d=Tt(I.width??R.pipWidth,150),T=Tt(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=Tt(z.cta?.container?.height,42),S=L?C+24:0,_=Tt(z.pipBottomPadding,20),E=Tt(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",gt=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=N=>{if(!k||a||N.target.closest("[data-control-button='true']"))return;let Q=N.currentTarget.getBoundingClientRect();b.current={x:N.clientX-Q.left,y:N.clientY-Q.top},f({x:Q.left,y:Q.top}),g(!0)},at=()=>{if(!I.link)return;H("clicked",w.id);let N=String(I.link).trim();try{let Y=F.getState(),Q=Y.allCampaigns||[],tt=Y.campaigns||[],pt=Q.find(lt=>lt.id===N);if(console.log("[Pip] clicked link=",N,"allCount=",Q.length,"visibleCount=",tt.length,"referenced=",!!pt),pt){let lt={...pt};delete lt.trigger_event,delete lt.trigger,lt.display_trigger=!0;let vt=tt.findIndex(Bt=>Bt.id===lt.id);if(vt===-1)Y.saveCampaigns([lt,...tt]);else{let Bt=tt[vt];if(!!(Bt.trigger_event??Bt.trigger)){let Ot=[...tt];Ot[vt]=lt,Y.saveCampaigns(Ot)}}return}}catch{}window.open(I.link,"_blank")};return $?qt("div",{style:J,onMouseDown:V,children:[st("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:at,onEnded:()=>{y&&H("analyze",y.id)}}),qt("div",{style:{position:"absolute",top:8,right:8,display:"flex",gap:8,zIndex:2},children:[P&&st(ho,{iconType:u?"mute":"unmute",config:X,imageOverride:u?I.muteImage:I.unmuteImage,onClick:()=>x(N=>!N)}),G&&st(ho,{iconType:a?"minimize":"expand",config:j,imageOverride:a?I.minimiseImage:I.maximiseImage,onClick:()=>{console.log("[Pip] expand button clicked - isExpanded before:",a),c(N=>{let Y=!N;return Y&&w?.id&&(H("viewed",w.id),H("analyze",w.id)),Y})}}),O&&st(ho,{iconType:"close",config:gt,imageOverride:I.crossButtonImage,onClick:()=>s(!0)})]}),a&&L&&st("button",{"data-control-button":"true",onClick:at,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 ur,{useEffect as bo,useRef as xo,useState as Oe}from"react";import{LottiePlayer as gr}from"lottie-react";K();import{jsx as Zt}from"react/jsx-runtime";var bt=(t,e=0)=>{let o=Number(t);return Number.isFinite(o)?o:e},So=t=>(t||"").trim().toLowerCase(),fr="appstorysmediabucketdev.s3.ap-south-1.amazonaws.com",mr=t=>{try{if(typeof window>"u")return[t];let e=new URL(t);if(e.hostname!==fr)return[t];let o=!!window.location.port,i=`/appstorys-media${e.pathname}${e.search}`;return o?[i,t]:[t]}catch{return[t]}},yr=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"},Co=class extends ur.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}},hr=()=>{let[t,e]=Oe(null),[o,i]=Oe([]),[n,r]=Oe(!1),[s,a]=Oe(!1),c=xo(null),u=xo(null),x=ut("FLT"),m=F(C=>C.campaigns),g=F(C=>C.allCampaigns),v=F(C=>C.currentScreen),f=F(C=>C.isVisible),b=xo(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:!So(_.screen)||So(_.screen)===So(v)});if(C)try{return mt(C)}catch{return C}})(),y=h?.id,w=F(C=>y?C.variantMappings[y]:void 0);if(bo(()=>{if(!h?.id||!f||po(h)&&!w)return;let S=`${h.id}:${w||""}`;b.current!==S&&(b.current=S,H("viewed",h.id))},[h?.id,w,f]),bo(()=>{let C=h?.details?.lottie_data;if(e(null),i([]),r(!1),a(!1),!C)return;if(yr(C)){e(C),a(!0);return}if(typeof C!="string"){r(!0);return}let S=mr(C);i(S),a(!0)},[h?.details?.lottie_data]),bo(()=>{if(!h?.details?.lottie_data||!c.current)return;let C=gr;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"?bt(z.marginLeft,12):void 0,right:d==="left"?void 0:bt(z.marginRight,12),top:bt(z.marginTop,0)>0?bt(z.marginTop,0):void 0,bottom:bt(z.marginTop,0)>0?void 0:bt(z.marginBottom,80),zIndex:10040,display:"flex"},l={width:bt(I.width,60),height:bt(I.height,60),background:"transparent",overflow:"hidden",borderBottomLeftRadius:bt(z.bottomLeftRadius,0),borderBottomRightRadius:bt(z.bottomRightRadius,0),borderTopLeftRadius:bt(z.topLeftRadius,0),borderTopRightRadius:bt(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:Zt("div",{style:T,children:Zt("div",{style:l,onClick:()=>{p()},children:M?Zt(Co,{onError:()=>r(!0),children:Zt("div",{ref:c,style:{width:"100%",height:"100%",display:"block"}})},String(I.lottie_data)):L?Zt("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:"..."}):Zt("img",{src:I.image,alt:"floater",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}})})})},br=hr;K();function Fn(t){return(t||"").trim().toLowerCase()}function vo(t,e){let o=Fn(t.screen),i=Fn(e);return!o||o===i}async function wo(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:Ct(),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)&&vo(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=>vo(I,t)))}let v=[...u,...g],f=a.filter(y=>{let w=!!(y.trigger_event??y.trigger);return vo(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)}}Pe();K();Ee();async function ko(t){try{let e=await dt(),o=Ct(),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 Nt();n={...n,...r};let s={user_id:o,attributes:n},a=i.baseUrl||"https://users.appstorys.co";await _e({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 je(t){if(!t||t.trim()==="")return t;let e=F.getState().personalizationData;if(!e||Object.keys(e).length===0)return xr(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 xr(t){let e=/\{\{[^|}\s]+\s*\|\s*([^}]+)\}\}/g;return t.replace(e,(o,i)=>i.trim())}Xt();K();K();var Ro="appstorys_campaigns_cache",In="appstorys_campaigns_etag",To="appstorys_campaigns_version";async function Fo(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 et.getItem(Ro),r=await et.getItem(In),s=await et.getItem(To),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=Ct(),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=Ct(),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 et.setItem(Ro,JSON.stringify(g)),await et.setItem(To,m.toString()),u&&await et.setItem(In,u),{campaigns:g,version:m}}catch(o){console.error("Error fetching campaigns:",o);let i=await et.getItem(Ro),n=await et.getItem(To);return{campaigns:i?JSON.parse(i):[],version:n?parseInt(n):1}}}K();K();K();async function Ne(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 Io=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&&uo()&&this.triggerCampaign()};handlePopState=()=>{uo()&&(window.history.pushState("appstorys_navigation",""),this.triggerCampaign())};triggerCampaign(){let e=F.getState(),{trackedEvents:o}=e;o.includes(Ae)||(console.log("AppStorys: Exit Intent triggered. Displaying campaign."),e.setTrackedEvents([...o,Ae]))}},zn=new Io;K();var zo=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))}},Bo=new zo;Xt();var qe="anonymous_user_id";async function Bn(){let t=Date.now(),e=navigator.userAgent.split(" ")[0].replace(/[^a-zA-Z0-9]/g,"_");return`${t}_${e}`}async function An(){try{let t=await et.getItem(qe);if(t)return t;let e=await Bn();return await et.setItem(qe,e),e}catch(t){return console.error("Error managing anonymous user ID:",t),await Bn()}}async function Ao(){try{await et.removeItem(qe)}catch(t){console.error("Error clearing anonymous user ID:",t)}}async function Eo(){try{return await et.getItem(qe)}catch(t){return console.error("Error getting stored anonymous user ID:",t),null}}function Sr(){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,10 @@ var si=Object.defineProperty;var Et=(t,e)=>()=>(t&&(e=t(t=0)),e);var ai=(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 No(t){let e=document.createElement("div");return e.className="appstorys-widget-debug-pill",e.textContent=t,e}function Ei(t){let e=t,o=getComputedStyle(e);(o.position==="static"||!o.position)&&(e.style.position="relative")}window.AppStorysShowWidgetElements=function(){try{Pi();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=No("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;Ei(n),n.classList.add("appstorys-widget-debug-overlay");let r=n.querySelector(".appstorys-widget-debug-pill");r&&r.remove();let a=No("Widget "+(i+1));n.appendChild(a)})}catch(e){console.error("AppStorysShowWidgetElements error",e)}};K();import{useState as An,useEffect as Pn}from"react";import{useEffect as Li,useState as qo}from"react";import*as qt from"lottie-react";import{jsx as Ho}from"react/jsx-runtime";var Uo=qt.default?.default??qt.default??qt.Lottie??qt,bt=({src:t,alt:e,style:o,size:i})=>{let[n,r]=qo(null),[a,l]=qo(!1);Li(()=>{t&&t.toLowerCase().endsWith(".json")?fetch(t).then(p=>{if(!p.ok)throw new Error("Failed to fetch Lottie");return p.json()}).then(p=>{r(p),l(!1)}).catch(p=>{console.error("AppStorys: Error loading Lottie thumbnail:",p),l(!0)}):(r(null),l(!1))},[t]);let g={width:i?`${i}px`:o?.width||"100%",height:i?`${i}px`:o?.height||"100%",objectFit:"cover",display:"block",...o};if(n&&!a){let p=Uo.default||Uo;return Ho(p,{animationData:n,loop:!0,autoplay:!0,style:g})}return Ho("img",{src:t,alt:e||"story thumbnail",style:g,onError:()=>l(!0)})};import{jsx as Ke,jsxs as Di}from"react/jsx-runtime";var Vo=({story:t,isViewed:e,onClick:o})=>{let i=t.styling||{},n=i.size||80,r=i.ringWidth||3,a=e?"#E5E7EB":t.ringColor||"#FF0000",l=t.nameColor||"#333333",g=i.cornerRadius,p=g?`${g.topLeft||0}px ${g.topRight||0}px ${g.bottomRight||0}px ${g.bottomLeft||0}px`:"50%",x=g?`${Math.max(0,(g.topLeft||0)-3)}px ${Math.max(0,(g.topRight||0)-3)}px ${Math.max(0,(g.bottomRight||0)-3)}px ${Math.max(0,(g.bottomLeft||0)-3)}px`:"50%";return Di("div",{onClick:o,style:{display:"flex",flexDirection:"column",alignItems:"center",cursor:"pointer",flexShrink:0},children:[Ke("div",{style:{width:`${n}px`,height:`${n}px`,borderRadius:p,border:`${r}px solid ${a}`,padding:"3px",boxSizing:"border-box",transition:"transform 0.1s ease",overflow:"hidden",backgroundColor:"#f5f5f5"},children:Ke(bt,{src:t.thumbnail,alt:t.name,style:{borderRadius:x}})}),Ke("span",{style:{marginTop:"6px",fontSize:`${i.name?.size||12}px`,fontFamily:i.name?.fontFamily||"sans-serif",fontWeight:i.name?.font==="Bold"?"bold":"normal",color:l,maxWidth:`${n+10}px`,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.name})]})};import{jsx as Yo}from"react/jsx-runtime";var Qo=({stories:t,viewedStories:e,onStoryClick:o})=>Yo("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)=>Yo(Vo,{story:i,isViewed:e.includes(i.id),onClick:()=>o(n)},i.id))});import{useState as Bt,useEffect as ee,useRef as ao}from"react";K();import{jsx as Go,jsxs as Xe}from"react/jsx-runtime";var Jo=({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||{},a={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"},l={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'},g={display:"flex",flexDirection:i?"row":"column",gap:"4px",width:"100%",backgroundColor:"#1A1A1A",borderRadius:"12px",overflow:"hidden",padding:"2px"},p={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=u=>{o||e?.({type:"poll",pollId:t.id,optionId:u,stickerId:t.id})},m=Array.isArray(t.options)?t.options:[];return Xe("div",{style:a,children:[Go("h3",{style:l,children:t.question||"Ask A Question..."}),Go("div",{style:g,children:m.map((u,v)=>Xe("button",{style:{...p,borderRight:i&&v===m.length-1?"none":p.borderRight,borderBottom:!i&&v===m.length-1?"none":p.borderBottom},onClick:()=>x(u.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:[u.text,u.percentage!==void 0&&Xe("span",{style:{fontSize:"11px",opacity:.6,marginLeft:"8px"},children:[u.percentage,"%"]})]},u.id))})]})};import{useState as Wi}from"react";import{jsx as be,jsxs as Ko}from"react/jsx-runtime";var Xo=({data:t,onInteraction:e,isEditing:o=!1})=>{let[i,n]=Wi(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"},a=t.styling||{},l=a.padding??r.padding,g=a.fontSize?a.fontSize+6:22,p=a.optionFontSize||17,x=a.optionBorderRadius||14,m=a.borderColor||r.borderColor,u=Math.min(Math.max(Math.round(p*2.1),18),32),v={backgroundColor:a.backgroundColor||r.backgroundColor,borderRadius:`${a.borderRadius??r.borderRadius}px`,padding:`${l}px`,paddingTop:0,boxShadow:a.shadow||"0 10px 30px rgba(0,0,0,0.12)",boxSizing:"border-box",width:"100%",display:"flex",flexDirection:"column",overflow:"hidden",opacity:a.opacity??1},f={color:a.questionTextColor||r.questionTextColor,backgroundColor:a.questionBgColor||r.questionBgColor,fontWeight:"900",fontSize:`${g}px`,lineHeight:1.25,margin:`0 -${l}px 16px -${l}px`,textAlign:"center",padding:`24px ${l}px`,borderTopLeftRadius:`${a.borderRadius??r.borderRadius}px`,borderTopRightRadius:`${a.borderRadius??r.borderRadius}px`,letterSpacing:"-0.01em"},b={backgroundColor:a.optionBgColor||r.optionBgColor,color:a.optionTextColor||r.optionTextColor,padding:`${a.optionPadding||Math.max(l*.7,10)}px ${Math.max(l*.8,12)}px`,borderRadius:`${x}px`,border:`1px solid ${m}`,display:"flex",alignItems:"center",gap:`${Math.max(Math.round(u*.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:`${u}px`,height:`${u}px`,minWidth:`${u}px`,borderRadius:"50%",backgroundColor:a.labelBgColor||r.labelBgColor,color:a.labelTextColor||r.labelTextColor,border:`${Math.max(Math.round(u*.08),1)}px solid ${a.labelBorderColor||r.labelBorderColor}`,display:"flex",alignItems:"center",justifyContent:"center",fontWeight:"700",fontSize:`${Math.max(Math.round(u*.46),10)}px`},y={backgroundColor:a.backgroundColor||r.backgroundColor,borderRadius:`0 0 ${a.borderRadius??r.borderRadius}px ${a.borderRadius??r.borderRadius}px`,display:"flex",flexDirection:"column",gap:`${Math.max(l*.55,8)}px`},k=I=>{o||i||(n(I),e?.({type:"quiz",quizId:t.id,optionId:I,stickerId:t.id}))},S=["A","B","C","D","E","F"],T=Array.isArray(t.options)?t.options:[];return T.length===0&&!o&&console.warn("AppStorys: QuizSticker has no options!",t.id),Ko("div",{style:{...v,background:a.backgroundColor||r.backgroundColor},children:[t.question&&be("h3",{style:f,children:t.question}),be("div",{style:{...y,background:"transparent"},children:T.map((I,c)=>{let w=I.label||S[c]||"\u2022",s=I.id===i,d=I.isCorrect===!0,E={...b},F={...h};return i&&(d?(E.backgroundColor=a.activeColor||r.activeColor,E.borderColor=a.activeColor||r.activeColor,E.color="#FFFFFF"):s&&(E.backgroundColor=a.incorrectColor||r.incorrectColor,E.borderColor=a.incorrectColor||r.incorrectColor,E.color="#FFFFFF")),Ko("button",{style:E,onClick:()=>k(I.id),disabled:!!i,children:[be("div",{style:h,className:"letter-circle",children:w}),be("span",{style:{fontWeight:"600",fontSize:`${p}px`},children:I.text})]},I.id)})})]})};import{useState as _i,useEffect as $i}from"react";import{jsx as Tt,jsxs as Zo}from"react/jsx-runtime";var tn=({data:t})=>{let[e,o]=_i({days:"00",hours:"00",minutes:"00",seconds:"00"});$i(()=>{if(!t.targetDate)return;let w=()=>{let d=+new Date(t.targetDate)-+new Date;if(d>0){let E=Math.floor(d/864e5),F=Math.floor(d/(1e3*60*60)%24),A=Math.floor(d/1e3/60%60),C=Math.floor(d/1e3%60);o({days:E.toString().padStart(2,"0"),hours:F.toString().padStart(2,"0"),minutes:A.toString().padStart(2,"0"),seconds:C.toString().padStart(2,"0")})}else o({days:"00",hours:"00",minutes:"00",seconds:"00"})},s=setInterval(w,1e3);return w(),()=>clearInterval(s)},[t.targetDate]);let i=t.styling||{},n=t.display||{showDays:!0,showHours:!0,showMinutes:!0,showSeconds:!0},r=Number(i.digitSize||18),a=!isNaN(r)&&r>0?r:18,l=typeof i.labelFontSize<"u"?Number(i.labelFontSize):Math.max(10,Math.round(a*.55)),g=Math.max(30,Math.round(a*1.8)),p=Math.max(24,Math.round(a*1.3)),x=Math.max(6,Math.round(a*.35)),m=Math.max(6,Math.round(a*.25)),u={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:`${p}px`,height:`${g}px`,display:"flex",alignItems:"center",justifyContent:"center",fontSize:`${a}px`,fontWeight:"bold",color:i.digitColor||"#1A202C",padding:"0 4px"},k={fontSize:`${Math.max(9,l)}px`,color:i.labelColor||"#A0AEC0",fontWeight:"600",textTransform:"lowercase"},S={fontSize:`${Math.max(14,Math.round(a*.9))}px`,fontWeight:"700",color:i.labelColor||"#A0AEC0",display:"flex",alignItems:"center",lineHeight:1},T=(w,s)=>Zo("div",{style:b,children:[Tt("div",{style:h,children:w.split("").map((d,E)=>Tt("div",{style:y,children:d},E))}),Tt("span",{style:k,children:s})]}),I=[],c=0;return n.showDays!==!1&&(I.push(T(e.days,"days")),c++),n.showHours!==!1&&(c>0&&I.push(Tt("div",{style:S,children:":"},"sep-h")),I.push(T(e.hours,"hours")),c++),n.showMinutes!==!1&&(c>0&&I.push(Tt("div",{style:S,children:":"},"sep-m")),I.push(T(e.minutes,"min")),c++),n.showSeconds!==!1&&(c>0&&I.push(Tt("div",{style:S,children:":"},"sep-s")),I.push(T(e.seconds,"sec")),c++),Zo("div",{style:u,children:[t.title&&Tt("div",{style:v,children:t.title}),Tt("div",{style:f,children:I})]})};import{useState as Mi}from"react";import{jsx as Ut,jsxs as xe}from"react/jsx-runtime";var en=({data:t,onInteraction:e})=>{let[o,i]=Mi(!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||{},a={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:`
33
+ `,document.head.appendChild(t)}function En(t){let e=document.createElement("div");return e.className="appstorys-widget-debug-pill",e.textContent=t,e}function Cr(t){let e=t,o=getComputedStyle(e);(o.position==="static"||!o.position)&&(e.style.position="relative")}window.AppStorysShowWidgetElements=function(){try{Sr();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=En("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;Cr(n),n.classList.add("appstorys-widget-debug-overlay");let r=n.querySelector(".appstorys-widget-debug-pill");r&&r.remove();let s=En("Widget "+(i+1));n.appendChild(s)})}catch(e){console.error("AppStorysShowWidgetElements error",e)}};K();import{useState as Si,useEffect as Ci}from"react";import{useEffect as vr,useState as Pn}from"react";import*as te from"lottie-react";import{jsx as Dn}from"react/jsx-runtime";var Ln=te.default?.default??te.default??te.Lottie??te,Ft=({src:t,alt:e,style:o,size:i})=>{let[n,r]=Pn(null),[s,a]=Pn(!1);vr(()=>{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=Ln.default||Ln;return Dn(u,{animationData:n,loop:!0,autoplay:!0,style:c})}return Dn("img",{src:t,alt:e||"story thumbnail",style:c,onError:()=>a(!0)})};import{jsx as Po,jsxs as wr}from"react/jsx-runtime";var _n=({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 wr("div",{onClick:o,style:{display:"flex",flexDirection:"column",alignItems:"center",cursor:"pointer",flexShrink:0},children:[Po("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:Po(Ft,{src:t.thumbnail,alt:t.name,style:{borderRadius:x}})}),Po("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 $n}from"react/jsx-runtime";var Wn=({stories:t,viewedStories:e,onStoryClick:o})=>$n("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)=>$n(_n,{story:i,isViewed:e.includes(i.id),onClick:()=>o(n)},i.id))});import yi,{useState as xt,useEffect as be,useRef as Ho}from"react";K();import{jsx as Mn,jsxs as Lo}from"react/jsx-runtime";var On=({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 Lo("div",{style:s,children:[Mn("h3",{style:a,children:t.question||"Ask A Question..."}),Mn("div",{style:c,children:m.map((g,v)=>Lo("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&&Lo("span",{style:{fontSize:"11px",opacity:.6,marginLeft:"8px"},children:[g.percentage,"%"]})]},g.id))})]})};import{useState as kr}from"react";import{jsx as Ue,jsxs as jn}from"react/jsx-runtime";var Nn=({data:t,onInteraction:e,isEditing:o=!1})=>{let[i,n]=kr(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),jn("div",{style:{...v,background:s.backgroundColor||r.backgroundColor},children:[t.question&&Ue("h3",{style:f,children:t.question}),Ue("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")),jn("button",{style:M,onClick:()=>w(R.id),disabled:!!i,children:[Ue("div",{style:h,className:"letter-circle",children:T}),Ue("span",{style:{fontWeight:"600",fontSize:`${u}px`},children:R.text})]},R.id)})})]})};import{useState as Rr,useEffect as Tr}from"react";import{jsx as _t,jsxs as qn}from"react/jsx-runtime";var Un=({data:t})=>{let[e,o]=Rr({days:"00",hours:"00",minutes:"00",seconds:"00"});Tr(()=>{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)=>qn("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++),qn("div",{style:g,children:[t.title&&_t("div",{style:v,children:t.title}),_t("div",{style:f,children:R})]})};import{useState as Fr}from"react";import{jsx as ee,jsxs as He}from"react/jsx-runtime";var Hn=({data:t,onInteraction:e})=>{let[o,i]=Fr(!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
34
  radial-gradient(circle at 0px 30px, transparent 8px, white 8.5px),
35
35
  radial-gradient(circle at 100% 30px, transparent 8px, white 8.5px)
36
- `,backgroundPosition:"0 0, 100% 0",backgroundSize:"100% 100%",backgroundRepeat:"no-repeat"},l={width:"36px",height:"36px",borderRadius:"8px",backgroundColor:"#F1F3F5",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"18px",fontWeight:"800",color:"#2D3748",border:"1px solid #E2E8F0"},g={fontSize:`${r.fontSize||18}px`,fontWeight:"800",color:"#1A202C",letterSpacing:"1px",flex:1,textAlign:"center"};return xe("div",{style:a,onClick:n,children:[xe("div",{style:{display:"flex",alignItems:"center",gap:"12px",flex:1},children:[Ut("div",{style:l,children:"%"}),Ut("span",{style:g,children:t.code||"OFFER20"})]}),xe("div",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[o&&Ut("span",{style:{fontSize:"11px",color:"#10B981",fontWeight:"700"},children:"Copied!"}),Ut("div",{style:{padding:"8px",display:"flex",alignItems:"center"},children:xe("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"#4A5568",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[Ut("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),Ut("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 on}from"react/jsx-runtime";var nn=({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=g=>{o||e?.({type:"reaction",reactionId:t.id,emoji:g,stickerId:t.id})},a={display:"flex",gap:"20px",justifyContent:"center",alignItems:"center",width:"100%",padding:"12px"},l={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 on("div",{style:a,children:n.map((g,p)=>on("button",{style:l,onClick:()=>r(g),onMouseOver:x=>{o||(x.currentTarget.style.transform="scale(1.15) translateY(-4px)")},onMouseOut:x=>{o||(x.currentTarget.style.transform="scale(1) translateY(0)")},children:g},p))})};import{useState as rn,useRef as Oi,useEffect as ji}from"react";import{jsx as Ze,jsxs as sn}from"react/jsx-runtime";var an=({data:t,onInteraction:e,isEditing:o=!1})=>{let i=t.maxRating||5,n=t.currentRating??Math.floor(i/2),[r,a]=rn(n),l=Oi(null),[g,p]=rn(!1),x={backgroundColor:"#FFFFFF",borderRadius:36,padding:24,titleColor:"#000000",titleFontSize:24,sliderTrackColor:"#F3F4F6",sliderFillColor:"#F97316",emojiSize:42},m=t.styling||{},u={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:g?"none":"width 0.1s ease"},y=m.emojiSize||x.emojiSize,k={position:"absolute",left:`calc(${b}% - ${y/2}px)`,top:`-${y/4}px`,fontSize:`${y}px`,userSelect:"none",cursor:"grab",transition:g?"none":"left 0.1s ease",filter:"drop-shadow(0 4px 8px rgba(0,0,0,0.2))"},S=c=>{if(!l.current||o)return;let w=l.current.getBoundingClientRect(),s=c-w.left;s<0&&(s=0),s>w.width&&(s=w.width);let d=s/w.width,E=Math.round(d*i*10)/10;a(E)},T=c=>{o||(p(!0),S(c.clientX))},I=c=>{o||(p(!0),S(c.touches[0].clientX))};return ji(()=>{let c=d=>{g&&S(d.clientX)},w=()=>{g&&(p(!1),e?.({type:"rating",ratingId:t.id,value:r,stickerId:t.id}))},s=d=>{g&&S(d.touches[0].clientX)};return g&&(window.addEventListener("mousemove",c),window.addEventListener("mouseup",w),window.addEventListener("touchmove",s),window.addEventListener("touchend",w)),()=>{window.removeEventListener("mousemove",c),window.removeEventListener("mouseup",w),window.removeEventListener("touchmove",s),window.removeEventListener("touchend",w)}},[g,r]),sn("div",{style:u,children:[Ze("h3",{style:v,children:t.title||"Do you like my space?"}),sn("div",{ref:l,style:f,onMouseDown:T,onTouchStart:I,children:[Ze("div",{style:h}),Ze("div",{style:k,className:"interactive-emoji-thumb",children:t.emoji||"\u{1F60D}"})]})]})};import{useState as Ni}from"react";import{jsx as Jt,jsxs as to}from"react/jsx-runtime";var ln=({data:t,onInteraction:e,isEditing:o=!1})=>{let[i,n]=Ni(""),r={backgroundColor:"#FFFFFF",borderRadius:16,padding:16,promptColor:"#111111",inputBgColor:"#FFFFFF",borderColor:"#EFEFEF",textColor:"#333333",placeholderColor:"#A0AEC0"},a=t.styling||{},l={backgroundColor:a.backgroundColor||r.backgroundColor,borderRadius:`${a.borderRadius??r.borderRadius}px`,padding:`${a.padding??r.padding}px`,boxShadow:a.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 ${a.borderColor||"#F0F0F0"}`},g={color:a.promptColor||r.promptColor,fontWeight:"700",fontSize:`${a.fontSize?a.fontSize+2:16}px`,textAlign:"center",marginBottom:"2px",width:"100%"},p={width:"100%",position:"relative",display:"flex",alignItems:"center"},x={backgroundColor:a.inputBgColor||"#F1F3F5",border:"none",borderRadius:"30px",padding:"14px 45px 14px 20px",width:"100%",boxSizing:"border-box",color:a.inputTextColor||"#1A202C",fontSize:`${a.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:a.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"},u=f=>{o||n(f.target.value)},v=()=>{o||!i.trim()||(e?.({type:"question",questionId:t.id,value:i.trim(),stickerId:t.id}),n(""))};return to("div",{style:l,children:[Jt("div",{style:g,children:t.question||"Ask me anything"}),to("div",{style:p,children:[Jt("input",{type:"text",value:i,placeholder:t.placeholder||"Type your answer...",style:x,disabled:o,onChange:u,onKeyDown:f=>f.key==="Enter"&&v()}),Jt("button",{style:m,onClick:v,children:to("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:[Jt("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),Jt("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]})})]})]})};import{useState as qi}from"react";import{jsx as Kt,jsxs as eo}from"react/jsx-runtime";var dn=({data:t,onInteraction:e,isEditing:o=!1})=>{let[i,n]=qi(null),r={backgroundColor:"#FFFFFF",borderRadius:20,padding:16,questionTextColor:"#111111",optionBgColor:"#F7FAFC",optionTextColor:"#2D3748",borderColor:"#E2E8F0",activeColor:"#10B981",incorrectColor:"#EF4444"},a=t.styling||{},l={backgroundColor:a.backgroundColor||r.backgroundColor,borderRadius:`${a.borderRadius??r.borderRadius}px`,padding:`${a.padding??r.padding}px`,boxShadow:a.shadow||"0 8px 24px rgba(0,0,0,0.06)",boxSizing:"border-box",width:"100%",display:"flex",flexDirection:"column",gap:"12px",border:a.borderColor?`1px solid ${a.borderColor}`:"none"},g={color:a.questionTextColor||r.questionTextColor,fontWeight:"800",fontSize:`${a.fontSize?a.fontSize+2:16}px`,margin:"0 0 4px 0",textAlign:"left"},p={display:"grid",gridTemplateColumns:"repeat(2, 1fr)",gap:"12px",width:"100%"},x={backgroundColor:a.optionBgColor||r.optionBgColor,color:a.optionTextColor||r.optionTextColor,borderRadius:"16px",border:`2px solid ${a.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}))},u="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 eo("div",{style:l,children:[t.question&&Kt("h3",{style:g,children:t.question}),Kt("div",{style:p,children:v.map(f=>{let b=f.id===i,h=f.isCorrect===!0,y={...x};return i&&(h?(y.borderColor=a.activeColor||r.activeColor,y.backgroundColor="rgba(16, 185, 129, 0.05)"):b&&(y.borderColor=a.incorrectColor||r.incorrectColor,y.backgroundColor="rgba(239, 68, 68, 0.05)")),eo("button",{style:y,onClick:()=>m(f.id),disabled:!!i,onMouseOver:k=>{!o&&!i&&(k.currentTarget.style.transform="translateY(-2px)")},onMouseOut:k=>{!o&&!i&&(k.currentTarget.style.transform="translateY(0)")},children:[eo("div",{style:{width:"100%",aspectRatio:"1",borderRadius:"12px",overflow:"hidden",backgroundColor:"#EDF2F7",display:"flex",alignItems:"center",justifyContent:"center",marginBottom:"8px",position:"relative"},children:[Kt("img",{src:f.image||u,alt:f.text,style:{width:"100%",height:"100%",objectFit:"cover"}}),i&&Kt("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":""})]}),Kt("span",{style:{fontWeight:"600",fontSize:`${a.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 yn}from"react";import{useState as Xt,useEffect as Ui}from"react";import{jsx as H,jsxs as et}from"react/jsx-runtime";var mn=({product:t,styling:e,onClose:o,onAddToCart:i})=>{let[n,r]=Xt(""),[a,l]=Xt(0),[g,p]=Xt(1),[x,m]=Xt(!1),[u,v]=Xt(!1),f=t.attributes||{},b=f.colors||[],h=f.sizes||[],y=f.imageUrls||[t.image],k=f.description||"";Ui(()=>{h.length>0&&r(h[0]),v(!0)},[h]);let S=()=>{let C={productId:t.productId||t.id,title:t.title,selectedSize:n,selectedColor:b[a]?.name,quantity:g,price:t.price};i(C);let R=t.redirectUrl||t.url;if(R){!R.startsWith("http")&&!R.startsWith("//")&&(R="https://"+R);try{window.open(R,"_blank","noopener,noreferrer")}catch(P){console.error("AppStorys: Redirect failed",P)}}m(!0)},T=()=>{v(!1),setTimeout(o,400)},I=e?.buttonBackground||"#000000",c=e?.buttonTextColor||"#ffffff",w=e?.titleColor||e?.textColor||"#1a1a2e",s=e?.priceColor||e?.textColor||"#1a1a2e",d=e?.mrpColor||"#8b8b98",E=e?.titleFontWeight||"600",F=e?.priceFontWeight||"700",A=e?.mrpFontWeight||"500";return x?et("div",{className:"appstorys-shopable-success-overlay",style:cn,children:[H("div",{className:"appstorys-shopable-backdrop",style:pn,onClick:T}),et("div",{className:"appstorys-shopable-sheet",style:{...un,height:"auto",minHeight:"310px",animation:"appstorys-slide-up 0.4s cubic-bezier(0.2, 0.8, 0.2, 1)"},children:[H("div",{style:gn,onClick:T}),et("div",{style:{padding:"0 20px 24px",textAlign:"center"},children:[et("div",{style:{backgroundColor:"#F3F4F6",borderRadius:"20px",padding:"22px",marginTop:"16px",display:"flex",flexDirection:"column",alignItems:"center",gap:"12px"},children:[et("h3",{style:{margin:0,fontSize:"16px",fontWeight:"600",lineHeight:"1.4"},children:["Added to your bag",H("br",{}),"successfully"]}),H("svg",{width:"44",height:"26",viewBox:"0 0 44 26",fill:"none",children:H("path",{d:"M4 4C4 4 11 22 22 22C33 22 40 4 40 4",stroke:"currentColor",strokeWidth:"2.8",strokeLinecap:"round"})})]}),et("div",{style:{marginTop:"24px",display:"flex",flexDirection:"column",gap:"8px"},children:[H("button",{onClick:T,style:{...io,backgroundColor:"#000000",color:"#ffffff",padding:"17px",fontSize:"16px",fontWeight:"600"},children:et("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},children:[et("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[H("path",{d:"M6 2L3 6v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6l-3-4Z"}),H("path",{d:"M3 6h18"}),H("path",{d:"M16 10a4 4 0 0 1-8 0"})]}),"Go to checkout"]})}),H("button",{onClick:T,style:{...io,backgroundColor:"transparent",color:"#000000",border:"1px solid rgba(0,0,0,0.1)",padding:"15px",fontSize:"16px"},children:"Continue with stories"})]})]})]})]}):et("div",{className:`appstorys-shopable-overlay ${u?"visible":""}`,style:cn,children:[H("div",{className:"appstorys-shopable-backdrop",style:pn,onClick:T}),et("div",{className:"appstorys-shopable-sheet",style:{...un,transform:u?"translateY(0)":"translateY(100%)",opacity:u?1:0},children:[et("div",{style:Hi,children:[H("div",{style:gn,onClick:T}),H("button",{style:Vi,onClick:T,children:et("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:[H("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),H("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),et("div",{style:Yi,children:[H("div",{style:Qi,children:y.map((C,R)=>H("div",{style:{minWidth:y.length>1?"85%":"100%",aspectRatio:"1.2 / 1",maxHeight:"240px",borderRadius:"16px",overflow:"hidden",backgroundColor:"#F9FAFB"},children:H("img",{src:C,alt:t.title,style:{width:"100%",height:"100%",objectFit:"contain"}})},R))}),et("div",{style:{padding:"0 20px 20px"},children:[H("h2",{style:{margin:"16px 0 4px",fontSize:e?.titleFontSize?`${e.titleFontSize}px`:"20px",fontWeight:E,color:w,lineHeight:"1.2"},children:t.title}),et("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",marginBottom:"16px"},children:[H("span",{style:{fontSize:e?.priceFontSize?`${e.priceFontSize}px`:"18px",fontWeight:F,color:s},children:t.price}),t.oldPrice&&H("span",{style:{fontSize:e?.mrpFontSize?`${e.mrpFontSize}px`:"14px",color:d,textDecoration:"line-through",fontWeight:A},children:t.oldPrice})]}),b.length>0&&et("div",{style:oo,children:[H("div",{style:no,children:"COLOR"}),H("div",{style:{display:"flex",gap:"14px",marginTop:"12px"},children:b.map((C,R)=>et("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"5px"},children:[H("button",{onClick:()=>l(R),style:{width:"36px",height:"36px",borderRadius:"50%",border:"none",backgroundColor:C.hex||"#gray",position:"relative",cursor:"pointer",boxShadow:a===R?"0 0 0 2px #fff, 0 0 0 4px #000":"none",transition:"all 0.2s ease"}}),H("div",{style:{width:"5px",height:"5px",borderRadius:"50%",backgroundColor:a===R?"#000":"transparent",transition:"all 0.2s ease"}})]},C.id))})]}),h.length>0&&et("div",{style:oo,children:[H("div",{style:no,children:"SIZE"}),H("div",{style:{display:"flex",gap:"10px",marginTop:"12px",flexWrap:"wrap"},children:h.map(C=>et("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"4px"},children:[H("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}),H("div",{style:{width:"5px",height:"5px",borderRadius:"50%",backgroundColor:n===C?"#000":"transparent",transition:"all 0.2s ease"}})]},C))})]}),k&&et("div",{style:oo,children:[H("div",{style:no,children:"DESCRIPTION"}),H("p",{style:{margin:"8px 0 0",fontSize:"14px",lineHeight:"1.5",color:"#8b8b98",wordBreak:"break-word"},children:k})]})]})]}),et("div",{style:Gi,children:[et("div",{style:{display:"flex",flexDirection:"column",gap:"1px",minWidth:"75px"},children:[H("div",{style:{fontSize:"15px",fontWeight:F,color:s},children:t.price}),t.oldPrice&&H("div",{style:{fontSize:"11px",color:d,textDecoration:"line-through",fontWeight:A},children:t.oldPrice})]}),et("div",{style:Ji,children:[H("button",{style:fn,onClick:()=>p(C=>Math.max(1,C-1)),children:H("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:H("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})}),H("span",{style:{fontSize:"16px",fontWeight:"700",minWidth:"18px",textAlign:"center",color:"#000000",display:"inline-block"},children:g}),H("button",{style:fn,onClick:()=>p(C=>C+1),children:et("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[H("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),H("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})})]}),(()=>{let C=f.availability?.toLowerCase()||"",R=C==="out of stock"||C==="out-of-stock";return et("button",{onClick:R?void 0:S,disabled:R,style:{...io,backgroundColor:R?"#F3F4F6":I,color:R?"#9CA3AF":c,flex:"1",padding:"12px 8px",gap:"6px",cursor:R?"not-allowed":"pointer",opacity:R?.8:1},children:[!R&&et("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[H("path",{d:"M6 2L3 6v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6l-3-4Z"}),H("path",{d:"M3 6h18"}),H("path",{d:"M16 10a4 4 0 0 1-8 0"})]}),H("span",{style:{fontSize:"12px",fontWeight:"700",whiteSpace:"nowrap"},children:R?"Out of Stock":"Add to cart"})]})})()]})]}),H("style",{children:`
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 He("div",{style:s,onClick:n,children:[He("div",{style:{display:"flex",alignItems:"center",gap:"12px",flex:1},children:[ee("div",{style:a,children:"%"}),ee("span",{style:c,children:t.code||"OFFER20"})]}),He("div",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[o&&ee("span",{style:{fontSize:"11px",color:"#10B981",fontWeight:"700"},children:"Copied!"}),ee("div",{style:{padding:"8px",display:"flex",alignItems:"center"},children:He("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"#4A5568",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[ee("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),ee("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 Vn}from"react/jsx-runtime";var Yn=({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 Vn("div",{style:s,children:n.map((c,u)=>Vn("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 Qn,useRef as Ir,useEffect as zr}from"react";import{jsx as Do,jsxs as Gn}from"react/jsx-runtime";var Jn=({data:t,onInteraction:e,isEditing:o=!1})=>{let i=t.maxRating||5,n=t.currentRating??Math.floor(i/2),[r,s]=Qn(n),a=Ir(null),[c,u]=Qn(!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 zr(()=>{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]),Gn("div",{style:g,children:[Do("h3",{style:v,children:t.title||"Do you like my space?"}),Gn("div",{ref:a,style:f,onMouseDown:z,onTouchStart:R,children:[Do("div",{style:h}),Do("div",{style:w,className:"interactive-emoji-thumb",children:t.emoji||"\u{1F60D}"})]})]})};import{useState as Br}from"react";import{jsx as ge,jsxs as _o}from"react/jsx-runtime";var Xn=({data:t,onInteraction:e,isEditing:o=!1})=>{let[i,n]=Br(""),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 _o("div",{style:a,children:[ge("div",{style:c,children:t.question||"Ask me anything"}),_o("div",{style:u,children:[ge("input",{type:"text",value:i,placeholder:t.placeholder||"Type your answer...",style:x,disabled:o,onChange:g,onKeyDown:f=>f.key==="Enter"&&v()}),ge("button",{style:m,onClick:v,children:_o("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:[ge("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),ge("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]})})]})]})};import{useState as Ar}from"react";import{jsx as fe,jsxs as $o}from"react/jsx-runtime";var Kn=({data:t,onInteraction:e,isEditing:o=!1})=>{let[i,n]=Ar(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&&fe("h3",{style:c,children:t.question}),fe("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:[fe("img",{src:f.image||g,alt:f.text,style:{width:"100%",height:"100%",objectFit:"cover"}}),i&&fe("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":""})]}),fe("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 ri}from"react";import{useState as me,useEffect as Er}from"react";import{jsx as U,jsxs as ot}from"react/jsx-runtime";var ii=({product:t,styling:e,onClose:o,onAddToCart:i})=>{let[n,r]=me(""),[s,a]=me(0),[c,u]=me(1),[x,m]=me(!1),[g,v]=me(!1),f=t.attributes||{},b=f.colors||[],h=f.sizes||[],y=f.imageUrls||[t.image],w=f.description||"";Er(()=>{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:Zn,children:[U("div",{className:"appstorys-shopable-backdrop",style:ti,onClick:z}),ot("div",{className:"appstorys-shopable-sheet",style:{...ei,height:"auto",minHeight:"310px",animation:"appstorys-slide-up 0.4s cubic-bezier(0.2, 0.8, 0.2, 1)"},children:[U("div",{style:oi,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:{...Oo,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:{...Oo,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:Zn,children:[U("div",{className:"appstorys-shopable-backdrop",style:ti,onClick:z}),ot("div",{className:"appstorys-shopable-sheet",style:{...ei,transform:g?"translateY(0)":"translateY(100%)",opacity:g?1:0},children:[ot("div",{style:Pr,children:[U("div",{style:oi,onClick:z}),U("button",{style:Lr,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:Dr,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:Wo,children:[U("div",{style:Mo,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:Wo,children:[U("div",{style:Mo,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:Wo,children:[U("div",{style:Mo,children:"DESCRIPTION"}),U("p",{style:{margin:"8px 0 0",fontSize:"14px",lineHeight:"1.5",color:"#8b8b98",wordBreak:"break-word"},children:w})]})]})]}),ot("div",{style:$r,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:Wr,children:[U("button",{style:ni,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:ni,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:{...Oo,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:`
37
37
  @keyframes appstorys-slide-up {
38
38
  from { transform: translateY(100%); }
39
39
  to { transform: translateY(0); }
@@ -46,10 +46,10 @@ var si=Object.defineProperty;var Et=(t,e)=>()=>(t&&(e=t(t=0)),e);var ai=(t,e)=>{
46
46
  .appstorys-shopable-overlay.visible {
47
47
  visibility: visible;
48
48
  }
49
- `})]})},cn={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"},pn={position:"absolute",top:0,left:0,right:0,bottom:0,backgroundColor:"rgba(0,0,0,0.45)",cursor:"pointer"},un={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"},Hi={height:"48px",display:"flex",alignItems:"center",justifyContent:"center",position:"relative",flexShrink:0},gn={width:"36px",height:"5px",backgroundColor:"rgba(0,0,0,0.1)",borderRadius:"3px",cursor:"pointer"},Vi={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"},Yi={flex:1,overflowY:"auto",WebkitOverflowScrolling:"touch"},Qi={padding:"0 16px 20px",display:"flex",gap:"8px",overflowX:"auto",scrollSnapType:"x mandatory"},oo={marginTop:"20px"},no={fontSize:"11px",fontWeight:"600",color:"rgba(0,0,0,0.5)",letterSpacing:"1.4px"},Gi={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"},Ji={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"100px",border:"1px solid rgba(0,0,0,0.1)"},fn={border:"none",backgroundColor:"transparent",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"},io={border:"none",borderRadius:"100px",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",transition:"all 0.2s ease"};import{Fragment as Ki,jsx as zt,jsxs as Zt}from"react/jsx-runtime";var hn=({data:t,onInteraction:e,isEditing:o})=>{let{products:i,styling:n}=t,[r,a]=yn(!1),[l,g]=yn(null),p=(b,h)=>{if(b.stopPropagation(),o)return;if(t.shopableType==="product"){g(h),a(!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(k){console.error("AppStorys: Redirect failed",k),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"},u={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 Zt(Ki,{children:[Zt("div",{style:m,className:"shopable-container",children:[zt("style",{children:`
49
+ `})]})},Zn={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"},ti={position:"absolute",top:0,left:0,right:0,bottom:0,backgroundColor:"rgba(0,0,0,0.45)",cursor:"pointer"},ei={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"},Pr={height:"48px",display:"flex",alignItems:"center",justifyContent:"center",position:"relative",flexShrink:0},oi={width:"36px",height:"5px",backgroundColor:"rgba(0,0,0,0.1)",borderRadius:"3px",cursor:"pointer"},Lr={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"},Dr={flex:1,overflowY:"auto",WebkitOverflowScrolling:"touch"},_r={padding:"0 16px 20px",display:"flex",gap:"8px",overflowX:"auto",scrollSnapType:"x mandatory"},Wo={marginTop:"20px"},Mo={fontSize:"11px",fontWeight:"600",color:"rgba(0,0,0,0.5)",letterSpacing:"1.4px"},$r={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"},Wr={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"100px",border:"1px solid rgba(0,0,0,0.1)"},ni={border:"none",backgroundColor:"transparent",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"},Oo={border:"none",borderRadius:"100px",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",transition:"all 0.2s ease"};import{Fragment as Mr,jsx as $t,jsxs as ye}from"react/jsx-runtime";var si=({data:t,onInteraction:e,isEditing:o})=>{let{products:i,styling:n}=t,[r,s]=ri(!1),[a,c]=ri(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 ye(Mr,{children:[ye("div",{style:m,className:"shopable-container",children:[$t("style",{children:`
50
50
  .shopable-container::-webkit-scrollbar { display: none; }
51
51
  .shopable-card:active { transform: scale(0.98); }
52
- `}),i.map(b=>Zt("div",{style:u,className:"shopable-card",onClick:h=>p(h,b),children:[zt("div",{style:v,children:zt("img",{src:b.image,alt:b.title,style:{width:"100%",height:"100%",objectFit:"cover"}})}),Zt("div",{style:f,children:[zt("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}),Zt("div",{style:{display:"flex",alignItems:"baseline",gap:"6px",flexWrap:"wrap"},children:[zt("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&&zt("span",{style:{color:n?.mrpColor||"#8b8b98",fontSize:n?.mrpFontSize?`${n.mrpFontSize}px`:"12px",fontWeight:n?.mrpFontWeight||"500",textDecoration:"line-through"},children:b.oldPrice})]})]}),zt("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&&l&&zt(mn,{product:l,styling:n,onClose:()=>a(!1),onAddToCart:x})]})};import{jsx as mt,jsxs as Xi}from"react/jsx-runtime";var bn=({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,a=t.width??i.width,l=t.rotation??i.rotation,g={position:"absolute",top:`${r}%`,left:`${n}%`,width:`${a}%`,height:t.height?`${t.height}%`:"auto",transform:`rotate(${l}deg)`,zIndex:10,transformOrigin:"center center",boxSizing:"border-box",cursor:o?"move":"default",pointerEvents:"auto"},p={width:"100%",height:"100%",animation:t.styling?.animation,animationFillMode:"forwards"},x=()=>{switch(t.type){case"poll":return mt(Jo,{data:t,onInteraction:e,isEditing:o});case"quiz":return mt(Xo,{data:t,onInteraction:e,isEditing:o});case"rating":return mt(an,{data:t,onInteraction:e,isEditing:o});case"question":case"input":return mt(ln,{data:t,onInteraction:e,isEditing:o});case"image_quiz":return mt(dn,{data:t,onInteraction:e,isEditing:o});case"countdown":return mt(tn,{data:t,onInteraction:e,isEditing:o});case"promo_code":case"promo":return mt(en,{data:t,onInteraction:e,isEditing:o});case"reaction":return mt(nn,{data:t,onInteraction:e,isEditing:o});case"buy":case"shopable":return mt(hn,{data:t,onInteraction:e,isEditing:o});case"image":return mt("img",{src:t.url,alt:"static overlay",style:{width:"100%",height:"100%",objectFit:"fill"}});case"text":{let u=t.styling||{};return mt("span",{style:{color:u.color||"#000000",fontSize:`${u.fontSize||14}px`,fontFamily:u.fontFamily||"Arial",fontStyle:u.fontStyle||"normal",fontWeight:u.fontWeight||"normal",wordBreak:"break-word",display:"inline-block"},children:t.text})}default:return Xi("div",{style:{padding:"10px",background:"white",color:"black",borderRadius:"4px"},children:["Unsupported interactive element: ",t.type]})}};return mt("div",{style:g,className:`interactive-item-z${t.z??0}`,children:mt("div",{style:p,children:x()})})};var Ft=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,l={right:"to right",left:"to left",top:"to top",bottom:"to bottom"}[o]||o;if(r.length>0){let g=r.map(p=>`${p.color} ${Math.round((p.offset||0)*100)}%`).join(", ");return`linear-gradient(${l}, ${g})`}return`linear-gradient(${l}, ${i}, ${n})`}return e.solid||e.value||void 0},Se=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 kn,jsxs as Zi}from"react/jsx-runtime";var xn=(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"},Wt=(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,a=typeof o=="string"?o:o?.text||o?.title||r||"";return{id:String(n),text:a,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)}}):[],Sn=t=>Array.isArray(t?.emojis)?t.emojis.map(e=>String(e)):Wt(t?.options).map(e=>e.text).filter(Boolean),Cn=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},vn=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()}},wn=({content:t={},onInteraction:e,isEditing:o=!1,elapsedTime:i=0})=>{let n=t?.canva||{height:1920,width:1080},r=n?.width||1080,a=n?.height||1920,l=.352,g=t?.elements||[],p=t?.image||[],x=t?.text||[],m=t?.interactions||[],u=Array.isArray(t?.shopable)&&t.shopable.length>0?t.shopable:Array.isArray(t?.styling?.shopable)?t.styling.shopable:[],v=new Set(u.map(c=>c.id)),f=(t?.styling?.shopable||[]).concat(u.map(c=>c.styling).filter(Boolean));if(g.length===0&&p.length===0&&x.length===0&&m.length===0&&u.length===0)return null;let b=g.filter(c=>!v.has(c.id)).map(c=>{let w=c.custom||{},s=w.data||{},d=w.style||c.styling||{},E=xn(c,t),F=c.position||c.postion||{},A=c.size||{},C=c.x!==void 0?c.x:F.x,R=c.y!==void 0?c.y:F.y,P=c.width!==void 0?c.width:A.width,B=C!==void 0&&!isNaN(Number(C))?Number(C)/r*100:10,_=R!==void 0&&!isNaN(Number(R))?Number(R)/a*100:15,$=P!==void 0&&!isNaN(Number(P))?Number(P)/r*100:80,D={id:c.id||Math.random().toString(),type:Cn(w.interactiveType||c.widgetType||c.type||"unknown"),x:B,y:_,width:$,rotation:d.rotation??c.rotation??0,z:c.z??c.position?.z??d.z??10,duration:s.duration||d.duration,styling:{backgroundColor:Ft(d.background||d.containerBgColor||d.backgroundColor),borderRadius:d.borderRadius!==void 0?d.borderRadius>=100?999:d.borderRadius*l:d.radius!==void 0?d.radius>=100?999:d.radius*l:0,padding:(d.containerPadding!==void 0?d.containerPadding:d.padding!==void 0?d.padding:0)*l,shadow:d.shadow,fontSize:d.questionFontSize?d.questionFontSize*l:void 0,opacity:d.opacity??1,animation:Se(d.animation)}};if(D.type==="poll"){let O=Wt(s.options);return{...D,type:"poll",question:s.question||s.title||"Poll Question",options:O,layout:s.layout||{type:"vertical",columns:1},styling:{...D.styling,headerColor:d.headerBgColor||d.background,headerTextColor:d.questionColor||d.questionTextColor||d.question?.color,optionBgColor:d.optionBgColor||d.options?.background||"#1A1A1A",optionTextColor:d.optionTextColor||d.options?.textColor||"#ffffff",optionBorderRadius:d.optionBorderRadius!==void 0?d.optionBorderRadius*l:d.options?.radius!==void 0?d.options?.radius*l:0}}}if(D.type==="quiz"){let O=d.colors||{},W=Wt(s.options,s.isCorrect);return{...D,type:"quiz",question:s.question||s.title||"Quiz Question",options:W,showExplanation:s.showExplanation,url:s.url,styling:{...D.styling,backgroundColor:d.background||d.containerBgColor||d.backgroundColor||"transparent",questionTextColor:d.questionColor||O.questionColor||d.question?.color||d.colors?.questionText||"#FF0000",questionBgColor:d.questionBgColor||O.questionBackground||d.question?.background||d.colors?.questionBg||"#3BFF00",optionBgColor:d.optionBgColor||O.optionBackground||d.options?.background||d.colors?.optionBg||"#C100FF",optionTextColor:d.optionTextColor||O.optionTextColor||d.options?.textColor||d.colors?.optionText||"#ffffff",borderColor:d.borderColor||"transparent",activeColor:d.correctColor||O.correctColor||d.correctBorderColor||"#00D9FF",incorrectColor:d.incorrectColor||O.incorrectColor||"#ef4444",optionBorderRadius:d.optionRadius!==void 0?d.optionRadius>=100?999:d.optionRadius*l:d.optionBorderRadius!==void 0?d.optionBorderRadius>=100?999:d.optionBorderRadius*l:100,optionFontSize:(d.optionFontSize?d.optionFontSize:d.typography?.optionSize?d.typography?.optionSize:d.options?.fontSize?d.options?.fontSize:16)*l*1.25}}}if(D.type==="rating")return{...D,type:"rating",title:s.title||"Do you like my space?",emoji:s.emoji||"\u{1F60D}",currentRating:s.currentRating,maxRating:s.maxRating,styling:{...D.styling,sliderTrackColor:d.colors?.sliderTrack||d.sliderTrack,sliderFillColor:d.colors?.sliderFill||d.sliderFill,emojiSize:d.emojiSize?d.emojiSize*.45:void 0,titleColor:d.colors?.titleColor||d.titleColor,titleFontSize:d.titleFontSize?d.titleFontSize*.4:void 0}};if(D.type==="question")return{...D,type:"question",question:s.question||s.title||"Ask me a question",placeholder:s.placeholder||"Type your answer...",styling:{...D.styling,promptColor:d.questionColor||d.textColor,inputBgColor:d.inputBgColor,inputTextColor:d.inputTextColor,submitBackground:d.submitBackground}};if(D.type==="image_quiz"||D.type==="imageQuiz"||(w.interactiveType||"").toLowerCase()==="media_quiz")return{...D,type:"image_quiz",question:s.question||s.title||"Image Quiz",options:Wt(s.options||[]),styling:{...D.styling,questionTextColor:d.questionColor,activeColor:d.correctColor||d.correctBorderColor,incorrectColor:d.incorrectColor,imageRadius:d.imageRadius?d.imageRadius*l:void 0}};if(D.type==="countdown")return{...D,type:"countdown",title:s.title||"Ends in...",targetDate:vn(s),styling:{...D.styling,borderColor:d.borderColor,digitBackground:d.digitBackground,digitColor:d.digitColor,digitSize:d.digitSize?d.digitSize*l:void 0,labelColor:d.labelColor,titleColor:d.titleColor},display:s.display};if(D.type==="promo_code")return{...D,type:"promo_code",code:s.code||"CODE20",styling:{...D.styling,borderColor:d.borderColor}};if(D.type==="reaction"||D.type==="emoji_reaction"){let O=Sn(s);return{...D,type:"reaction",emojis:O.length>0?O:["\u{1F60D}","\u{1F44D}"],source:E}}return D}),h=(t?.interactions||[]).filter(c=>!v.has(c.id)).map(c=>{let w=c.config||{},s=c.styling||c.style||{},d=xn(c,t),E=Cn(c.interaction_type||c.type),F=s.position||c.position||{},A=s.size||c.size||{},C=F.x??c.x,R=F.y??c.y,P=A.width??c.width,B=A.height??c.height,_=C!==void 0&&!isNaN(Number(C))?Number(C)/r*100:10,$=R!==void 0&&!isNaN(Number(R))?Number(R)/a*100:15,D=P!==void 0&&!isNaN(Number(P))?Number(P)/r*100:80,O=B!==void 0&&!isNaN(Number(B))?Number(B)/a*100:void 0,W={id:c.id||Math.random().toString(),type:E,x:_,y:$,width:D,height:O,rotation:s.rotation??c.rotation??0,z:c.z??c.position?.z??s.z??10,source:d,duration:w.duration||s.duration,styling:{backgroundColor:Ft(s.background||s.containerBgColor||s.backgroundColor),borderRadius:s.borderRadius!==void 0?s.borderRadius>=100?999:s.borderRadius*l:s.radius!==void 0?s.radius>=100?999:s.radius*l:0,padding:(s.containerPadding!==void 0?s.containerPadding:s.padding!==void 0?s.padding:0)*l,shadow:s.shadow,fontSize:s.questionSize?s.questionSize*l:s.questionFontSize?s.questionFontSize*l:void 0,opacity:s.opacity??1,animation:Se(s.animation)}};if(W.type==="rating"||W.type==="rate"){let Y=s.colors||{};return{...W,type:"rating",title:w.title||"Do you like my space?",emoji:w.emoji||"\u{1F60D}",currentRating:w.currentRating,maxRating:w.maxRating,styling:{...W.styling,sliderTrackColor:Y.sliderTrack||s.colors?.sliderTrack||s.colors?.sliderTrack,sliderFillColor:Y.sliderFill||s.colors?.sliderFill||s.sliderFill,emojiSize:s.emojiSize?s.emojiSize*.45:void 0,titleColor:Y.titleColor||s.colors?.titleColor||s.titleColor,titleFontSize:s.titleFontSize?s.titleFontSize*.4:void 0}}}if(W.type==="poll"){let Y=Wt(w.options);return{...W,type:"poll",question:w.question||w.title||"Poll Question",options:Y,layout:w.layout||{type:"vertical",columns:1},styling:{...W.styling,headerColor:s.headerBgColor||s.background,headerTextColor:s.questionColor||s.questionTextColor||s.question?.color,optionBgColor:s.optionBgColor||s.options?.background||"#1A1A1A",optionTextColor:s.optionTextColor||s.options?.textColor||"#ffffff",optionBorderRadius:s.optionBorderRadius!==void 0?s.optionBorderRadius*l:s.options?.radius!==void 0?s.options?.radius*l:0}}}if(W.type==="quiz"){let Y=s.colors||{},dt=Wt(w.options,w.isCorrect);return{...W,type:"quiz",question:w.question||w.title||"Quiz Question",options:dt,showExplanation:w.showExplanation,url:w.url,styling:{...W.styling,backgroundColor:s.background||s.containerBgColor||s.backgroundColor||"transparent",questionTextColor:s.questionColor||Y.questionColor||s.question?.color||s.colors?.questionText||"#FF0000",questionBgColor:s.questionBgColor||Y.questionBackground||s.question?.background||s.colors?.questionBg||"#3BFF00",optionBgColor:s.optionBgColor||Y.optionBackground||s.options?.background||s.colors?.optionBg||"#C100FF",optionTextColor:s.optionTextColor||Y.optionTextColor||s.options?.textColor||s.colors?.optionText||"#ffffff",borderColor:s.borderColor||"transparent",activeColor:s.correctColor||Y.correctColor||s.correctBorderColor||"#00D9FF",incorrectColor:s.incorrectColor||Y.incorrectColor||"#ef4444",optionBorderRadius:s.optionRadius!==void 0?s.optionRadius>=100?999:s.optionRadius*l:s.optionBorderRadius!==void 0?s.optionBorderRadius>=100?999:s.optionBorderRadius*l:100,optionFontSize:(s.optionFontSize?s.optionFontSize:s.typography?.optionSize?s.typography?.optionSize:s.options?.fontSize?s.options?.fontSize:16)*l*1.25}}}if(W.type==="question")return{...W,type:"question",question:w.question||w.title||"Ask me a question",placeholder:w.placeholder||"Type your answer...",styling:{...W.styling,promptColor:s.questionColor||s.promptColor||s.textColor,inputBgColor:s.inputBackground||s.inputBgColor,inputTextColor:s.inputTextColor,submitBackground:s.submitBackground}};if(W.type==="image_quiz"||W.type==="imageQuiz"||E==="media_quiz")return{...W,type:"image_quiz",question:w.question||w.title||"Image Quiz",options:Wt(w.options||[]),styling:{...W.styling,questionTextColor:s.questionColor,activeColor:s.correctColor||s.correctBorderColor,incorrectColor:s.incorrectColor,imageRadius:s.imageRadius?s.imageRadius*l:void 0}};if(W.type==="countdown")return{...W,type:"countdown",title:w.title||"Ends in...",targetDate:vn(w),styling:{...W.styling,borderColor:s.borderColor,digitBackground:s.digitBackground,digitColor:s.digitColor,digitSize:s.digitSize||s.fontSize?Number(s.digitSize||s.fontSize):void 0,labelColor:s.labelColor,titleColor:s.titleColor,labelFontSize:s.labelFontSize?Number(s.labelFontSize):void 0},display:w.display||c.display};if(W.type==="promo_code")return{...W,type:"promo_code",code:w.code||"CODE20",styling:{...W.styling,borderColor:s.borderColor}};if(W.type==="reaction"||W.type==="emoji_reaction"){let Y=Sn(w);return{...W,type:"reaction",emojis:Y.length>0?Y:["\u{1F60D}","\u{1F44D}"]}}return W}),y=u.map(c=>{let w=f.find(M=>String(M?.id)===String(c?.id))||f.find(M=>M?.id===void 0)||{},s={position:c?.position,size:c?.size,rotation:c?.rotation,z:c?.z,background:c?.background,cardBackground:c?.cardBackground,cardBorderRadius:c?.cardBorderRadius,cardRadiusPercent:c?.cardRadiusPercent,transparent:c?.transparent,textColor:c?.textColor,buttonBackground:c?.buttonBackground,buttonTextColor:c?.buttonTextColor,buttonFontSize:c?.buttonFontSize,buttonBorderRadius:c?.buttonBorderRadius,titleColor:c?.titleColor,titleFontSize:c?.titleFontSize,titleFontWeight:c?.titleFontWeight,priceColor:c?.priceColor,priceFontSize:c?.priceFontSize,priceFontWeight:c?.priceFontWeight,mrpColor:c?.mrpColor,mrpFontSize:c?.mrpFontSize,mrpFontWeight:c?.mrpFontWeight,imageRadius:c?.imageRadius,opacity:c?.opacity,animation:c?.animation},d={...w,...c?.styling||{},...Object.fromEntries(Object.entries(s).filter(([,M])=>M!==void 0))},E=d.position||{},F=d.size||{},A=d.cardBorderRadius!==void 0?Number(d.cardBorderRadius):void 0,C=d.cardRadiusPercent!==void 0?Number(d.cardRadiusPercent):void 0,R=F.height!==void 0?Number(F.height):void 0,P=A===void 0&&C!==void 0&&R!==void 0?Math.max(0,Math.min(100,C))/100*(R/2):void 0,B=A??P,_=B!==void 0&&!isNaN(B)?B*l:void 0,$=E.x!==void 0?Number(E.x)/r*100:0,D=F.width!==void 0?Number(F.width)/r*100:100,O=F.height!==void 0?Number(F.height)/a*100:void 0,W=E.y!==void 0?Number(E.y)/a*100:O?100-O-2.5:85;O&&W+O>96?W=Math.max(0,100-O):W>75&&O&&W+O>91&&(W=Math.max(0,100-O-1));let Y=Array.isArray(c.product)&&c.product.length>0,dt=Y?c.product:c.static||[];return{id:c.id||Math.random().toString(),type:"buy",shopableType:Y?"product":"static",x:$,y:W,width:D,height:O,rotation:d.rotation??0,z:d.z??10,products:dt.map(M=>{let N=M.productData||M||{},U=N.attributes||M.attributes||{},rt=U.sales_price||N.price||U.price||M.price,ct=U.sales_price?N.price||U.price||M.price:N.oldPrice||M.oldPrice,q=N.color||U.color||M.color,Q=N.size||U.size||M.size,st=U.colors||[];st.length===0&&q&&(st=[{id:q,hex:q,name:q}]);let pt=U.sizes||[];pt.length===0&&Q&&(pt=typeof Q=="string"?Q.split(",").map(at=>at.trim()):[Q]);let ft={description:N.description||U.description||M.description,color:q,size:Q,colors:st,sizes:pt,imageUrls:U.imageUrls||[U.image_link||N.imageUrl||N.image||M.imageUrl||M.image||M.url].filter(Boolean),availability:N.availability||U.availability||M.availability,tags:N.tags||U.tags||M.tags,...U};return{id:N.productId||N.id||M.productId||M.id||Math.random().toString(),image:U.image_link||N.imageUrl||N.image||M.imageUrl||M.image||M.url,url:N.link||N.url||M.link||M.url||M.redirectUrl,title:N.title||M.title,price:rt,oldPrice:ct,redirectUrl:M.redirectUrl||N.link||M.link||M.url,svg:N.svg||M.svg,productId:N.productId||M.productId,collectionId:N.collectionId||M.collectionId,feedId:N.feedId||M.feedId,attributes:ft}}),styling:{backgroundColor:Ft(d.background),cardBackground:Ft(d.cardBackground)||Ft(d.background)||"#ffffff",cardBorderRadius:_!==void 0?_:10,cardRadiusPercent:C,transparent:d.transparent===!0,textColor:d.textColor||"#ffffff",buttonBackground:d.buttonBackground||"#000000",buttonTextColor:d.buttonTextColor||"#ffffff",buttonFontSize:d.buttonFontSize||12,buttonBorderRadius:d.buttonBorderRadius!==void 0?d.buttonBorderRadius:100,titleColor:d.titleColor||d.textColor||"#1a1a2e",titleFontSize:d.titleFontSize||14,titleFontWeight:d.titleFontWeight?String(d.titleFontWeight):"600",priceColor:d.priceColor||d.textColor||"#1a1a2e",priceFontSize:d.priceFontSize||16,priceFontWeight:d.priceFontWeight?String(d.priceFontWeight):"700",mrpColor:d.mrpColor||"#8b8b98",mrpFontSize:d.mrpFontSize||12,mrpFontWeight:d.mrpFontWeight?String(d.mrpFontWeight):"500",imageRadius:d.imageRadius!==void 0?Number(d.imageRadius)*l:10,animation:Se(d.animation)}}}),k=p.map(c=>{let w=c.position||c.postion||{x:0,y:0};return{id:c.id||Math.random().toString(),type:"image",x:w.x/r*100,y:w.y/a*100,width:c.width/r*100,height:c.height?c.height/a*100:void 0,url:c.link||c.url,z:c.z??0}}),S=x.map(c=>{let w=c.position||{x:0,y:0},s=c.font||{};return{id:c.id||Math.random().toString(),type:"text",x:w.x/r*100,y:w.y/a*100,width:c.size?.width?c.size.width/r*100:void 0,text:c.value,z:c.z??1,styling:{color:c.color||"#000000",fontSize:s.fontSize?s.fontSize*l:void 0,fontFamily:s.fontFamily,fontStyle:s.fontStyle,fontWeight:s.fontWeight}}}),T=[...b,...h,...y,...k,...S].filter(c=>{if(!c.duration)return!0;let{start:w,end:s}=c.duration;return i>=w&&i<=s}).sort((c,w)=>(c.z??0)-(w.z??0));return Zi("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:10,pointerEvents:"none",overflow:"hidden"},children:[kn("style",{children:`
52
+ `}),i.map(b=>ye("div",{style:g,className:"shopable-card",onClick:h=>u(h,b),children:[$t("div",{style:v,children:$t("img",{src:b.image,alt:b.title,style:{width:"100%",height:"100%",objectFit:"cover"}})}),ye("div",{style:f,children:[$t("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}),ye("div",{style:{display:"flex",alignItems:"baseline",gap:"6px",flexWrap:"wrap"},children:[$t("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&&$t("span",{style:{color:n?.mrpColor||"#8b8b98",fontSize:n?.mrpFontSize?`${n.mrpFontSize}px`:"12px",fontWeight:n?.mrpFontWeight||"500",textDecoration:"line-through"},children:b.oldPrice})]})]}),$t("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&&$t(ii,{product:a,styling:n,onClose:()=>s(!1),onAddToCart:x})]})};import{jsx as ht,jsxs as Or}from"react/jsx-runtime";var ai=({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 ht(On,{data:t,onInteraction:e,isEditing:o});case"quiz":return ht(Nn,{data:t,onInteraction:e,isEditing:o});case"rating":return ht(Jn,{data:t,onInteraction:e,isEditing:o});case"question":case"input":return ht(Xn,{data:t,onInteraction:e,isEditing:o});case"image_quiz":return ht(Kn,{data:t,onInteraction:e,isEditing:o});case"countdown":return ht(Un,{data:t,onInteraction:e,isEditing:o});case"promo_code":case"promo":return ht(Hn,{data:t,onInteraction:e,isEditing:o});case"reaction":return ht(Yn,{data:t,onInteraction:e,isEditing:o});case"buy":case"shopable":return ht(si,{data:t,onInteraction:e,isEditing:o});case"image":return ht("img",{src:t.url,alt:"static overlay",style:{width:"100%",height:"100%",objectFit:"fill"}});case"text":{let g=t.styling||{};return ht("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 Or("div",{style:{padding:"10px",background:"white",color:"black",borderRadius:"4px"},children:["Unsupported interactive element: ",t.type]})}};return ht("div",{style:c,className:`interactive-item-z${t.z??0}`,children:ht("div",{style:u,children:x()})})};var Et=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},Ve=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 ui,jsxs as jr}from"react/jsx-runtime";var li=(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"},Ut=(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)}}):[],di=t=>Array.isArray(t?.emojis)?t.emojis.map(e=>String(e)):Ut(t?.options).map(e=>e.text).filter(Boolean),ci=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},pi=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()}},jo=({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=li(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:ci(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:Et(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:Ve(p.animation)}};if(k.type==="poll"){let P=Ut(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=Ut(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:Ut(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:pi(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=di(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=li(d,t),M=ci(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:Et(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:Ve(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=Ut(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||{},gt=Ut(T.options,T.isCorrect);return{...O,type:"quiz",question:T.question||T.title||"Quiz Question",options:gt,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:Ut(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:pi(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=di(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,gt=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:gt.map(j=>{let X=j.productData||j||{},J=X.attributes||j.attributes||{},V=J.sales_price||X.price||J.price||j.price,at=J.sales_price?X.price||J.price||j.price:X.oldPrice||j.oldPrice,N=X.color||J.color||j.color,Y=X.size||J.size||j.size,Q=J.colors||[];Q.length===0&&N&&(Q=[{id:N,hex:N,name:N}]);let tt=J.sizes||[];tt.length===0&&Y&&(tt=typeof Y=="string"?Y.split(",").map(lt=>lt.trim()):[Y]);let pt={description:X.description||J.description||j.description,color:N,size:Y,colors:Q,sizes:tt,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:at,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:pt}}),styling:{backgroundColor:Et(p.background),cardBackground:Et(p.cardBackground)||Et(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:Ve(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 jr("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:10,pointerEvents:"none",overflow:"hidden"},children:[ui("style",{children:`
53
53
  @keyframes appstorys-fade-in {
54
54
  from { opacity: 0; transform: translateY(10px); }
55
55
  to { opacity: 1; transform: translateY(0); }
@@ -69,14 +69,16 @@ var si=Object.defineProperty;var Et=(t,e)=>()=>(t&&(e=t(t=0)),e);var ai=(t,e)=>{
69
69
  70% { opacity: 1; transform: scale(0.95); }
70
70
  100% { opacity: 1; transform: scale(1); }
71
71
  }
72
- `}),T.map(c=>!c||typeof c!="object"||!(c.type||"").toLowerCase()?null:kn(bn,{data:c,onInteraction:e,isEditing:o},c.id))]})};import{useState as tr}from"react";import{jsx as te,jsxs as or}from"react/jsx-runtime";var er=({isPaused:t,onPress:e,style:o,size:i=36})=>{let[n,r]=tr(!1);return te("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?te("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"white",children:te("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"})}):or("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"white",children:[te("rect",{x:"6",y:"4",width:"4",height:"16",rx:"1"}),te("rect",{x:"14",y:"4",width:"4",height:"16",rx:"1"})]})})},Rn=er;import{jsx as ro}from"react/jsx-runtime";var nr=t=>{switch(t){case"left":return"flex-start";case"right":return"flex-end";default:return"center"}},ir=({cta:t,buttonText:e,onPress:o})=>!t||!e||e.trim()===""?null:ro("div",{style:{position:"absolute",bottom:t?.margin?.bottom,left:t?.margin?.left,right:t?.margin?.right,display:"flex",justifyContent:nr(t?.container?.alignment),width:"100%",pointerEvents:"none",boxSizing:"border-box",zIndex:10},children:ro("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:ro("span",{style:{color:t?.text?.color||"#ffffff",fontSize:t?.text?.fontSize||14,fontFamily: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:ye(e)})})}),Tn=ir;import{jsx as Ce,jsxs as sr}from"react/jsx-runtime";var rr=({config:t,onPress:e,style:o,ignoreSizeAndMargin:i=!1})=>{if(!t||!t.enabled)return null;let{size:n=18,margin:r,color:a,image:l,selectedStyle:g}=t,p=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:p,height:p,backgroundColor:a?.fill||"transparent",borderColor:a?.stroke||"transparent",borderWidth:p*.05,borderRadius:"50%",justifyContent:"center",alignItems:"center",zIndex:1e6,position:"absolute",display:"flex",padding:0,cursor:"pointer",outline:"none",borderStyle:a?.stroke?"solid":"none",...o},m=()=>{let u=a?.cross||"#ffffff";return sr("svg",{viewBox:"0 0 24 24",width:"70%",height:"70%","aria-hidden":!0,children:[Ce("line",{x1:"6",y1:"6",x2:"18",y2:"18",stroke:u,strokeWidth:"2.2",strokeLinecap:"round"}),Ce("line",{x1:"18",y1:"6",x2:"6",y2:"18",stroke:u,strokeWidth:"2.2",strokeLinecap:"round"})]})};return Ce("button",{onClick:e,style:x,title:g||"",children:l&&l.trim()!==""?Ce("img",{src:l,style:{width:p,height:p,objectFit:"contain"},alt:"close"}):m()})},kt=rr;import{jsx as It,jsxs as zn}from"react/jsx-runtime";var so=({config:t,onPress:e,ignoreSizeAndMargin:o=!1,enabled:i,style:n,type:r})=>{if(!t||!i)return null;let{size:a=18,margin:l,color:g,image:p,selectedStyle:x}=t,m=o?40:a,u=o?0:l?.top??0,v=o?0:l?.bottom??0,f=o?0:l?.left??0,b=o?0:l?.right??0,h={marginTop:u,marginBottom:v,marginLeft:f,marginRight:b,width:m,height:m,backgroundColor:g?.fill||"transparent",borderColor:g?.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 k=g?.cross||"#ffffff";return r==="mute"?zn("svg",{viewBox:"0 0 24 24",width:"70%",height:"70%","aria-hidden":!0,children:[It("polygon",{points:"4,10 8,10 13,6 13,18 8,14 4,14",fill:"none",stroke:k,strokeWidth:"2.2",strokeLinejoin:"round"}),It("line",{x1:"16",y1:"8",x2:"21",y2:"16",stroke:k,strokeWidth:"2.2",strokeLinecap:"round"}),It("line",{x1:"21",y1:"8",x2:"16",y2:"16",stroke:k,strokeWidth:"2.2",strokeLinecap:"round"})]}):zn("svg",{viewBox:"0 0 24 24",width:"70%",height:"70%","aria-hidden":!0,children:[It("polygon",{points:"4,10 8,10 13,6 13,18 8,14 4,14",fill:"none",stroke:k,strokeWidth:"2.2",strokeLinejoin:"round"}),It("path",{d:"M16 10 Q18 12 16 14",fill:"none",stroke:k,strokeWidth:"2.2",strokeLinecap:"round"}),It("path",{d:"M18 8 Q22 12 18 16",fill:"none",stroke:k,strokeWidth:"2.2",strokeLinecap:"round"})]})};return It("button",{onClick:e,style:{...h,border:h.borderColor?`${h.borderWidth}px solid ${h.borderColor}`:"none",padding:0,cursor:"pointer",outline:"none"},title:x||"",children:p&&p.trim()!==""?It("img",{src:p,style:{width:m,height:m,objectFit:"contain"},alt:r}):y()})};import{jsx as _t,jsxs as lr}from"react/jsx-runtime";var ar=({config:t,onPress:e,ignoreSizeAndMargin:o=!1,style:i})=>{if(!t||t.enabled===!1)return null;let{size:n=18,margin:r,color:a,image:l,selectedStyle:g}=t,p=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:p,height:p,backgroundColor:a?.fill||"transparent",borderColor:a?.stroke||"transparent",borderWidth:p*.05,borderRadius:"50%",justifyContent:"center",alignItems:"center",zIndex:1e6,position:"absolute",display:"flex",padding:0,cursor:"pointer",outline:"none",borderStyle:a?.stroke?"solid":"none",...i},m=()=>{let u=a?.cross||"#ffffff";return lr("svg",{viewBox:"0 0 24 24",width:"60%",height:"60%",fill:"none",stroke:u,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[_t("circle",{cx:"18",cy:"5",r:"3"}),_t("circle",{cx:"6",cy:"12",r:"3"}),_t("circle",{cx:"18",cy:"19",r:"3"}),_t("line",{x1:"8.59",y1:"13.51",x2:"15.42",y2:"17.49"}),_t("line",{x1:"15.41",y1:"6.51",x2:"8.59",y2:"10.49"})]})};return _t("button",{onClick:e,style:x,title:g||"",children:l&&l.trim()!==""?_t("img",{src:l,style:{width:p,height:p,objectFit:"contain"},alt:"share"}):m()})},Fn=ar;import{Fragment as In,jsx as L,jsxs as J}from"react/jsx-runtime";var Bn=({stories:t,activeStoryIndex:e,dataId:o,viewedStories:i,setViewedStories:n,onNextStory:r,onPrevStory:a,onClose:l})=>{let[g,p]=Bt(0),[x,m]=Bt(0),[u,v]=Bt(!1),[f,b]=Bt(!1),[h,y]=Bt(!1),[k,S]=Bt(!1),[T,I]=Bt(null),[c,w]=Bt(typeof window<"u"?window.innerWidth>=1024:!1);ee(()=>{let j=()=>{w(window.innerWidth>=1024)};return window.addEventListener("resize",j),()=>window.removeEventListener("resize",j)},[]);let s=ao(null),d=ao(null),E=ao(0),F=t[e],A=F?.slides[g],C=A?.styling,R=C?.editorSource||C?.meta?.editorSource,P=R==="studio"||R==="editor",B=P?C?.background?.media?.mediaUrl:A?.image,_=P?A?.content?.button_text:A?.button_text,$=P?A?.content?.link:A?.link,D=A?.video||(P?A?.content?.video?.[0]?.link:void 0),O=async()=>{let j={title:F.name,text:`Check out this story: ${F.name}`,url:window.location.href};if(A?.id&&V("shared",o,{story_slide:A.id}),navigator.share)try{await navigator.share(j)}catch{}else if(navigator.clipboard)try{await navigator.clipboard.writeText(window.location.href),I("Story link copied to clipboard!"),setTimeout(()=>I(null),2500)}catch{}};if(ee(()=>{p(0),m(0),b(!1),y(!1)},[e]),ee(()=>{let j=G=>{if(!(document.activeElement?.tagName==="INPUT"||document.activeElement?.tagName==="TEXTAREA"))switch(G.key){case"ArrowRight":W();break;case"ArrowLeft":Y();break;case" ":G.preventDefault(),y(X=>!X);break;case"Escape":l();break;case"s":case"S":G.preventDefault(),O();break}};return window.addEventListener("keydown",j),()=>window.removeEventListener("keydown",j)},[g,e,h,F,l]),ee(()=>{F&&A&&V("viewed",o,{story_slide:A.id})},[g,F?.id,o]),ee(()=>{if(F&&A){let j=F.styling?.slideShowTime||5,G=!!D;if(s.current&&clearInterval(s.current),h){d.current&&d.current.pause();return}else d.current&&d.current.play().catch(()=>{});return G&&!f?void 0:(s.current=setInterval(()=>{m(X=>X>=100?(W(),100):X+100/(j*10))},100),()=>{s.current&&clearInterval(s.current)})}},[e,g,h,f]),!A)return null;let W=()=>{if(g<F.slides.length-1)p(j=>j+1),m(0);else{if(!i.includes(F.id)){let j=[...i,F.id];n(j),localStorage.setItem("app_storys_viewed_stories",JSON.stringify(j))}r()}},Y=()=>{g>0?(p(j=>j-1),m(0)):a()},dt=()=>{E.current=Date.now(),y(!0)},M=j=>{y(!1),Date.now()-E.current<300&&(j==="next"?W():Y())},N=()=>{b(!0)},U=j=>{let G=j?.styling,X=G?.editorSource||G?.meta?.editorSource,vt=X==="studio"||X==="editor"?j.content?.link:j.link;vt&&(V("clicked",o,{story_slide:j.id}),vt.startsWith("http")?window.open(vt,"_blank"):window.location.href=vt)},rt=j=>{j.stopPropagation(),v(!u)},ct=F?.styling?.crossButton,q=F?.styling?.soundToggle,Q=A?.styling?.cta,st=Q?.container,pt=Q?.text,ft=c?{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"},at=c?{position:"relative",width:"380px",height:"680px",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)",transition:"all 0.3s ease",zIndex:5}:{position:"relative",width:"100%",maxWidth:"450px",height:"100%",maxHeight:"850px",backgroundColor:"#000",borderRadius:"0px",overflow:"hidden",display:"flex",flexDirection:"column"},wt={width:"240px",height:"420px",backgroundColor:"#000",borderRadius:"16px",overflow:"hidden",opacity:.45,filter:"none",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"};return J("div",{style:ft,onClick:()=>!c&&W(),children:[J("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:[D?L("video",{src:D,style:{width:"100%",height:"100%",objectFit:"cover",filter:"blur(120px) saturate(1.8) opacity(0.35)"},muted:!0}):L(bt,{src:B||F.thumbnail,style:{width:"100%",height:"100%",filter:"blur(120px) saturate(1.8) opacity(0.35)"}}),L("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,background:"rgba(5, 5, 8, 0.4)"}})]},`${e}-${g}`),c&&J(In,{children:[L("div",{style:{width:"100%",display:"flex",gap:"8px",padding:"12px 20px",boxSizing:"border-box",zIndex:10},children:F.slides.map((j,G)=>{let X="0%";return G<g?X="100%":G===g&&(X=`${x}%`),L("div",{style:{flex:1,height:"3px",backgroundColor:"rgba(255,255,255,0.15)",borderRadius:"2px",overflow:"hidden"},children:L("div",{style:{width:X,height:"100%",backgroundColor:"white",transition:G===g?"width 0.1s linear":"none"}})},G)})}),J("div",{style:{width:"100%",display:"grid",gridTemplateColumns:"1fr 380px 1fr",alignItems:"center",padding:"12px 20px",boxSizing:"border-box",zIndex:k?2e3:10},children:[L("div",{}),J("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%"},children:[J("div",{style:{display:"flex",alignItems:"center",gap:"10px"},children:[L(bt,{src:F.thumbnail,alt:F.name,style:{width:"36px",height:"36px",borderRadius:"50%",border:"2px solid #F97316"}}),L("span",{style:{color:"white",fontWeight:"bold",fontSize:"15px",whiteSpace:"nowrap"},children:F.name})]}),J("div",{style:{display:"flex",gap:"8px"},children:[L(Fn,{config:{enabled:(F?.styling?.share?.enabled??!0)&&!!$,image:F?.styling?.share?.image??"",color:{cross:F?.styling?.share?.color?.cross??"#ffffff",fill:F?.styling?.share?.color?.fill??"rgba(255,255,255,0.08)",stroke:F?.styling?.share?.color?.stroke??"transparent"},margin:{top:0,bottom:0,left:0,right:0},size:F?.styling?.share?.size??36},onPress:O,style:{position:"relative",borderRadius:"10px"}}),L(so,{config:{size:36,color:{cross:"#ffffff",fill:"rgba(255,255,255,0.08)",stroke:"transparent"},margin:{top:0,bottom:0,left:0,right:0},image:u?F?.styling?.soundToggle?.mute?.image||"":F?.styling?.soundToggle?.unmute?.image||""},onPress:rt,type:u?"mute":"unmute",enabled:!!q?.enabled&&!!D,style:{position:"relative",borderRadius:"10px"}}),L(Rn,{isPaused:h,onPress:()=>y(!h)})]})]}),J("div",{style:{display:"flex",gap:"10px",flex:1,justifyContent:"flex-end"},children:[J("div",{style:{position:"relative"},children:[L("button",{onClick:()=>{S(!k),y(!k)},style:{width:"36px",height:"36px",background:k?"rgba(255,255,255,0.15)":"rgba(255,255,255,0.08)",border:k?"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",padding:0,outline:"none"},children:J("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[L("rect",{x:"3",y:"3",width:"7",height:"7"}),L("rect",{x:"14",y:"3",width:"7",height:"7"}),L("rect",{x:"14",y:"14",width:"7",height:"7"}),L("rect",{x:"3",y:"14",width:"7",height:"7"})]})}),k&&J(In,{children:[L("style",{children:`
73
- @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
74
- @keyframes fadeUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
75
- `}),L("div",{style:{position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0, 0, 0, 0.45)",zIndex:1e3,animation:"fadeIn 0.2s ease-out forwards"},onClick:()=>{S(!1),y(!1)}}),J("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:[L("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"}),J("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[J("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[L("div",{style:{display:"flex",gap:"4px"},children:L("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:"\u2192"})}),L("span",{style:{fontSize:"13px",color:"#E5E7EB",fontWeight:"500"},children:"Next slide"})]}),J("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[L("div",{style:{display:"flex",gap:"4px"},children:L("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:"\u2190"})}),L("span",{style:{fontSize:"13px",color:"#E5E7EB",fontWeight:"500"},children:"Previous slide"})]}),J("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[L("div",{style:{display:"flex",gap:"4px"},children:L("span",{style:{background:"rgba(255,255,255,0.08)",padding:"4px 10px",borderRadius:"5px",fontSize:"11px",color:"#9CA3AF",textTransform:"lowercase",border:"1px solid rgba(255,255,255,0.1)"},children:"space"})}),L("span",{style:{fontSize:"13px",color:"#E5E7EB",fontWeight:"500"},children:"Play/Pause"})]}),J("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[L("div",{style:{display:"flex",gap:"4px"},children:L("span",{style:{background:"rgba(255,255,255,0.08)",padding:"4px 10px",borderRadius:"5px",fontSize:"11px",color:"#9CA3AF",textTransform:"lowercase",border:"1px solid rgba(255,255,255,0.1)"},children:"esc"})}),L("span",{style:{fontSize:"13px",color:"#E5E7EB",fontWeight:"500"},children:"Close story"})]}),J("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[L("div",{style:{display:"flex",gap:"4px"},children:L("span",{style:{background:"rgba(255,255,255,0.08)",padding:"5px 10px",borderRadius:"5px",fontSize:"12px",color:"white",fontWeight:"bold",border:"1px solid rgba(255,255,255,0.1)"},children:"S"})}),L("span",{style:{fontSize:"13px",color:"#E5E7EB",fontWeight:"500"},children:"Share story link"})]})]})]})]})]}),L(kt,{config:{enabled:ct?.enabled??!0,image:ct?.image??"",color:{cross:"#ffffff",fill:"rgba(255,255,255,0.08)",stroke:"transparent"},margin:{top:0,bottom:0,left:0,right:0},size:36},onPress:l,style:{position:"relative",borderRadius:"10px"}})]})]})]}),J("div",{style:{display:c?"grid":"flex",gridTemplateColumns:c?"1fr 380px 1fr":"none",alignItems:"center",justifyContent:"center",gap:"12px",flex:1,width:"100%",maxWidth:"1400px",position:"relative"},onClick:j=>c&&j.stopPropagation(),children:[c&&J("div",{style:{display:"flex",justifyContent:"flex-end",alignItems:"center",gap:"12px",width:"100%",boxSizing:"border-box"},children:[g>0&&(()=>{let j=F.slides[g-1];if(!j)return null;let G=j.styling,X=G?.editorSource||G?.meta?.editorSource,vt=X==="studio"||X==="editor"?G?.background?.media?.mediaUrl:j.image;return J("div",{style:wt,onClick:Y,children:[L(bt,{src:vt||F.thumbnail}),L("div",{style:{position:"absolute",top:0,bottom:0,left:0,right:0,background:"rgba(0,0,0,0.2)",backdropFilter:"blur(1px)"}})]})})(),g>0&&L("button",{onClick:Y,style:{background:"rgba(255,255,255,0.15)",border:"1px solid rgba(255,255,255,0.2)",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:j=>j.currentTarget.style.background="rgba(255,255,255,0.25)",onMouseLeave:j=>j.currentTarget.style.background="rgba(255,255,255,0.15)",children:"\u2039"})]}),J("div",{style:at,onClick:j=>j.stopPropagation(),children:[!c&&L("div",{style:{position:"absolute",top:"0px",left:"0px",right:"0px",display:"flex",gap:"4px",padding:"10px",zIndex:10},children:F.slides.map((j,G)=>{let X="0%";return G<g?X="100%":G===g&&(X=`${x}%`),L("div",{style:{flex:1,height:"3px",backgroundColor:"rgba(255,255,255,0.3)",borderRadius:"2px",overflow:"hidden"},children:L("div",{style:{width:X,height:"100%",backgroundColor:"white",transition:G===g?"width 0.1s linear":"none"}})},G)})}),!c&&J("div",{style:{position:"absolute",top:"20px",left:"10px",right:"10px",display:"flex",alignItems:"center",justifyContent:"space-between",zIndex:10,padding:"5px"},children:[J("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[L(bt,{src:F.thumbnail,alt:F.name,style:{width:"32px",height:"32px",borderRadius:"50%"}}),L("span",{style:{color:"white",fontWeight:"bold",fontSize:"14px",textShadow:"0 1px 3px rgba(0,0,0,0.8)"},children:F.name})]}),J("div",{style:{display:"flex",alignItems:"center",gap:"12px"},children:[L(so,{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:rt,type:u?"mute":"unmute",enabled:!!q?.enabled&&!!D,style:{position:"relative",borderRadius:"10px"}}),L(kt,{config:{enabled:ct?.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:l,style:{position:"relative",borderRadius:"10px"}})]})]}),L("div",{style:{position:"absolute",top:0,bottom:0,left:0,width:"30%",zIndex:5,cursor:"pointer"},onMouseDown:dt,onMouseUp:()=>M("prev"),onTouchStart:dt,onTouchEnd:()=>M("prev")}),L("div",{style:{position:"absolute",top:0,bottom:0,right:0,width:"70%",zIndex:4,cursor:"pointer"},onMouseDown:dt,onMouseUp:()=>M("next"),onTouchStart:dt,onTouchEnd:()=>M("next")}),(()=>{let j=Ft(C?.background)||"#000000";return J("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",background:P?j:"#000",position:"relative",width:"100%",maxHeight:c?"none":"100%",aspectRatio:"1080 / 1920",overflow:"hidden",borderRadius:c?"16px":"0",boxShadow:c?"0 12px 36px rgba(0,0,0,0.4)":"none"},children:[D?L("video",{ref:d,src:D,autoPlay:!0,playsInline:!0,muted:u,onLoadedData:N,style:{width:"100%",height:"100%",objectFit:"cover"}}):(B||!P&&F?.thumbnail)&&L(bt,{src:B||F?.thumbnail,alt:"Story content",style:{width:"100%",height:"100%",objectFit:P?"contain":"cover"}}),L(wn,{content:{...A.content,styling:{...A.content?.styling,...A?.styling},interactions:A.interactions},elapsedTime:x/100*(F.styling?.slideShowTime||5),onInteraction:async X=>{y(!0);let{type:Pt,questionId:vt,pollId:Fe,quizId:Jn,optionId:Kn,value:Xn,stickerId:Zn}=X,ae=Pt?.split("_")[0]||"interaction";ae==="quizz"&&(ae="quiz"),Pt?.startsWith("image_quiz")&&(ae="quiz");let ti=Zn||vt||Fe||Jn||A.id,ei=Kn||X.selected_option||"",vo=z.getState(),oi=vo.userId||"anonymous",ni=vo.trackingUrl||"https://tracking.appstorys.co",ko=await it(),ii={user_id:oi,campaign_id:o,event:"interaction",metadata:{interaction_type:ae,interaction_id:ti,slide_id:A.id,selected_option:String(ei),value:String(Xn||"")}};fetch(`${ni}/capture-event`,{method:"POST",headers:{"Content-Type":"application/json",...ko?{Authorization:`Bearer ${ko}`}:{}},body:JSON.stringify(ii)}).catch(ri=>console.error("AppStorys: Instant Tracking Failed",ri))}})]})})(),(_||$)&&L(Tn,{cta:A?.styling?.cta,buttonText:_||"Learn More",onPress:j=>{j&&j.stopPropagation&&j.stopPropagation(),U(A)}})]}),c&&J("div",{style:{display:"flex",justifyContent:"flex-start",alignItems:"center",gap:"12px",width:"100%",boxSizing:"border-box"},children:[g<F.slides.length-1&&L("button",{onClick:W,style:{background:"rgba(255,255,255,0.15)",border:"1px solid rgba(255,255,255,0.2)",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:j=>j.currentTarget.style.background="rgba(255,255,255,0.25)",onMouseLeave:j=>j.currentTarget.style.background="rgba(255,255,255,0.15)",children:"\u203A"}),(()=>{let G=g<F.slides.length-1?F.slides[g+1]:null;if(!G)return null;let X=G.styling,Pt=X?.editorSource||X?.meta?.editorSource,Fe=Pt==="studio"||Pt==="editor"?X?.background?.media?.mediaUrl:G.image;return J("div",{style:wt,onClick:W,children:[L(bt,{src:Fe||F.thumbnail}),L("div",{style:{position:"absolute",top:0,bottom:0,left:0,right:0,background:"rgba(0,0,0,0.2)",backdropFilter:"blur(1px)"}})]})})()]}),c&&e>0&&J("div",{style:{position:"absolute",bottom:"40px",left:"40px",display:"flex",flexDirection:"column",alignItems:"flex-start",gap:"5px",zIndex:20},children:[L("span",{style:{fontSize:"11px",fontWeight:"bold",color:"rgba(255,255,255,0.75)",letterSpacing:"0.4px",paddingLeft:"2px"},children:"Previous Stories"}),J("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:a,children:[L("span",{style:{color:"white",fontSize:"15px",fontWeight:"normal"},children:"\u2190"}),L("div",{style:{width:"40px",height:"40px",borderRadius:"50%",border:"2px solid white",display:"flex",alignItems:"center",justifyContent:"center",background:"white",flexShrink:0},children:L(bt,{src:t[e-1].thumbnail,style:{width:"36px",height:"36px",borderRadius:"50%"}})}),L("span",{style:{fontSize:"14px",color:"white",fontWeight:"500",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",minWidth:0},children:t[e-1].name})]})]}),c&&e<t.length-1&&J("div",{style:{position:"absolute",bottom:"40px",right:"40px",display:"flex",flexDirection:"column",alignItems:"flex-start",gap:"5px",zIndex:20},children:[L("span",{style:{fontSize:"11px",fontWeight:"bold",color:"rgba(255,255,255,0.75)",letterSpacing:"0.4px",paddingLeft:"2px"},children:"Next Stories"}),J("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:[L("div",{style:{width:"40px",height:"40px",borderRadius:"50%",border:"2px solid white",display:"flex",alignItems:"center",justifyContent:"center",background:"white",flexShrink:0},children:L(bt,{src:t[e+1].thumbnail,style:{width:"36px",height:"36px",borderRadius:"50%"}})}),L("span",{style:{fontSize:"14px",color:"white",fontWeight:"500",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",minWidth:0},children:t[e+1].name}),L("span",{style:{color:"white",fontSize:"15px",fontWeight:"normal"},children:"\u2192"})]})]}),T&&L("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:T})]})]})};import{jsx as En,jsxs as cr}from"react/jsx-runtime";var dr=()=>{let t=lt("STR"),e=z(p=>p.isVisible),[o,i]=An(null),[n,r]=An([]);if(Pn(()=>{try{let p=localStorage.getItem("app_storys_viewed_stories");p&&r(JSON.parse(p))}catch(p){console.error("Failed to load viewed stories:",p)}},[]),Pn(()=>{t&&t.details&&V("story_module_viewed",t.id)},[t]),!t||!t.details||t.details.length===0||!e)return null;let a=p=>{i(p);let x=t.details[p];V("story_opened",t.id,{story_id:x.id,story_name:x.name})},l=()=>{o!==null&&(o<t.details.length-1?i(o+1):i(null))},g=()=>{o!==null&&o>0&&i(o-1)};return cr("div",{className:"story-group-container",style:{width:"100vw",position:"relative",left:"50%",right:"50%",marginLeft:"-50vw",marginRight:"-50vw",boxSizing:"border-box"},children:[En(Qo,{stories:t.details,viewedStories:n,onStoryClick:a}),o!==null&&En(Bn,{stories:t.details,activeStoryIndex:o,dataId:t.id,viewedStories:n,setViewedStories:r,onNextStory:l,onPrevStory:g,onClose:()=>i(null)})]})};import{useState as pr,useRef as lo,useEffect as co}from"react";import{createPortal as ur}from"react-dom";K();import{jsx as At,jsxs as fr}from"react/jsx-runtime";var gr=({position:t})=>{let e=lt("WID",{position:t}),o=z(s=>s.campaigns),i=z(s=>s.allCampaigns),n=z(s=>s.currentScreen),r=s=>(s||"").trim().toLowerCase(),a=e??(()=>{let s=r(n),d=[...o||[],...i||[]].find(E=>{let F=E;if(F.campaign_type!=="WID"||t&&F.position!==t)return!1;let A=!!(F.trigger_event??F.trigger),C=F.display_trigger!==!1&&!A,R=!r(F.screen)||r(F.screen)===s;return C&&R});if(d)try{return ut(d)}catch{return d}})(),[l,g]=pr(0),p=lo(null),x=lo(null),m=a?.details||{},u=m.widget_images||[],v=m.styling||{},f=m.type||"full",b=f==="half",h=lo([]),y=s=>{!a?.id||!s||h.current.includes(s)||(h.current.push(s),V("viewed",a.id,{widget_image:s}))};co(()=>{if(f==="full"&&u.length>1)return x.current=setInterval(()=>{g(s=>{let d=s+1;return d>=u.length?0:d})},5e3),()=>{x.current&&clearInterval(x.current)}},[f,u.length]);let k=(s,d)=>{if(a?.id&&V("clicked",a.id,{widget_image:s}),d){if(!d.startsWith("http")){try{if(gt(d))return}catch(E){console.warn("[Widget] revealCampaignFromLink error",E)}console.log("[Widget] Internal link:",d);return}window.open(d,"_blank")}},S=()=>{if(p.current&&b){let{scrollLeft:s,offsetWidth:d}=p.current,E=d/2+12,F=Math.round(s/E);g(F)}};co(()=>{if(!a?.id||f!=="full"||u.length===0)return;let s=u[l];s&&s.id&&y(s.id)},[l,a?.id,u,f]),co(()=>{if(!a?.id||!p.current||!b)return;let s=p.current,d=()=>{let{scrollLeft:E,offsetWidth:F}=s,A=F/2+12;u.forEach((C,R)=>{let P=R*A,B=P+A,_=E,$=E+F;Math.max(0,Math.min(B,$)-Math.max(P,_))/A>=.5&&y(C.id)})};return d(),s.addEventListener("scroll",d),()=>s.removeEventListener("scroll",d)},[a?.id,b,u]);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"},I=s=>({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"}),c=fr("div",{style:{width:"100%",position:"relative"},children:[At("style",{children:`
72
+ `}),z.map(d=>!d||typeof d!="object"||!(d.type||"").toLowerCase()?null:ui(ai,{data:d,onInteraction:e,isEditing:o},d.id))]})};import{useState as Nr}from"react";import{jsx as he,jsxs as Ur}from"react/jsx-runtime";var qr=({isPaused:t,onPress:e,style:o,size:i=36})=>{let[n,r]=Nr(!1);return he("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?he("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"white",children:he("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"})}):Ur("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"white",children:[he("rect",{x:"6",y:"4",width:"4",height:"16",rx:"1"}),he("rect",{x:"14",y:"4",width:"4",height:"16",rx:"1"})]})})},gi=qr;import{jsx as No}from"react/jsx-runtime";var Hr=t=>{switch(t){case"left":return"flex-start";case"right":return"flex-end";default:return"center"}},Vr=({cta:t,buttonText:e,onPress:o})=>!t||!e||e.trim()===""?null:No("div",{style:{position:"absolute",bottom:t?.margin?.bottom,left:t?.margin?.left,right:t?.margin?.right,display:"flex",justifyContent:Hr(t?.container?.alignment),width:"100%",pointerEvents:"none",boxSizing:"border-box",zIndex:10},children:No("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:No("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:je(e)})})}),qo=Vr;import{jsx as Ye,jsxs as Qr}from"react/jsx-runtime";var Yr=({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 Qr("svg",{viewBox:"0 0 24 24",width:"70%",height:"70%","aria-hidden":!0,children:[Ye("line",{x1:"6",y1:"6",x2:"18",y2:"18",stroke:g,strokeWidth:"2.2",strokeLinecap:"round"}),Ye("line",{x1:"18",y1:"6",x2:"6",y2:"18",stroke:g,strokeWidth:"2.2",strokeLinecap:"round"})]})};return Ye("button",{onClick:e,style:x,title:c||"",children:a&&a.trim()!==""?Ye("img",{src:a,style:{width:u,height:u,objectFit:"contain"},alt:"close"}):m()})},Pt=Yr;import{jsx as Wt,jsxs as fi}from"react/jsx-runtime";var Uo=({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"?fi("svg",{viewBox:"0 0 24 24",width:"70%",height:"70%","aria-hidden":!0,children:[Wt("polygon",{points:"4,10 8,10 13,6 13,18 8,14 4,14",fill:"none",stroke:w,strokeWidth:"2.2",strokeLinejoin:"round"}),Wt("line",{x1:"16",y1:"8",x2:"21",y2:"16",stroke:w,strokeWidth:"2.2",strokeLinecap:"round"}),Wt("line",{x1:"21",y1:"8",x2:"16",y2:"16",stroke:w,strokeWidth:"2.2",strokeLinecap:"round"})]}):fi("svg",{viewBox:"0 0 24 24",width:"70%",height:"70%","aria-hidden":!0,children:[Wt("polygon",{points:"4,10 8,10 13,6 13,18 8,14 4,14",fill:"none",stroke:w,strokeWidth:"2.2",strokeLinejoin:"round"}),Wt("path",{d:"M16 10 Q18 12 16 14",fill:"none",stroke:w,strokeWidth:"2.2",strokeLinecap:"round"}),Wt("path",{d:"M18 8 Q22 12 18 16",fill:"none",stroke:w,strokeWidth:"2.2",strokeLinecap:"round"})]})};return Wt("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()!==""?Wt("img",{src:u,style:{width:m,height:m,objectFit:"contain"},alt:r}):y()})};import{jsx as Ht,jsxs as Jr}from"react/jsx-runtime";var Gr=({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 Jr("svg",{viewBox:"0 0 24 24",width:"60%",height:"60%",fill:"none",stroke:g,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[Ht("circle",{cx:"18",cy:"5",r:"3"}),Ht("circle",{cx:"6",cy:"12",r:"3"}),Ht("circle",{cx:"18",cy:"19",r:"3"}),Ht("line",{x1:"8.59",y1:"13.51",x2:"15.42",y2:"17.49"}),Ht("line",{x1:"15.41",y1:"6.51",x2:"8.59",y2:"10.49"})]})};return Ht("button",{onClick:e,style:x,title:c||"",children:a&&a.trim()!==""?Ht("img",{src:a,style:{width:u,height:u,objectFit:"contain"},alt:"share"}):m()})},mi=Gr;import{Fragment as Kr,jsx as W,jsxs as nt}from"react/jsx-runtime";var oe=400,Vo=700,xe=.63,Go=420,hi=Go+oe*xe+27,Lt=580,Yo="cubic-bezier(0.65, 0, 0.35, 1)",Qo="cubic-bezier(0.45, 0, 0.25, 1)";function Xr(t){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(-${Go}px) scale(${xe})`,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(${Go}px) scale(${xe})`,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(-${hi}px) scale(${xe})`,opacity:1,filter:"brightness(0.3)",zIndex:2,pointerEvents:"none"};case"far-right":return{transform:`translateX(${hi}px) scale(${xe})`,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 bi=({src:t,isActive:e,isAnimating:o,isMuted:i,onLoadedData:n,activeVideoRef:r})=>{let s=yi.useRef(null);return yi.useEffect(()=>{e&&!o?(r.current=s.current,s.current?.play().catch(()=>{})):(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"}})},xi=({stories:t,activeStoryIndex:e,dataId:o,viewedStories:i,setViewedStories:n,onNextStory:r,onPrevStory:s,onClose:a})=>{let[c,u]=xt(0),[x,m]=xt(0),[g,v]=xt(!1),[f,b]=xt(!1),[h,y]=xt(!1),[w,I]=xt(!1),[z,R]=xt(null),[d,T]=xt(typeof window<"u"?window.innerWidth>=1024:!1),[l,p]=xt(!1),[M,B]=xt(null),[L,C]=xt(null),[S,_]=xt(null);be(()=>{let A=()=>{T(window.innerWidth>=1024)};return window.addEventListener("resize",A),()=>window.removeEventListener("resize",A)},[]);let E=Ho(null),$=Ho(null),D=Ho(0),k=t[e],P=k?.slides[c],O=P?.styling,G=O?.editorSource||O?.meta?.editorSource,gt=G==="studio"||G==="editor",j=gt?O?.background?.media?.mediaUrl:P?.image,X=gt?P?.content?.button_text:P?.button_text,J=gt?P?.content?.link:P?.link,V=P?.video||(gt?P?.content?.video?.[0]?.link:void 0),at=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(be(()=>{u(0),m(0),b(!1),y(!1),p(!1),B(null),C(null),_(null)},[e]),be(()=>{let A=q=>{if(!(document.activeElement?.tagName==="INPUT"||document.activeElement?.tagName==="TEXTAREA"))switch(q.key){case"ArrowRight":Y();break;case"ArrowLeft":Q();break;case" ":q.preventDefault(),y(rt=>!rt);break;case"Escape":a();break;case"s":case"S":q.preventDefault(),at();break}};return window.addEventListener("keydown",A),()=>window.removeEventListener("keydown",A)},[c,e,h,k,a]),be(()=>{k&&P&&H("viewed",o,{story_slide:P.id})},[c,k?.id,o]),be(()=>{if(k&&P){let A=k.styling?.slideShowTime||5,q=!!V;if(E.current&&clearInterval(E.current),h){$.current&&$.current.pause();return}else $.current&&$.current.play().catch(()=>{});return q&&!f||l?void 0:(E.current=setInterval(()=>{m(rt=>rt>=100?(Y(),100):rt+100/(A*10))},100),()=>{E.current&&clearInterval(E.current)})}},[e,c,h,f,l]),!P)return null;let N=(A,q)=>{l||(_(A),B(c),C(q),p(!0),setTimeout(()=>{u(q),m(0),b(!1),p(!1),B(null),C(null),_(null)},Lt+20))},Y=()=>{if(!l)if(c<k.slides.length-1)N("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()}},Q=()=>{l||(c>0?N("prev",c-1):s())},tt=()=>{D.current=Date.now(),y(!0)},pt=A=>{y(!1),Date.now()-D.current<300&&(A==="next"?Y():Q())},lt=()=>b(!0),vt=A=>{let q=A?.styling,rt=q?.editorSource||q?.meta?.editorSource,ft=rt==="studio"||rt==="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)},Bt=A=>{A.stopPropagation(),v(!g)},ae=k?.styling?.crossButton,Ot=k?.styling?.soundToggle,Os=P?.styling?.cta,ln=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",ji=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"},dn=d?{position:"absolute",width:`${oe}px`,height:`${Vo}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"},js={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"},Ni=k.slides.reduce((A,q,rt)=>(ln(rt)!=="hidden"&&A.push(rt),A),[]),Qt=new Set(Ni);return Qt.add(c),c>0&&Qt.add(c-1),c>1&&Qt.add(c-2),c<k.slides.length-1&&Qt.add(c+1),c<k.slides.length-2&&Qt.add(c+2),nt("div",{style:ji,onClick:()=>!d&&Y(),children:[nt("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(Ft,{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&&nt("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,q)=>{let rt=l&&L!==null?L:c,wt="0%";return q<rt?wt="100%":q===rt&&(wt=`${x}%`),W("div",{style:{flex:1,height:"3px",backgroundColor:"rgba(255,255,255,0.15)",borderRadius:"2px",overflow:"hidden"},children:W("div",{style:{width:wt,height:"100%",backgroundColor:"white",transition:q===rt?"width 0.1s linear":"none"}})},q)})}),nt("div",{style:{width:"100%",maxWidth:"1400px",margin:"0 auto",display:"grid",gridTemplateColumns:`minmax(0, 1fr) ${oe}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"}}),nt("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%"},children:[nt("div",{style:{display:"flex",alignItems:"center",gap:"12px"},children:[W(Ft,{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})]}),nt("div",{style:{display:"flex",gap:"8px"},children:[W(mi,{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:at,style:{position:"relative",borderRadius:"12px"}}),W(Uo,{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:Bt,type:g?"mute":"unmute",enabled:!!Ot?.enabled&&!!V,style:{position:"relative",borderRadius:"12px"}}),W(gi,{isPaused:h,onPress:()=>y(!h),size:44,style:{borderRadius:"12px"}})]})]}),nt("div",{style:{display:"flex",gap:"10px",flex:1,justifyContent:"flex-end",paddingRight:"0px"},children:[nt("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:nt("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&&nt(Kr,{children:[W("style",{children:`
73
+ @keyframes fadeUp {
74
+ from { opacity: 0; transform: translateY(10px) scale(0.95); }
75
+ to { opacity: 1; transform: translateY(0) scale(1); }
76
+ }
77
+ `}),nt("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:q})=>nt("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:q})]},A))})]})]})]}),W(Pt,{config:{enabled:ae?.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:nt("div",{style:{display:d?"grid":"flex",gridTemplateColumns:d?`minmax(0, 1fr) ${oe}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:Q,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:`${oe}px`,height:`${Vo}px`,position:"relative",zIndex:5,overflow:"visible"},children:Array.from(Qt).sort((A,q)=>A-q).map(A=>{let q=k.slides[A];if(!q)return null;let rt=ln(A),wt=Xr(rt),ft=q?.styling,le=ft?.editorSource||ft?.meta?.editorSource,kt=le==="studio"||le==="editor",Te=ft?.background?.media?.mediaUrl||q?.image,de=q?.video||(kt?q?.content?.video?.[0]?.link:void 0),oo=Et(ft?.background)||"#000000",ce=kt?q?.content?.button_text:q?.button_text,St=kt?q?.content?.link:q?.link,pe=A===c&&!l||l&&A===L,no={display:"flex",justifyContent:"center",alignItems:"center",background:kt?oo:"#000",position:"relative",width:"100%",height:"100%",overflow:"hidden",borderRadius:"16px"};return nt("div",{style:{...dn,position:"absolute",top:0,left:0,width:`${oe}px`,height:`${Vo}px`,...wt,transition:rt==="hidden"||rt==="far-left"||rt==="far-right"?`opacity ${Lt}ms ease, transform ${Lt}ms ease`:A===M?`transform ${Lt}ms ${Yo}, opacity ${Lt}ms ${Yo}, filter ${Lt}ms ${Yo}`:`transform ${Lt}ms ${Qo}, opacity ${Lt}ms ${Qo}, filter ${Lt}ms ${Qo}`,transformOrigin:"center center",willChange:"transform, opacity, filter"},onClick:Rt=>Rt.stopPropagation(),children:[W("div",{style:{position:"absolute",top:0,bottom:0,left:0,width:"30%",zIndex:5,cursor:"pointer"},onMouseDown:tt,onMouseUp:()=>pt("prev"),onTouchStart:tt,onTouchEnd:()=>pt("prev")}),W("div",{style:{position:"absolute",top:0,bottom:0,right:0,width:"70%",zIndex:4,cursor:"pointer"},onMouseDown:tt,onMouseUp:()=>pt("next"),onTouchStart:tt,onTouchEnd:()=>pt("next")}),nt("div",{style:no,children:[de?W(bi,{src:de,isActive:pe,isAnimating:l,isMuted:g,onLoadedData:lt,activeVideoRef:$}):(Te||!kt&&k?.thumbnail)&&W(Ft,{src:Te||k?.thumbnail,alt:"Story content",style:{width:"100%",height:"100%",objectFit:kt?"contain":"cover"}}),W(jo,{content:{...q.content,styling:{...q.content?.styling,...q?.styling},interactions:q.interactions},elapsedTime:pe?x/100*(k.styling?.slideShowTime||5):0,onInteraction:async Rt=>{if(!pe)return;y(!0);let{type:Ie,questionId:io,pollId:Gt,quizId:ro,optionId:so,value:ze,stickerId:ao}=Rt,Jt=Ie?.split("_")[0]||"interaction";Jt==="quizz"&&(Jt="quiz"),Ie?.startsWith("image_quiz")&&(Jt="quiz");let Be=ao||io||Gt||ro||q.id,lo=so||Rt.selected_option||"",cn=F.getState(),qi=cn.userId||"anonymous",Ui=cn.trackingUrl||"https://tracking.appstorys.co",pn=await dt();fetch(`${Ui}/capture-event`,{method:"POST",headers:{"Content-Type":"application/json",...pn?{Authorization:`Bearer ${pn}`}:{}},body:JSON.stringify({user_id:qi,campaign_id:o,event:"interaction",metadata:{interaction_type:Jt,interaction_id:Be,slide_id:q.id,selected_option:String(lo),value:String(ze||"")}})}).catch(Hi=>console.error("AppStorys: Instant Tracking Failed",Hi))}})]}),(ce||St)&&W(qo,{cta:q?.styling?.cta,buttonText:ce||"Learn More",onPress:Rt=>{Rt&&Rt.stopPropagation&&Rt.stopPropagation(),vt(q)}})]},q.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,q)=>{if(Math.abs(q-c)>1)return W("div",{style:{display:"none"}},A.id||q);let rt=A?.styling,wt=rt?.editorSource||rt?.meta?.editorSource,ft=wt==="studio"||wt==="editor",le=rt?.background?.media?.mediaUrl||A?.image,kt=A?.video||(ft?A?.content?.video?.[0]?.link:void 0),Te=Et(rt?.background)||"#000000",de=ft?A?.content?.button_text:A?.button_text,oo=ft?A?.content?.link:A?.link,ce=q===c;return ce?W("div",{style:{width:"100%",height:"100%",display:"flex",justifyContent:"center",alignItems:"center"},children:nt("div",{style:{...dn},onClick:St=>St.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((St,Dt)=>{let Fe=Dt<c?"100%":Dt===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:Fe,height:"100%",backgroundColor:"white",transition:Dt===c?"width 0.1s linear":"none"}})},Dt)})}),nt("div",{style:{position:"absolute",top:"20px",left:"10px",right:"10px",display:"flex",alignItems:"center",justifyContent:"space-between",zIndex:10,padding:"5px"},children:[nt("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[W(Ft,{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})]}),nt("div",{style:{display:"flex",alignItems:"center",gap:"12px"},children:[W(Uo,{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:Bt,type:g?"mute":"unmute",enabled:!!Ot?.enabled&&!!kt,style:{position:"relative",borderRadius:"10px"}}),W(Pt,{config:{enabled:ae?.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:tt,onMouseUp:()=>pt("prev"),onTouchStart:tt,onTouchEnd:()=>pt("prev")}),W("div",{style:{position:"absolute",top:0,bottom:0,right:0,width:"70%",zIndex:4,cursor:"pointer"},onMouseDown:tt,onMouseUp:()=>pt("next"),onTouchStart:tt,onTouchEnd:()=>pt("next")}),nt("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",background:ft?Te:"#000",position:"relative",width:"100%",height:"100%",overflow:"hidden",borderRadius:"0px"},children:[kt?W(bi,{src:kt,isActive:ce,isAnimating:l,isMuted:g,onLoadedData:lt,activeVideoRef:$}):(le||k?.thumbnail)&&W(Ft,{src:le||k?.thumbnail,alt:"Story content",style:{width:"100%",height:"100%",objectFit:ft?"contain":"cover"}}),W(jo,{content:{...A.content,styling:{...A.content?.styling,...A?.styling},interactions:A.interactions},elapsedTime:x/100*(k.styling?.slideShowTime||5),onInteraction:async St=>{y(!0);let{type:Dt,questionId:Fe,pollId:pe,quizId:no,optionId:Rt,value:Ie,stickerId:io}=St,Gt=Dt?.split("_")[0]||"interaction";Gt==="quizz"&&(Gt="quiz"),Dt?.startsWith("image_quiz")&&(Gt="quiz");let ro=io||Fe||pe||no||A.id,so=Rt||St.selected_option||"",ze=F.getState(),ao=ze.userId||"anonymous",Jt=ze.trackingUrl||"https://tracking.appstorys.co",Be=await dt();fetch(`${Jt}/capture-event`,{method:"POST",headers:{"Content-Type":"application/json",...Be?{Authorization:`Bearer ${Be}`}:{}},body:JSON.stringify({user_id:ao,campaign_id:o,event:"interaction",metadata:{interaction_type:Gt,interaction_id:ro,slide_id:A.id,selected_option:String(so),value:String(Ie||"")}})}).catch(lo=>console.error("AppStorys: Instant Tracking Failed",lo))}})]}),(de||oo)&&W(qo,{cta:A?.styling?.cta,buttonText:de||"Learn More",onPress:St=>{St&&St.stopPropagation&&St.stopPropagation(),vt(A)}})]})},A.id||q):null})}),d&&W("div",{style:{display:"flex",justifyContent:"flex-start",alignItems:"center",gap:"12px",width:"100%",boxSizing:"border-box"},children:W("button",{onClick:Y,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&&nt("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"}),nt("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(Ft,{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&&nt("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"}),nt("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(Ft,{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 vi,jsxs as ts}from"react/jsx-runtime";var Zr=()=>{let t=ut("STR"),e=F(u=>u.isVisible),[o,i]=Si(null),[n,r]=Si([]);if(Ci(()=>{try{let u=localStorage.getItem("app_storys_viewed_stories");u&&r(JSON.parse(u))}catch(u){console.error("Failed to load viewed stories:",u)}},[]),Ci(()=>{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 ts("div",{className:"story-group-container",style:{width:"100vw",position:"relative",left:"50%",right:"50%",marginLeft:"-50vw",marginRight:"-50vw",boxSizing:"border-box"},children:[vi(Wn,{stories:t.details,viewedStories:n,onStoryClick:s}),o!==null&&vi(xi,{stories:t.details,activeStoryIndex:o,dataId:t.id,viewedStories:n,setViewedStories:r,onNextStory:a,onPrevStory:c,onClose:()=>i(null)})]})};import{useState as es,useRef as Ge,useEffect as Jo,useCallback as os}from"react";import{createPortal as ns}from"react-dom";K();import{useEffect as wi,useRef as Qe}from"react";function Se(t,e=.5){let o=Qe(t),i=Qe(!1),n=Qe(null),r=Qe(null);wi(()=>{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 wi(()=>()=>{r.current?.disconnect()},[]),s}import{jsx as Mt,jsxs as rs}from"react/jsx-runtime";var is=({position:t})=>{let e=ut("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 mt(L)}catch{return L}})(),[a,c]=es(0),u=Ge(null),x=Ge(null),m=s?.details||{},g=m.widget_images||[],v=m.styling||{},f=m.type||"full",b=f==="half",h=Ge([]),y=Ge(!1),w=os(()=>{y.current=!0;let B=g[a];B?.id&&z(B.id)},[g,a]),I=Se(w),z=B=>{!s?.id||!B||y.current&&(h.current.includes(B)||(h.current.push(B),H("viewed",s.id,{widget_image:B})))};Jo(()=>{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(yt(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)}};Jo(()=>{if(!s?.id||f!=="full"||g.length===0)return;let B=g[a];B&&B.id&&z(B.id)},[a,s?.id,g,f]),Jo(()=>{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=rs("div",{style:{width:"100%",position:"relative"},children:[Mt("style",{children:`
76
78
  .widget-scroll-container::-webkit-scrollbar {
77
79
  display: none;
78
80
  }
79
- `}),At("div",{ref:p,className:"widget-scroll-container",style:T,onScroll:S,children:b?u.map((s,d)=>At("div",{style:I(d),children:At("img",{src:s.image,alt:"widget",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"},onClick:()=>k(s.id,s.link)})},s.id)):u.length>0&&At("div",{style:I(0),children:At("img",{src:u[l].image,alt:"widget",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"},onClick:()=>k(u[l].id,u[l].link)})},`slide-${l}`)}),f==="full"&&u.length>1&&At("div",{style:{display:"flex",justifyContent:"center",gap:"6px",marginTop:"8px",width:"100%"},children:u.map((s,d)=>At("div",{style:{width:"6px",height:"6px",borderRadius:"50%",backgroundColor:d===l?"#333":"#ccc",transition:"background-color 0.2s ease"}},d))})]}),w=null;if(a?.position){let s=String(a.position||"").replace(/^widget_/,""),d=[`[data-as-id="${s}"]`,`#${s}`,`.${s}`,`[data-widget="${s}"]`];for(let E of d)try{let F=document.querySelector(E);if(F){w=F,console.log("[Widget] Portal target found:",E,"for campaign",a?.id);break}}catch{}w||console.log("[Widget] No portal target found for position:",a?.position,"rendering inline for campaign:",a?.id)}return w?ur(c,w):c};import{useEffect as po,useLayoutEffect as mr,useMemo as Ln,useRef as uo,useState as ve}from"react";K();import{Fragment as br,jsx as Ht,jsxs as Dn}from"react/jsx-runtime";var go=t=>(t||"").trim().toLowerCase(),yr=()=>{let t=lt("TTP"),e=z(N=>N.campaigns),o=z(N=>N.allCampaigns),i=z(N=>N.currentScreen),n=z(N=>N.isVisible),[r,a]=ve(0),[l,g]=ve(!1),[p,x]=ve(null),[m,u]=ve({width:0,height:0}),v=uo(null),f=uo(null),b=Ln(()=>{if(t)return t;let N=go(i),U=rt=>rt.find(ct=>{let q=ct,Q=q.campaign_type==="TTP"||q.campaign_type==="TLTP",st=!go(q.screen)||go(q.screen)===N,pt=!!(q.trigger_event??q.trigger),ft=q.display_trigger!==!1&&!pt;return Q&&st&&ft});return U(e)??U(o)},[t,e,o,i]),h=Ln(()=>b?.details?.tooltips&&Array.isArray(b.details.tooltips)?[...b.details.tooltips].sort((N,U)=>(N.order??0)-(U.order??0)):b?.details?.target||b?.details?.titleText?[{...b.details,_id:b.id}]:[],[b]),y=h[r];po(()=>{},[b]);let k=uo(new Set);if(po(()=>{if(!(!b||!y||!p||l||!n))try{let N=y._id||y.id||void 0,U=String(b.id||"")+"::"+String(N||"");k.current.has(U)||(k.current.add(U),V("viewed",b.id,{tooltip_id:N}))}catch{}},[b,y,p,l,n]),po(()=>{if(!y?.target||l)return;x(null);let N=(ct=!1)=>{let q=y.target;if(!q)return null;let Q=document.getElementById(q)||document.querySelector(`[data-id="${q}"]`)||document.querySelector(`.${q}`);return Q?(x(Q.getBoundingClientRect()),ct&&Q.scrollIntoView({behavior:"smooth",block:"center"}),Q):null};N(!0)||(f.current=new MutationObserver(()=>{N(!0)&&f.current?.disconnect()}),f.current.observe(document.body,{childList:!0,subtree:!0}));let rt=()=>{let ct=N(!1);ct&&x(ct.getBoundingClientRect())};return window.addEventListener("resize",rt),window.addEventListener("scroll",rt,{passive:!0}),()=>{f.current?.disconnect(),window.removeEventListener("resize",rt),window.removeEventListener("scroll",rt)}},[y,l,r]),mr(()=>{if(v.current&&p){let{width:N,height:U}=v.current.getBoundingClientRect();u({width:N,height:U})}},[y,p]),!b||!y||l||!n||!p)return null;let S=y.styling||{},T=S.appearance||{},I=T.colors||{},c=S.cta||{},w=c.container||{},s=c.cornerRadius||{},d=c.text||{},E=y.arrowPosition||"left",A=(T.arrowStyle||{width:6,height:12}).width||6,C=p.top+window.scrollY,R=p.left+window.scrollX,P=0,B=0,_=8;E==="left"?(P=R+p.width+_,B=C+p.height/2-m.height/2):E==="right"?(P=R-m.width-_,B=C+p.height/2-m.height/2):E==="top"?(B=C+p.height+_,P=R+p.width/2-m.width/2):E==="bottom"&&(B=C-m.height-_,P=R+p.width/2-m.width/2);let $=8,D=window.scrollY,O=window.scrollY+window.innerHeight,W=window.scrollX,Y=window.scrollX+window.innerWidth;m.height>0&&(B=Math.max(D+$,Math.min(O-m.height-$,B))),m.width>0&&(P=Math.max(W+$,Math.min(Y-m.width-$,P)));let dt=()=>{let N=y.clickAction||"nextStep",U=y.link||y.url;try{let rt=y._id||y.id||void 0;b?.id&&V("clicked",b.id,{tooltip_id:rt})}catch{}if(N==="close"){g(!0),U&&window.open(U,"_blank");return}r<h.length-1?a(rt=>rt+1):(g(!0),U&&window.open(U,"_blank"))},M=()=>{y.enableBackdrop&&g(!0)};return Dn(br,{children:[y.enableBackdrop&&Ht("div",{style:{position:"fixed",top:0,left:0,right:0,bottom:0,backgroundColor:I.backdrop||"rgba(0, 0, 0, 0.7)",opacity:T.backdropOpacity?T.backdropOpacity/100:.7,zIndex:1e4},onClick:M}),Dn("div",{ref:v,style:{position:"absolute",top:B,left:P,zIndex:10001,backgroundColor:I.tooltip||"#FE6B35",padding:`${T.padding?.top??8}px ${T.padding?.right??8}px ${T.padding?.bottom??8}px ${T.padding?.left??8}px`,borderRadius:`${T.cornerRadius?.topLeft??12}px ${T.cornerRadius?.topRight??12}px ${T.cornerRadius?.bottomRight??12}px ${T.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:[Ht("div",{style:{position:"absolute",width:0,height:0,borderStyle:"solid",...E==="left"&&{left:-_,top:Math.max(12,Math.min(m.height-A*2-12,C+p.height/2-B-A)),borderWidth:`${A}px ${_}px ${A}px 0`,borderColor:`transparent ${I.tooltip||"#FE6B35"} transparent transparent`},...E==="right"&&{right:-_,top:Math.max(12,Math.min(m.height-A*2-12,C+p.height/2-B-A)),borderWidth:`${A}px 0 ${A}px ${_}px`,borderColor:`transparent transparent transparent ${I.tooltip||"#FE6B35"}`},...E==="top"&&{top:-_,left:Math.max(12,Math.min(m.width-A*2-12,R+p.width/2-P-A)),borderWidth:`0 ${A}px ${_}px ${A}px`,borderColor:`transparent transparent ${I.tooltip||"#FE6B35"} transparent`},...E==="bottom"&&{bottom:-_,left:Math.max(12,Math.min(m.width-A*2-12,R+p.width/2-P-A)),borderWidth:`${_}px ${A}px 0 ${A}px`,borderColor:`${I.tooltip||"#FE6B35"} transparent transparent transparent`}}}),y.titleText&&Ht("div",{style:{color:S.title?.color||"#ffffff",fontFamily:S.title?.fontFamily||"Arial",fontSize:S.title?.fontSize||14,textAlign:S.title?.textAlign||"center",marginBottom:S.title?.margin?.bottom??4,marginTop:S.title?.margin?.top??0,marginLeft:S.title?.margin?.left??0,marginRight:S.title?.margin?.right??0,fontWeight:S.title?.fontDecoration?.includes("bold")?"bold":600,fontStyle:S.title?.fontDecoration?.includes("italic")?"italic":"normal",textDecoration:S.title?.fontDecoration?.includes("underline")?"underline":"none"},children:y.titleText}),y.subtitleText&&Ht("div",{style:{color:S.subTitle?.color||"#ffffff",fontFamily:S.subTitle?.fontFamily||"Arial",fontSize:S.subTitle?.fontSize||12,textAlign:S.subTitle?.textAlign||"center",marginBottom:S.subTitle?.margin?.bottom??8,marginTop:S.subTitle?.margin?.top??0,marginLeft:S.subTitle?.margin?.left??0,marginRight:S.subTitle?.margin?.right??0,fontWeight:S.subTitle?.fontDecoration?.includes("bold")?"bold":"normal",fontStyle:S.subTitle?.fontDecoration?.includes("italic")?"italic":"normal",textDecoration:S.subTitle?.fontDecoration?.includes("underline")?"underline":"none"},children:y.subtitleText}),y.ctaText&&Ht("div",{style:{display:"flex",justifyContent:w.alignment==="right"?"flex-end":w.alignment==="left"?"flex-start":"center",marginTop:8},children:Ht("button",{onClick:dt,style:{width:w.ctaFullWidth?"100%":w.ctaWidth||"auto",height:w.height||35,background:w.backgroundColor||"#F7921C",color:d.color||"#ffffff",border:`${w.borderWidth||0}px solid ${w.borderColor||"transparent"}`,borderRadius:`${s.topLeft??7}px ${s.topRight??7}px ${s.bottomRight??7}px ${s.bottomLeft??7}px`,fontSize:d.fontSize||14,fontFamily: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",padding:"0 12px",display:"inline-flex",alignItems:"center",justifyContent:"center"},children:y.ctaText})})]})]})},hr=yr;import{useEffect as xr,useState as Sr}from"react";K();import{Fragment as vr,jsx as St,jsxs as fo}from"react/jsx-runtime";var Cr=()=>{let t=lt("BTS"),e=z(f=>f.campaigns),o=z(f=>f.allCampaigns),i=z(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 S=(h.screen||"").trim().toLowerCase();return!S||S===f});if(b)try{return ut(b)}catch{return b}})(),r=z(f=>f.isVisible),[a,l]=Sr(!1);xr(()=>{n&&(l(!1),V("viewed",n.id))},[n]);let g=f=>{try{let b=z.getState(),y=(b.trackedEvents||[]).filter(k=>k!==f);b.setTrackedEvents(y)}catch{}};if(!n||a||!r)return null;let{details:p}=n,m=[...p.elements||[]].sort((f,b)=>(f.order||0)-(b.order||0)),u=p.backdropOpacity??.5;u>1&&(u=u/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 St("div",{style:{textAlign:f.alignment||"left",width:"100%"},children:f.url&&St("img",{src:f.url,alt:"",style:b,onClick:()=>{if(f.imageLink){n?.id&&V("clicked",n.id);try{let h=String(f.imageLink||"").trim();if(h&&!h.startsWith("http")&&gt(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||{},k=b.margin||{},S=b.text||{};return St("div",{style:{display:"flex",justifyContent:h.alignment==="center"?"center":h.alignment==="right"?"flex-end":"flex-start",width:"100%",marginTop:k.top??0,marginBottom:k.bottom??0,marginLeft:k.left??0,marginRight:k.right??0},children:St("button",{style:{width:h.ctaFullWidth?"100%":h.ctaWidth||"auto",height:h.height||45,backgroundColor:h.ctaBoxColor||h.backgroundColor||"#FE6B35",color:S.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:S.fontSize||14,fontFamily:S.fontFamily||"Arial",fontWeight:S.fontDecoration?.includes("bold")?"bold":"normal",fontStyle:S.fontDecoration?.includes("italic")?"italic":"normal",textDecoration:S.fontDecoration?.includes("underline")?"underline":"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",padding:"0 16px"},onClick:()=>{let T=f.ctaLink||f.url;if(T){n?.id&&V("clicked",n.id);try{let I=String(T||"").trim();if(I&&!I.startsWith("http")&&gt(I))return}catch(I){console.warn("revealCampaignFromLink error",I)}try{window.open(T,"_blank")}catch{}}},children:f.ctaText||"Button"})},f.id)}case"body":{let b=f.titleFontStyle||{},h=f.descriptionFontStyle||{};return fo("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&&St("div",{style:{color:b.colour||"#000000",fontSize:b.fontSize?`${b.fontSize}px`:f.titleFontSize?`${f.titleFontSize}px`:"16px",fontFamily: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&&St("div",{style:{color:h.colour||"#000000",fontSize:h.fontSize?`${h.fontSize}px`:f.descriptionFontSize?`${f.descriptionFontSize}px`:"14px",fontFamily: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 fo(vr,{children:[St("div",{style:{position:"fixed",top:0,left:0,right:0,bottom:0,backgroundColor:p.backdropColor||"rgba(0,0,0,0.5)",opacity:u,zIndex:999998,transition:"opacity 0.3s ease"},onClick:()=>{n?.id&&g(`viaAppStorys${n.id}`),l(!0)}}),fo("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:[St("div",{style:{width:"40px",height:"5px",backgroundColor:"#E0E0E0",borderRadius:"2.5px",marginBottom:"16px",cursor:"pointer"},onClick:()=>l(!0)}),p.crossButton?.enabled&&St(kt,{config:p.crossButton,onPress:()=>{n?.id&&g(`viaAppStorys${n.id}`),l(!0)},style:{top:p.crossButton?.margin?.top??12,right:p.crossButton?.margin?.right??12}}),St("div",{style:{width:"100%",display:"flex",flexDirection:"column",gap:"12px"},children:m.map(v)})]})]})};import{useEffect as kr,useMemo as wr,useState as Vt}from"react";K();import{Fragment as bo,jsx as Z,jsxs as ne}from"react/jsx-runtime";var Wn=5,mo=3;function Ct(t){if(t!=null)return`${t}px`}function oe(t){return{marginTop:Ct(t?.top),marginRight:Ct(t?.right),marginBottom:Ct(t?.bottom),marginLeft:Ct(t?.left)}}function xo(t){if(t&&!(t.startsWith("http://")||t.startsWith("https://")))return t}function Yt(t){return t?{color:t.color,fontSize:t.fontSize,fontFamily:xo(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 yo(t){return`${t?.topLeft??8}px ${t?.topRight??8}px ${t?.bottomRight??8}px ${t?.bottomLeft??8}px`}function Rr(t){return t==="right"?"flex-end":t==="left"?"flex-start":"center"}function Tr(t){let e=t.styling?.rating?.ratingType;return e==="number"||e==="emoji"||e==="star"?e:"star"}function zr(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 Fr(t){return Array.from({length:5},(e,o)=>o+1)}function ho(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 Ir(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=ho(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 a of r){let l=ho(a);if(l!=null)return l}}return 8}var Br=({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"})}),Ar=({details:t,appearance:e,rating:o,selectedOptions:i,comments:n,isHighRating:r,feedbackOptions:a,onRate:l,onToggleOption:g,onCommentChange:p,onInlineSubmit:x,canSubmit:m})=>{let u=t.styling||{},v=u.feedbackPage||{},f=u.rating||{},b=u.initialFeedback||{},h=v.submitButton?.cta,y=Tr(t),k=y==="number"?Fr(t):[],S=y==="emoji"?zr(t):[],T=y==="number"?Ir(t):8,I=r?f.star?.high:f.star?.low;return ne(bo,{children:[Z("div",{style:oe(b.title?.margin),children:Z("div",{style:{...Yt(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:oe(b.subtitle?.margin),children:Z("div",{style:{...Yt(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."})}),ne("div",{style:{marginTop:8,display:"flex",justifyContent:"center",gap:y==="number"?T:8,flexWrap:"wrap"},children:[y==="star"&&Array.from({length:Wn},(c,w)=>{let s=w+1,d=s<=o,E=d?I?.stylingContainer:f.star?.unselected?.stylingContainer,F=d?I?.stylingStar:f.star?.unselected?.stylingStar;return Z("button",{onClick:()=>l(s),style:{border:`${E?.borderWidth??1}px solid ${E?.border||"#d1d5db"}`,background:E?.background||"#ffffff",borderRadius:10,width:44,height:44,display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0},"aria-label":`Rate ${s} out of ${Wn}`,children:Z(Br,{fill:F?.background||(d?"#f59e0b":"#e5e7eb"),stroke:F?.border||(d?"#d97706":"#9ca3af")})},s)}),y==="number"&&k.map((c,w)=>{let s=c===o;return Z("button",{onClick:()=>l(c),style:{border:`1px solid ${s?"#1d4ed8":"#d1d5db"}`,background:s?"#dbeafe":"#ffffff",color:s?"#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 ${c}`,children:c},`${c}-${w}`)}),y==="emoji"&&S.map((c,w)=>{let s=w+1,d=s===o;return Z("button",{onClick:()=>l(s),style:{border:`1px solid ${d?"#1d4ed8":"#d1d5db"}`,background:d?"#dbeafe":"#ffffff",borderRadius:"999px",width:44,height:44,display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:"pointer",fontSize:22},"aria-label":`Emoji rating ${w+1}`,children:c},`${c}-${w}`)})]}),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<=mo&&ne(bo,{children:[a.length>0&&Z("div",{style:{...oe(v.options?.margin),display:"flex",flexDirection:"column",alignItems:"stretch",gap:v.options?.optionsSpacing??8,width:"100%"},children:a.map(c=>{let s=i.includes(c)?v.options?.selectedOptions:v.options?.nonSelectedOptions;return Z("button",{onClick:()=>g(c),style:{border:`${s?.borderWidth??1}px solid ${s?.colors?.border||"#d1d5db"}`,background:s?.colors?.background||"#f9fafb",color:s?.colors?.text||"#111827",width:"100%",height:v.options?.optionsHeight||38,borderRadius:yo(v.options?.cornerRadius),padding:"0 14px",cursor:"pointer",textAlign:"center",...Yt(s?.textStyle)},children:c},c)})}),Z("textarea",{value:n,onChange:c=>p(c.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",...Yt(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(ho(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:yo(h?.cornerRadius),fontFamily:xo(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"})})]})]})},Pr=({details:t,isHighRating:e,onDone:o})=>{let i=t.styling||{},n=i.thankyouPage||{},r=i.rating||{},a=Rr(n.doneButton?.cta?.container?.alignment);return ne(bo,{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:{...oe(n.title?.margin),textAlign:"center"},children:Z("div",{style:{...Yt(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:{...oe(n.subtitle?.margin),textAlign:"center"},children:Z("div",{style:{...Yt(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:a},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:yo(n.doneButton?.cta?.cornerRadius),fontFamily:xo(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")})})]})},Er=()=>{let t=lt("CSAT"),e=z(C=>C.isVisible),o=z(C=>C.campaigns),i=z(C=>C.allCampaigns),n=z(C=>C.currentScreen),r=t??(()=>{let C=(n||"").trim().toLowerCase(),R=[...o||[],...i||[]].find(P=>{if(!P||P.campaign_type!=="CSAT")return!1;let B=!!(P.trigger_event??P.trigger);if(!(P.display_trigger!==!1&&!B))return!1;let $=(P.screen||"").trim().toLowerCase();return!$||$===C});if(R)try{return ut(R)}catch{return R}})(),[a,l]=Vt(!1),[g,p]=Vt(!1),[x,m]=Vt(0),[u,v]=Vt([]),[f,b]=Vt(""),[h,y]=Vt(!1);kr(()=>{if(!r)return;l(!1),p(!1),m(0),v([]),b(""),y(!1);let C=r.details?.styling?.appearance?.displayDelay??0,R=globalThis.setTimeout(()=>{p(!0),V("viewed",r.id)},Math.max(0,C)*1e3);return()=>globalThis.clearTimeout(R)},[r]);let k=wr(()=>{let C=r?.details?.feedback_option||{};return Object.keys(C).sort((R,P)=>R.localeCompare(P)).map(R=>C[R]).filter(Boolean)},[r]);if(!r||!e||a||!g)return null;let S=r.details,T=S.styling||{},I=T.appearance||{},c=x>mo,w=Number(S.width??80),s=Math.max(660,Math.min(1080,w*10)),d=C=>{v(R=>R.includes(C)?R.filter(P=>P!==C):[...R,C])},E=async C=>{let R=C?.rating??x;if(R<1)return;y(!0);let P=S.id||r.id,B=(C?.options??u)[0]||"",_=C?.comments??f??"";V("csat captured",P,{starCount:R,selectedOption:B,additionalComments:_})},F=C=>{if(m(C),C>mo){v([]),b("");let R=S.id||r?.id;setTimeout(()=>{y(!0);try{V("csat captured",R,{starCount:C,selectedOption:"",additionalComments:""})}catch(P){console.warn("Error sending csat captured",P)}},1e3)}},A=()=>{if(c&&S.link){let C=r&&r.id||void 0;try{C&&V("clicked",C)}catch{}try{let R=String(S.link||"").trim();if(R&&!R.startsWith("http")&&gt(R)){l(!0);return}}catch(R){console.warn("revealCampaignFromLink error",R)}try{globalThis.open(S.link,"_blank")}catch{}}l(!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:ne("div",{style:{position:"relative",width:`min(${s}px, 96vw)`,maxWidth:"96vw",minWidth:"320px",minHeight:"220px",maxHeight:"55vh",overflow:"hidden",backgroundColor:I.backgroundColor||"#2f6ef5",borderRadius:`${I.borderRadius??12}px`,boxSizing:"border-box",paddingTop:"8px",paddingRight:Ct(I.padding?.right)||"12px",paddingBottom:"4px",paddingLeft:Ct(I.padding?.left)||"12px",marginTop:Ct(I.margin?.top),marginRight:Ct(I.margin?.right),marginBottom:Ct(I.margin?.bottom),marginLeft:Ct(I.margin?.left),pointerEvents:"auto",boxShadow:"0 14px 36px rgba(0, 0, 0, 0.25)",display:"flex",flexDirection:"column"},children:[Z("style",{children:`
81
+ `}),Mt("div",{ref:B=>{u.current=B,I(B)},className:"widget-scroll-container",style:T,onScroll:d,children:b?g.map((B,L)=>Mt("div",{style:l(L),children:Mt("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&&Mt("div",{style:l(0),children:Mt("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&&Mt("div",{style:{display:"flex",justifyContent:"center",gap:"6px",marginTop:"8px",width:"100%"},children:g.map((B,L)=>Mt("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?ns(p,M):p};import{useEffect as ki,useLayoutEffect as ss,useMemo as Ri,useRef as Xo,useState as Je,useCallback as as}from"react";K();import{Fragment as cs,jsx as ne,jsxs as Ti}from"react/jsx-runtime";var Ko=t=>(t||"").trim().toLowerCase(),ls=()=>{let t=ut("TTP"),e=F(V=>V.campaigns),o=F(V=>V.allCampaigns),i=F(V=>V.currentScreen),n=F(V=>V.isVisible),[r,s]=Je(0),[a,c]=Je(!1),[u,x]=Je(null),[m,g]=Je({width:0,height:0}),v=Xo(null),f=Xo(null),b=Ri(()=>{if(t)return t;let V=Ko(i),at=N=>N.find(Y=>{let Q=Y,tt=Q.campaign_type==="TTP"||Q.campaign_type==="TLTP",pt=!Ko(Q.screen)||Ko(Q.screen)===V,lt=!!(Q.trigger_event??Q.trigger),vt=Q.display_trigger!==!1&&!lt;return tt&&pt&&vt});return at(e)??at(o)},[t,e,o,i]),h=Ri(()=>b?.details?.tooltips&&Array.isArray(b.details.tooltips)?[...b.details.tooltips].sort((V,at)=>(V.order??0)-(at.order??0)):b?.details?.target||b?.details?.titleText?[{...b.details,_id:b.id}]:[],[b]),y=h[r];ki(()=>{},[b]);let w=Xo(new Set),I=as(()=>{if(!(!b||!y||a||!n))try{let V=y._id||y.id||void 0,at=String(b.id||"")+"::"+String(V||"");w.current.has(at)||(w.current.add(at),H("viewed",b.id,{tooltip_id:V}))}catch{}},[b,y,a,n]),z=Se(I);if(ki(()=>{if(!y?.target||a)return;x(null);let V=(Y=!1)=>{let Q=y.target;if(!Q)return null;let tt=document.getElementById(Q)||document.querySelector(`[data-id="${Q}"]`)||document.querySelector(`.${Q}`);return tt?(x(tt.getBoundingClientRect()),Y&&tt.scrollIntoView({behavior:"smooth",block:"center"}),tt):null};V(!0)||(f.current=new MutationObserver(()=>{V(!0)&&f.current?.disconnect()}),f.current.observe(document.body,{childList:!0,subtree:!0}));let N=()=>{let Y=V(!1);Y&&x(Y.getBoundingClientRect())};return window.addEventListener("resize",N),window.addEventListener("scroll",N,{passive:!0}),()=>{f.current?.disconnect(),window.removeEventListener("resize",N),window.removeEventListener("scroll",N)}},[y,a,r]),ss(()=>{if(v.current&&u){let{width:V,height:at}=v.current.getBoundingClientRect();g({width:V,height:at})}},[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,gt=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(gt+P,Math.min(j-m.width-P,$)));let X=()=>{let V=y.clickAction||"nextStep",at=y.link||y.url;try{let N=y._id||y.id||void 0;b?.id&&H("clicked",b.id,{tooltip_id:N})}catch{}if(V==="close"){c(!0),at&&window.open(at,"_blank");return}r<h.length-1?s(N=>N+1):(c(!0),at&&window.open(at,"_blank"))},J=()=>{y.enableBackdrop&&c(!0)};return Ti(cs,{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}),Ti("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})})]})]})},ds=ls;import{useEffect as ps,useState as us}from"react";K();import{Fragment as fs,jsx as It,jsxs as Zo}from"react/jsx-runtime";var gs=()=>{let t=ut("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 mt(b)}catch{return b}})(),r=F(f=>f.isVisible),[s,a]=us(!1);ps(()=>{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 It("div",{style:{textAlign:f.alignment||"left",width:"100%"},children:f.url&&It("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")&&yt(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 It("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:It("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")&&yt(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 Zo("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&&It("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&&It("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 Zo(fs,{children:[It("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)}}),Zo("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:[It("div",{style:{width:"40px",height:"5px",backgroundColor:"#E0E0E0",borderRadius:"2.5px",marginBottom:"16px",cursor:"pointer"},onClick:()=>a(!0)}),u.crossButton?.enabled&&It(Pt,{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}}),It("div",{style:{width:"100%",display:"flex",flexDirection:"column",gap:"12px"},children:m.map(v)})]})]})};import{useEffect as ms,useMemo as ys,useState as ie}from"react";K();import{Fragment as nn,jsx as Z,jsxs as ve}from"react/jsx-runtime";var Fi=5,tn=3;function zt(t){if(t!=null)return`${t}px`}function Ce(t){return{marginTop:zt(t?.top),marginRight:zt(t?.right),marginBottom:zt(t?.bottom),marginLeft:zt(t?.left)}}function rn(t){return ct(t)}function re(t){return t?{color:t.color,fontSize:t.fontSize,fontFamily:rn(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 en(t){return`${t?.topLeft??8}px ${t?.topRight??8}px ${t?.bottomRight??8}px ${t?.bottomLeft??8}px`}function hs(t){return t==="right"?"flex-end":t==="left"?"flex-start":"center"}function bs(t){let e=t.styling?.rating?.ratingType;return e==="number"||e==="emoji"||e==="star"?e:"star"}function xs(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 Ss(t){return Array.from({length:5},(e,o)=>o+1)}function on(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 Cs(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=on(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=on(s);if(a!=null)return a}}return 8}var vs=({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"})}),ws=({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=bs(t),w=y==="number"?Ss(t):[],I=y==="emoji"?xs(t):[],z=y==="number"?Cs(t):8,R=r?f.star?.high:f.star?.low;return ve(nn,{children:[Z("div",{style:Ce(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:Ce(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."})}),ve("div",{style:{marginTop:8,display:"flex",justifyContent:"center",gap:y==="number"?z:8,flexWrap:"wrap"},children:[y==="star"&&Array.from({length:Fi},(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 ${Fi}`,children:Z(vs,{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<=tn&&ve(nn,{children:[s.length>0&&Z("div",{style:{...Ce(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:en(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(on(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:en(h?.cornerRadius),fontFamily:rn(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"})})]})]})},ks=({details:t,isHighRating:e,onDone:o})=>{let i=t.styling||{},n=i.thankyouPage||{},r=i.rating||{},s=hs(n.doneButton?.cta?.container?.alignment);return ve(nn,{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:{...Ce(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:{...Ce(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:en(n.doneButton?.cta?.cornerRadius),fontFamily:rn(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")})})]})},Rs=()=>{let t=ut("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 mt(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);ms(()=>{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=ys(()=>{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>tn,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>tn){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")&&yt(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:ve("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:zt(R.padding?.right)||"12px",paddingBottom:"4px",paddingLeft:zt(R.padding?.left)||"12px",marginTop:zt(R.margin?.top),marginRight:zt(R.margin?.right),marginBottom:zt(R.margin?.bottom),marginLeft:zt(R.margin?.left),pointerEvents:"auto",boxShadow:"0 14px 36px rgba(0, 0, 0, 0.25)",display:"flex",flexDirection:"column"},children:[Z("style",{children:`
80
82
  .appstorys-csat-scroll {
81
83
  scrollbar-width: none; /* Firefox */
82
84
  -ms-overflow-style: none; /* IE/Edge */
@@ -86,7 +88,7 @@ var si=Object.defineProperty;var Et=(t,e)=>()=>(t&&(e=t(t=0)),e);var ai=(t,e)=>{
86
88
  height: 0;
87
89
  display: none; /* Chrome/Safari */
88
90
  }
89
- `}),T.crossButton?.enabled&&Z(kt,{config:T.crossButton,onPress:()=>l(!0),style:{top:T.crossButton?.margin?.top??10,right:T.crossButton?.margin?.right??10}}),Z("div",{className:"appstorys-csat-scroll",style:{flex:1,minHeight:0,overflowY:"auto",paddingBottom:4},children:h?Z(Pr,{details:S,isHighRating:c,onDone:A}):Z(Ar,{details:S,rating:x,selectedOptions:u,comments:f,isHighRating:c,feedbackOptions:k,onRate:F,onToggleOption:d,onCommentChange:b,onInlineSubmit:E,canSubmit:x>=1,appearance:I})})]})})},Lr=Er;import{useEffect as _n,useMemo as On,useState as $t}from"react";K();import{Fragment as Nn,jsx as ot,jsxs as re}from"react/jsx-runtime";function ke(t){if(t!=null)return`${t}px`}function So(t){if(t&&!(t.startsWith("http://")||t.startsWith("https://")))return t}function Qt(t){return t?{color:t.color,fontSize:t.fontSize,fontFamily:So(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 we(t){return{marginTop:ke(t?.top),marginRight:ke(t?.right),marginBottom:ke(t?.bottom),marginLeft:ke(t?.left)}}function Re(t){return`${t?.topLeft??12}px ${t?.topRight??12}px ${t?.bottomRight??t?.topRight??12}px ${t?.bottomLeft??t?.topLeft??12}px`}function jn(t){return t==="right"?"flex-end":t==="left"?"flex-start":"center"}function ie(t){return Math.max(0,Math.min(1,t))}function Dr(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}, ${ie(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}, ${ie(e)})`}return`rgba(0, 0, 0, ${ie(e)})`}function Wr(t){if(t==null)return .4;let e=Number(t);return Number.isFinite(e)?e>1?ie(e/100):ie(e):.4}function $n(t){return[...t.slides||[]].sort((o,i)=>(o.order??0)-(i.order??0))}function _r(t){let e=t?.options||{},o=Object.keys(e),i=n=>{let r=/(\d+)/.exec(n);if(!r)return;let a=Number(r[1]);return Number.isFinite(a)?a:void 0};return o.sort((n,r)=>{let a=i(n),l=i(r);return a!=null&&l!=null?a-l:a!=null?-1:l!=null?1:n.localeCompare(r)}),o.map(n=>e[n]).filter(n=>typeof n=="string"&&n.trim().length>0)}function $r(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 Mr(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 Mn(t){return Mr(t?.borderwidth)??1}var Or=({details:t,slide:e,appearance:o,selectedOption:i,comment:n,onSelectOption:r,onCommentChange:a,onSubmit:l,canSubmit:g})=>{let p=t.styling||{},x=p.options||{},m=p.cta,u=On(()=>_r(e),[e]),v=x.optionsSpacing??8,f=x.bulletSpacing??10,b=x.optionsHeight??44,h=jn(m?.container?.alignment);return re(Nn,{children:[ot("div",{style:we(p.title?.textStyle?.margin),children:ot("div",{style:{...Qt(p.title?.textStyle),color:p.title?.textStyle?.color||"#111827",fontSize:p.title?.textStyle?.fontSize||20,lineHeight:1.3,fontWeight:p.title?.textStyle?.fontDecoration?.includes("bold")?"bold":700},children:e.title||e.question||t.name||"Survey"})}),(e.subtitle||p.subtitle?.textStyle)&&ot("div",{style:we(p.subtitle?.textStyle?.margin),children:ot("div",{style:{...Qt(p.subtitle?.textStyle),color:p.subtitle?.textStyle?.color||"#6b7280",fontSize:p.subtitle?.textStyle?.fontSize||14,lineHeight:1.35},children:e.subtitle||""})}),u.length>0&&ot("div",{style:{marginTop:10,display:"flex",flexDirection:"column",gap:v},children:u.map((y,k)=>{let S=i===y,T=S?x.selectedOptions:x.nonSelectedOptions,I=Mn(T?.textStyle),c=$r(x.optionListStyle,k);return re("button",{onClick:()=>r(y),style:{width:"100%",boxSizing:"border-box",height:b,borderRadius:Re(x.cornerRadius),border:`${I}px solid ${T?.colors?.border||"#e5e7eb"}`,background:T?.colors?.background||"#ffffff",color:T?.colors?.text||"#111827",cursor:"pointer",display:"flex",alignItems:"center",gap:f,paddingLeft:14,paddingRight:14,textAlign:"left",...Qt(T?.textStyle)},"aria-pressed":S,children:[ot("span",{"aria-hidden":!0,style:{width:16,height:16,borderRadius:4,display:"inline-flex",alignItems:"center",justifyContent:"center",border:`1.5px solid ${T?.colors?.border||"#111827"}`,background:"#ffffff",flex:"0 0 auto",fontSize:11,fontWeight:700,color:T?.colors?.text||"#111827"},children:S?"\u2713":c||""}),ot("span",{style:{flex:1,minWidth:0},children:y})]},`${y}-${k}`)})}),e.additionalComment?.enabled&&ot("textarea",{value:n,onChange:y=>a(y.target.value),placeholder:e.additionalComment?.placeholder||"",style:{marginTop:10,width:"100%",boxSizing:"border-box",minHeight:72,resize:"none",overflowY:"auto",border:`${Mn(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",...Qt(x.additionalComments?.textStyle)}}),ot("div",{style:{position:"sticky",bottom:0,marginTop:12,paddingTop:10,paddingBottom:6,background:o?.backgroundColor||"#ffffff"},children:ot("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:ot("button",{onClick:l,disabled:!g,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:Re(m?.cornerRadius),fontFamily:So(m?.text?.fontFamily),fontSize:m?.text?.fontSize||14,fontWeight:m?.text?.fontDecoration?.includes("bold")?"bold":600,cursor:g?"pointer":"not-allowed",opacity:g?1:.6,padding:"0 16px"},children:e.submitButtonText||"Submit"})})})]})},jr=({details:t,onDone:e})=>{let i=(t.styling||{}).thankyouPage||{},n=i.cta,r=jn(n?.container?.alignment);return re(Nn,{children:[t.thankYouImage&&ot("div",{style:{display:"flex",justifyContent:"center",marginTop:8},children:ot("img",{src:t.thankYouImage,alt:"thank you",style:{width:i.imageStyle?.width||80,height:i.imageStyle?.height||80,objectFit:"cover",borderRadius:10}})}),ot("div",{style:{...we(i.title?.textStyle?.margin)},children:ot("div",{style:{...Qt(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"})}),ot("div",{style:{...we(i.subtitle?.textStyle?.margin)},children:ot("div",{style:{...Qt(i.subtitle?.textStyle),color:i.subtitle?.textStyle?.color||"#6b7280",fontSize:i.subtitle?.textStyle?.fontSize||14,lineHeight:1.35},children:t.thankYouText||""})}),(t.thankYouButtonText||n)&&ot("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:ot("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:Re(n?.cornerRadius),fontFamily:So(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"})})]})},Nr=()=>{let t=lt("SUR"),e=z(B=>B.isVisible),o=z(B=>B.campaigns),i=z(B=>B.allCampaigns),n=z(B=>B.currentScreen),r=t??(()=>{let B=(n||"").trim().toLowerCase(),_=[...o||[],...i||[]].find($=>{if(!$||$.campaign_type!=="SUR")return!1;let D=!!($.trigger_event??$.trigger);if(!($.display_trigger!==!1&&!D))return!1;let W=($.screen||"").trim().toLowerCase();return!W||W===B});if(_)try{return ut(_)}catch{return _}})(),[a,l]=$t(!1),[g,p]=$t(!1),[x,m]=$t(0),[u,v]=$t(null),[f,b]=$t(""),[h,y]=$t({}),[k,S]=$t(!1);_n(()=>{if(!r)return;l(!1),p(!1),m(0),v(null),b(""),y({}),S(!1);let B=r.details?.styling?.appearance?.displayDelay??0,_=globalThis.setTimeout(()=>{p(!0);let $=r.details?.id,D=$n(r.details),O=D.length>0?D[0].id:void 0;V("viewed",r.id,{survey_id:$,slide_id:O})},Math.max(0,B)*1e3);return()=>globalThis.clearTimeout(_)},[r]);let T=On(()=>r?$n(r.details):[],[r]),I=T[x];if(_n(()=>{if(!I)return;let B=h[I.id];v(B?.option??null),b(B?.comment??"")},[I?.id]),!r||!e||a||!g)return null;let c=r.details,w=c.styling||{},s=w.appearance||{},d=s.backdropColor||"#000000",E=Wr(s.backdropOpacity),F=B=>{v(_=>_===B?null:B)},A=async(B,_)=>{let $=T.map(M=>({slide_id:M.id,order:M.order,title:M.title,question:M.question,selected_options:B[M.id]?.option,comment:B[M.id]?.comment})),D=r.id,O=[];for(let M of T){let N=B[M.id]?.option;if(!N)continue;let U=Object.entries(M.options||{}).find(([,rt])=>String(rt)===String(N));U&&O.push(U[0])}let W=$.map(M=>M.comment).filter(Boolean).join(" || ")||"",Y=c.id||D;V("survey captured",Y,{survey_id:c.id,slide_id:_,selected_options:O,otherText:W}),w.content?.isThankyouPage!==!1?S(!0):l(!0)},C=async()=>{if(!I||!u)return;let B={...h,[I.id]:{option:u,comment:f}};y(B);try{let O=r.id,W=null;if(u&&I&&I.options){let dt=Object.entries(I.options).find(([,M])=>String(M)===String(u));dt&&(W=dt[0])}let Y=c.id||O;V("survey captured",Y,{survey_id:c.id,slide_id:I.id,selected_options:W?[W]:[],otherText:f||""})}catch(O){console.warn("Error sending per-slide survey captured",O)}if((I.logic||[]).find(O=>(O.selectOption||[]).includes(u))?.redirectTo==="thank-you"){await A(B,I.id);return}if(x>=T.length-1){await A(B,I.id);return}m(O=>Math.min(O+1,T.length-1))},R=()=>{let B=c.thankYouButtonConfig;if(B?.enabled&&B.redirectUrl){try{let _=String(B.redirectUrl||"").trim();if(_&&!_.startsWith("http")&&gt(_)){l(!0);return}}catch(_){console.warn("revealCampaignFromLink error",_)}try{globalThis.open(B.redirectUrl,"_blank")}catch{}}l(!0)},P=async()=>{try{let B=r?.id,_=c?.id,$=I?.id;await V("SurveyDismissed",B,{survey_id:_,slide_id:$})}catch(B){console.warn("Error sending SurveyDismissed",B)}finally{l(!0)}};return I?re("div",{style:{position:"fixed",inset:0,zIndex:999999,display:"flex",justifyContent:"flex-end",alignItems:"flex-end",padding:12,pointerEvents:"none"},children:[ot("div",{"aria-hidden":!0,style:{position:"absolute",inset:0,background:Dr(d,E)}}),re("div",{style:{position:"relative",width:"min(420px, 92vw)",maxWidth:"92vw",minWidth:"320px",maxHeight:"80vh",overflow:"hidden",backgroundColor:s.backgroundColor||"#ffffff",borderRadius:Re(s.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:[ot("style",{children:`
91
+ `}),z.crossButton?.enabled&&Z(Pt,{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(ks,{details:I,isHighRating:d,onDone:L}):Z(ws,{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})})]})})},Ts=Rs;import{useEffect as Ii,useMemo as Ai,useState as Vt}from"react";K();import{Fragment as Pi,jsx as it,jsxs as ke}from"react/jsx-runtime";function Xe(t){if(t!=null)return`${t}px`}function sn(t){return ct(t)}function se(t){return t?{color:t.color,fontSize:t.fontSize,fontFamily:sn(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 Ke(t){return{marginTop:Xe(t?.top),marginRight:Xe(t?.right),marginBottom:Xe(t?.bottom),marginLeft:Xe(t?.left)}}function Ze(t){return`${t?.topLeft??12}px ${t?.topRight??12}px ${t?.bottomRight??t?.topRight??12}px ${t?.bottomLeft??t?.topLeft??12}px`}function Ei(t){return t==="right"?"flex-end":t==="left"?"flex-start":"center"}function we(t){return Math.max(0,Math.min(1,t))}function Fs(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}, ${we(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}, ${we(e)})`}return`rgba(0, 0, 0, ${we(e)})`}function Is(t){if(t==null)return .4;let e=Number(t);return Number.isFinite(e)?e>1?we(e/100):we(e):.4}function zi(t){return[...t.slides||[]].sort((o,i)=>(o.order??0)-(i.order??0))}function zs(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 Bs(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 As(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 Bi(t){return As(t?.borderwidth)??1}var Es=({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=Ai(()=>zs(e),[e]),v=x.optionsSpacing??8,f=x.bulletSpacing??10,b=x.optionsHeight??44,h=Ei(m?.container?.alignment);return ke(Pi,{children:[it("div",{style:Ke(u.title?.textStyle?.margin),children:it("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)&&it("div",{style:Ke(u.subtitle?.textStyle?.margin),children:it("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&&it("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=Bi(z?.textStyle),d=Bs(x.optionListStyle,w);return ke("button",{onClick:()=>r(y),style:{width:"100%",boxSizing:"border-box",height:b,borderRadius:Ze(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:[it("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||""}),it("span",{style:{flex:1,minWidth:0},children:y})]},`${y}-${w}`)})}),e.additionalComment?.enabled&&it("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:`${Bi(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)}}),it("div",{style:{position:"sticky",bottom:0,marginTop:12,paddingTop:10,paddingBottom:6,background:o?.backgroundColor||"#ffffff"},children:it("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:it("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:Ze(m?.cornerRadius),fontFamily:sn(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"})})})]})},Ps=({details:t,onDone:e})=>{let i=(t.styling||{}).thankyouPage||{},n=i.cta,r=Ei(n?.container?.alignment);return ke(Pi,{children:[t.thankYouImage&&it("div",{style:{display:"flex",justifyContent:"center",marginTop:8},children:it("img",{src:t.thankYouImage,alt:"thank you",style:{width:i.imageStyle?.width||80,height:i.imageStyle?.height||80,objectFit:"cover",borderRadius:10}})}),it("div",{style:{...Ke(i.title?.textStyle?.margin)},children:it("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"})}),it("div",{style:{...Ke(i.subtitle?.textStyle?.margin)},children:it("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)&&it("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:it("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:Ze(n?.cornerRadius),fontFamily:sn(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"})})]})},Ls=()=>{let t=ut("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 mt($)}catch{return $}})(),[s,a]=Vt(!1),[c,u]=Vt(!1),[x,m]=Vt(0),[g,v]=Vt(null),[f,b]=Vt(""),[h,y]=Vt({}),[w,I]=Vt(!1);Ii(()=>{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=zi(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=Ai(()=>r?zi(r.details):[],[r]),R=z[x];if(Ii(()=>{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=Is(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 gt=Object.entries(R.options).find(([,j])=>String(j)===String(g));gt&&(O=gt[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")&&yt($)){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?ke("div",{style:{position:"fixed",inset:0,zIndex:999999,display:"flex",justifyContent:"flex-end",alignItems:"flex-end",padding:12,pointerEvents:"none"},children:[it("div",{"aria-hidden":!0,style:{position:"absolute",inset:0,background:Fs(p,M)}}),ke("div",{style:{position:"relative",width:"min(420px, 92vw)",maxWidth:"92vw",minWidth:"320px",maxHeight:"80vh",overflow:"hidden",backgroundColor:l.backgroundColor||"#ffffff",borderRadius:Ze(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:[it("style",{children:`
90
92
  .appstorys-survey-scroll {
91
93
  scrollbar-width: none; /* Firefox */
92
94
  -ms-overflow-style: none; /* IE/Edge */
@@ -96,5 +98,5 @@ var si=Object.defineProperty;var Et=(t,e)=>()=>(t&&(e=t(t=0)),e);var ai=(t,e)=>{
96
98
  height: 0;
97
99
  display: none; /* Chrome/Safari */
98
100
  }
99
- `}),w.crossButton?.enabled&&ot(kt,{config:w.crossButton,onPress:P,style:{top:w.crossButton?.margin?.top??10,right:w.crossButton?.margin?.right??10}}),ot("div",{className:"appstorys-survey-scroll",style:{flex:1,minHeight:0,overflowY:"auto",paddingRight:2},children:k?ot(jr,{details:c,onDone:R}):ot(Or,{details:c,slide:I,appearance:s,selectedOption:u,comment:f,onSelectOption:F,onCommentChange:b,onSubmit:C,canSubmit:u!=null})})]})]}):null},qr=Nr;var Co=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=z.getState();if(r.appId===o&&r.accountId===i&&r.userId===n)return}this.state="initializing";try{let r,a;if(!n||n.trim()==="")r=await Oo(),a=!0;else{let m=await Je();m&&m!==n&&console.log("AppStorys: Found previous anonymous user, will reconcile after verification."),r=n,a=!1}if(!await Rt(i,o,r)){this.state="error";return}if(!a){let m=await Je();m&&m!==r&&(await Ve(m,r),await jo())}try{let m=await it(),u=e.baseUrl||"https://users.appstorys.co";fetch(`${u}/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=z.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:g,version:p}=await He(i),x=z.getState();x.setAppId(o),x.setAccountId(i),x.setUserId(r),x.setIsAnonymousUser(a),x.setBaseUrl(e.baseUrl),x.setTrackingUrl(e.trackingUrl),x.saveAllCampaigns(g),x.setCampaignVersion(p);try{z.getState().screenCaptureEnabled&&(await Promise.resolve().then(()=>(Gn(),Qn))).mountScreenCaptureButton()}catch(m){console.warn("Failed to mount screen capture button",m)}$o.setup(),Ge.setup(),this.state="initialized"}catch(r){this.state="error",console.error("AppStorys initialization failed:",r)}}}async trackScreen(e){return await this.ensureInitialized(),je(e)}async trackEvent(e,o,i){return await this.ensureInitialized(),V(e,o,i)}async setUserProperties(e){return await this.ensureInitialized(),Ne(e)}handleLink(e){if(e){if(typeof e=="string"){try{if(!e.startsWith("http")&&gt(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(gt(e.value))return}catch{}this.navigateToScreen?.(e.value)}}}get visibility(){return z.getState().isVisible}set visibility(e){Ge.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 ye(e)}},Pc=new Co;export{Pc as AppStorys,Si as Banner,Cr as BottomSheet,Lr as Csat,Bi as Floater,ki as Pip,wo as SdkState,dr as Story,qr as Survey,hr as Tooltip,gr as Widget,ye as personalizeText};
101
+ `}),T.crossButton?.enabled&&it(Pt,{config:T.crossButton,onPress:_,style:{top:T.crossButton?.margin?.top??10,right:T.crossButton?.margin?.right??10}}),it("div",{className:"appstorys-survey-scroll",style:{flex:1,minHeight:0,overflowY:"auto",paddingRight:2},children:w?it(Ps,{details:d,onDone:S}):it(Es,{details:d,slide:R,appearance:l,selectedOption:g,comment:f,onSelectOption:B,onCommentChange:b,onSubmit:C,canSubmit:g!=null})})]})]}):null},Ds=Ls;var an=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 An(),s=!0;else{let m=await Eo();m&&m!==n&&console.log("AppStorys: Found previous anonymous user, will reconcile after verification."),r=n,s=!1}if(!await At(i,o,r)){this.state="error";return}if(!s){let m=await Eo();m&&m!==r&&(await Ne(m,r),await Ao())}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 Fo(i);try{kn(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(()=>(Oi(),Mi))).mountScreenCaptureButton()}catch(m){console.warn("Failed to mount screen capture button",m)}zn.setup(),Bo.setup(),this.state="initialized"}catch(r){this.state="error",console.error("AppStorys initialization failed:",r)}}}async reconcileUser(e,o,i,n){try{if(!await At(n,i,o)){console.error("AppStorys: Failed to verify identified user account during reconciliation.");return}if(!await Ne(e,o)){console.error("AppStorys: Failed to reconcile anonymous and identified users.");return}await Ao();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(),wo(e)}async trackEvent(e,o,i){return await this.ensureInitialized(),H(e,o,i)}async setUserProperties(e){return await this.ensureInitialized(),ko(e)}handleLink(e){if(e){if(typeof e=="string"){try{if(!e.startsWith("http")&&yt(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(yt(e.value))return}catch{}this.navigateToScreen?.(e.value)}}}get visibility(){return F.getState().isVisible}set visibility(e){Bo.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 je(e)}},Op=new an;export{Op as AppStorys,sr as Banner,gs as BottomSheet,Ts as Csat,br as Floater,pr as Pip,un as SdkState,Zr as Story,Ds as Survey,ds as Tooltip,is as Widget,je as personalizeText};
100
102
  //# sourceMappingURL=index.mjs.map