PageSourceSearch

https://vibefunnel.ai/_nuxt/DSEjCknO.js

js vibefunnel.ai collected 2026-10-05 14:24:49 UTC 27,514 bytes, 3 lines download raw bytes

1import{_ as Ze}from"./DRtl49bf.js";import{N as b,aB as c,O as n,F as H,aH as ne,bJ as se,X as R,bM as h,Y as x,b7 as T,bR as D,M as V,bS as we,bT as et,J as I,w as ke,p as $e,bQ as tt,bX as rt,bw as g,L as W,bG as F,c0 as at,x as st,bZ as nt,b$ as it,bo as lt,bU as ot}from"./B4cWliYT.js";import{_ as ut}from"./D8bDSF2U.js";import{_ as dt}from"./DAuIhjjw.js";import{_ as qe}from"./Yh2J5Z2z.js";import{_ as ct}from"./Bso_jZST.js";import{u as mt,_ as pt}from"./DLwiG8XI.js";import{e as ft,a as gt}from"./CQ8GTUdS.js";import{r as yt}from"./Ck06SwWa.js";import"./C5gJt0-_.js";import"./CpPPBq3E.js";import"./x_rD_Ya3.js";import"./CI4q9Fal.js";import"./Cnag3G7B.js";import"./5SJH8lb3.js";import"./BhUrJ5t2.js";import"./DPAOmWTQ.js";import"./BJYnd4Iu.js";import"./BHbZIYNW.js";import"./ChCm7C6E.js";import"./baNLPNoI.js";import"./B3HmkSgu.js";import"./CaljZj8-.js";import"./C35H2EpQ.js";import"./BkvXbpTH.js";import"./DkFLgCZp.js";import"./DcJO_1Cc.js";import"./DGq9ti5X.js";import"./mFnqpxBy.js";import"./BDrRTSOG.js";import"./DbnyybKb.js";import"./znSy5XoC.js";import"./4m9t5G0n.js";import"./CvX38mz3.js";import"./jmMlW2Ei.js";import"./5pf0p05D.js";import"./DS1b7IF8.js";import"./Cqw_Nhyh.js";import"./CqPum14u.js";import"./_f6Oe1dT.js";import"./C-YF3ml4.js";import"./BQKh1PBF.js";import"./AHpN0A9I.js";import"./CqAX3Onb.js";const vt={class:"space-y-8"},bt={class:"grid gap-4 md:grid-cols-2"},ht=["onClick"],xt={class:"space-y-2"},wt={class:"text-lg font-semibold text-gray-900 dark:text-gray-100"},kt={class:"text-sm text-gray-600 dark:text-gray-300"},$t={class:"space-y-1 text-xs text-gray-500 dark:text-gray-400"},Ct={class:"flex justify-end"},_t={__name:"SelectEmailType",props:{typeOptions:{type:Array,required:!0},selectedType:{type:String,required:!0}},emits:["update:selected-type","next"],setup(t,{emit:N}){const p=N;function y(_){p("update:selected-type",_)}return(_,i)=>(c(),b("section",vt,[i[3]||(i[3]=n("header",{class:"space-y-2"},[n("h2",{class:"text-2xl font-semibold text-gray-900 dark:text-gray-100"}," What kind of email are we drafting? "),n("p",{class:"text-sm leading-6 text-gray-600 dark:text-gray-300"}," Choose the storyline that best fits the send. You can still remix copy and layout when we hit the builder. ")],-1)),n("div",bt,[(c(!0),b(H,null,ne(t.typeOptions,u=>(c(),b("button",{key:u.value,type:"button",class:se(["flex h-full flex-col justify-between gap-3 rounded-2xl border p-5 text-left transition-colors",t.selectedType===u.value?"border-primary-500 bg-primary-50 dark:border-primary-400/70 dark:bg-primary-500/10":"border-gray-200 hover:border-primary-300 dark:border-gray-700 dark:hover:border-primary-500/70"]),onClick:j=>y(u.value)},[n("div",xt,[n("div",{class:se(["inline-flex items-center gap-2 text-xs font-semibold uppercase tracking-[0.18em]",t.selectedType===u.value?"text-primary-500 dark:text-primary-300":"text-gray-400 dark:text-gray-500"])},[n("span",{class:se(["inline-flex h-2 w-2 rounded-full",t.selectedType===u.value?"bg-primary-500":"bg-gray-300 dark:bg-gray-600"])},null,2),R(" "+h(u.category),1)],2),n("h3",wt,h(u.label),1),n("p",kt,h(u.description),1)]),n("ul",$t,[(c(!0),b(H,null,ne(u.examples,(j,l)=>(c(),b("li",{key:l,class:"flex items-center gap-2"},[i[1]||(i[1]=n("span",{class:"inline-flex h-1.5 w-1.5 rounded-full bg-current"},null,-1)),R(" "+h(j),1)]))),128))])],10,ht))),128))]),n("div",Ct,[x(D,{size:"md",onClick:i[0]||(i[0]=u=>p("next"))},{default:T(()=>i[2]||(i[2]=[R(" Continue ")])),_:1})])]))}},qt={class:"space-y-8"},Pt={class:"rounded-2xl border border-gray-200 bg-white p-6 shadow-sm dark:border-gray-700 dark:bg-gray-800"},Et={class:"mt-6 space-y-6"},At={class:"space-y-4"},It={key:0,class:"mt-4 rounded-lg border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-700 dark:border-red-800/50 dark:bg-red-900/20 dark:text-red-300"},Tt={class:"mt-8 flex flex-col gap-3 md:flex-row md:items-center md:justify-between"},Nt={__name:"EmailDetailsStep",props:{name:{type:String,default:""},sequenceCount:{type:[Number,String],default:1},prompt:{type:String,required:!0},promptError:{type:String,default:""}},emits:["update:name","update:sequence-count","update:prompt","back","next"],setup(t,{emit:N}){const p=N;function y(_){const i=Number.parseInt(_,10);return Number.isNaN(i)||i<1?1:i}return(_,i)=>(c(),b("section",qt,[n("div",Pt,[i[8]||(i[8]=n("div",{class:"space-y-2"},[n("h2",{class:"text-xl font-semibold text-gray-900 dark:text-white"},"Dial in the brief"),n("p",{class:"text-sm text-gray-600 dark:text-gray-300"}," Share the essentials so the builder knows what to create. ")],-1)),n("div",Et,[n("div",At,[x(we,{"model-value":t.name,label:"Internal name",placeholder:"Weekly community pulse",hint:"We’ll use this label across the workspace and dashboard.","class-name":"text-base","onUpdate:modelValue":i[0]||(i[0]=u=>p("update:name",u))},null,8,["model-value"]),x(we,{"model-value":t.sequenceCount,label:"Number of emails in sequence",type:"number",min:"1",step:"1","class-name":"text-base","onUpdate:modelValue":i[1]||(i[1]=u=>p("update:sequence-count",y(u)))},null,8,["model-value"])]),n("div",null,[x(et,{"model-value":t.prompt,rows:"10",label:"What do we cover?",placeholder:"Outline the audience, offer, objections, CTA, and any links or proof to reference.",hint:"Mention offering details, exclusive discounts, duration, highlights, benefits.","class-name":"text-base","onUpdate:modelValue":i[2]||(i[2]=u=>p("update:prompt",u))},{"hint-right":T(()=>[x(dt,{inline:""})]),_:1},8,["model-value"]),i[5]||(i[5]=n("p",{class:"mt-2 text-xs text-gray-500 dark:text-gray-400 sm:hidden"}," Mention proof points, CTAs, and any assets you want referenced. ",-1))])]),t.promptError?(c(),b("div",It,h(t.promptError),1)):V("",!0),n("div",Tt,[x(D,{variant:"ghost",size:"md",class:"w-full md:w-auto border border-gray-200 dark:border-white/20",onClick:i[3]||(i[3]=u=>p("back"))},{default:T(()=>i[6]||(i[6]=[R(" Back ")])),_:1}),x(D,{size:"md",class:"w-full md:w-auto",onClick:i[4]||(i[4]=u=>p("next"))},{default:T(()=>i[7]||(i[7]=[R(" Generate concepts ")])),_:1})])])]))}},jt={class:"space-y-8"},St={class:"space-y-2"},Mt={class:"flex items-center justify-between gap-3"},Rt={key:0,class:"rounded-full bg-gray-100 px-3 py-1 text-xs font-semibold text-gray-700 dark:bg-gray-800 dark:text-gray-200"},zt={key:0,class:"grid gap-4 md:grid-cols-3"},Lt={key:1,class:"grid gap-4 md:grid-cols-3"},Bt=["tabindex","onClick","onKeyup"],Ut={key:0,class:"absolute -top-2 -right-2 roun
1ded-full bg-primary-500 px-3 py-1 text-xs font-medium text-white shadow-sm"},Ft={class:"relative flex flex-col gap-3 p-4 text-left"},Vt={class:"space-y-1"},Dt={class:"text-xs font-semibold uppercase tracking-[0.18em] text-gray-500 dark:text-gray-400"},Ot={class:"text-xs text-gray-500 dark:text-gray-400"},Wt={class:"text-xs text-gray-600 dark:text-gray-300"},Gt={class:"overflow-hidden rounded-xl border border-gray-200 bg-white shadow-sm dark:border-gray-700 dark:bg-gray-800"},Kt={key:0,class:"rounded-md bg-red-50 px-3 py-2 text-xs text-red-700 dark:bg-red-900/20 dark:text-red-300"},Yt={key:2,class:"rounded-lg border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-700 dark:border-red-800/50 dark:bg-red-900/20 dark:text-red-300"},Ht={class:"flex flex-col gap-3 md:flex-row md:items-center md:justify-between"},Jt={__name:"EmailProposalsStep",props:{isGenerating:{type:Boolean,default:!1},proposals:{type:Array,default:()=>[]},selectedProposalIndex:{type:Number,default:0},proposalError:{type:String,default:""},name:{type:String,default:""},subject:{type:String,default:""},previewText:{type:String,default:""},sequenceIndex:{type:Number,default:0},sequenceCount:{type:Number,default:1}},emits:["select","back","next","retry"],setup(t,{emit:N}){const p=t,y=N,_=I(()=>{if(p.isGenerating||!p.proposals.length||!p.proposals.some(a=>!(a!=null&&a.isLoading)&&!(a!=null&&a.hasError)))return!0;const d=p.proposals[p.selectedProposalIndex];return d?!!(d.isLoading||d.hasError):!0});function i(l){return{...l,name:p.name||(l==null?void 0:l.name),subject:p.subject||(l==null?void 0:l.subject),previewText:p.previewText||(l==null?void 0:l.previewText),isAiManaged:!0}}function u(l){const d=p.proposals[l];!d||d.isLoading||d.hasError||y("select",l)}function j(l,d){const a="border-2 border-primary-500 bg-primary-50 dark:border-primary-400/70 dark:bg-primary-500/10",f="border border-gray-200 hover:border-primary-300 dark:border-gray-700 dark:hover:border-primary-500/70";if(!l)return`${f} cursor-pointer`;const P=p.selectedProposalIndex===d&&!l.isLoading&&!l.hasError?a:f,L=l.isLoading?"cursor-wait opacity-60":"cursor-pointer",S=l.hasError?"border-red-300 dark:border-red-500/70":"";return`${P} ${L} ${S}`.trim()}return(l,d)=>(c(),b("section",jt,[n("header",St,[n("div",Mt,[d[2]||(d[2]=n("div",null,[n("h2",{class:"text-2xl font-semibold text-gray-900 dark:text-gray-100"}," Choose the angle that feels right "),n("p",{class:"text-sm leading-6 text-gray-600 dark:text-gray-300"}," We generated a few narrative passes from your brief. Pick one to continue the sequence. ")],-1)),t.sequenceCount>1?(c(),b("div",Rt," Email "+h(t.sequenceIndex+1)+" of "+h(t.sequenceCount),1)):V("",!0)])]),t.isGenerating&&!t.proposals.length?(c(),b("div",zt,[(c(),b(H,null,ne(3,a=>n("div",{key:`skeleton-${a}`,class:"h-72 rounded-2xl border border-dashed border-gray-300 bg-white/40 dark:border-gray-700 dark:bg-gray-800/40"})),64))])):(c(),b("div",Lt,[(c(!0),b(H,null,ne(t.proposals,(a,f)=>(c(),b("div",{key:a._id||f,role:"button",tabindex:a.isLoading||a.hasError?-1:0,class:se(["relative flex h-full flex-col rounded-2xl transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-primary-500",j(a,f)]),onClick:w=>u(f),onKeyup:[ke($e(w=>u(f),["prevent"]),["enter"]),ke($e(w=>u(f),["prevent"]),["space"])]},[t.selectedProposalIndex===f&&!a.isLoading&&!a.hasError?(c(),b("div",Ut," Selected ")):V("",!0),n("div",Ft,[n("div",Vt,[n("p",Dt,h(a.angle),1),n("p",Ot,h(a.angleDescription),1),n("p",Wt,h(a.description),1)]),n("div",Gt,[x(qe,{variant:i(a),"allow-renaming":!1,"allow-editing":!1,"allow-ai-managed":!1,"allow-load-template":!1,"show-minimize-button":!0,"show-save-button":!1,"builder-context":"email","apply-builder-transforms":!1,"is-loading":!!a.isLoading,"has-error":!!a.hasError,"error-message":a.errorMessage||"",onRetry:w=>y("retry",f)},null,8,["variant","is-loading","has-error","error-message","onRetry"])]),a.hasError?(c(),b("p",Kt," We couldn’t generate this concept. Try again. ")):V("",!0)])],42,Bt))),128))])),t.proposalError?(c(),b("div",Yt,h(t.proposalError),1)):V("",!0),n("div",Ht,[x(D,{variant:"ghost",size:"md",class:"w-full md:w-auto border border-gray-200 dark:border-white/20",onClick:d[0]||(d[0]=a=>y("back"))},{default:T(()=>d[3]||(d[3]=[R(" Back ")])),_:1}),x(D,{size:"md",class:"w-full md:w-auto",disabled:_.value,onClick:d[1]||(d[1]=a=>y("next"))},{default:T(()=>d[4]||(d[4]=[R(" Continue to builder ")])),_:1},8,["disabled"])])]))}};function ie(t){return{_id:t._id||"",id:t.id||"",html:t.html||"",name:t.name||"",description:t.description||"",angle:t.angle||"",angleDescription:t.angleDescription||"",subject:t.subject||"",previewText:t.previewText||"",summary:t.summary||"",isLoading:!1,hasError:!1,errorMessage:""}}function Ce(t){return t?{...ie(t),sequenceIndex:typeof t.sequenceIndex=="number"?t.sequenceIndex:0}:null}function _e(t){return t?{proposals:Array.isArray(t.proposals)?t.proposals.map(ie):[],selectedIndex:typeof t.selectedIndex=="number"?t.selectedIndex:0}:null}function Xt(t){function N(){return{currentStep:t.currentStep.value,selectedType:t.selectedType.value,emailName:t.emailName.value,emailSubject:t.emailSubject.value,emailPreviewText:t.emailPreviewText.value,prompt:t.prompt.value,sequenceCount:t.sequenceCount.value,currentEmailIndex:t.currentEmailIndex.value,proposals:Array.isArray(t.proposals.value)?t.proposals.value.map(ie):[],selectedProposalIndex:t.selectedProposalIndex.value,sequenceSelections:Array.isArray(t.sequenceSelections.value)?t.sequenceSelections.value.map(Ce):[],proposalCache:Array.isArray(t.proposalCache.value)?t.proposalCache.value.map(_e):[],sequencePrompts:Array.isArray(t.sequencePrompts.value)?[...t.sequencePrompts.value]:[],sequenceSummary:t.sequenceSummary.value,timestamp:Date.now()}}
1function p(a){if(!(!a||typeof a!="object"))try{typeof a.currentStep=="number"&&(t.currentStep.value=a.currentStep),typeof a.selectedType=="string"&&(t.selectedType.value=a.selectedType),typeof a.emailName=="string"&&(t.emailName.value=a.emailName),typeof a.emailSubject=="string"&&(t.emailSubject.value=a.emailSubject),typeof a.emailPreviewText=="string"&&(t.emailPreviewText.value=a.emailPreviewText),typeof a.prompt=="string"&&(t.prompt.value=a.prompt),typeof a.sequenceCount=="number"&&(t.sequenceCount.value=a.sequenceCount),typeof a.currentEmailIndex=="number"&&(t.currentEmailIndex.value=a.currentEmailIndex),Array.isArray(a.proposals)&&a.proposals.length>0&&(t.proposals.value=a.proposals.map(ie)),typeof a.selectedProposalIndex=="number"&&(t.selectedProposalIndex.value=a.selectedProposalIndex),Array.isArray(a.sequenceSelections)&&a.sequenceSelections.length>0&&(t.sequenceSelections.value=a.sequenceSelections.map(Ce)),Array.isArray(a.proposalCache)&&a.proposalCache.length>0&&(t.proposalCache.value=a.proposalCache.map(_e)),Array.isArray(a.sequencePrompts)&&(t.sequencePrompts.value=a.sequencePrompts),typeof a.sequenceSummary=="string"&&(t.sequenceSummary.value=a.sequenceSummary)}catch(f){console.error("Failed to restore email builder state:",f)}}const{snapshot:y,isVisible:_,message:i,details:u,restore:j,discard:l,clearAll:d}=mt({buildKey:()=>{const a=t.organizationId.value;return a?`builder:email:${a}`:null},getSnapshot:N,applySnapshot:p,watchSources:[t.currentStep,t.selectedType,t.emailName,t.emailSubject,t.emailPreviewText,t.prompt,t.sequenceCount,t.currentEmailIndex,[t.proposals,{deep:!0}],t.selectedProposalIndex,[t.sequenceSelections,{deep:!0}],[t.proposalCache,{deep:!0}],[t.sequencePrompts,{deep:!0}],t.sequenceSummary],buildMessage:a=>{if(a!=null&&a.emailName){const f=a.sequenceCount>1?` (${a.sequenceCount} emails)`:"";return`Email name: ${a.emailName}${f}`}return"We can restore your last set of edits."},buildDetails:a=>{var P;if(!a)return"";const f=a.currentStep??0,w=(P=t.steps[f])==null?void 0:P.id;return w==="proposals"&&typeof a.currentEmailIndex=="number"?`Last step worked on: proposals (email ${a.currentEmailIndex+1} of ${a.sequenceCount||1})`:w?`Last step worked on: ${w}`:""}});return{snapshot:y,shouldPromptRecovery:_,recoveryMessage:i,recoveryDetails:u,restoreSnapshot:j,discardSnapshot:l,clearRecovery:d}}const Qt={class:"min-h-screen"},Zt={class:"mx-auto max-w-6xl px-4 pb-12"},er={class:"space-y-5"},tr={class:"flex items-start gap-4"},rr={class:"flex h-12 w-12 items-center justify-center rounded-full bg-amber-100 dark:bg-amber-900/30"},ar={class:"space-y-2"},sr={class:"text-sm text-gray-600 dark:text-gray-300"},nr={class:"flex items-center justify-between rounded-lg border border-gray-200 bg-gray-50 px-4 py-3 text-sm dark:border-gray-700 dark:bg-gray-800/60"},ir={class:"font-semibold text-gray-900 dark:text-white"},lr={key:0,class:"text-xs text-red-600 dark:text-red-400"},or={class:"flex items-center justify-end gap-3 pt-2"},ur={key:0,class:"fixed inset-0 z-50 bg-black/60"},ve=3,ea={__name:"create",setup(t){const N=nt(),p=it(),y=ot(),{$api:_}=tt(),i=rt(),u=I(()=>N.params.organizationId),j=[{id:"type"},{id:"details"},{id:"proposals"},{id:"review"}],l=g(0),d=ft,a=gt,f=g(d[0].value),w=g(""),P=g(""),L=g(""),S=g(""),J=g(1),C=g(0),q=g(""),X=g(""),v=g([]),E=g(0),Pe=I(()=>v.value[E.value]||null),Q=g(!1),Z=g(!1),A=g(""),z=g([]),B=g([]),le=g(!1),be=g(0),oe=g(null),G=g([]),K=g(!1),ue=g(!1),Ee=I(()=>d.find(e=>e.value===f.value)||d[0]),$=I(()=>{const e=Number.parseInt(J.value,10);return Number.isNaN(e)||e<1?1:e}),Ae=I(()=>{var r;const e=Number((r=i.activePlan)==null?void 0:r.landingPagesLimit);return Number.isFinite(e)&&e>0?e:0}),Ie=I(()=>{var r;const e=Number((r=i.currentUsage)==null?void 0:r.landingPagesUsed);return Number.isFinite(e)&&e>0?e:0}),ee=I(()=>Math.max(Ae.value-Ie.value,0)),O=I(()=>$.value),de=I(()=>O.value<=ee.value),{shouldPromptRecovery:ce,recoveryMessage:Te,recoveryDetails:Ne,restoreSnapshot:je,discardSnapshot:Se,clearRecovery:Me}=Xt({organizationId:u,currentStep:l,selectedType:f,emailName:w,emailSubject:P,emailPreviewText:L,prompt:S,sequenceCount:J,currentEmailIndex:C,proposals:v,selectedProposalIndex:E,sequenceSelections:z,proposalCache:B,sequencePrompts:G,sequenceSummary:q,steps:j});function me(e){e&&(typeof e.subject=="string"&&e.subject.trim()&&(P.value=e.subject.trim()),typeof e.previewText=="string"&&e.previewText.trim()&&(L.value=e.previewText.trim()),typeof e.summary=="string"&&e.summary.trim()&&(q.value=e.summary.trim()))}function Re(e){f.value=e}function ze(){C.value=0,q.value="",l.value=1}
1function pe(){if(l.value===2&&C.value>0){const e=C.value-1;re(e);return}if(l.value===0){p.push({path:`/organization/${u.value}/emails`});return}X.value="",l.value===2&&(A.value=""),l.value=Math.max(l.value-1,0)}function Le(){const e=Math.max($.value-1,0);re(e)}async function Be(){const e=S.value.trim();if(!e){X.value="Add a short brief so the builder knows what to include.";return}X.value="",S.value=e,await he()&&(K.value=!0)}async function he(){if(ue.value)return!1;const e=!i.activePlan;ue.value=!0;try{if(e&&await i.fetchPlan(),!await i.fetchCurrentUsage())throw new Error("Missing usage data");return!0}catch(r){return console.error("Failed to refresh usage data:",r),y.add({title:"Unable to check credits",description:"Refresh the page or try again.",color:"red"}),!1}finally{ue.value=!1}}async function Ue(){if(await he()){if(!de.value){y.add({title:"Not enough credits",description:`You need ${O.value} but only have ${ee.value} available.`,color:"red"});return}K.value=!1,q.value="",z.value=Array.from({length:$.value},()=>null),G.value=Array.from({length:$.value},()=>""),B.value=Array.from({length:$.value},()=>null),re(0)}}function Fe(e){z.value[C.value]={...e,sequenceIndex:C.value}}function Ve(){const e=Pe.value;if(!e){A.value="Select a concept before continuing.";return}if(e.isLoading){A.value="Wait for the concept to finish generating before continuing.";return}if(e.hasError){A.value="Retry the concept generation before moving on.";return}if(me(e),Fe(e),!(C.value>=$.value-1)){const m=C.value+1;re(m);return}l.value=3}async function De(){Q.value=!0,A.value="",v.value=Array.from({length:ve},(e,r)=>te(r)),E.value=0;try{const e=Array.from({length:ve},(m,s)=>xe(s).then(()=>{fe()}));if(await Promise.all(e),fe()===-1)throw new Error("No proposals generated")}catch(e){console.error("Failed to generate email proposals:",e),A.value=ge(e,"Unable to generate options. Please try again."),v.value.some(m=>!m.hasError&&!m.isLoading&&m.html)||(v.value=[],E.value=0)}finally{Q.value=!1,ye()}}async function xe(e){const r=a[e%a.length];if(!r)throw new Error(`Missing email proposal angle config for index ${e}`);const m=v.value[e]?{...v.value[e]}:te(e);v.value[e]={...m,isLoading:!0,hasError:!1,errorMessage:""};const s=[S.value.trim(),(G.value[C.value]||"").trim()].filter(Boolean).join(`
2`),k=r.name?`Angle: ${r.name}${r.description?` — ${r.description}`:""}${Array.isArray(r.examples)&&r.examples.length?` (Examples: ${r.examples.join(", ")})`:""}`:"",M={type:f.value,prompt:[s,k,r==null?void 0:r.promptAddon].filter(Boolean).join(`
3`),n:e+1,sequenceContext:Ke()};try{const{data:o}=await _.post("/ai-processing/email",M),ae=Array.isArray(o==null?void 0:o.proposals)?o.proposals:[],U=ae[ae.length-1]||ae[0]||o,Y=(o==null?void 0:o.summary)||(U==null?void 0:U.summary);if(!U)throw new Error("Email generation returned no data");typeof Y=="string"&&Y.trim()&&(q.value=Y.trim()),v.value[e]=Ge(U,e,m)}catch(o){console.error(`Failed to generate email proposal ${e+1}:`,o),v.value[e]={...m,isLoading:!1,hasError:!0,errorMessage:ge(o,"Failed to generate this concept. Try again.")}}}function Oe(e){const r=v.value[e];!r||r.isLoading||r.hasError||(E.value=e,A.value="",me(r),typeof r.summary=="string"&&r.summary.trim()&&(q.value=r.summary.trim()),ye())}async function We(e){e<0||e>=ve||(A.value="",await xe(e),fe(),ye())}function fe(){const e=v.value.findIndex(r=>!r.isLoading&&!r.hasError&&r.html);return e!==-1&&(E.value=e,me(v.value[e]),typeof v.value[e].summary=="string"&&v.value[e].summary.trim()&&(q.value=v.value[e].summary.trim())),e}function te(e){const r=a[e%a.length]||{angle:"",description:""},m=`email-proposal-${Date.now()}-${e}`;return{_id:m,id:m,html:"",angle:r.angle,angleDescription:r.description,name:w.value?`${w.value} concept ${e+1}`:`Concept ${e+1}`,subject:P.value,previewText:L.value,summary:q.value,description:"",isLoading:!0,hasError:!1,errorMessage:""}}function Ge(e,r,m=te(r)){const s=m||te(r),k=(e==null?void 0:e._id)||(e==null?void 0:e.id)||s.id;return{...s,...e,_id:k,id:k,html:(e==null?void 0:e.html)||"",name:(e==null?void 0:e.name)||s.name,subject:(e==null?void 0:e.subject)||P.value,previewText:(e==null?void 0:e.previewText)||L.value,summary:(e==null?void 0:e.summary)||s.summary||"",description:(e==null?void 0:e.description)??s.description,isLoading:!1,hasError:!1,errorMessage:""}}function Ke(e=C.value){var s;const r=[],m=Math.max(0,Math.min(e,$.value-1));for(let k=0;k<m;k+=1){const M=(s=z.value[k])==null?void 0:s.summary;
3typeof M=="string"&&M.trim()&&r.push({summary:M.trim()})}return!r.length&&q.value.trim()&&r.push({summary:q.value.trim()}),r}function re(e){var M;const r=Math.max(0,Math.min(e,$.value-1));for(C.value=r;G.value.length<$.value;)G.value.push("");const m=r>0&&((M=z.value[r-1])==null?void 0:M.summary)||"";q.value=m;const s=z.value[r]||null;P.value=(s==null?void 0:s.subject)||"",L.value=(s==null?void 0:s.previewText)||"",A.value="",v.value=[],E.value=0,l.value=2;const k=Array.isArray(B.value)?B.value[r]:null;if(k&&Array.isArray(k.proposals)&&k.proposals.length){v.value=k.proposals,E.value=Math.min(k.selectedIndex||0,Math.max(k.proposals.length-1,0));return}De()}async function Ye(){if(Z.value)return;if(!u.value){y.add({title:"Missing organization",description:"Choose an organization before saving your email.",color:"red"});return}const e=$.value,r=z.value;if(r.filter(Boolean).length!==e){y.add({title:"Select all emails",description:`Choose concepts for all ${e} emails before saving.`,color:"yellow"});return}const s=r.map((o,ae)=>{const U=((o==null?void 0:o.subject)||"").trim(),Y=((o==null?void 0:o.previewText)||"").trim(),Xe=typeof(o==null?void 0:o.html)=="string"?o.html:"",Qe=((o==null?void 0:o.summary)||"").trim();return{subject:U,previewText:Y,summary:Qe,html:Xe}});if(s.some(o=>!o.subject)){y.add({title:"Subject required",description:"Each email needs a subject line before saving.",color:"yellow"});return}if(s.some(o=>!o.html||!o.html.trim())){y.add({title:"HTML required",description:"Each email needs generated content before saving.",color:"yellow"});return}Z.value=!0;try{const o={type:f.value,prompt:S.value.trim(),status:"draft",name:w.value||`Email sequence (${e})`,emails:s};await _.post(`/organizations/${u.value}/emails`,JSON.parse(JSON.stringify(o))),y.add({title:"Sequence saved",description:`Saved ${s.length} email${s.length===1?"":"s"} in your sequence.`,color:"green"}),Me(),p.push({path:`/organization/${u.value}/emails`})}catch(o){console.error("Failed to save email:",o),y.add({title:"Unable to save email",description:ge(o,"Fix any validation issues and try again."),color:"red"}),await i.fetchCurrentUsage()}finally{Z.value=!1}}function He(e){const r=(e==null?void 0:e.selection)||e;if(!r||!r.html){y.add({title:"Preview unavailable",description:"Generate or select a concept with content to preview.",color:"yellow"});return}oe.value={...r,maximized:!0,isAiManaged:!1},be.value+=1,le.value=!0}function Je(){le.value=!1}function ge(e,r){var m;if((m=e==null?void 0:e.response)!=null&&m.data){const s=e.response.data;if(typeof s=="string")return s;if(Array.isArray(s==null?void 0:s.message))return s.message.join(", ");if(typeof(s==null?void 0:s.message)=="string")return s.message}return e!=null&&e.message?e.message:r}function ye(){Array.isArray(B.value)||(B.value=[]);const e=v.value.map(r=>({...r}));B.value[C.value]={proposals:e,selectedIndex:E.value}}return(e,r)=>{const m=Ze;return c(),b(H,null,[n("div",Qt,[x(ut,{steps:j,"current-step":l.value,title:"Create Email",onBack:pe},null,8,["current-step"]),n("div",Zt,[l.value===0?(c(),W(_t,{key:0,"type-options":F(d),"selected-type":f.value,"onUpdate:selectedType":Re,onNext:ze},null,8,["type-options","selected-type"])):l.value===1?(c(),W(Nt,{key:1,name:w.value,"onUpdate:name":r[0]||(r[0]=s=>w.value=s),"sequence-count":J.value,"onUpdate:sequenceCount":r[1]||(r[1]=s=>J.value=s),prompt:S.value,"onUpdate:prompt":r[2]||(r[2]=s=>S.value=s),"prompt-error":X.value,onBack:pe,onNext:Be},null,8,["name","sequence-count","prompt","prompt-error"])):l.value===2?(c(),W(Jt,{key:2,proposals:v.value,"selected-proposal-index":E.value,"is-generating":Q.value,"proposal-error":A.value,name:w.value,"sequence-index":C.value,"sequence-count":$.value,onSelect:Oe,onBack:pe,onRetry:We,onNext:Ve},null,8,["proposals","selected-proposal-index","is-generating","proposal-error","name","sequence-index","sequence-count"])):(c(),W(ct,{key:3,selections:z.value,"type-meta":Ee.value,"sequence-count":$.value,"is-saving":Z.value,"is-generating-proposals":Q.value,"allow-delete":!1,"allow-add":!1,"allow-drag":!1,onBack:Le,onPreview:He,onFinish:Ye}
3,null,8,["selections","type-meta","sequence-count","is-saving","is-generating-proposals"]))]),x(m,null,{default:T(()=>[x(pt,{modelValue:F(ce),"onUpdate:modelValue":r[3]||(r[3]=s=>lt(ce)?ce.value=s:null),title:"Restore unsaved progress?",message:F(Te),details:F(Ne),"primary-label":"Restore progress","secondary-label":"Discard progress",onConfirm:F(je),onCancel:F(Se)},null,8,["modelValue","message","details","onConfirm","onCancel"])]),_:1})]),x(at,{modelValue:K.value,"onUpdate:modelValue":r[5]||(r[5]=s=>K.value=s),size:"md",title:"Confirm credit usage","show-close-button":!0},{default:T(()=>[n("div",er,[n("div",tr,[n("div",rr,[x(F(yt),{class:"h-7 w-7 text-amber-500","aria-hidden":"true"})]),n("div",ar,[r[6]||(r[6]=n("p",{class:"text-base font-semibold text-gray-900 dark:text-white"}," You’re about to use credits ",-1)),n("p",sr," Generating "+h($.value)+" page"+h($.value===1?"":"s")+" will consume "+h(O.value)+" credit"+h(O.value===1?"":"s")+" from your plan. ",1)])]),n("div",nr,[r[7]||(r[7]=n("span",{class:"text-gray-600 dark:text-gray-300"},"Credits available",-1)),n("span",ir,h(ee.value),1)]),de.value?V("",!0):(c(),b("p",lr," You need "+h(O.value)+" credit"+h(O.value===1?"":"s")+" but only have "+h(ee.value)+" available. Reduce the number of pages or upgrade your plan. ",1)),n("div",or,[x(D,{variant:"ghost",size:"sm",class:"border border-gray-200 dark:border-gray-700",onClick:r[4]||(r[4]=s=>K.value=!1)},{default:T(()=>r[8]||(r[8]=[R(" Cancel ")])),_:1}),x(D,{size:"sm",disabled:!de.value,onClick:Ue},{default:T(()=>r[9]||(r[9]=[R(" Continue ")])),_:1},8,["disabled"])])])]),_:1},8,["modelValue"]),(c(),W(st,{to:"body"},[le.value&&oe.value?(c(),b("div",ur,[(c(),W(qe,{key:be.value,class:"h-full",variant:oe.value,variants:[],"allow-renaming":!1,"allow-editing":!1,"allow-load-template":!1,"allow-ai-managed":!1,"show-minimize-button":!0,"show-save-button":!1,"is-loading":!1,"has-error":!1,"error-message":"","builder-context":"email","apply-builder-transforms":!1,"collapsed-height-class":"h-full",onMinimize:Je},null,8,["variant"]))])):V("",!0)]))],64)}}};export{ea as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.