import"./rolldown-runtime-DIIn1E2Q.js";import{A as e,D as t,F as n,I as r,It as i,O as a,Q as o,R as s,Rt as c,S as l,Ut as u,_t as d,d as f,et as p,ft as m,j as h,k as g,kt as _,nt as v,pt as y,v as b,vt as x,w as S}from"./vendor-vue-core-DO0afONr.js";import"./vendor-other-CiPV8GBG.js";import"./types-DPJvCrdo.js";import{I as C,nt as w}from"./vendor-vueuse-DUMtJaL2.js";import{n as T}from"./vendor-i18n-JbyM4Qz7.js";import"./vendor-reka-ui-B53kLmAc.js";import{t as E}from"./Button-Ca3rDegY.js";var D=`Comfy.FeatureUsage`;function useFeatureUsageTracker(e){let n=C(D,{}),r=t(()=>n.value[e]),i=t(()=>r.value?.useCount??0);function trackUsage(){let t=Date.now(),r=n.value[e];n.value[e]={useCount:(r?.useCount??0)+1,firstUsed:r?.firstUsed??t,lastUsed:t}}function reset(){delete n.value[e]}return{usage:r,useCount:i,trackUsage,reset}}var O=`Comfy.SurveyState`,k=5760*60*1e3,A=3,j=5e3;function useSurveyEligibility(e){let n=C(O,{optedOut:!1,seenSurveys:{}}),r=t(()=>i(e)),{useCount:a}=useFeatureUsageTracker(r.value.featureId),o=t(()=>r.value.triggerThreshold??A),s=t(()=>r.value.delayMs??j),c=t(()=>r.value.enabled??!0),l=t(()=>!1),u=t(()=>a.value>=o.value),d=t(()=>!!n.value.seenSurveys[r.value.featureId]),f=t(()=>{let e=Object.values(n.value.seenSurveys);if(e.length===0)return!1;let t=Math.max(...e);return Date.now()-t<k}),p=t(()=>n.value.optedOut),m=t(()=>!(!c.value||!l.value||!u.value||d.value||f.value||p.value));function markSurveyShown(){n.value.seenSurveys[r.value.featureId]=Date.now()}function optOut(){n.value.optedOut=!0}function resetState(){n.value={optedOut:!1,seenSurveys:{}}}return{isEligible:m,delayMs:s,markSurveyShown,optOut,resetState}}var M={key:0,"data-testid":`nightly-survey-popover`,class:`fixed right-4 bottom-4 z-10000 w-80 rounded-lg border border-border-subtle bg-base-background p-4 shadow-lg`},N={class:`mb-3 flex items-start justify-between`},P={class:`text-sm font-medium text-text-primary`},F=[`aria-label`],I={class:`mb-4 text-sm text-text-secondary`},L={key:0,class:`text-danger mb-4 text-sm`},R=[`data-tf-widget`],z={class:`mt-4 flex flex-col gap-2`},B={class:`flex gap-2`},V=`https://embed.typeform.com/next/embed.js`,H=s({__name:`NightlySurveyPopover`,props:{config:{}},emits:[`shown`,`dismissed`,`optedOut`],setup(i,{emit:s}){let l=s,{t:v}=T(),{isEligible:C,delayMs:D,markSurveyShown:O,optOut:k}=useSurveyEligibility(()=>i.config),A=_(!1),j=_(!1),H=m(`typeformRef`),U=null,W=t(()=>/^[A-Za-z0-9]+$/.test(i.config.typeformId)),G=t(()=>W.value?i.config.typeformId:``);y(C,e=>{if(!e){U&&=(clearTimeout(U),null);return}A.value||U||(U=setTimeout(()=>{U=null,A.value=!0,l(`shown`)},D.value))},{immediate:!0}),o(()=>{U&&clearTimeout(U)}),w(H,()=>{if(document.querySelector(`script[src="${V}"]`))return;let e=document.createElement(`script`);e.src=V,e.async=!0,e.onerror=()=>{j.value=!0},document.head.appendChild(e)});function handleAccept(){O()}function handleDismiss(){A.value=!1,l(`dismissed`)}function handleOptOut(){k(),A.value=!1,l(`optedOut`)}return(t,i)=>(p(),g(S,{to:`body`},[r(f,{"enter-active-class":`transition duration-300 ease-out`,"enter-from-class":`translate-x-full opacity-0`,"enter-to-class":`translate-x-0 opacity-100`,"leave-active-class":`transition duration-300 ease-in`,"leave-from-class":`translate-x-0 opacity-100`,"leave-to-class":`translate-x-full opacity-0`},{default:d(()=>[A.value?(p(),h(`div`,M,[a(`div`,N,[a(`h3`,P,u(c(v)(`nightlySurvey.title`)),1),a(`button`,{class:`text-text-muted hover:text-text-primary`,"aria-label":c(v)(`g.close`),onClick:handleDismiss},i[0]||=[a(`i`,{class:`icon-[lucide--x] size-4`},null,-1)],8,F)]),a(`p`,I,u(c(v)(`nightlySurvey.description`)),1),j.value?(p(),h(`div`,L,u(c(v)(`nightlySurvey.loadError`)),1)):e(``,!0),x(a(`div`,{ref_key:`typeformRef`,ref:H,"data-tf-auto-resize":``,"data-tf-widget":G.value,class:`min-h-[300px]`},null,8,R),[[b,A.value&&!j.value&&W.value]]),a(`div`,z,[r(E,{variant:`primary`,class:`w-full`,onClick:handleAccept},{default:d(()=>[n(u(c(v)(`nightlySurvey.accept`)),1)]),_:1}),a(`div`,B,[r(E,{variant:`textonly`,class:`flex-1 text-xs`,onClick:handleDismiss},{default:d(()=>[n(u(c(v)(`nightlySurvey.notNow`)),1)]),_:1}),r(E,{variant:`muted-textonly`,class:`flex-1 text-xs`,onClick:handleOptOut},{default:d(()=>[n(u(c(v)(`nightlySurvey.dontAskAgain`)),1)]),_:1})])])])):e(``,!0)]),_:1})]))}}),U={};function getEnabledSurveys(){return Object.values(U).filter(e=>e.enabled!==!1)}var W=s({__name:`NightlySurveyController`,setup(e){let n=t(()=>getEnabledSurveys());return(e,t)=>(p(!0),h(l,null,v(n.value,e=>(p(),g(H,{key:e.featureId,config:e},null,8,[`config`]))),128))}});export{W as default};
//# sourceMappingURL=NightlySurveyController-DDb0txKq.js.map