1import{j as e}from"./vendor-markdown-BcWX1uEp.js";import{r as h}from"./vendor-react-CvxdUEaJ.js";import{k as j,u as z,X as B,e as H}from"./index-BOKTLVbi.js";import{logAnalyticsEvent as o}from"./firebaseAnalytics-BF-sHBVI.js";import"./firebase-init-BzZZWMhi.js";import"./vendor-firebase-app-BoD0q7fW.js";import"./vendor-firebase-analytics-CVSn4EwJ.js";const J=[["path",{d:"M3.85 8.62a4 4 0 0 1 4.78-4.77 4 4 0 0 1 6.74 0 4 4 0 0 1 4.78 4.78 4 4 0 0 1 0 6.74 4 4 0 0 1-4.77 4.78 4 4 0 0 1-6.75 0 4 4 0 0 1-4.78-4.77 4 4 0 0 1 0-6.76Z",key:"3c2336"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"M9 9h.01",key:"1q5me6"}],["path",{d:"M15 15h.01",key:"lqbp3k"}]],V=j("badge-percent",J);const X=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"10",x2:"10",y1:"15",y2:"9",key:"c1nkhi"}],["line",{x1:"14",x2:"14",y1:"15",y2:"9",key:"h65svq"}]],Z=j("circle-pause",X);const G=[["path",{d:"M2 9.5a5.5 5.5 0 0 1 9.591-3.676.56.56 0 0 0 .818 0A5.49 5.49 0 0 1 22 9.5c0 2.29-1.5 4-3 5.5l-5.492 5.313a2 2 0 0 1-3 .019L5 15c-1.5-1.5-3-3.2-3-5.5",key:"mvr1a0"}]],K=j("heart",G),c={MONTHLY_DISCOUNT_PERCENT:40,ANNUAL_DISCOUNT_PERCENT:20,PAUSE_DAYS:30,DISCOUNT_COOLDOWN_DAYS:365,PAUSE_COOLDOWN_DAYS:365},Q=[{id:"finished_project",label:"I finished my book / project"},{id:"too_expensive",label:"It's too expensive"},{id:"not_using",label:"I'm not using it enough"},{id:"missing_features",label:"It's missing features I need"},{id:"technical_issues",label:"I ran into technical problems"},{id:"found_alternative",label:"I found an alternative"},{id:"other",label:"Other"}];function ee({billingCycle:x,reason:m}){return m==="found_alternative"?"none":x==="annual"?m==="too_expensive"?"discount":"none":m==="too_expensive"?"discount":"pause"}function te(x){return x==="annual"?c.ANNUAL_DISCOUNT_PERCENT:c.MONTHLY_DISCOUNT_PERCENT}const se=1440*60*1e3,ue=({isOpen:x,onClose:m,onContinueToPortal:A})=>{const{currentUser:C,userStats:f,refreshUserStats:v}=z(),[i,l]=h.useState("intent"),[s,k]=h.useState(null),[r,y]=h.useState(!1),[b,p]=h.useState(null),[g,_]=h.useState(null);if(!x||!C||!f)return null;const d=f.billingCycle==="annual"?"annual":"monthly",u=te(d),S=(t,n)=>typeof t=="number"&&Date.now()-t<n*se,U=d==="monthly"&&!S(f.saveOfferPauseRedeemedAt,c.PAUSE_COOLDOWN_DAYS),T=!S(f.saveOfferDiscountRedeemedAt,c.DISCOUNT_COOLDOWN_DAYS),a={billing_cycle:d},N=async t=>{const n=await C.getIdToken(),E=await fetch("/api/cancel-flow",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify(t)}),P=await E.json();if(!E.ok)throw new Error(P?.error||"Something went wrong");return P},Y=t=>{let n=ee({billingCycle:d,reason:t});n==="pause"&&!U&&(n="none"),n==="discount"&&!T&&(n="none"),o("save_offer_shown",{...a,offer_type:n,cancel_reason:t}),l(n==="pause"?"offer_pause":n==="discount"?"offer_discount":"confirm_cancel")},I=()=>{o("cancel_flow_manage_billing",a),A()},R=()=>{o("cancel_flow_opened",a),l("reason")},$=async()=>{s&&(o("cancel_flow_reason_selected",{...a,cancel_reason:s}),N({action:"record_reason",reason:s}).catch(()=>{}),Y(s))},L=async()=>{y(!0),p(null);try{const t=await N({action:"pause",reason:s});o("save_offer_accepted",{...a,offer_type:"pause",cancel_reason:s}),_({type:"pause",resumesAt:t.resumesAt}),l("saved"),v?.()}catch(t){p(t.message)}finally{y(!1)}},M=async()=>{y(!0),p(null);try{const t=await N({action:"discount",reason:s});o("save_offer_accepted",{...a,offer_type:"discount",cancel_reason:s,discount_percent:t.discountPercent}),_({type:"discount",discountPercent:t.discountPercent}),l("saved"),v?.()}catch(t){p(t.message)}finally{y(!1)}},F=()=>{o("save_offer_declined",{...a,offer_type:"pause",cancel_reason:s}),l("confirm_cancel")},W=()=>{o("save_offer_declined",{...a,offer_type:"discount",cancel_reason:s}),l("confirm_cancel")},D=t=>{o("cancel_flow_direct_cancel",{...a,offer_type:t,cancel_reason:s}),l("confirm_cancel")},q=()=>{o("cancel_flow_portal_redirect",{...a,cancel_reason:s}),A()},w=()=>{l("intent"),k(null),p(null),_(null),m()},O=f.pagesProcessed||0;return e.jsx("div",{className:"fixed inset-0 bg-gray-900/60 backdrop-blur-sm flex items-center justify-center z-50 p-4",children:e.jsxs("div",{className:"bg-white rounded-2xl max-w-md w-full max-h-[90vh] overflow-y-auto relative shadow-2xl border border-[#
1E8DED1]",children:[e.jsx("button",{onClick:w,"aria-label":"Close",className:"absolute top-4 right-4 w-8 h-8 flex items-center justify-center rounded-full bg-[#F5F1ED] text-gray-500 hover:text-[#B85C4A] hover:bg-[#E8DED1] transition-colors z-10",children:e.jsx(B,{className:"w-4 h-4"})}),e.jsxs("div",{className:"p-6 sm:p-8",children:[i==="intent"&&e.jsxs("div",{className:"space-y-4",children:[e.jsx("h2",{className:"text-xl font-bold text-gray-900",children:"Manage your subscription"}),e.jsx("p",{className:"text-sm text-gray-600",children:"What would you like to do?"}),e.jsxs("button",{onClick:I,className:"flex w-full items-center gap-3 rounded-xl border border-orange-200 p-4 text-left transition-colors hover:bg-orange-50",children:[e.jsx(H,{className:"h-5 w-5 shrink-0 text-[#B85C4A]"}),e.jsxs("span",{children:[e.jsx("span",{className:"block text-sm font-semibold text-gray-900",children:"Manage billing"}),e.jsx("span",{className:"block text-xs text-gray-600",children:"Update payment method, view invoices"})]})]}),e.jsxs("button",{onClick:R,className:"flex w-full items-center gap-3 rounded-xl border border-gray-200 p-4 text-left transition-colors hover:bg-gray-50",children:[e.jsx(B,{className:"h-5 w-5 shrink-0 text-gray-500"}),e.jsxs("span",{children:[e.jsx("span",{className:"block text-sm font-semibold text-gray-900",children:"Cancel my subscription"}),e.jsx("span",{className:"block text-xs text-gray-600",children:"We'll ask one quick question first"})]})]})]}),i==="reason"&&e.jsxs("div",{className:"space-y-4",children:[e.jsx("h2",{className:"text-xl font-bold text-gray-900",children:"Before you go â what's the main reason?"}),e.jsx("div",{className:"space-y-2",role:"radiogroup","aria-label":"Cancel reason",children:Q.map(t=>e.jsxs("label",{className:`flex cursor-pointer items-center gap-3 rounded-xl border p-3 text-sm transition-colors ${s===t.id?"border-[#B85C4A] bg-orange-50":"border-gray-200 hover:bg-gray-50"}`,children:[e.jsx("input",{type:"radio",name:"cancel-reason",value:t.id,checked:s===t.id,onChange:()=>k(t.id),className:"accent-[#B85C4A]"}),e.jsx("span",{className:"text-gray-800",children:t.label})]},t.id))}),e.jsx("button",{onClick:$,disabled:!s,className:"w-full rounded-lg bg-[#B85C4A] px-4 py-2.5 text-sm font-semibold text-white transition-colors hover:bg-[#A04A3A] disabled:cursor-not-allowed disabled:opacity-50",children:"Continue"})]}),i==="offer_pause"&&e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex h-12 w-12 items-center justify-center rounded-xl bg-gradient-to-br from-[#B85C4A] to-[#D97757]",children:e.jsx(Z,{className:"h-6 w-6 text-white"})}),e.jsxs("h2",{className:"text-xl font-bold text-gray-900",children:["Pause instead â free for ",c.PAUSE_DAYS," days"]}),e.jsxs("p",{className:"text-sm text-gray-600",children:["Take a break without losing anything. Billing stops for ",c.PAUSE_DAYS," days after your current period ends, your account and settings stay put, and billing resumes automatically. Perfect if your next book is a few weeks away."]}),b&&e.jsx("p",{role:"alert",className:"text-sm font-medium text-red-600",children:b}),e.jsx("button",{onClick:L,disabled:r,className:"w-full rounded-lg bg-[#B85C4A] px-4 py-2.5 text-sm font-semibold text-white transition-colors hover:bg-[#A04A3A] disabled:opacity-50",children:r?"Pausingâ¦":"Pause my subscription"}),e.jsx("button",{onClick:F,disabled:r,className:"w-full rounded-lg border border-gray-200 px-4 py-2.5 text-sm font-medium text-gray-600 transition-colors hover:bg-gray-50",children:"No thanks"}),e.jsx("button",{onClick:()=>D("pause"),disabled:r,className:"w-full rounded-lg border border-[#B85C4A] px-4 py-2.5 text-sm font-semibold text-[#B85C4A] transition-colors hover:bg-orange-50 disabled:opacity-50",children:"Cancel my subscription"})]}),i==="offer_discount"&&e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex h-12 w-12 items-center justify-center rounded-xl bg-gradient-to-br from-[#B85C4A] to-[#D97757]",children:e.jsx(V,{className:"h-6 w-6 text-white"})}),e.jsx("h2",{className:"text-xl font-bold text-gray-900",children:d==="annual"?`${u}% off your next renewal`:`${u}% off your next month`}),e.jsx("p",{className:"text-sm text-gray-600",children:d==="annual"?`Stay with us and your next annual renewal is ${u}% off. One-time offer â applied automatically.`:`Stay with us and your next month is ${u}% off. One-time offer â applied automatically.`}),b&&e.jsx("p",{role:"alert",className:"text-sm font-medium text-red-600",children:b}),e.jsx("button",{onClick:M,disabled:r,className:"w-full rounded-lg bg-[#B85C4A] px-4 py-2.5 text-sm font-semibold text-white transition-colors hover:bg-[#A04A3A] disabled:opacity-50",children:r?"Applyingâ¦":`Apply ${u}% off`}),e.jsx("button",{onClick:W,disabled:r,className:"w-full rounded-lg border border-gray-200 px-4 py-2.5 text-sm font-medium text-gray-600 transition-colors hover:bg-gray-50",children:"No thanks, continue to cancel"}),e.jsx("button",{onClick:()=>D("discount"),disabled:r,className:"w-full rounded-lg border border-[#B85C4A] px-4 py-2.5 text-sm font-semibold text-[#B85C4A] transition-colors hover:bg-orange-50 disabled:opacity-50",children:"Cancel my subscription"})]}),i==="saved"&&e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex h-12 w-12 items-center justify-center rounded-xl bg-emerald-100",children:e.jsx(K,{className:"h-6 w-6 text-emerald-600"})}),e.jsx("h2",{className:"text-xl font-bold text-gray-900",children:g?.type==="pause"?"Your subscription is paused":"Discount applied"}),e.jsx("p",{className:"text-sm text-gray-600",children:g?.type==="pause"?`You won't be billed for ${c.PAUSE_DAYS} days after your current period ends. Billing resumes automatically â nothing else to do.`:`Your ${g?.discountPercent||u}% discount will show on your next invoice automatically.`}),e.jsx("button",{onClick:w,className:"w-full rounded-lg bg-[#B85C4A] px-4 py-2.5 text-sm font-semibold text-white transition-colors hover:bg-[#A04A3A]",children:"Done"})]}),i==="confirm_cancel"&&e.jsxs("div",{className:"space-y-4",children:[e.jsx("h2",{className:"text-xl font-bold text-gray-900",children:"Sorry to see you go"}),O>0&&e.jsxs("p",{className:"text-sm text-gray-600",children:["You've extracted ",e.jsx("span",{className:"font-semibold text-gray-800",children:O})," pages with TextMuncher â your account and history stay saved if you ever come back."]}),e.jsx("p",{className:"text-sm text-gray-600",children:"You can finish canceling in our secure billing portal. Your access continues until the end of the peri
1od you've paid for."}),e.jsx("button",{onClick:q,className:"w-full rounded-lg bg-[#B85C4A] px-4 py-2.5 text-sm font-semibold text-white transition-colors hover:bg-[#A04A3A]",children:"Continue to cancel"}),e.jsx("button",{onClick:w,className:"w-full rounded-lg border border-gray-200 px-4 py-2.5 text-sm font-medium text-gray-600 transition-colors hover:bg-gray-50",children:"Never mind, keep my subscription"})]})]})]})})};export{ue 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.