1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/jspdf.es.min-DzBf_Ezd.js","assets/index-Bch6FxxE.js","assets/index-BX2dXEWU.css"])))=>i.map(i=>d[i]); 2import{c as Fe,_ as Os,r as v,j as e,C as F,v as R,w as I,R as Q,k as B,o as k,B as E,W as Us,a as qs,u as zs,b as Yt,P as Ht,d as ue,e as Gt,Y as Ks,f as Ys,Z as Hs,$ as Gs,a0 as Qs,a1 as Vs,D as $s,g as Js,a2 as Ws,i as U,a3 as Zs,m as X,a4 as ae,a5 as T,p as Xs,S as fe,T as Ct,A as _t,x as Pt,y as St,z as Et,E as At,F as Mt,G as kt,H as en,n as we,X as tn,l as Qt}from"./index-Bch6FxxE.js";import{R as sn,A as Vt,c as $t,C as nn,a as an,N as rn,S as Jt,j as on,u as O}from"./Navigation-O3HKhA9y.js";import{u as W}from"./use-notify-toast-DQfOhbOl.js";import{R as ln}from"./ReferralLink-Dt-D2Q5I.js";import{b as cn,S as We,a as dn}from"./star-DVIv_dEp.js";import{I as xe,E as Oe}from"./image-Cl8TN05p.js";import{F as Wt,M as Zt,S as it,f as Ee,T as Ae,a as un,i as Ue}from"./plan-limits-NktqlouV.js";import{T as qe,P as Tt,C as ze}from"./theme-options-DxQtfrug.js";import{B as Y}from"./badge-C_oFfiDp.js";import{I as G}from"./input-tl3JpQyF.js";import{L as q}from"./label-Dtq4aW7i.js";import{S as H}from"./separator-CbI132sE.js";import{S as Me}from"./switch-DKzrYa9l.js";import{D as ot,a as lt,b as ct,c as dt,d as ut,e as mt}from"./dialog-BSSLDoDa.js";import{C as mn,a as hn,b as fn,G as xn}from"./collapsible-Dp9TopnS.js";import{S as pn,C as gn,Z as ge,a as me,M as ht,F as Xt,H as Ft,E as Ke,U as es}from"./zap-DF8ZDfuF.js";import{U as ts}from"./user-plus-BAoPMNSL.js";import{C as ft,B as jn}from"./check-DeGVJ_bj.js";import{L as yn,S as ss}from"./shopping-cart-kACIxgjL.js";import{C as Ze}from"./chevron-down-GO_-Sq_k.js";import{L as xt,R as Rt,a as It}from"./rotate-ccw-GCdQKzDD.js";import{P as ns}from"./plus-BG94A3Bc.js";import{C as Nn}from"./circle-x-CMhZBMeK.js";import{A as Xe}from"./arrow-right-CuHeByKy.js";import{M as wn}from"./mail-DNjW6b69.js";import{C as as}from"./crown-C2dTF1iz.js";import"./index-DKJhGL22.js";/** 3 * @license lucide-react v0.462.0 - ISC 4 * 5 * This source code is licensed under the ISC license. 6 * See the LICENSE file in the root directory of this source tree. 7 */const rs=Fe("Bell",[["path",{d:"M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9",key:"1qo2s2"}],["path",{d:"M10.3 21a1.94 1.94 0 0 0 3.4 0",key:"qgo35s"}]]);/** 8 * @license lucide-react v0.462.0 - ISC 9 * 10 * This source code is licensed under the ISC license. 11 * See the LICENSE file in the root directory of this source tree. 12 */const vn=Fe("DollarSign",[["line",{x1:"12",x2:"12",y1:"2",y2:"22",key:"7eqyqh"}],["path",{d:"M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6",key:"1b0p4s"}]]);/** 13 * @license lucide-react v0.462.0 - ISC 14 * 15 * This source code is licensed under the ISC license. 16 * See the LICENSE file in the root directory of this source tree. 17 */const Bt=Fe("QrCode",[["rect",{width:"5",height:"5",x:"3",y:"3",rx:"1",key:"1tu5fj"}],["rect",{width:"5",height:"5",x:"16",y:"3",rx:"1",key:"1v8r4q"}],["rect",{width:"5",height:"5",x:"3",y:"16",rx:"1",key:"1x03jg"}],["path",{d:"M21 16h-3a2 2 0 0 0-2 2v3",key:"177gqh"}],["path",{d:"M21 21v.01",key:"ents32"}],["path",{d:"M12 7v3a2 2 0 0 1-2 2H7",key:"8crl2c"}],["path",{d:"M3 12h.01",key:"nlz23k"}],["path",{d:"M12 3h.01",key:"n36tog"}],["path",{d:"M12 16v.01",key:"133mhm"}],["path",{d:"M16 12h1",key:"1slzba"}],["path",{d:"M21 12v.01",key:"1lwtk9"}],["path",{d:"M12 21v-1",key:"1880an"}]]);/** 18 * @license lucide-react v0.462.0 - ISC 19 * 20 * This source code is licensed under the ISC license. 21 * See the LICENSE file in the root directory of this source tree. 22 */const Lt=Fe("Receipt",[["path",{d:"M4 2v20l2-1 2 1 2-1 2 1 2-1 2 1 2-1 2 1V2l-2 1-2-1-2 1-2-1-2 1-2-1-2 1Z",key:"q3az6g"}],["path",{d:"M16 8h-6a2 2 0 1 0 0 4h4a2 2 0 1 1 0 4H8",key:"1h4pet"}],["path",{d:"M12 17.5v-11",key:"1jc1ny"}]]);var je={},bn=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then},is={},K={};let pt;const Cn=[0,26,44,70,100,134,172,196,242,292,346,404,466,532,581,655,733,815,901,991,1085,1156,1258,1364,1474,1588,1706,1828,1921,2051,2185,2323,2465,2611,2761,2876,3034,3196,3362,3532,3706];K.getSymbolSize=function(n){if(!n)throw new Error('"version" cannot be null or undefined');if(n<1||n>40)throw new Error('"version" should be in range from 1 to 40');return n*4+17};K.getSymbolTotalCodewords=function(n){return Cn[n]};K.getBCHDigit=function(t){let n=0;for(;t!==0;)n++,t>>>=1;return n};K.setToSJISFunction=function(n){if(typeof n!="function")throw new Error('"toSJISFunc" is not a valid function.');pt=n};K.isKanjiModeEnabled=function(){return typeof pt<"u"};K.toSJIS=function(n){return pt(n)};var Re={};(function(t){t.L={bit:1},t.M={bit:0},t.Q={bit:3}
vendor: 21,796 bytes, lines 22-28
22,t.H={bit:2};function n(s){if(typeof s!="string")throw new Error("Param is not a string");switch(s.toLowerCase()){case"l":case"low":return t.L;case"m":case"medium":return t.M;case"q":case"quartile":return t.Q;case"h":case"high":return t.H;default:throw new Error("Unknown EC Level: "+s)}}t.isValid=function(r){return r&&typeof r.bit<"u"&&r.bit>=0&&r.bit<4},t.from=function(r,a){if(t.isValid(r))return r;try{return n(r)}catch{return a}}})(Re);function os(){this.buffer=[],this.length=0}os.prototype={get:function(t){const n=Math.floor(t/8);return(this.buffer[n]>>>7-t%8&1)===1},put:function(t,n){for(let s=0;s<n;s++)this.putBit((t>>>n-s-1&1)===1)},getLengthInBits:function(){return this.length},putBit:function(t){const n=Math.floor(this.length/8);this.buffer.length<=n&&this.buffer.push(0),t&&(this.buffer[n]|=128>>>this.length%8),this.length++}};var _n=os;function ye(t){if(!t||t<1)throw new Error("BitMatrix size must be defined and greater than 0");this.size=t,this.data=new Uint8Array(t*t),this.reservedBit=new Uint8Array(t*t)}ye.prototype.set=function(t,n,s,r){const a=t*this.size+n;this.data[a]=s,r&&(this.reservedBit[a]=!0)};ye.prototype.get=function(t,n){return this.data[t*this.size+n]};ye.prototype.xor=function(t,n,s){this.data[t*this.size+n]^=s};ye.prototype.isReserved=function(t,n){return this.reservedBit[t*this.size+n]};var Pn=ye,ls={};(function(t){const n=K.getSymbolSize;t.getRowColCoords=function(r){if(r===1)return[];const a=Math.floor(r/7)+2,i=n(r),o=i===145?26:Math.ceil((i-13)/(2*a-2))*2,l=[i-7];for(let c=1;c<a-1;c++)l[c]=l[c-1]-o;return l.push(6),l.reverse()},t.getPositions=function(r){const a=[],i=t.getRowColCoords(r),o=i.length;for(let l=0;l<o;l++)for(let c=0;c<o;c++)l===0&&c===0||l===0&&c===o-1||l===o-1&&c===0||a.push([i[l],i[c]]);return a}})(ls);var cs={};const Sn=K.getSymbolSize,Dt=7;cs.getPositions=function(n){const s=Sn(n);return[[0,0],[s-Dt,0],[0,s-Dt]]};var ds={};(function(t){t.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};const n={N1:3,N2:3,N3:40,N4:10};t.isValid=function(a){return a!=null&&a!==""&&!isNaN(a)&&a>=0&&a<=7},t.from=function(a){return t.isValid(a)?parseInt(a,10):void 0},t.getPenaltyN1=function(a){const i=a.size;let o=0,l=0,c=0,h=null,m=null;for(let w=0;w<i;w++){l=c=0,h=m=null;for(let x=0;x<i;x++){let g=a.get(w,x);g===h?l++:(l>=5&&(o+=n.N1+(l-5)),h=g,l=1),g=a.get(x,w),g===m?c++:(c>=5&&(o+=n.N1+(c-5)),m=g,c=1)}l>=5&&(o+=n.N1+(l-5)),c>=5&&(o+=n.N1+(c-5))}return o},t.getPenaltyN2=function(a){const i=a.size;let o=0;for(let l=0;l<i-1;l++)for(let c=0;c<i-1;c++){const h=a.get(l,c)+a.get(l,c+1)+a.get(l+1,c)+a.get(l+1,c+1);(h===4||h===0)&&o++}return o*n.N2},t.getPenaltyN3=function(a){const i=a.size;let o=0,l=0,c=0;for(let h=0;h<i;h++){l=c=0;for(let m=0;m<i;m++)l=l<<1&2047|a.get(h,m),m>=10&&(l===1488||l===93)&&o++,c=c<<1&2047|a.get(m,h),m>=10&&(c===1488||c===93)&&o++}return o*n.N3},t.getPenaltyN4=function(a){let i=0;const o=a.data.length;for(let c=0;c<o;c++)i+=a.data[c];return Math.abs(Math.ceil(i*100/o/5)-10)*n.N4};function s(r,a,i){switch(r){case t.Patterns.PATTERN000:return(a+i)%2===0;case t.Patterns.PATTERN001:return a%2===0;case t.Patterns.PATTERN010:return i%3===0;case t.Patterns.PATTERN011:return(a+i)%3===0;case t.Patterns.PATTERN100:return(Math.floor(a/2)+Math.floor(i/3))%2===0;case t.Patterns.PATTERN101:return a*i%2+a*i%3===0;case t.Patterns.PATTERN110:return(a*i%2+a*i%3)%2===0;case t.Patterns.PATTERN111:return(a*i%3+(a+i)%2)%2===0;default:throw new Error("bad maskPattern:"+r)}}t.applyMask=function(a,i){const o=i.size;for(let l=0;l<o;l++)for(let c=0;c<o;c++)i.isReserved(c,l)||i.xor(c,l,s(a,c,l))},t.getBestMask=function(a,i){const o=Object.keys(t.Patterns).length;let l=0,c=1/0;for(let h=0;h<o;h++){i(h),t.applyMask(h,a);const m=t.getPenaltyN1(a)+t.getPenaltyN2(a)+t.getPenaltyN3(a)+t.getPenaltyN4(a);t.applyMask(h,a),m<c&&(c=m,l=h)}return l}})(ds);var Ie={};const Z=Re,ve=[1,1,1,1,1,1,1,1,1,1,2,2,1,2,2,4,1,2,4,4,2,4,4,4,2,4,6,5,2,4,6,6,2,5,8,8,4,5,8,8,4,5,8,11,4,8,10,11,4,9,12,16,4,9,16,16,6,10,12,18,6,10,17,16,6,11,16,19,6,13,18,21,7,14,21,25,8,16,20,25,8,17,23,25,9,17,23,34,9,18,25,30,10,20,27,32,12,21,29,35,12,23,34,37,12,25,34,40,13,26,35,42,14,28,38,45,15,29,40,48,16,31,43,51,17,33,45,54,18,35,48,57,19,37,51,60,19,38,53,63,20,40,56,66,21,43,59,70,22,45,62,74,24,47,65,77,25,49,68,81],be=[7,10,13,17,10,16,22,28,15,26,36,44,20,36,52,64,26,48,72,88,36,64,96,112,40,72,108,130,48,88,132,156,60,110,160,192,72,130,192,224,80,150,224,264,96,176,260,308,104,198,288,352,120,216,320,384,132,240,360,432,144,280,408,480,168,308,448,532,180,338,504,588,196,364,546,650,224,416,600,700,224,442,644,750,252,476,690,816,270,504,750,900,300,560,810,960,312,588,870,1050,336,644,952,1110,360,700,1020,1200,390,728,1050,1260,420,784,1140,1350,450,812,1200,1440,480,868,1290,1530,510,924,1350,1620,540,980,1440,1710,570,1036,1530,1800,570,1064,1590,1890,600,1120,1680,1980,630,1204,1770,2100,660,1260,1860,2220,720,1316,1950,2310,750,1372,2040,2430];Ie.getBlocksCount=function(n,s){switch(s){case Z.L:return ve[(n-1)*4+0];case Z.M:return ve[(n-1)*4+1];case Z.Q:return ve[(n-1)*4+2];case Z.H:return ve[(n-1)*4+3];default:return}};Ie.getTotalCodewordsCount=function(n,s){switch(s){case Z.L:return be[(n-1)*4+0];case Z.M:return be[(n-1)*4+1];case Z.Q:return be[(n-1)*4+2];case Z.H:return be[(n-1)*4+3];default:return}};var us={},Be={};const he=new Uint8Array(512),ke=new Uint8Array(256);(function(){let n=1;for(let s=0;s<255;s++)he[s]=n,ke[n]=s,n<<=1,n&256&&(n^=285);for(let s=255;s<512;s++)he[s]=he[s-255]})();Be.log=function(n){if(n<1)throw new Error("log("+n+")");return ke[n]};Be.exp=function(n){return he[n]};Be.mul=function(n,s){return n===0||s===0?0:he[ke[n]+ke[s]]};(function(t){const n=Be;t.mul=function(r,a){const i=new Uint8Array(r.length+a.length-1);for(let o=0;o<r.length;o++)for(let l=0;l<a.length;l++)i[o+l]^=n.mul(r[o],a[l]);return i},t.mod=function(r,a){let i=new Uint8Array(r);for(;i.length-a.length>=0;){const o=i[0];for(let c=0;c<a.length;c++)i[c]^=n.mul(a[c],o);let l=0;for(;l<i.length&&i[l]===0;)l++;i=i.slice(l)}return i},t.generateECPolynomial=function(r){let a=new Uint8Array([1]);for(let i=0;i<r;i++)a=t.mul(a,new Uint8Array([1,n.exp(i)]));return a}})(us);const ms=us;function gt(t){this.genPoly=void 0,this.degree=t,this.degree&&this.initialize(this.degree)}gt.prototype.initialize=function(n){this.degree=n,this.genPoly=ms.generateECPolynomial(this.degree)};gt.prototype.encode=function(n){if(!this.genPoly)throw new Error("Encoder not initialized");const s=new Uint8Array(n.length+this.degree);s.set(n);const r=ms.mod(s,this.genPoly),a=this.degree-r.length;if(a>0){const i=new Uint8Array(this.degree);return i.set(r,a),i}return r};var En=gt,hs={},ee={},jt={};jt.isValid=function(n){return!isNaN(n)&&n>=1&&n<=40};var J={};const fs="[0-9]+",An="[A-Z $%*+\\-./:]+";let pe="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";pe=pe.replace(/u/g,"\\u");const Mn="(?:(?![A-Z0-9 $%*+\\-./:]|"+pe+`)(?:.|[\r 23]))+`;J.KANJI=new RegExp(pe,"g");J.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g");J.BYTE=new RegExp(Mn,"g");J.NUMERIC=new RegExp(fs,"g");J.ALPHANUMERIC=new RegExp(An,"g");const kn=new RegExp("^"+pe+"$"),Tn=new RegExp("^"+fs+"$"),Fn=new RegExp("^[A-Z0-9 $%*+\\-./:]+$");J.testKanji=function(n){return kn.test(n)};J.testNumeric=function(n){return Tn.test(n)};J.testAlphanumeric=function(n){return Fn.test(n)};(function(t){const n=jt,s=J;t.NUMERIC={id:"Numeric",bit:1,ccBits:[10,12,14]},t.ALPHANUMERIC={id:"Alphanumeric",bit:2,ccBits:[9,11,13]},t.BYTE={id:"Byte",bit:4,ccBits:[8,16,16]},t.KANJI={id:"Kanji",bit:8,ccBits:[8,10,12]},t.MIXED={bit:-1},t.getCharCountIndicator=function(i,o){if(!i.ccBits)throw new Error("Invalid mode: "+i);if(!n.isValid(o))throw new Error("Invalid version: "+o);return o>=1&&o<10?i.ccBits[0]:o<27?i.ccBits[1]:i.ccBits[2]},t.getBestModeForData=function(i){return s.testNumeric(i)?t.NUMERIC:s.testAlphanumeric(i)?t.ALPHANUMERIC:s.testKanji(i)?t.KANJI:t.BYTE},t.toString=function(i){if(i&&i.id)return i.id;throw new Error("Invalid mode")},t.isValid=function(i){return i&&i.bit&&i.ccBits};function r(a){if(typeof a!="string")throw new Error("Param is not a string");switch(a.toLowerCase()){case"numeric":return t.NUMERIC;case"alphanumeric":return t.ALPHANUMERIC;case"kanji":return t.KANJI;case"byte":return t.BYTE;default:throw new Error("Unknown mode: "+a)}}t.from=function(i,o){if(t.isValid(i))return i;try{return r(i)}catch{return o}}})(ee);(function(t){const n=K,s=Ie,r=Re,a=ee,i=jt,o=7973,l=n.getBCHDigit(o);function c(x,g,C){for(let d=1;d<=40;d++)if(g<=t.getCapacity(d,C,x))return d}function h(x,g){return a.getCharCountIndicator(x,g)+4}function m(x,g){let C=0;return x.forEach(function(d){const y=h(d.mode,g);C+=y+d.getBitsLength()}),C}function w(x,g){for(let C=1;C<=40;C++)if(m(x,C)<=t.getCapacity(C,g,a.MIXED))return C}t.from=function(g,C){return i.isValid(g)?parseInt(g,10):C},t.getCapacity=function(g,C,d){if(!i.isValid(g))throw new Error("Invalid QR Code version");typeof d>"u"&&(d=a.BYTE);const y=n.getSymbolTotalCodewords(g),N=s.getTotalCodewordsCount(g,C),p=(y-N)*8;if(d===a.MIXED)return p;const u=p-h(d,g);switch(d){case a.NUMERIC:return Math.floor(u/10*3);case a.ALPHANUMERIC:return Math.floor(u/11*2);case a.KANJI:return Math.floor(u/13);case a.BYTE:default:return Math.floor(u/8)}},t.getBestVersionForData=function(g,C){let d;const y=r.from(C,r.M);if(Array.isArray(g)){if(g.length>1)return w(g,y);if(g.length===0)return 1;d=g[0]}else d=g;return c(d.mode,d.getLength(),y)},t.getEncodedBits=function(g){if(!i.isValid(g)||g<7)throw new Error("Invalid QR Code version");let C=g<<12;for(;n.getBCHDigit(C)-l>=0;)C^=o<<n.getBCHDigit(C)-l;return g<<12|C}})(hs);var xs={};const et=K,ps=1335,Rn=21522,Ot=et.getBCHDigit(ps);xs.getEncodedBits=function(n,s){const r=n.bit<<3|s;let a=r<<10;for(;et.getBCHDigit(a)-Ot>=0;)a^=ps<<et.getBCHDigit(a)-Ot;return(r<<10|a)^Rn};var gs={};const In=ee;function re(t){this.mode=In.NUMERIC,this.data=t.toString()}re.getBitsLength=function(n){return 10*Math.floor(n/3)+(n%3?n%3*3+1:0)};re.prototype.getLength=function(){return this.data.length};re.prototype.getBitsLength=function(){return re.getBitsLength(this.data.length)};re.prototype.write=function(n){let s,r,a;for(s=0;s+3<=this.data.length;s+=3)r=this.data.substr(s,3),a=parseInt(r,10),n.put(a,10);const i=this.data.length-s;i>0&&(r=this.data.substr(s),a=parseInt(r,10),n.put(a,i*3+1))};var Bn=re;const Ln=ee,Ye=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"," ","$","%","*","+","-",".","/",":"];function ie(t){this.mode=Ln.ALPHANUMERIC,this.data=t}ie.getBitsLength=function(n){return 11*Math.floor(n/2)+6*(n%2)};ie.prototype.getLength=function(){return this.data.length};ie.prototype.getBitsLength=function(){return ie.getBitsLength(this.data.length)};ie.prototype.write=function(n){let s;for(s=0;s+2<=this.data.length;s+=2){let r=Ye.indexOf(this.data[s])*45;r+=Ye.indexOf(this.data[s+1]),n.put(r,11)}this.data.length%2&&n.put(Ye.indexOf(this.data[s]),6)};var Dn=ie;const On=ee;function oe(t){this.mode=On.BYTE,typeof t=="string"?this.data=new TextEncoder().encode(t):this.data=new Uint8Array(t)}oe.getBitsLength=function(n){return n*8};oe.prototype.getLength=function(){return this.data.length};oe.prototype.getBitsLength=function(){return oe.getBitsLength(this.data.length)};oe.prototype.write=function(t){for(let n=0,s=this.data.length;n<s;n++)t.put(this.data[n],8)};var Un=oe;const qn=ee,zn=K;function le(t){this.mode=qn.KANJI,this.data=t}le.getBitsLength=function(n){return n*13};le.prototype.getLength=function(){return this.data.length};le.prototype.getBitsLength=function(){return le.getBitsLength(this.data.length)};le.prototype.write=function(t){let n;for(n=0;n<this.data.length;n++){let s=zn.toSJIS(this.data[n]);if(s>=33088&&s<=40956)s-=33088;else if(s>=57408&&s<=60351)s-=49472;else throw new Error("Invalid SJIS character: "+this.data[n]+` 24Make sure your charset is UTF-8`);s=(s>>>8&255)*192+(s&255),t.put(s,13)}};var Kn=le,js={exports:{}};(function(t){var n={single_source_shortest_paths:function(s,r,a){var i={},o={};o[r]=0;var l=n.PriorityQueue.make();l.push(r,0);for(var c,h,m,w,x,g,C,d,y;!l.empty();){c=l.pop(),h=c.value,w=c.cost,x=s[h]||{};for(m in x)x.hasOwnProperty(m)&&(g=x[m],C=w+g,d=o[m],y=typeof o[m]>"u",(y||d>C)&&(o[m]=C,l.push(m,C),i[m]=h))}if(typeof a<"u"&&typeof o[a]>"u"){var N=["Could not find a path from ",r," to ",a,"."].join("");throw new Error(N)}return i},extract_shortest_path_from_predecessor_list:function(s,r){for(var a=[],i=r;i;)a.push(i),s[i],i=s[i];return a.reverse(),a},find_path:function(s,r,a){var i=n.single_source_shortest_paths(s,r,a);return n.extract_shortest_path_from_predecessor_list(i,a)},PriorityQueue:{make:function(s){var r=n.PriorityQueue,a={},i;s=s||{};for(i in r)r.hasOwnProperty(i)&&(a[i]=r[i]);return a.queue=[],a.sorter=s.sorter||r.default_sorter,a},default_sorter:function(s,r){return s.cost-r.cost},push:function(s,r){var a={value:s,cost:r};this.queue.push(a),this.queue.sort(this.sorter)},pop:function(){return this.queue.shift()},empty:function(){return this.queue.length===0}}};t.exports=n})(js);var Yn=js.exports;(function(t){const n=ee,s=Bn,r=Dn,a=Un,i=Kn,o=J,l=K,c=Yn;function h(N){return unescape(encodeURIComponent(N)).length}function m(N,p,u){const f=[];let S;for(;(S=N.exec(u))!==null;)f.push({data:S[0],index:S.index,mode:p,length:S[0].length});return f}function w(N){const p=m(o.NUMERIC,n.NUMERIC,N),u=m(o.ALPHANUMERIC,n.ALPHANUMERIC,N);let f,S;return l.isKanjiModeEnabled()?(f=m(o.BYTE,n.BYTE,N),S=m(o.KANJI,n.KANJI,N)):(f=m(o.BYTE_KANJI,n.BYTE,N),S=[]),p.concat(u,f,S).sort(function(j,A){return j.index-A.index}).map(function(j){return{data:j.data,mode:j.mode,length:j.length}})}function x(N,p){switch(p){case n.NUMERIC:return s.getBitsLength(N);case n.ALPHANUMERIC:return r.getBitsLength(N);case n.KANJI:return i.getBitsLength(N);case n.BYTE:return a.getBitsLength(N)}}function g(N){return N.reduce(function(p,u){const f=p.length-1>=0?p[p.length-1]:null;return f&&f.mode===u.mode?(p[p.length-1].data+=u.data,p):(p.push(u),p)},[])}function C(N){const p=[];for(let u=0;u<N.length;u++){const f=N[u];switch(f.mode){case n.NUMERIC:p.push([f,{data:f.data,mode:n.ALPHANUMERIC,length:f.length},{data:f.data,mode:n.BYTE,length:f.length}]);break;case n.ALPHANUMERIC:p.push([f,{data:f.data,mode:n.BYTE,length:f.length}]);break;case n.KANJI:p.push([f,{data:f.data,mode:n.BYTE,length:h(f.data)}]);break;case n.BYTE:p.push([{data:f.data,mode:n.BYTE,length:h(f.data)}])}}return p}function d(N,p){const u={},f={start:{}};let S=["start"];for(let P=0;P<N.length;P++){const j=N[P],A=[];for(let M=0;M<j.length;M++){const L=j[M],V=""+P+M;A.push(V),u[V]={node:L,lastCount:0},f[V]={};for(let se=0;se<S.length;se++){const $=S[se];u[$]&&u[$].node.mode===L.mode?(f[$][V]=x(u[$].lastCount+L.length,L.mode)-x(u[$].lastCount,L.mode),u[$].lastCount+=L.length):(u[$]&&(u[$].lastCount=L.length),f[$][V]=x(L.length,L.mode)+4+n.getCharCountIndicator(L.mode,p))}}S=A}for(let P=0;P<S.length;P++)f[S[P]].end=0;return{map:f,table:u}}function y(N,p){let u;const f=n.getBestModeForData(N);if(u=n.from(p,f),u!==n.BYTE&&u.bit<f.bit)throw new Error('"'+N+'" cannot be encoded with mode '+n.toString(u)+`. 25 Suggested mode is: `+n.toString(f));switch(u===n.KANJI&&!l.isKanjiModeEnabled()&&(u=n.BYTE),u){case n.NUMERIC:return new s(N);case n.ALPHANUMERIC:return new r(N);case n.KANJI:return new i(N);case n.BYTE:return new a(N)}}t.fromArray=function(p){return p.reduce(function(u,f){return typeof f=="string"?u.push(y(f,null)):f.data&&u.push(y(f.data,f.mode)),u},[])},t.fromString=function(p,u){const f=w(p,l.isKanjiModeEnabled()),S=C(f),P=d(S,u),j=c.find_path(P.map,"start","end"),A=[];for(let M=1;M<j.length-1;M++)A.push(P.table[j[M]].node);return t.fromArray(g(A))},t.rawSplit=function(p){return t.fromArray(w(p,l.isKanjiModeEnabled()))}})(gs);const Le=K,He=Re,Hn=_n,Gn=Pn,Qn=ls,Vn=cs,tt=ds,st=Ie,$n=En,Te=hs,Jn=xs,Wn=ee,Ge=gs;function Zn(t,n){const s=t.size,r=Vn.getPositions(n);for(let a=0;a<r.length;a++){const i=r[a][0],o=r[a][1];for(let l=-1;l<=7;l++)if(!(i+l<=-1||s<=i+l))for(let c=-1;c<=7;c++)o+c<=-1||s<=o+c||(l>=0&&l<=6&&(c===0||c===6)||c>=0&&c<=6&&(l===0||l===6)||l>=2&&l<=4&&c>=2&&c<=4?t.set(i+l,o+c,!0,!0):t.set(i+l,o+c,!1,!0))}}function Xn(t){const n=t.size;for(let s=8;s<n-8;s++){const r=s%2===0;t.set(s,6,r,!0),t.set(6,s,r,!0)}}function ea(t,n){const s=Qn.getPositions(n);for(let r=0;r<s.length;r++){const a=s[r][0],i=s[r][1];for(let o=-2;o<=2;o++)for(let l=-2;l<=2;l++)o===-2||o===2||l===-2||l===2||o===0&&l===0?t.set(a+o,i+l,!0,!0):t.set(a+o,i+l,!1,!0)}}function ta(t,n){const s=t.size,r=Te.getEncodedBits(n);let a,i,o;for(let l=0;l<18;l++)a=Math.floor(l/3),i=l%3+s-8-3,o=(r>>l&1)===1,t.set(a,i,o,!0),t.set(i,a,o,!0)}function Qe(t,n,s){const r=t.size,a=Jn.getEncodedBits(n,s);let i,o;for(i=0;i<15;i++)o=(a>>i&1)===1,i<6?t.set(i,8,o,!0):i<8?t.set(i+1,8,o,!0):t.set(r-15+i,8,o,!0),i<8?t.set(8,r-i-1,o,!0):i<9?t.set(8,15-i-1+1,o,!0):t.set(8,15-i-1,o,!0);t.set(r-8,8,1,!0)}function sa(t,n){const s=t.size;let r=-1,a=s-1,i=7,o=0;for(let l=s-1;l>0;l-=2)for(l===6&&l--;;){for(let c=0;c<2;c++)if(!t.isReserved(a,l-c)){let h=!1;o<n.length&&(h=(n[o]>>>i&1)===1),t.set(a,l-c,h),i--,i===-1&&(o++,i=7)}if(a+=r,a<0||s<=a){a-=r,r=-r;break}}}function na(t,n,s){const r=new Hn;s.forEach(function(c){r.put(c.mode.bit,4),r.put(c.getLength(),Wn.getCharCountIndicator(c.mode,t)),c.write(r)});const a=Le.getSymbolTotalCodewords(t),i=st.getTotalCodewordsCount(t,n),o=(a-i)*8;for(r.getLengthInBits()+4<=o&&r.put(0,4);r.getLengthInBits()%8!==0;)r.putBit(0);const l=(o-r.getLengthInBits())/8;for(let c=0;c<l;c++)r.put(c%2?17:236,8);return aa(r,t,n)}function aa(t,n,s){const r=Le.getSymbolTotalCodewords(n),a=st.getTotalCodewordsCount(n,s),i=r-a,o=st.getBlocksCount(n,s),l=r%o,c=o-l,h=Math.floor(r/o),m=Math.floor(i/o),w=m+1,x=h-m,g=new $n(x);let C=0;const d=new Array(o),y=new Array(o);let N=0;const p=new Uint8Array(t.buffer);for(let j=0;j<o;j++){const A=j<c?m:w;d[j]=p.slice(C,C+A),y[j]=g.encode(d[j]),C+=A,N=Math.max(N,A)}const u=new Uint8Array(r);let f=0,S,P;for(S=0;S<N;S++)for(P=0;P<o;P++)S<d[P].length&&(u[f++]=d[P][S]);for(S=0;S<x;S++)for(P=0;P<o;P++)u[f++]=y[P][S];return u}function ra(t,n,s,r){let a;if(Array.isArray(t))a=Ge.fromArray(t);else if(typeof t=="string"){let h=n;if(!h){const m=Ge.rawSplit(t);h=Te.getBestVersionForData(m,s)}a=Ge.fromString(t,h||40)}else throw new Error("Invalid data");const i=Te.getBestVersionForData(a,s);if(!i)throw new Error("The amount of data is too big to be stored in a QR Code");if(!n)n=i;else if(n<i)throw new Error(` 26The chosen QR Code version cannot contain this amount of data. 27Minimum version required to store current data is: `+i+`. 28`);const o=na(n,s,a),l=Le.getSymbolSize(n),c=new Gn(l);return Zn(c,n),Xn(c),ea(c,n),Qe(c,s,0),n>=7&&ta(c,n),sa(c,o),isNaN(r)&&(r=tt.getBestMask(c,Qe.bind(null,c,s))),tt.applyMask(r,c),Qe(c,s,r),{modules:c,version:n,errorCorrectionLevel:s,maskPattern:r,segments:a}}is.create=function(n,s){if(typeof n>"u"||n==="")throw new Error("No input text");let r=He.M,a,i;return typeof s<"u"&&(r=He.from(s.errorCorrectionLevel,He.M),a=Te.from(s.version),i=tt.from(s.maskPattern),s.toSJISFunc&&Le.setToSJISFunction(s.toSJISFunc)),ra(n,a,r,i)};var ys={},yt={};(function(t){function n(s){if(typeof s=="number"&&(s=s.toString()),typeof s!="string")throw new Error("Color should be defined as hex string");let r=s.slice().replace("#","").split("");if(r.length<3||r.length===5||r.length>8)throw new Error("Invalid hex color: "+s);(r.length===3||r.length===4)&&(r=Array.prototype.concat.apply([],r.map(function(i){return[i,i]}))),r.length===6&&r.push("F","F");const a=parseInt(r.join(""),16);return{r:a>>24&255,g:a>>16&255,b:a>>8&255,a:a&255,hex:"#"+r.slice(0,6).join("")}}t.getOptions=function(r){r||(r={}),r.color||(r.color={});const a=typeof r.margin>"u"||r.margin===null||r.margin<0?4:r.margin,i=r.width&&r.width>=21?r.width:void 0,o=r.scale||4;return{width:i,scale:i?4:o,margin:a,color:{dark:n(r.color.dark||"#000000ff"),light:n(r.color.light||"#ffffffff")},type:r.type,rendererOpts:r.rendererOpts||{}}},t.getScale=function(r,a){return a.width&&a.width>=r+a.margin*2?a.width/(r+a.margin*2):a.scale},t.getImageWidth=function(r,a){const i=t.getScale(r,a);return Math.floor((r+a.margin*2)*i)},t.qrToImageData=function(r,a,i){const o=a.modules.size,l=a.modules.data,c=t.getScale(o,i),h=Math.floor((o+i.margin*2)*c),m=i.margin*c,w=[i.color.light,i.color.dark];for(let x=0;x<h;x++)for(let g=0;g<h;g++){let C=(x*h+g)*4,d=i.color.light;if(x>=m&&g>=m&&x<h-m&&g<h-m){const y=Math.floor((x-m)/c),N=Math.floor((g-m)/c);d=w[l[y*o+N]?1:0]}r[C++]=d.r,r[C++]=d.g,r[C++]=d.b,r[C]=d.a}}})(yt);(function(t){const n=yt;function s(a,i,o){a.clearRect(0,0,i.width,i.height),i.style||(i.style={}),i.height=o,i.width=o,i.style.height=o+"px",i.style.width=o+"px"}function r(){try{return document.createElement("canvas")}catch{throw new Error("You need to specify a canvas element")}}t.render=function(i,o,l){let c=l,h=o;typeof c>"u"&&(!o||!o.getContext)&&(c=o,o=void 0),o||(h=r()),c=n.getOptions(c);const m=n.getImageWidth(i.modules.size,c),w=h.getContext("2d"),x=w.createImageData(m,m);return n.qrToImageData(x.data,i,c),s(w,h,m),w.putImageData(x,0,0),h},t.renderToDataURL=function(i,o,l){let c=l;typeof c>"u"&&(!o||!o.getContext)&&(c=o,o=void 0),c||(c={});const h=t.render(i,o,c),m=c.type||"image/png",w=c.rendererOpts||{};return h.toDataURL(m,w.quality)}})(ys);var Ns={};const ia=yt;function Ut(t,n){const s=t.a/255,r=n+'="'+t.hex+'"';return s<1?r+" "+n+'-opacity="'+s.toFixed(2).slice(1)+'"':r}function Ve(t,n,s){let r=t+n;return typeof s<"u"&&(r+=" "+s),r}
28function oa(t,n,s){let r="",a=0,i=!1,o=0;for(let l=0;l<t.length;l++){const c=Math.floor(l%n),h=Math.floor(l/n);!c&&!i&&(i=!0),t[l]?(o++,l>0&&c>0&&t[l-1]||(r+=i?Ve("M",c+s,.5+h+s):Ve("m",a,0),a=0,i=!1),c+1<n&&t[l+1]||(r+=Ve("h",o),o=0)):a++}return r}Ns.render=function(n,s,r){const a=ia.getOptions(s),i=n.modules.size,o=n.modules.data,l=i+a.margin*2,c=a.color.light.a?"<path "+Ut(a.color.light,"fill")+' d="M0 0h'+l+"v"+l+'H0z"/>':"",h="<path "+Ut(a.color.dark,"stroke")+' d="'+oa(o,i,a.margin)+'"/>',m='viewBox="0 0 '+l+" "+l+'"',x='<svg xmlns="http://www.w3.org/2000/svg" '+(a.width?'width="'+a.width+'" height="'+a.width+'" ':"")+m+' shape-rendering="crispEdges">'+c+h+`</svg> 29`;return typeof r=="function"&&r(null,x),x};const la=bn,nt=is,ws=ys,ca=Ns;function Nt(t,n,s,r,a){const i=[].slice.call(arguments,1),o=i.length,l=typeof i[o-1]=="function";if(!l&&!la())throw new Error("Callback required as last argument");if(l){if(o<2)throw new Error("Too few arguments provided");o===2?(a=s,s=n,n=r=void 0):o===3&&(n.getContext&&typeof a>"u"?(a=r,r=void 0):(a=r,r=s,s=n,n=void 0))}else{if(o<1)throw new Error("Too few arguments provided");return o===1?(s=n,n=r=void 0):o===2&&!n.getContext&&(r=s,s=n,n=void 0),new Promise(function(c,h){try{const m=nt.create(s,r);c(t(m,n,r))}catch(m){h(m)}})}try{const c=nt.create(s,r);a(null,t(c,n,r))}catch(c){a(c)}}je.create=nt.create;je.toCanvas=Nt.bind(null,ws.render);je.toDataURL=Nt.bind(null,ws.renderToDataURL);je.toString=Nt.bind(null,function(t,n,s){return ca.render(t,s)});const da="#9229f5",ua="#ff42a7",ma="#111111",Ce='"Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif',ha='ui-monospace, "SF Mono", Menlo, Consolas, monospace',vs="Tutoremy AI",fa=["Turn your notes into study","guides, flashcards & quizzes"],xa="Scan to join â we both get bonus credits";async function bs(t,n){const s=await je.toDataURL(t,{errorCorrectionLevel:"M",margin:2,width:n,color:{dark:ma,light:"#ffffff"}});return Cs(s)}function Cs(t){return new Promise((n,s)=>{const r=new Image;r.onload=()=>n(r),r.onerror=()=>s(new Error(`Could not load ${t}`)),r.src=t})}async function pa(){try{return await Cs("/tutoremy-icon.png")}catch{return null}}function qt(t,n,s,r,a,i){t.beginPath(),t.moveTo(n+i,s),t.arcTo(n+r,s,n+r,s+a,i),t.arcTo(n+r,s+a,n,s+a,i),t.arcTo(n,s+a,n,s,i),t.arcTo(n,s,n+r,s,i),t.closePath()}const ga={square:{w:1080,h:1080,logo:96,logoY:76,wordmark:56,wordmarkY:236,headline:40,headlineY:300,headlineGap:52,card:480,cardY:396,cardPad:40,cardRadius:36,codeSize:46,codeY:940,urlSize:27,urlY:984,footSize:28,footY:1036},story:{w:1080,h:1920,logo:128,logoY:360,wordmark:68,wordmarkY:570,headline:46,headlineY:655,headlineGap:62,card:620,cardY:790,cardPad:48,cardRadius:44,codeSize:58,codeY:1510,urlSize:32,urlY:1566,footSize:34,footY:1655}};function _s(t){return t.replace(/^https?:\/\//,"").replace(/\/$/,"")}async function $e(t,n){var x;const s=ga[n];typeof document<"u"&&((x=document.fonts)!=null&&x.ready)&&await document.fonts.ready;const r=document.createElement("canvas");r.width=s.w,r.height=s.h;const a=r.getContext("2d");if(!a)throw new Error("Canvas is not available in this browser");const i=a.createLinearGradient(0,0,s.w,s.h);i.addColorStop(0,da),i.addColorStop(1,ua),a.fillStyle=i,a.fillRect(0,0,s.w,s.h);const o=s.w/2;a.textAlign="center",a.textBaseline="alphabetic";const l=await pa();l&&(a.save(),qt(a,o-s.logo/2,s.logoY,s.logo,s.logo,s.logo*.22),a.clip(),a.drawImage(l,o-s.logo/2,s.logoY,s.logo,s.logo),a.restore()),a.fillStyle="#ffffff",a.font=`700 ${s.wordmark}px ${Ce}`,a.fillText(vs,o,s.wordmarkY),a.fillStyle="rgba(255,255,255,0.92)",a.font=`500 ${s.headline}px ${Ce}`,fa.forEach((g,C)=>{a.fillText(g,o,s.headlineY+C*s.headlineGap)});const c=o-s.card/2;a.fillStyle="#ffffff",qt(a,c,s.cardY,s.card,s.card,s.cardRadius),a.fill();const h=s.card-s.cardPad*2,m=await bs(t.url,h),w=Math.min(m.width,h);return a.drawImage(m,o-w/2,s.cardY+s.card/2-w/2,w,w),a.fillStyle="#ffffff",a.font=`700 ${s.codeSize}px ${ha}`,a.fillText(t.code,o,s.codeY),a.fillStyle="rgba(255,255,255,0.85)",a.font=`400 ${s.urlSize}px ${Ce}`,a.fillText(_s(t.url),o,s.urlY),a.font=`500 ${s.footSize}px ${Ce}`,a.fillText(xa,o,s.footY),new Promise((g,C)=>{r.toBlob(d=>d?g(d):C(new Error("Could not export the image")),"image/png")})}const Je=612,_e=54;async function ja(t){const{jsPDF:n}
29=await Os(async()=>{const{jsPDF:o}=await import("./jspdf.es.min-DzBf_Ezd.js").then(l=>l.j);return{jsPDF:o}},__vite__mapDeps([0,1,2])),s=new n({unit:"pt",format:"letter",orientation:"portrait"}),r=Je/2;s.setTextColor("#000000"),s.setFont("helvetica","bold"),s.setFontSize(30),s.text(vs,r,104,{align:"center"}),s.setFont("helvetica","normal"),s.setFontSize(12),s.text("Study guides, flashcards and quizzes from your own notes",r,128,{align:"center"}),s.setDrawColor("#000000"),s.setLineWidth(1),s.line(_e,156,Je-_e,156),s.setFont("helvetica","bold"),s.setFontSize(34),s.text("Join me on Tutoremy AI",r,212,{align:"center"}),s.setFont("helvetica","normal"),s.setFontSize(14),s.text("Scan the code - we both get bonus credits",r,240,{align:"center"});const a=300,i=await bs(t.url,900);return s.addImage(i.src,"PNG",r-a/2,276,a,a,void 0,"FAST"),s.setFont("courier","bold"),s.setFontSize(28),s.text(t.code,r,630,{align:"center"}),s.setFont("helvetica","normal"),s.setFontSize(15),s.text(_s(t.url),r,660,{align:"center"}),s.setLineWidth(.5),s.line(_e,700,Je-_e,700),s.setFontSize(10),s.text("Or enter the code above when you sign up.",r,722,{align:"center"}),s.output("blob")}function zt(t,n){const s=URL.createObjectURL(t),r=document.createElement("a");r.href=s,r.download=n,document.body.appendChild(r),r.click(),r.remove(),setTimeout(()=>URL.revokeObjectURL(s),1e4)}function ya(){if(typeof navigator>"u"||!navigator.canShare||!navigator.share)return!1;try{return navigator.canShare({files:[new File([new Blob([""],{type:"image/png"})],"probe.png",{type:"image/png"})]})}catch{return!1}}function Na({url:t,code:n}){const s=W(),r=v.useMemo(()=>({url:t,code:n}),[t,n]),[a,i]=v.useState(null),[o,l]=v.useState(!1),[c,h]=v.useState(null),m=v.useMemo(ya,[]);v.useEffect(()=>{let d=!1,y=null;return $e(r,"square").then(N=>{d||(y=URL.createObjectURL(N),i(y),l(!1))}).catch(()=>{d||l(!0)}),()=>{d=!0,y&&URL.revokeObjectURL(y)}},[r]);const w=r.code.toLowerCase(),x=async d=>{h(d);try{const y=await $e(r,d);zt(y,`tutoremy-${w}-${d}.png`)}catch{s.error("Could not generate the image")}finally{h(null)}},g=async()=>{h("pdf");try{const d=await ja(r);zt(d,`tutoremy-${w}-flyer.pdf`)}catch{s.error("Could not generate the PDF")}finally{h(null)}},C=async()=>{h("share");try{const d=await $e(r,"square"),y=new File([d],`tutoremy-${w}.png`,{type:"image/png"});await navigator.share({files:[y],title:"Tutoremy AI",text:`Join me on Tutoremy AI â use code ${r.code}`})}catch(d){(d==null?void 0:d.name)!=="AbortError"&&s.error("Could not open the share sheet")}finally{h(null)}};return e.jsxs(F,{children:[e.jsxs(R,{children:[e.jsxs(I,{className:"text-base flex items-center gap-2",children:[e.jsx(Bt,{className:"h-4 w-4"}),"QR Code & Poster"]}),e.jsx(Q,{children:"Post the image to Instagram or a group chat, or print the flyer and pin it up â both carry a QR code that signs people up under your link."})]}),e.jsx(B,{className:"space-y-4",children:e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-start",children:[e.jsx("div",{className:"mx-auto w-40 shrink-0 sm:mx-0",children:a?e.jsx("img",{src:a,alt:`Referral card for code ${r.code}`,className:"w-40 rounded-lg border shadow-sm"}):e.jsx("div",{className:"flex aspect-square w-40 items-center justify-center rounded-lg border bg-muted",children:o?e.jsx(Bt,{className:"h-8 w-8 text-muted-foreground"}):e.jsx(k,{className:"h-5 w-5 animate-spin text-muted-foreground"})})}),e.jsxs("div",{className:"flex flex-1 flex-col gap-2",children:[m&&e.jsxs(E,{onClick:C,disabled:c!==null,className:"gap-2",children:[c==="share"?e.jsx(k,{className:"h-4 w-4 animate-spin"}):e.jsx(cn,{className:"h-4 w-4"}),"Share image"]}),e.jsxs(E,{variant:"outline",onClick:()=>x("square"),disabled:c!==null,className:"gap-2",children:[c==="square"?e.jsx(k,{className:"h-4 w-4 animate-spin"}):e.jsx(xe,{className:"h-4 w-4"}),"Download square (post)"]}),e.jsxs(E,{variant:"outline",onClick:()=>x("story"),disabled:c!==null,className:"gap-2",children:[c==="story"?e.jsx(k,{className:"h-4 w-4 animate-spin"}):e.jsx(xe,{className:"h-4 w-4"}),"Download story (9:16)"]}),e.jsxs(E,{variant:"outline",onClick:g,disabled:c!==null,className:"gap-2",children:[c==="pdf"?e.jsx(k,{className:"h-4 w-4 animate-spin"}):e.jsx(Wt,{className:"h-4 w-4"}),"Download printable flyer (PDF)"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:m?"Share opens your phoneâs share sheet â pick Instagram, WhatsApp or Messages.":"Download the image, then post it from your phone. The flyer prints black-and-white on US Letter."})]})]})})]})}function wa(t){const n=va(t),s=v.forwardRef((r,a)=>{const{children:i,...o}=r,l=v.Children.toArray(i),c=l.find(Ca);if(c){const h=c.props.children,m=l.map(w=>w===c?v.Children.count(h)>1?v.Children.only(null):v.isValidElement(h)?h.props.children:null:w);return e.jsx(n,{...o,ref:a,children:v.isValidElement(h)?v.cloneElement(h,void 0,m):null})}return e.jsx(n,{...o,ref:a,children:i})});return s.displayName=`${t}.Slot`,s}function va(t){const n=v.forwardRef((s,r)=>{const{children:a,...i}=s;
vendor: 4,256 bytes, line 29
29if(v.isValidElement(a)){const o=Pa(a),l=_a(i,a.props);return a.type!==v.Fragment&&(l.ref=r?Us(r,o):o),v.cloneElement(a,l)}return v.Children.count(a)>1?v.Children.only(null):null});return n.displayName=`${t}.SlotClone`,n}var ba=Symbol("radix.slottable");function Ca(t){return v.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===ba}function _a(t,n){const s={...n};for(const r in n){const a=t[r],i=n[r];/^on[A-Z]/.test(r)?a&&i?s[r]=(...l)=>{const c=i(...l);return a(...l),c}:a&&(s[r]=a):r==="style"?s[r]={...a,...i}:r==="className"&&(s[r]=[a,i].filter(Boolean).join(" "))}return{...t,...s}}function Pa(t){var r,a;let n=(r=Object.getOwnPropertyDescriptor(t.props,"ref"))==null?void 0:r.get,s=n&&"isReactWarning"in n&&n.isReactWarning;return s?t.ref:(n=(a=Object.getOwnPropertyDescriptor(t,"ref"))==null?void 0:a.get,s=n&&"isReactWarning"in n&&n.isReactWarning,s?t.props.ref:t.props.ref||t.ref)}var De="Popover",[Ps]=Ys(De,[$t]),Ne=$t(),[Sa,te]=Ps(De),Ss=t=>{const{__scopePopover:n,children:s,open:r,defaultOpen:a,onOpenChange:i,modal:o=!1}=t,l=Ne(n),c=v.useRef(null),[h,m]=v.useState(!1),[w,x]=qs({prop:r,defaultProp:a??!1,onChange:i,caller:De});return e.jsx(sn,{...l,children:e.jsx(Sa,{scope:n,contentId:zs(),triggerRef:c,open:w,onOpenChange:x,onOpenToggle:v.useCallback(()=>x(g=>!g),[x]),hasCustomAnchor:h,onCustomAnchorAdd:v.useCallback(()=>m(!0),[]),onCustomAnchorRemove:v.useCallback(()=>m(!1),[]),modal:o,children:s})})};Ss.displayName=De;var Es="PopoverAnchor",Ea=v.forwardRef((t,n)=>{const{__scopePopover:s,...r}=t,a=te(Es,s),i=Ne(s),{onCustomAnchorAdd:o,onCustomAnchorRemove:l}=a;return v.useEffect(()=>(o(),()=>l()),[o,l]),e.jsx(Vt,{...i,...r,ref:n})});Ea.displayName=Es;var As="PopoverTrigger",Ms=v.forwardRef((t,n)=>{const{__scopePopover:s,...r}=t,a=te(As,s),i=Ne(s),o=Yt(n,a.triggerRef),l=e.jsx(Ht.button,{type:"button","aria-haspopup":"dialog","aria-expanded":a.open,"aria-controls":a.contentId,"data-state":Is(a.open),...r,ref:o,onClick:ue(t.onClick,a.onOpenToggle)});return a.hasCustomAnchor?l:e.jsx(Vt,{asChild:!0,...i,children:l})});Ms.displayName=As;var wt="PopoverPortal",[Aa,Ma]=Ps(wt,{forceMount:void 0}),ks=t=>{const{__scopePopover:n,forceMount:s,children:r,container:a}=t,i=te(wt,n);return e.jsx(Aa,{scope:n,forceMount:s,children:e.jsx(Gt,{present:s||i.open,children:e.jsx(Ks,{asChild:!0,container:a,children:r})})})};ks.displayName=wt;var ce="PopoverContent",Ts=v.forwardRef((t,n)=>{const s=Ma(ce,t.__scopePopover),{forceMount:r=s.forceMount,...a}=t,i=te(ce,t.__scopePopover);return e.jsx(Gt,{present:r||i.open,children:i.modal?e.jsx(Ta,{...a,ref:n}):e.jsx(Fa,{...a,ref:n})})});Ts.displayName=ce;var ka=wa("PopoverContent.RemoveScroll"),Ta=v.forwardRef((t,n)=>{const s=te(ce,t.__scopePopover),r=v.useRef(null),a=Yt(n,r),i=v.useRef(!1);return v.useEffect(()=>{const o=r.current;if(o)return Hs(o)},[]),e.jsx(Gs,{as:ka,allowPinchZoom:!0,children:e.jsx(Fs,{...t,ref:a,trapFocus:s.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:ue(t.onCloseAutoFocus,o=>{var l;o.preventDefault(),i.current||(l=s.triggerRef.current)==null||l.focus()}),onPointerDownOutside:ue(t.onPointerDownOutside,o=>{const l=o.detail.originalEvent,c=l.button===0&&l.ctrlKey===!0,h=l.button===2||c;i.current=h},{checkForDefaultPrevented:!1}),onFocusOutside:ue(t.onFocusOutside,o=>o.preventDefault(),{checkForDefaultPrevented:!1})})})}),Fa=v.forwardRef((t,n)=>{const s=te(ce,t.__scopePopover),r=v.useRef(!1),a=v.useRef(!1);return e.jsx(Fs,{...t,ref:n,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:i=>{var o,l;(o=t.onCloseAutoFocus)==null||o.call(t,i),i.defaultPrevented||(r.current||(l=s.triggerRef.current)==null||l.focus(),i.preventDefault()),r.current=!1,a.current=!1},onInteractOutside:i=>{var c,h;(c=t.onInteractOutside)==null||c.call(t,i),i.defaultPrevented||(r.current=!0,i.detail.originalEvent.type==="pointerdown"&&(a.current=!0));const o=i.target;((h=s.triggerRef.current)==null?void 0:h.contains(o))&&i.preventDefault(),i.detail.originalEvent.type==="focusin"&&a.current&&i.preventDefault()}})}),Fs=v.forwardRef((t,n)=>{const{__scopePopover:s,trapFocus:r,onOpenAutoFocus:a,onCloseAutoFocus:i,disableOutsidePointerEvents:o,onEscapeKeyDown:l,onPointerDownOutside:c,onFocusOutside:h,onInteractOutside:m,...w}
29=t,x=te(ce,s),g=Ne(s);return Qs(),e.jsx(Vs,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:a,onUnmountAutoFocus:i,children:e.jsx($s,{asChild:!0,disableOutsidePointerEvents:o,onInteractOutside:m,onEscapeKeyDown:l,onPointerDownOutside:c,onFocusOutside:h,onDismiss:()=>x.onOpenChange(!1),children:e.jsx(nn,{"data-state":Is(x.open),role:"dialog",id:x.contentId,...g,...w,ref:n,style:{...w.style,"--radix-popover-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-popover-content-available-width":"var(--radix-popper-available-width)","--radix-popover-content-available-height":"var(--radix-popper-available-height)","--radix-popover-trigger-width":"var(--radix-popper-anchor-width)","--radix-popover-trigger-height":"var(--radix-popper-anchor-height)"}})})})}),Rs="PopoverClose",Ra=v.forwardRef((t,n)=>{const{__scopePopover:s,...r}=t,a=te(Rs,s);return e.jsx(Ht.button,{type:"button",...r,ref:n,onClick:ue(t.onClick,()=>a.onOpenChange(!1))})});Ra.displayName=Rs;var Ia="PopoverArrow",Ba=v.forwardRef((t,n)=>{const{__scopePopover:s,...r}=t,a=Ne(s);return e.jsx(an,{...a,...r,ref:n})});Ba.displayName=Ia;function Is(t){return t?"open":"closed"}var La=Ss,Da=Ms,Oa=ks,Bs=Ts;const Ua=La,qa=Da,Ls=v.forwardRef(({className:t,align:n="center",sideOffset:s=4,...r},a)=>e.jsx(Oa,{children:e.jsx(Bs,{ref:a,align:n,sideOffset:s,className:Js("z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",t),...r})}));Ls.displayName=Bs.displayName;function at(t){if(t===0)return"0 B";const n=1024,s=["B","KB","MB","GB","TB"],r=Math.floor(Math.log(t)/Math.log(n));return`${parseFloat((t/Math.pow(n,r)).toFixed(1))} ${s[r]}`}function _(t){return t.toLocaleString()}function de(t){return t>=80?"[&>div]:bg-red-500":t>=50?"[&>div]:bg-yellow-500":"[&>div]:bg-green-500"}function Pe(t){if(!t)return null;const n=new Date(t);if(isNaN(n.getTime()))return null;const s=new Date,r=n.getTime()-s.getTime();if(r<=0)return"Resets soon";const a=Math.floor(r/(1e3*60*60*24)),i=Math.floor(r%(1e3*60*60*24)/(1e3*60*60));return a>1?`Resets in ${a} days`:a===1?`Resets in 1 day, ${i}h`:i>0?`Resets in ${i}h`:"Resets soon"}const za={free_tier:{icon:e.jsx(ge,{className:"h-5 w-5"})},basic_tier:{icon:e.jsx(it,{className:"h-5 w-5"})},beta:{icon:e.jsx(Jt,{className:"h-5 w-5"})},pro_tier:{icon:e.jsx(dn,{className:"h-5 w-5"})},alpha:{icon:e.jsx(es,{className:"h-5 w-5"})},owner:{icon:e.jsx(as,{className:"h-5 w-5"})}};function Ka(t){var r;const n=[];n.push(un(t.max_guides,"guide"));const s=Ue(t.max_resources_per_guide)?"Unlimited resources per guide":`${t.max_resources_per_guide} resource${t.max_resources_per_guide===1?"":"s"} per guide`;if((r=t.allowed_resource_types)!=null&&r.length){const a=t.allowed_resource_types.map(i=>i==="youtube"?"YouTube videos":`${i}s`).join(", ");n.push(`${s}: ${a}`)}else n.push(s);return t.youtube_max_duration_minutes&&n.push(`YouTube videos up to ${t.youtube_max_duration_minutes} minutes watched in full`),n.push(Ue(t.max_storage_mb)?"Unlimited storage":`${Ee(t.max_storage_mb)} total storage`),n.push(Ue(t.max_file_size_mb)?"No file size limit":`${t.max_file_size_mb} MB max file size`),n.push("All study material types"),n.push("AI-generated images"),n}const Ya=["free_tier","basic_tier","beta","pro_tier","alpha","owner"];function ne(t){return Ya.indexOf(t)}function Ha(t){return{visa:"Visa",mastercard:"Mastercard",amex:"Amex",other:"Card"}[t]||"Card"}const Kt=["general","usage","plan","billing","notifications","security","referrals","feedback"];function Rr(){const[t,n]=Ws(),s=t.get("tab"),[r,a]=v.useState(s&&Kt.includes(s)?s:"general"),i=m=>{a(m),n({tab:m},{replace:!0})};v.useEffect(()=>{const m=t.get("tab");m&&Kt.includes(m)&&m!==r&&a(m)},[t]);const{data:o,isLoading:l}=U({queryKey:["usage-dashboard"],queryFn:()=>T.dashboard().then(m=>m.data)}),{data:c}=U({queryKey:["profile"],queryFn:()=>fe.get().then(m=>m.data),staleTime:5*60*1e3}),h=[{id:"general",label:"General",icon:e.jsx(pn,{className:"h-4 w-4"})},{id:"usage",label:"Usage",icon:e.jsx(gn,{className:"h-4 w-4"})},{id:"plan",label:"Plan",icon:e.jsx(ge,{className:"h-4 w-4"})},{id:"billing",label:"Billing",icon:e.jsx(me,{className:"h-4 w-4"})},{id:"notifications",label:"Notifications",icon:e.jsx(rs,{className:"h-4 w-4"})},{id:"security",label:"Security",icon:e.jsx(Jt,{className:"h-4 w-4"})},{id:"referrals",label:"Referrals",icon:e.jsx(ts,{className:"h-4 w-4"})},{id:"feedback",label:"Feedback",icon:e.jsx(ht,{className:"h-4 w-4"})}];return e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx(rn,{}),e.jsxs("div",{className:"container py-4 md:py-8",children:[e.jsx("h1",{className:"text-2xl font-bold mb-6",children:"Settings"}),e.jsxs("div",{className:"flex flex-col md:flex-row md:gap-8",children:[e.jsx("nav",{className:"md:w-48 md:shrink-0",children:e.jsx("div",{className:"flex flex-row overflow-x-auto gap-1 border-b pb-2 mb-4 md:flex-col md:border-b-0 md:pb-0 md:mb-0",children:h.map(m=>e.jsxs(E,{variant:r===m.id?"secondary":"ghost",className:"justify-start gap-2 shrink-0",onClick:()=>i(m.id),children:[m.icon,m.label]},m.id))})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[r==="general"&&e.jsx(Ga,{}),r==="usage"&&e.jsx(Va,{dashboard:o,isLoading:l,isAdmin:(c==null?void 0:c.is_admin)??!1}),r==="plan"&&e.jsx(Xa,{}),r==="billing"&&e.jsx(tr,{}),r==="notifications"&&e.jsx(rr,{}),r==="security"&&e.jsx(sr,{}),r==="referrals"&&e.jsx(nr,{}),r==="feedback"&&e.jsx(ir,{})]})]})]})]})}function Ga(){const{colorScheme:t,setColorScheme:n}=Zs(),[s,r]=v.useState(!1),a=X(),{data:i}=U({queryKey:["profile"],queryFn:()=>fe.get().then(w=>
29w.data)}),o=(i==null?void 0:i.image_generation)??!0,l=w=>{a.setQueryData(["profile"],x=>x&&{...x,image_generation:w}),fe.update({image_generation:w})},c=i==null?void 0:i.enabled_themes,h=qe.find(w=>w.id===t)??qe[0],m=qe.filter(w=>w.id!==t&&(!c||c.includes(w.id)));return e.jsxs("div",{className:"space-y-6",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"General"}),e.jsxs(F,{children:[e.jsxs(R,{children:[e.jsxs(I,{className:"text-base flex items-center gap-2",children:[e.jsx(on,{className:"h-4 w-4"}),"App"]}),e.jsx(Q,{children:"Configure application behavior"})]}),e.jsx(B,{children:e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx(xe,{className:"h-5 w-5 text-muted-foreground shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-medium",children:"Image Generation"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Generate visual aids for flashcards and memory joggers using AI"})]})]}),e.jsx(Me,{checked:o,onCheckedChange:l,className:"shrink-0"})]})})]}),e.jsxs(F,{children:[e.jsxs(R,{children:[e.jsxs(I,{className:"text-base flex items-center gap-2",children:[e.jsx(Tt,{className:"h-4 w-4"}),"Theme"]}),e.jsx(Q,{children:"Choose a color scheme for the app"})]}),e.jsx(B,{children:e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx(ze,{colors:h.colors,size:24}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-medium",children:h.name}),e.jsx("p",{className:"text-xs text-muted-foreground",children:h.description})]})]}),e.jsxs(Ua,{open:s,onOpenChange:r,children:[e.jsx(qa,{asChild:!0,children:e.jsxs(E,{variant:"outline",size:"sm",className:"gap-2",children:[e.jsx(Tt,{className:"h-4 w-4"}),"Change"]})}),e.jsx(Ls,{className:"w-64 p-2",align:"end",children:e.jsxs("div",{className:"space-y-1",children:[e.jsxs("button",{className:"flex w-full items-center gap-3 rounded-md px-3 py-2 text-left bg-secondary",disabled:!0,children:[e.jsx(ze,{colors:h.colors}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsx("p",{className:"text-sm font-medium",children:h.name})}),e.jsx(ft,{className:"h-4 w-4 text-primary shrink-0"})]}),m.map(w=>e.jsxs("button",{className:"flex w-full items-center gap-3 rounded-md px-3 py-2 text-left hover:bg-muted transition-colors",onClick:()=>{n(w.id),r(!1)},children:[e.jsx(ze,{colors:w.colors}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsx("p",{className:"text-sm font-medium",children:w.name})})]},w.id))]})})]})]})})]})]})}function Qa(){const t=Qt(),{data:n}=U({queryKey:["plans"],queryFn:()=>T.plans().then(r=>r.data)});return(n==null?void 0:n.payments_enabled)??!1?e.jsxs("div",{className:"flex gap-3",children:[e.jsxs(E,{className:"flex-1 gap-2",onClick:()=>t("/settings?tab=plan"),children:[e.jsx(as,{className:"h-4 w-4"}),"Upgrade Plan"]}),e.jsxs(E,{variant:"outline",className:"flex-1 gap-2",onClick:()=>t("/settings?tab=plan#credits"),children:[e.jsx(ss,{className:"h-4 w-4"}),"Buy Credits"]})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"Paid plans and credit purchases are coming soon."})}function Va({dashboard:t,isLoading:n,isAdmin:s}){var d,y,N,p;const[r,a]=v.useState(!1);if(n)return e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(k,{className:"h-6 w-6 animate-spin text-muted-foreground"})});const i=t==null?void 0:t.weekly,o=t==null?void 0:t.monthly,l=t==null?void 0:t.all_time_stats,c=(i==null?void 0:i.effective_limit)??(i==null?void 0:i.limit)??0,h=(i==null?void 0:i.bonus_credits)??0,m=i?Math.min(i.total_credits/c*100,100):0,w=(o==null?void 0:o.effective_limit)??(o==null?void 0:o.limit)??0,x=(o==null?void 0:o.bonus_credits)??0,g=o?Math.min(o.total_credits/w*100,100):0,C=[{label:"Guides Created",value:_((l==null?void 0:l.guides_created)??0),icon:e.jsx(Wt,{className:"h-5 w-5 text-blue-500"})},{label:"Files Uploaded",value:_((l==null?void 0:l.files_uploaded)??0),icon:e.jsx(Xt,{className:"h-5 w-5 text-green-500"})},{label:"Recordings Made",value:_((l==null?void 0:l.recordings_made)??0),icon:e.jsx(Zt,{className:"h-5 w-5 text-red-500"})},{label:"Storage Used",value:at((l==null?void 0:l.total_file_size)??0),icon:e.jsx(Ft,{className:"h-5 w-5 text-purple-500"})},{label:"Processing Runs",value:_((l==null?void 0:l.processing_runs)??
290),icon:e.jsx(ge,{className:"h-5 w-5 text-yellow-500"})},{label:"AI Tokens Used",value:_((l==null?void 0:l.ai_tokens_used)??0),icon:e.jsx(it,{className:"h-5 w-5 text-orange-500"})},{label:"Chat Messages",value:_((l==null?void 0:l.chat_messages_sent)??0),icon:e.jsx(ht,{className:"h-5 w-5 text-cyan-500"})},{label:"Images Generated",value:_((l==null?void 0:l.images_generated)??0),icon:e.jsx(xe,{className:"h-5 w-5 text-pink-500"})}];return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Usage"}),e.jsxs(Y,{variant:"secondary",children:[(t==null?void 0:t.plan_display_name)??"Free"," Plan"]})]}),e.jsxs(F,{children:[e.jsx(R,{className:"pb-2",children:e.jsx(I,{className:"text-base",children:"Credits"})}),e.jsx(B,{className:"space-y-5",children:(d=t==null?void 0:t.trial)!=null&&d.trial_enabled&&((y=t==null?void 0:t.trial)!=null&&y.trial_expired)?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-lg border border-red-500/30 bg-red-500/10 p-4 space-y-2",children:[e.jsx("p",{className:"text-sm font-semibold text-red-600 dark:text-red-400",children:"Free Trial Expired"}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Your ",t.trial.trial_days,"-day free trial ended on"," ",t.trial.trial_end_date?new Date(t.trial.trial_end_date).toLocaleDateString():"N/A",". Upgrade your plan or purchase credits to continue using the app."]})]}),e.jsx(Qa,{})]}):(N=t==null?void 0:t.trial)!=null&&N.trial_enabled&&!((p=t==null?void 0:t.trial)!=null&&p.trial_expired)?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("p",{className:"text-sm font-medium text-muted-foreground",children:["Trial Period (",t.trial.trial_days," days)"]}),e.jsx(ae,{value:g,className:`h-3 ${de(g)}`}),e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsxs("span",{className:"text-muted-foreground",children:[_(Math.round((o==null?void 0:o.total_credits)??0))," / ",_(w)]}),e.jsxs("span",{className:"font-medium",children:[Math.round(g),"%"]})]}),x>0&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["(includes ",(()=>{const u=o==null?void 0:o.bonus_credits_breakdown;if(!u)return`${_(x)} extra credits`;const f=[];return u.purchased>0&&f.push(`${_(u.purchased)} purchased`),u.referral>0&&f.push(`${_(u.referral)} referral`),u.admin>0&&f.push(`${_(u.admin)} bonus`),f.length>0?f.join(", "):`${_(x)} extra credits`})(),")"]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[Math.max(t.trial.trial_days-t.trial.account_age_days,0)," day(s) remaining"]})]}),x>0&&(()=>{const u=(o==null?void 0:o.limit)??0,f=Math.round((o==null?void 0:o.total_credits)??0),S=Math.min(Math.max(f-u,0),x),P=o==null?void 0:o.bonus_credits_breakdown;return e.jsxs(e.Fragment,{children:[e.jsx(H,{}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"Extra Credits"}),e.jsxs("p",{className:"text-sm",children:[e.jsx("span",{className:"font-medium",children:_(S)}),e.jsx("span",{className:"text-muted-foreground",children:" used out of "}),e.jsx("span",{className:"font-medium",children:_(x)})]}),P&&(P.purchased>0||P.referral>0||P.admin>0)&&e.jsxs("div",{className:"text-xs text-muted-foreground space-y-0.5 mt-1",children:[P.purchased>0&&e.jsxs("p",{children:["Purchased: ",_(P.purchased)," (expires at month end)"]}),P.referral>0&&e.jsxs("p",{children:["Referral: ",_(P.referral)," (30-day)"]}),P.admin>0&&e.jsxs("p",{children:["Bonus: ",_(P.admin)," (this month)"]})]})]})]})})()]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"Weekly"}),e.jsx(ae,{value:m,className:`h-3 ${de(m)}`}),e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsxs("span",{className:"text-muted-foreground",children:[_(Math.round((i==null?void 0:i.total_credits)??0))," / ",_(c)]}),e.jsxs("span",{className:"font-medium",children:[Math.round(m),"%"]})]}),h>0&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["(includes ",(()=>{const u=i==null?void 0:i.bonus_credits_breakdown;if(!u)return`${_(h)} extra credits`;const f=[];return u.purchased>0&&f.push(`${_(u.purchased)} purchased`),u.referral>0&&f.push(`${_(u.referral)} referral`),u.admin>0&&f.push(`${_(u.admin)} bonus`),f.length>0?f.join(", "):`${_(h)} extra credits`})(),")"]}),Pe(i==null?void 0:i.window_end)&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:[Pe(i==null?void 0:i.window_end)," (every Monday midnight PT)"]})]}),e.jsx(H,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"Monthly"}),e.jsx(ae,{value:g,className:`h-3 ${de(g)}`}),e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsxs("span",{className:"text-muted-foreground",children:[_(Math.round((o==null?void 0:o.total_credits)??0))," / ",_(w)]}),e.jsxs("span",{className:"font-medium",children:[Math.round(g),"%"]})]}),x>0&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["(includes ",(()=>{const u=o==null?void 0:o.bonus_credits_breakdown;if(!u)return`${_(x)} extra credits`;const f=[];return u.purchased>0&&f.push(`${_(u.purchased)} purchased`),u.referral>0&&f.push(`${_(u.referral)} referral`),u.admin>0&&f.push(`${_(u.admin)} bonus`),f.length>0?f.join(", "):`${_(x)} extra credits`})(),")"]}),Pe(o==null?void 0:o.window_end)&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:[Pe(o==null?void 0:o.window_end)," (1st of each month, midnight PT)"]})]}),x>0&&(()=>{const u=(o==null?void 0:o.limit)??0,f=Math.round((o==null?void 0:o.total_credits)??0),S=Math.min(Math.max(f-u,0),x),P=o==null?void 0:o.bonus_credits_breakdown;return e.jsxs(e.Fragment,{children:[e.jsx(H,{}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"Extra Credits"}),e.jsxs("p",{className:"text-sm",children:[e.jsx("span",{className:"font-medium",children:_(S)}),e.jsx("span",{className:"text-muted-foreground",children:" used out of "}),e.jsx("span",{className:"font-medium",children:_(x)})]}),P&&(P.purchased>0||P.referral>0||P.admin>0)&&e.jsxs("div",{className:"text-xs text-muted-foreground space-y-0.5 mt-1",children:[P.purchased>0&&e.jsxs("p",{children:["Purchased: ",_(P.purchased)," (expires at month end)"]}
29),P.referral>0&&e.jsxs("p",{children:["Referral: ",_(P.referral)," (30-day)"]}),P.admin>0&&e.jsxs("p",{children:["Bonus: ",_(P.admin)," (this month)"]})]})]})]})})()]})})]}),(t==null?void 0:t.plan_limits)&&(()=>{const u=t.plan_limits,f=u.current_storage_bytes/(1024*1024),S=u.max_storage_mb>0?Math.min(f/u.max_storage_mb*100,100):0,P=u.max_guides>0?Math.min(u.current_guides/u.max_guides*100,100):0;return e.jsxs(F,{children:[e.jsx(R,{className:"pb-2",children:e.jsx(I,{className:"text-base",children:"Plan Limits"})}),e.jsxs(B,{className:"space-y-5",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(jn,{className:"h-4 w-4 text-blue-500"}),e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"Guides"})]}),u.max_guides>0?e.jsxs(e.Fragment,{children:[e.jsx(ae,{value:P,className:`h-3 ${de(P)}`}),e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsxs("span",{className:"text-muted-foreground",children:[u.current_guides," / ",u.max_guides," guides"]}),e.jsxs("span",{className:"font-medium",children:[Math.round(P),"%"]})]})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"Unlimited"})]}),e.jsx(H,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ft,{className:"h-4 w-4 text-purple-500"}),e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"Total Storage"})]}),u.max_storage_mb>0?e.jsxs(e.Fragment,{children:[e.jsx(ae,{value:S,className:`h-3 ${de(S)}`}),e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsxs("span",{className:"text-muted-foreground",children:[at(u.current_storage_bytes)," / ",Ee(u.max_storage_mb)]}),e.jsxs("span",{className:"font-medium",children:[Math.round(S),"%"]})]})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"Unlimited"})]}),e.jsx(H,{}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(yn,{className:"h-4 w-4 text-orange-500"}),e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"Per-Guide Limits"})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3",children:[e.jsxs("div",{className:"rounded-lg border p-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Max File Size"}),e.jsx("p",{className:"text-sm font-semibold mt-0.5",children:Ee(u.max_file_size_mb)})]}),e.jsxs("div",{className:"rounded-lg border p-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Guide Storage"}),e.jsx("p",{className:"text-sm font-semibold mt-0.5",children:Ee(u.max_guide_storage_mb)})]}),e.jsxs("div",{className:"rounded-lg border p-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Resources / Guide"}),e.jsx("p",{className:"text-sm font-semibold mt-0.5",children:u.max_resources_per_guide>0?u.max_resources_per_guide:"Unlimited"})]})]})]})]})]})})(),e.jsxs(F,{children:[e.jsx(R,{className:"pb-2",children:e.jsx(I,{className:"text-base",children:"Credits Breakdown"})}),e.jsxs(B,{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-muted-foreground mb-2",children:"This Week"}),e.jsxs("div",{className:"flex flex-wrap gap-4 text-sm",children:[e.jsxs("span",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Processing:"})," ",e.jsx("span",{className:"font-medium",children:_(Math.round((i==null?void 0:i.credits_from_processing)??0))})]}),e.jsxs("span",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Chats:"})," ",e.jsx("span",{className:"font-medium",children:_(Math.round((i==null?void 0:i.credits_from_tokens)??0))})]}),e.jsxs("span",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Recordings:"})," ",e.jsx("span",{className:"font-medium",children:_(Math.round((i==null?void 0:i.credits_from_recordings)??0))})]}),e.jsxs("span",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Files:"})," ",e.jsx("span",{className:"font-medium",children:_(Math.round((i==null?void 0:i.credits_from_files)??0))})]}),e.jsxs("span",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Images:"})," ",e.jsx("span",{className:"font-medium",children:_(Math.round((i==null?void 0:i.credits_from_images)??0))})]})]})]}),e.jsx(H,{}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-muted-foreground mb-2",children:"This Month"}),e.jsxs("div",{className:"flex flex-wrap gap-4 text-sm",children:[e.jsxs("span",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Processing:"})," ",e.jsx("span",{className:"font-medium",children:_(Math.round((o==null?void 0:o.credits_from_processing)??0))})]}),e.jsxs("span",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Chats:"})," ",e.jsx("span",{className:"font-medium",children:_(Math.round((o==null?void 0:o.credits_from_tokens)??0))})]}),e.jsxs("span",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Files:"})," ",e.jsx("span",{className:"font-medium",children:_(Math.round((o==null?void 0:o.credits_from_files)??0))})]}),e.jsxs("span",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Recordings:"})," ",e.jsx("span",{className:"font-medium",children:_(Math.round((o==null?void 0:o.credits_from_recordings)??0))})]}),e.jsxs("span",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Images:"})," ",e.jsx("span",{className:"font-medium",children:_(Math.round((o==null?void 0:o.credits_from_images)??0))})]})]})]})]})]}),e.jsx(Za,{}),s&&e.jsxs(mn,{open:r,onOpenChange:a,children:[e.jsx(hn,{asChild:!0,children:e.jsxs(E,{variant:"ghost",className:"flex items-center gap-2 w-full justify-between px-4",children:[e.jsx("span",{className:"text-sm font-medium",children:"Detailed Metrics"}),e.jsx(Ze,{className:`h-4 w-4 transition-transform ${r?"rotate-180":""}`})]})}),e.jsx(fn,{children:e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4 pt-4",children:C.map(u=>e.jsxs(F,{children:[e.jsxs(R,{className:"flex flex-row items-center justify-between pb-2",children:[e.jsx(I,{className:"text-sm font-medium text-muted-foreground",children:u.label}),u.icon]}),e.jsx(B,{children:e.jsx("p",{className:"text-2xl font-bold",children:u.value})})]},u.label))})})]})]})}const $a=[{key:"processing",label:"File processing",icon:ge,className:"text-yellow-500"},{key:"ai_chat",label:"AI chat",icon:it,className:"text-orange-500"},{key:"images",label:"Images",icon:xe,className:"text-pink-500"},{key:"audio",label:"Audio processing",icon:Zt,className:"text-red-500"},{key:"files",label:"Uploads",icon:Xt,className:"text-green-500"},{key:"reserved",label:"Reserved",icon:k,className:"text-muted-foreground"}];function Se(t){return t?new Date(t).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"}):"â"}function Ja(t){return t.title?t.title:t.state==="unattributed"?"E
29arlier usage":"Deleted guide"}const Ds=[{key:"week",label:"Week",days:7},{key:"month",label:"Month",days:30},{key:"sixMonths",label:"6 months",days:182},{key:"all",label:"All",days:null}],rt=5;function Wa(t,n,s,r=Date.now()){var h;const a=((h=Ds.find(m=>m.key===n))==null?void 0:h.days)??null,i=a===null?null:r-a*24*60*60*1e3,o=t.filter(m=>i===null?!0:m.last_activity_at?new Date(m.last_activity_at).getTime()>=i:!1).sort((m,w)=>w.total_credits-m.total_credits),l=t.length>rt,c=l&&!s?o.slice(0,rt):o;return{rows:c,filtered:o,needsControls:l,shownCredits:c.reduce((m,w)=>m+w.total_credits,0),isPartial:c.length<t.length}}function Za(){const t=Qt(),[n,s]=v.useState(null),[r,a]=v.useState("all"),[i,o]=v.useState(!1),{data:l,isLoading:c}=U({queryKey:["guide-credit-history"],queryFn:()=>T.guideCreditHistory().then(y=>y.data)}),h=(l==null?void 0:l.guides)??[],m=(l==null?void 0:l.total_credits)??0,{rows:w,filtered:x,needsControls:g,shownCredits:C,isPartial:d}=Wa(h,r,i);return e.jsxs(F,{children:[e.jsxs(R,{className:"pb-2",children:[e.jsx(I,{className:"text-base",children:"Credit History"}),e.jsx(Q,{children:"Credits used by each guide, for as long as you have had an account. Guides you have deleted stay listed, because the credits they used were still spent."})]}),e.jsx(B,{children:c?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(k,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):h.length===0?e.jsx("p",{className:"py-6 text-center text-sm text-muted-foreground",children:"No credits used yet. Create a guide to get started."}):e.jsxs("div",{className:"divide-y",children:[g&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2 pb-3",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Used in:"}),Ds.map(y=>e.jsx(E,{variant:r===y.key?"secondary":"ghost",size:"sm",className:"h-7 px-2.5 text-xs",onClick:()=>{a(y.key),s(null)},children:y.label},y.key))]}),w.length===0?e.jsx("p",{className:"py-6 text-center text-sm text-muted-foreground",children:"No guides used in this period."}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"hidden sm:grid grid-cols-[1fr_auto_auto] gap-4 pb-2 text-xs font-medium text-muted-foreground",children:[e.jsx("span",{children:"Guide"}),e.jsx("span",{className:"w-24 text-right",children:"Created"}),e.jsx("span",{className:"w-20 text-right",children:"Credits"})]}),w.map(y=>{const N=y.guide_id??"unattributed",p=n===N;return e.jsxs("div",{children:[e.jsxs("button",{type:"button",onClick:()=>s(p?null:N),"aria-expanded":p,className:"w-full py-3 text-left hover:bg-muted/50 transition-colors sm:grid sm:grid-cols-[1fr_auto_auto] sm:gap-4 sm:items-center",children:[e.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(Ze,{className:`h-4 w-4 shrink-0 text-muted-foreground transition-transform ${p?"rotate-180":"-rotate-90"}`}),e.jsx("span",{className:"truncate text-sm font-medium",children:Ja(y)}),y.state==="deleted"&&e.jsxs(Y,{variant:"outline",className:"shrink-0 gap-1 text-xs font-normal",children:[e.jsx(Ae,{className:"h-3 w-3"}),"Deleted"]}),y.state==="deleted_unknown"&&e.jsx(Y,{variant:"outline",className:"shrink-0 text-xs font-normal",children:"Deleted"}),y.state==="unattributed"&&e.jsx(Y,{variant:"secondary",className:"shrink-0 text-xs font-normal",children:"Not itemised"})]}),e.jsx("span",{className:"ml-6 mt-1 block text-xs text-muted-foreground sm:ml-0 sm:mt-0 sm:w-24 sm:text-right sm:text-sm",children:Se(y.created_at)}),e.jsx("span",{className:"ml-6 mt-1 block text-sm font-semibold sm:ml-0 sm:mt-0 sm:w-20 sm:text-right",children:_(Math.round(y.total_credits))})]}),p&&e.jsxs("div",{className:"pb-4 pl-6 space-y-4",children:[y.state==="unattributed"&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Credits used before we started recording which guide each action belonged to. They count towards your totals but cannot be split per guide."}),y.state==="deleted_unknown"&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"This guide was deleted before we started keeping a record of deleted guides, so its name and dates are no longer available."}),e.jsxs("div",{className:"grid grid-cols-2 gap-x-6 gap-y-1 text-xs sm:grid-cols-3",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Created: "}),e.jsx("span",{className:"font-medium",children:Se(y.created_at)})]}),y.deleted_at&&e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Deleted: "}),e.jsx("span",{className:"font-medium",children:Se(y.deleted_at)})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Last activity: "}),e.jsx("span",{className:"font-medium",children:Se(y.last_activity_at)})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:"Credits breakdown"}),$a.filter(u=>y.credits[u.key]>0).map(u=>{const f=u.icon,S=y.total_credits>0?y.credits[u.key]/y.total_credits*100:0;return e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(f,{className:`h-3.5 w-3.5 shrink-0 ${u.className}`}),e.jsx("span",{className:"w-32 shrink-0 text-muted-foreground",children:u.label}),e.jsx(ae,{value:S,className:"h-1.5 flex-1"}),e.jsx("span",{className:"w-12 text-right font-medium",children:_(Math.round(y.credits[u.key]))})]},u.key)}),y.total_credits===0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"No credits used."})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:"Activity"}),e.jsxs("div",{className:"flex flex-wrap gap-x-4 gap-y-1 text-xs text-muted-foreground",children:[e.jsxs("span",{children:[_(y.usage.processing_runs)," processing runs"]}),e.jsxs("span",{children:[_(y.usage.chat_messages)," chat messages"]}),e.jsxs("span",{children:[_(y.usage.ai_tokens)," AI tokens"]}),e.jsxs("span",{children:[_(y.usage.images_generated)," images"]}),e.jsxs("span",{children:[_(y.usage.files_uploaded)," files"]}),y.usage.total_bytes>0&&e.jsxs("span",{children:[at(y.usage.total_bytes)," uploaded"]})]})]}),y.state==="active"&&y.slug&&e.jsxs(E,{variant:"outline",size:"sm",className:"gap-2",onClick:()=>t(`/guide/${y.slug}`),children:["Open guide",e.jsx(Xe,{className:"h-3.5 w-3.5"})]})]})]},N)}),g&&x.length>rt&&e.jsx("div",{className:"pt-2",children:e.jsxs(E,{variant:"ghost",size:"sm",className:"w-full gap-2 text-xs",onClick:()=>o(!i),children:[e.jsx(Ze,{className:`h-3.5 w-3.5 transition-transform ${i?"rotate-180":""}`}),i?"Show fewer":`Show all ${_(x.length)} guides`]})}),e.jsxs("div",{className:"flex flex-wrap justify-between gap-2 pt-3 text-sm font-medium",children:[e.jsx("span",{children:d?`Showing ${_(w.length)} of ${_(h.length)}`:"Total"}),e.jsx("span",{children:d?e.jsxs(e.Fragment,{children:[e.jsx("span",{children:_(Math.round(C))}),e.jsxs("span",{className:"text-muted-foreground",children:[" ","of ",_(Math.round(m))," credits"]})]}):`${_(Math.round(m))} credits`})]})]})]})})]})}
29function vt({open:t,onOpenChange:n,onSuccess:s,title:r,description:a}){const i=X(),o=W(),[l,c]=v.useState(""),[h,m]=v.useState(""),[w,x]=v.useState(""),[g,C]=v.useState(""),d=O({mutationFn:p=>T.addPaymentMethod(p),onSuccess:p=>{o.success("billing","Payment method added"),i.invalidateQueries({queryKey:["payment-methods"]}),y(),n(!1),s==null||s(p.data)},onError:p=>{var u,f;o.error(((f=(u=p==null?void 0:p.response)==null?void 0:u.data)==null?void 0:f.error)||"Failed to add payment method")}}),y=()=>{c(""),m(""),x(""),C("")},N=()=>{const p=h.split("/"),u=parseInt(p[0],10);let f=parseInt(p[1],10);f<100&&(f+=2e3),d.mutate({card_number:l.replace(/\s/g,""),exp_month:u,exp_year:f,cardholder_name:g})};return e.jsx(ot,{open:t,onOpenChange:p=>{p||y(),n(p)},children:e.jsxs(lt,{className:"sm:max-w-md",children:[e.jsxs(ct,{children:[e.jsxs(dt,{className:"flex items-center gap-2",children:[e.jsx(me,{className:"h-5 w-5"}),r||"Add Payment Method"]}),a&&e.jsx(ut,{children:a})]}),e.jsxs("div",{className:"space-y-4 py-2",children:[e.jsxs("div",{className:"rounded-lg border bg-muted/50 p-3 flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(xt,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{children:"This is a demo payment form. No real charges will be made."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(q,{htmlFor:"pm-name",children:"Cardholder Name"}),e.jsx(G,{id:"pm-name",placeholder:"John Doe",value:g,onChange:p=>C(p.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(q,{htmlFor:"pm-card",children:"Card Number"}),e.jsx(G,{id:"pm-card",placeholder:"4242 4242 4242 4242",value:l,onChange:p=>{const f=p.target.value.replace(/\D/g,"").slice(0,16).replace(/(.{4})/g,"$1 ").trim();c(f)},inputMode:"numeric"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(q,{htmlFor:"pm-expiry",children:"Expiry"}),e.jsx(G,{id:"pm-expiry",placeholder:"MM/YY",value:h,onChange:p=>{const u=p.target.value;if(u.endsWith("/")&&u.length===3&&!h.includes("/")){m(u);return}const f=u.replace(/\D/g,"").slice(0,4);f.length>=3?m(f.slice(0,2)+"/"+f.slice(2)):m(f)},inputMode:"numeric"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(q,{htmlFor:"pm-cvc",children:"CVC"}),e.jsx(G,{id:"pm-cvc",placeholder:"123",value:w,onChange:p=>x(p.target.value)})]})]})]}),e.jsxs(mt,{children:[e.jsx(E,{variant:"outline",onClick:()=>{y(),n(!1)},children:"Cancel"}),e.jsx(E,{onClick:N,disabled:d.isPending,children:d.isPending?e.jsxs(e.Fragment,{children:[e.jsx(k,{className:"h-4 w-4 mr-2 animate-spin"}),"Adding..."]}):"Add Card"})]})]})})}function Xa(){var P;const t=X(),n=W(),[s,r]=v.useState(null),[a,i]=v.useState(!1),[o,l]=v.useState(null),{data:c,isLoading:h}=U({queryKey:["plans"],queryFn:()=>T.plans().then(j=>j.data)}),{data:m}=U({queryKey:["payment-methods"],queryFn:()=>T.paymentMethods().then(j=>j.data)}),w=O({mutationFn:j=>T.switchPlan(j),onSuccess:j=>{n.success("policy_changes",j.data.message),t.invalidateQueries({queryKey:["plans"]}),t.invalidateQueries({queryKey:["usage-dashboard"]}),t.invalidateQueries({queryKey:["invoices"]})},onError:j=>{var A,M;n.error(((M=(A=j==null?void 0:j.response)==null?void 0:A.data)==null?void 0:M.error)||"Failed to switch plan")}});if(h)return e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(k,{className:"h-6 w-6 animate-spin text-muted-foreground"})});const x=(c==null?void 0:c.current_plan)??"free_tier",g=(c==null?void 0:c.plans)??[],C=(c==null?void 0:c.payments_enabled)??!1,d=((m==null?void 0:m.length)??0)>0,y=[...g].sort((j,A)=>ne(j.plan_type)-ne(A.plan_type)),N=j=>ne(j)>ne(x),p=j=>ne(j)<ne(x),u=j=>{if(j.plan_type!==x&&!j.locked){if(x==="free_tier"&&N(j.plan_type)&&!d){l(j),i(!0);return}r(j)}},f=()=>{s&&(w.mutate(s.plan_type),r(null))},S=()=>{o&&(r(o),l(null))};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Plan"}),e.jsxs(Y,{variant:"secondary",children:["Current: ",((P=g.find(j=>j.plan_type===x))==null?void 0:P.display_name)??"Free"," Plan"]})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4",children:y.map(j=>{const A=za[j.plan_type],M=j.plan_type===x,L=!!j.locked&&!M;return e.jsxs(F,{className:`relative flex flex-col ${M?"border-2 border-primary":""} ${L?"opacity-60":""}`,children:[M&&e.jsx("div",{className:"absolute -top-3 left-4",children:e.jsx(Y,{variant:"default",className:"text-xs",children:"Current Plan"})}),e.jsxs(R,{className:"pb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[A==null?void 0:A.icon,e.jsx(I,{className:"text-lg",children:j.display_name}),L&&e.jsx(xt,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx(Q,{children:j.description})]}),e.jsxs(B,{className:"flex-1 flex flex-col",children:[e.jsxs("div",{className:"space-y-3 flex-1",children:[e.jsxs("div",{className:"text-sm space-y-1",children:[e.jsxs("div",{className:"flex justify-between text-muted-foreground",children:[e.jsx("span",{children:"Weekly Credits"}),e.jsx("span",{className:"font-medium text-foreground",children:_(j.weekly_compute_units_limit)})]}),e.jsxs("div",{className:"flex justify-between text-muted-foreground",children:[e.jsx("span",{children:"Monthly Credits"}),e.jsx("span",{className:"font-medium text-foreground",children:_(j.monthly_compute_units_limit)})]})]}),e.jsx("div",{className:"border-t pt-3",children:e.jsx("ul",{className:"space-y-2",children:Ka(j).map((V,se)=>e.jsxs("li",{className:"flex items-start gap-2 text-sm",children:[e.jsx(ft,{className:"h-4 w-4 mt-0.5 shrink-0 text-green-500"}),e.jsx("span",{children:V})]},se))})})]}),e.jsx("div",{className:"pt-4",children:M?e.jsx(E,{variant:"outline",className:"w-full",disabled:!0,children:"Current Plan"}):L||!C?e.jsx(E,{variant:"outline",className:"w-full gap-2",disabled:!0,children:"Coming Soon"}):N(j.plan_type)?e.jsx(E,{className:"w-full",onClick:()=>u(j),children:"Upgrade"}):e.jsx(E,{variant:"outline",className:"w-full",onClick:()=>u(j),children:"Downgrade"})})]})]},j.plan_type)})}),e.jsx(er,{hasCard:d,paymentsEnabled:C,onAddCard:()=>{l(null),i(!0)}}),e.jsx(ot,{open:!!s,onOpenChange:j=>!j&&r(null),children:e.jsxs(lt,{children:[e.jsxs(ct,{children:[e.jsx(dt,{children:s&&N(s.plan_type)?"Upgrade Plan":"Downgrade Plan"}),e.jsx(ut,{children:s&&p(s.plan_type)?e.jsxs(e.Fragment,{children:["Are you sure you want to downgrade to the"," ",e.jsx("span",{className:"font-semibold",children:s.display_name})," plan? Your credit limits will decrease to"," ",e.jsx("span",{className:"font-semibold",children:_(s.weekly_compute_units_limit)})," ","weekly and"," ",e.jsx("span",{className:"font-semibold",children:_(s.monthly_compute_units_limit)})," ","monthly credits."]}):e.jsxs(e.Fragment,{children:["Switch to the"," ",e.jsx("span",{className:"font-semibold",children:s==null?void 0:s.display_name})," plan? Your credit limits will change to"," ",e.jsx("span",{className:"font-semibold",children:_((s==null?void 0:s.weekly_compute_units_limit)??0)})," ","weekly and"," ",e.jsx("span",{className:"font-semibold",children:_((s==null?void 0:s.monthly_compute_units_limit)??0)})," ","monthly credits."]})})]}),e.jsxs(mt,{children:[e.jsx(E,{variant:"outline",onClick:()=>r(null),children:"Cancel"}),e.jsxs(E,{variant:s&&p(s.plan_type)?"destructive":"default",onClick:f,disabled:w.isPending,children:[w.isPending&&e.jsx(k,{className:"h-4 w-4 mr-2 animate-spin"}),s&&p(s.plan_type)?"Confirm Downgrade":"Confirm"]})]})]})}),e.jsx(vt,{open:a,onOpenChange:j=>{i(j),j||l(null)},onSuccess:S,title:"Add Payment Method",description:"A payment method is required to upgrade from the Free plan. Add a card to continue."})]})}function er({hasCard:t,paymentsEnabled:n,onAddCard:s}){const r=X(),a=W(),[i,o]=v.useState("1000"),[l,c]=v.useState(""),[h,m]=v.useState(!1),[w,x]=v.useState(!1),{data:g}=U({queryKey:["credit-purchase-status"],queryFn:()=>T.creditPurchaseStatus().then(j=>j.data)});v.useEffect(()=>
29{g&&(g.spending_limit_cents!==null?(m(!0),c(String(g.spending_limit_cents/100))):(m(!1),c("")))},[g]);const C=parseInt(i,10)||0,d=C>=100&&C<=5e4,N=(C*1/100).toFixed(2),p=O({mutationFn:j=>T.purchaseCredits(j),onSuccess:(j,A)=>{a.success("billing",`Purchased ${A.toLocaleString()} credits`),r.invalidateQueries({queryKey:["credit-purchase-status"]}),r.invalidateQueries({queryKey:["usage-dashboard"]}),r.invalidateQueries({queryKey:["invoices"]})},onError:j=>{var A,M;a.error(((M=(A=j==null?void 0:j.response)==null?void 0:A.data)==null?void 0:M.error)||"Failed to purchase credits")}}),u=O({mutationFn:j=>T.updateSpendingLimit(j),onSuccess:()=>{a.success("billing","Spending limit updated"),r.invalidateQueries({queryKey:["credit-purchase-status"]})},onError:j=>{var A,M;a.error(((M=(A=j==null?void 0:j.response)==null?void 0:A.data)==null?void 0:M.error)||"Failed to update spending limit")}}),f=()=>{if(d){if(!t){x(!0);return}p.mutate(C)}},S=()=>{x(!1),d&&p.mutate(C)},P=()=>{if(!h)u.mutate(null);else{const j=parseFloat(l);if(isNaN(j)||j<0){a.error("Please enter a valid amount");return}u.mutate(Math.round(j*100))}};return e.jsxs(e.Fragment,{children:[e.jsxs(F,{id:"credits",children:[e.jsxs(R,{children:[e.jsxs(I,{className:"text-base flex items-center gap-2",children:[e.jsx(ss,{className:"h-4 w-4"}),"Buy Extra Credits"]}),e.jsx(Q,{children:"Purchase additional credits on-demand at $0.01 per credit. Credits are added to your monthly limit."})]}),e.jsxs(B,{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(q,{htmlFor:"credit-amount",children:"Credits to buy"}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(G,{id:"credit-amount",type:"text",inputMode:"numeric",className:"flex-1",value:i,onChange:j=>o(j.target.value.replace(/[^0-9]/g,"")),onFocus:j=>j.target.select()}),e.jsx("span",{title:n?void 0:"Coming soon",className:"shrink-0",children:e.jsxs(E,{onClick:f,disabled:!n||p.isPending||!d,className:"gap-2",children:[p.isPending?e.jsx(k,{className:"h-4 w-4 animate-spin"}):e.jsx(vn,{className:"h-4 w-4"}),"Buy Credits"]})})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[C.toLocaleString()," credits = $",N," · Min 100 · Max 50,000"]})]}),g&&(g.purchased_credits_this_month>0||g.spent_cents_this_month>0)&&e.jsxs("div",{className:"rounded-lg border bg-muted/50 p-3",children:[e.jsx("p",{className:"text-sm font-medium mb-1",children:"This Month"}),e.jsxs("div",{className:"flex gap-4 text-sm text-muted-foreground",children:[e.jsxs("span",{children:["Credits purchased:"," ",e.jsx("span",{className:"font-medium text-foreground",children:g.purchased_credits_this_month.toLocaleString()})]}),e.jsxs("span",{children:["Amount spent:"," ",e.jsxs("span",{className:"font-medium text-foreground",children:["$",(g.spent_cents_this_month/100).toFixed(2)]})]})]})]}),n&&e.jsxs(e.Fragment,{children:[e.jsx(H,{}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Monthly Spending Limit"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Cap how much you can spend on extra credits each month"})]}),e.jsx(Me,{checked:h,onCheckedChange:m})]}),h&&e.jsxs("div",{className:"flex items-end gap-3",children:[e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx(q,{htmlFor:"spending-limit",children:"Limit (USD per month)"}),e.jsxs("div",{className:"relative",children:[e.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground text-sm",children:"$"}),e.jsx(G,{id:"spending-limit",type:"number",min:1,step:1,className:"pl-7",value:l,onChange:j=>c(j.target.value),placeholder:"e.g. 50"})]})]}),e.jsx(E,{variant:"outline",onClick:P,disabled:u.isPending,className:"shrink-0",children:u.isPending?e.jsx(k,{className:"h-4 w-4 animate-spin"}):"Save"})]}),!h&&(g==null?void 0:g.spending_limit_cents)!==null&&e.jsxs(E,{variant:"outline",size:"sm",onClick:P,disabled:u.isPending,children:[u.isPending?e.jsx(k,{className:"h-4 w-4 animate-spin mr-2"}):null,"Remove Limit"]})]})]})]})]}),e.jsx(vt,{open:w,onOpenChange:x,onSuccess:S,title:"Add Payment Method",description:"A payment method is required to purchase credits. Add a card to continue."})]})}function tr(){var bt;const t=X(),n=W(),{signOut:s}=Xs(),[r,a]=v.useState(!1),[i,o]=v.useState(!1),[l,c]=v.useState(!1),[h,m]=v.useState(!1),[w,x]=v.useState(""),{data:g,isLoading:C}=U({queryKey:["payment-methods"],queryFn:()=>T.paymentMethods().then(b=>b.data)}),{data:d,isLoading:y}=U({queryKey:["invoices"],queryFn:()=>T.invoices().then(b=>b.data)}),{data:N}=U({queryKey:["cancel-status"],queryFn:()=>T.cancelStatus().then(b=>b.data)}),{data:p}=U({queryKey:["plans"],queryFn:()=>T.plans().then(b=>b.data)}),u=O({mutationFn:b=>T.deletePaymentMethod(b),onSuccess:()=>{n.success("billing","Payment method removed"),t.invalidateQueries({queryKey:["payment-methods"]})},onError:b=>{var D,z;n.error(((z=(D=b==null?void 0:b.response)==null?void 0:D.data)==null?void 0:z.error)||"Failed to remove payment method")}}),f=O({mutationFn:()=>T.cancelPlan(),onSuccess:()=>{n.success("policy_changes","Your plan has been cancelled"),t.invalidateQueries({queryKey:["cancel-status"]}),t.invalidateQueries({queryKey:["plans"]}),t.invalidateQueries({queryKey:["usage-dashboard"]}),o(!1)},onError:b=>{var D,z;n.error(((z=(D=b==null?void 0:b.response)==null?void 0:D.data)==null?void 0:z.error)||"Failed to cancel plan")}}),S=O({mutationFn:()=>T.resumePlan(),onSuccess:b=>{n.success("policy_changes",b.data.message),t.invalidateQueries({queryKey:["cancel-status"]}),t.invalidateQueries({queryKey:["plans"]}),t.invalidateQueries({queryKey:["usage-dashboard"]}),c(!1)},onError:b=>{var D,z;n.error(((z=(D=b==null?void 0:b.response)==null?void 0:D.data)==null?void 0:z.error)||"Failed to resume plan")}}),P=O({mutationFn:b=>T.switchPlan(b),onSuccess:b=>{n.success("policy_changes",b.data.message),t.invalidateQueries({queryKey:["cancel-status"]}),t.invalidateQueries({queryKey:["plans"]}),t.invalidateQueries({queryKey:["usage-dashboard"]}),t.invalidateQueries({queryKey:["invoices"]}),c(!1)},onError:b=>{var D,z;n.error(((z=(D=b==null?void 0:b.response)==null?void 0:D.data)==null?void 0:z.error)||"Failed to switch plan")}}),j=O({mutationFn:()=>fe.deleteAccount(),onSuccess:()=>{s()},onError:b=>{var D,z;n.error(((z=(D=b==null?void 0:b.response)==null?void 0:D.data)==null?void 0:z.error)||"Failed to delete account")}}),A=(p==null?void 0:p.current_plan)??"free_tier",M=(p==null?void 0:p.plans)??[],L=(p==null?void 0:p.payments_enabled)??!1,V=((bt=M.find(b=>
29b.plan_type===A))==null?void 0:bt.display_name)??"Free",se=A==="free_tier";return C||y?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(k,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):e.jsxs("div",{className:"space-y-6",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Billing"}),e.jsxs(F,{children:[e.jsx(R,{children:e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx(I,{className:"text-base",children:"Payment Methods"}),e.jsx(Q,{children:L?"Manage your cards for plan upgrades":"Payment methods will be available when paid plans launch"})]}),L&&e.jsxs(E,{size:"sm",className:"w-full sm:w-auto",onClick:()=>a(!0),children:[e.jsx(ns,{className:"h-4 w-4 mr-1"}),"Add Card"]})]})}),e.jsx(B,{children:L?!g||g.length===0?e.jsxs("div",{className:"text-center py-6 text-muted-foreground",children:[e.jsx(me,{className:"h-8 w-8 mx-auto mb-2 opacity-50"}),e.jsx("p",{className:"text-sm",children:"No payment methods added yet"}),e.jsx("p",{className:"text-xs mt-1",children:"Add a card to upgrade your plan"})]}):e.jsx("div",{className:"space-y-3",children:g.map(b=>e.jsxs("div",{className:"flex items-center justify-between rounded-lg border p-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-md bg-muted",children:e.jsx(me,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-sm font-medium",children:[Ha(b.card_brand)," ****",b.last_four]}),b.is_default&&e.jsx(Y,{variant:"secondary",className:"text-xs",children:"Default"})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Expires ",String(b.exp_month).padStart(2,"0"),"/",b.exp_year,b.cardholder_name&&` - ${b.cardholder_name}`]})]})]}),e.jsx(E,{variant:"ghost",size:"sm",onClick:()=>u.mutate(b.id),disabled:u.isPending,children:e.jsx(Ae,{className:"h-4 w-4 text-muted-foreground"})})]},b.id))}):e.jsxs("div",{className:"text-center py-6 text-muted-foreground",children:[e.jsx(me,{className:"h-8 w-8 mx-auto mb-2 opacity-50"}),e.jsx("p",{className:"text-sm font-medium",children:"Coming Soon"}),e.jsx("p",{className:"text-xs mt-1",children:"Card management will be available when paid plans launch"})]})})]}),e.jsxs(F,{children:[e.jsx(R,{children:e.jsxs(I,{className:"text-base flex items-center gap-2",children:[e.jsx(Lt,{className:"h-4 w-4"}),"Recent Invoices"]})}),e.jsx(B,{children:!d||d.length===0?e.jsxs("div",{className:"text-center py-6 text-muted-foreground",children:[e.jsx(Lt,{className:"h-8 w-8 mx-auto mb-2 opacity-50"}),e.jsx("p",{className:"text-sm",children:"No invoices yet"}),e.jsx("p",{className:"text-xs mt-1",children:"Invoices will appear here when you upgrade your plan"})]}):e.jsx("div",{className:"space-y-1",children:d.map((b,D)=>e.jsxs("div",{children:[D>0&&e.jsx(H,{className:"my-1"}),e.jsxs("div",{className:"flex items-center justify-between py-2",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium truncate",children:b.description}),e.jsx("p",{className:"text-xs text-muted-foreground",children:new Date(b.created_at).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"})})]}),e.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[e.jsxs("span",{className:"text-sm font-medium",children:["$",(b.amount_cents/100).toFixed(2)]}),e.jsx(Y,{variant:b.status==="paid"?"default":b.status==="pending"?"secondary":"destructive",className:"text-xs",children:b.status.charAt(0).toUpperCase()+b.status.slice(1)})]})]})]},b.id))})})]}),e.jsxs(F,{children:[e.jsx(R,{children:e.jsxs(I,{className:"text-base flex items-center gap-2",children:[e.jsx(Nn,{className:"h-4 w-4"}),"Subscription"]})}),e.jsx(B,{children:L?se?e.jsx("p",{className:"text-sm text-muted-foreground",children:"You're on the Free plan â no active subscription to cancel."}):N!=null&&N.pending?e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"rounded-lg border border-yellow-500/30 bg-yellow-500/5 p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Ct,{className:"h-5 w-5 text-yellow-500 mt-0.5 shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Your plan has been cancelled"}),e.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:["You'll have access to the ",N.plan_display_name," plan until"," ",new Date(N.cancel_effective_date).toLocaleDateString("en-US",{year:"numeric",month:"long",day:"numeric"}),"."]})]})]})}),e.jsx("div",{className:"flex items-center gap-3",children:e.jsxs(E,{onClick:()=>c(!0),className:"gap-2",children:[e.jsx(Rt,{className:"h-4 w-4"}),"Resume Subscription"]})})]}):e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Cancel your ",V," subscription. You'll retain access until the end of the current billing cycle."]}),e.jsx(E,{variant:"destructive",size:"sm",className:"shrink-0 w-full sm:w-auto",onClick:()=>o(!0),children:"Cancel Subscription"})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"You're on the Free plan. Paid subscriptions are coming soon."})})]}),e.jsx(_t,{open:i,onOpenChange:o,children:e.jsxs(Pt,{children:[e.jsxs(St,{children:[e.jsx(Et,{children:"Cancel Subscription"}),e.jsxs(At,{children:["Are you sure you want to cancel your ",V," plan? Your subscription will remain active until the end of the current monthly billing cycle. After that, you'll be moved to the Free plan."]})]}),e.jsxs(Mt,{children:[e.jsx(kt,{children:"Keep Plan"}),e.jsx(en,{className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",onClick:()=>f.mutate(),disabled:f.isPending,children:f.isPending?e.jsxs(e.Fragment,{children:[e.jsx(k,{className:"h-4 w-4 mr-2 animate-spin"}),"Cancelling..."]}):"Yes, Cancel Plan"})]})]})}),e.jsx(ot,{open:l,onOpenChange:c,children:e.jsxs(lt,{className:"sm:max-w-md",children:[e.jsxs(ct,{children:[e.jsxs(dt,{className:"flex items-center gap-2",children:[e.jsx(Rt,{className:"h-5 w-5"}),"Resume Subscription"]}),e.jsxs(ut,{children:["Your ",N==null?void 0:N.plan_display_name," plan is set to cancel on"," ",N!=null&&N.cancel_effective_date?new Date(N.cancel_effective_date).toLocaleDateString("en-US",{year:"numeric",month:"long",day:"numeric"}):"",". Would you like to continue with your current plan?"]})]}),e.jsxs("div",{className:"space-y-3 py-2",children:[e.jsxs(E,{className:"w-full justify-between gap-2",onClick:()=>S.mutate(),disabled:S.isPending||P.isPending,children:[e.jsxs("span",{children:["Continue ",N==null?void 0:N.plan_display_name," Plan"]}),S.isPending?e.jsx(k,{className:"h-4 w-4 animate-spin"}):e.jsx(Xe,{className:"h-4 w-4"})]}),M.filter(b=>b.plan_type!==A).length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-xs text-center text-muted-foreground",children:"Or switch to a different plan"}),M.filter(b=>b.plan_type!==A).map(b=>e.jsxs(E,{variant:"outline",size:"sm",className:"w-full justify-between gap-2",onClick:()=>P.mutate(b.plan_type),disabled:S.isPending||P.isPending,children:[e.jsxs("span",{children:["Switch to ",b.display_name]}),P.isPending?e.jsx(k,{className:"h-4 w-4 animate-spin"}):e.jsx(Xe,{className:"h-4 w-4"})]},b.plan_type))]})]}),e.jsx(mt,{children:e.jsx(E,{variant:"ghost",onClick:()=>c(!1),children:"Cancel"})})]})}),e.jsx(vt,{open:r,onOpenChange:a}),e.jsx(H,{}),e.jsxs(F,{className:"border-red-500/30",children:[e.jsx(R,{children:e.jsxs(I,{className:"text-base flex items-center gap-2 text-red-600",children:[e.jsx(Ct,{className:"h-4 w-4"}),"Danger Zone"]})}),e.jsx(B,{children:e.jsx("div",{className:"rounded-lg border border-red-500/30 bg-red-500/5 p-4",children:e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Delete Account"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Permanently delete your account and all associated data. This action cannot be undone."})]}),e.jsx(E,{variant:"destructive",size:"sm",className:"shrink-0 w-full sm:w-auto",onClick:()=>m(!0),children:"Delete Account"})]})})})]}),e.jsx(_t,{open:h,onOpenChange:b=>{m(b),b||x("")},children:e.jsxs(Pt,{children:[e.jsxs(St,{children:[e.jsx(Et,{children:"Delete Account"}),e.jsx(At,{asChild:!0,children:e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{children:"This will permanently delete your account, all your guides, study materials, and associated data. Shared copies already owned by other users will be preserved as read-only."}),e.jsx("p",{className:"font-medium text-foreground",children:"This action cannot be undone."}),e.jsxs("div",{className:"space-y-2 pt-1",children:[e.jsxs(q,{htmlFor:"delete-confirm",className:"text-sm text-muted-foreground",children:["Type ",e.jsx("span",{className:"font-mono font-semibold text-foreground",children:"delete"})," to confirm"]}),e.jsx(G,{id:"delete-confirm",placeholder:"delete",value:w,onChange:b=>x(b.target.value),autoComplete:"off"})]})]})})]}),e.jsxs(Mt,{children:[e.jsx(kt,{onClick:()=>x(""),children:"Cancel"}),e.jsx(E,{variant:"destructive",disabled:w!=="delete"||j.isPending,onClick:()=>j.mutate(),children:j.isPending?e.jsxs(e.Fragment,{children:[e.jsx(k,{className:"h-4 w-4 mr-2 animate-spin"}),"Deleting..."]}):"Permanently Delete Account"})]})]})})]})}function sr(){const t=X(),n=W(),[s,r]=v.useState(""),[a,i]=v.useState(""),[o,l]=v.useState(""),[c,h]=v.useState(!1),[m,w]=v.useState(!1),[x,g]=v.useState(!1),[C,d]=v.useState(""),{data:y,isLoading:N}=U({queryKey:["profile"],queryFn:()=>fe.get().then(S=>S.data)}),p=(y==null?void 0:y.has_password)??!1,u=O({mutationFn:S=>T.setPassword(S),onSuccess:()=>{n.success("transactional",p?"Password changed successfully":"Password set successfully"),t.invalidateQueries({queryKey:["profile"]}),r(""),i(""),l(""),d("")},onError:S=>{var P,j;d(((j=(P=S==null?void 0:S.response)==null?void 0:P.data)==null?void 0:j.error)||"Failed to update password")}}),f=S=>{if(S.preventDefault(),d(""),a.length<6){d("Password must be at least 6 characters");return}if(a!==o){d("Passwords do not match");return}const P={new_password:a,confirm_password:o};if(p){if(!s){d("Current password is required");return}P.current_password=s}u.mutate(P)};return N?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(k,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):e.jsxs("div",{className:"space-y-6",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Security"}),e.jsxs(F,{children:[e.jsxs(R,{children:[e.jsxs(I,{className:"text-base flex items-center gap-2",children:[e.jsx(xt,{className:"h-4 w-4"}),p?"Change Password":"Set Password"]}),e.jsx(Q,{children:p?"Update your account password.":"You signed in with Google. Add a password to al
29so sign in with email."})]}),e.jsx(B,{children:e.jsxs("form",{onSubmit:f,className:"space-y-4 max-w-md",children:[p&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(q,{htmlFor:"current-password",children:"Current Password"}),e.jsxs("div",{className:"relative",children:[e.jsx(G,{id:"current-password",type:c?"text":"password",value:s,onChange:S=>r(S.target.value),placeholder:"Enter current password"}),e.jsx("button",{type:"button",className:"absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",onClick:()=>h(!c),children:c?e.jsx(Ke,{className:"h-4 w-4"}):e.jsx(Oe,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(q,{htmlFor:"new-password",children:"New Password"}),e.jsxs("div",{className:"relative",children:[e.jsx(G,{id:"new-password",type:m?"text":"password",value:a,onChange:S=>i(S.target.value),placeholder:"Enter new password"}),e.jsx("button",{type:"button",className:"absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",onClick:()=>w(!m),children:m?e.jsx(Ke,{className:"h-4 w-4"}):e.jsx(Oe,{className:"h-4 w-4"})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Minimum 6 characters"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(q,{htmlFor:"confirm-password",children:"Confirm Password"}),e.jsxs("div",{className:"relative",children:[e.jsx(G,{id:"confirm-password",type:x?"text":"password",value:o,onChange:S=>l(S.target.value),placeholder:"Confirm new password"}),e.jsx("button",{type:"button",className:"absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",onClick:()=>g(!x),children:x?e.jsx(Ke,{className:"h-4 w-4"}):e.jsx(Oe,{className:"h-4 w-4"})})]})]}),C&&e.jsx("div",{className:"rounded-md bg-destructive/10 border border-destructive/20 px-3 py-2 text-sm text-destructive",children:C}),e.jsx(E,{type:"submit",disabled:u.isPending,children:u.isPending?e.jsxs(e.Fragment,{children:[e.jsx(k,{className:"h-4 w-4 mr-2 animate-spin"}),p?"Changing...":"Setting..."]}):p?"Change Password":"Set Password"})]})})]})]})}function nr(){const t=X(),n=W(),[s,r]=v.useState(""),[a,i]=v.useState([]),{data:o,isLoading:l}=U({queryKey:["referral-status"],queryFn:()=>we.getStatus().then(d=>d.data)}),c=O({mutationFn:d=>we.deleteInvite(d),onSuccess:()=>{n.success("transactional","Invite deleted"),t.invalidateQueries({queryKey:["referral-status"]})},onError:d=>{var y,N;n.error(((N=(y=d==null?void 0:d.response)==null?void 0:y.data)==null?void 0:N.error)||"Failed to delete invite")}}),h=O({mutationFn:d=>we.resendInvite(d),onSuccess:()=>{n.success("transactional","Invite resent"),t.invalidateQueries({queryKey:["referral-status"]})},onError:d=>{var y,N;n.error(((N=(y=d==null?void 0:d.response)==null?void 0:y.data)==null?void 0:N.error)||"Failed to resend invite")}}),m=O({mutationFn:d=>we.sendInvites(d),onSuccess:d=>{const y=d.data.results.filter(f=>f.status==="invited").length,N=d.data.results.filter(f=>f.status==="already_registered").length,p=d.data.results.filter(f=>f.status==="already_invited").length;let u=`${y} invite${y!==1?"s":""} sent`;N>0&&(u+=`, ${N} already registered`),p>0&&(u+=`, ${p} already invited`),n.success("transactional",u),i([]),t.invalidateQueries({queryKey:["referral-status"]})},onError:d=>{var y,N;n.error(((N=(y=d==null?void 0:d.response)==null?void 0:y.data)==null?void 0:N.error)||"Failed to send invites")}}),w=()=>{const d=s.trim().toLowerCase();if(d){if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(d)){n.error("Please enter a valid email address");return}if(a.includes(d)){n.error("Email already added");return}if(a.length>=10){n.error("Maximum 10 emails per batch");return}i([...a,d]),r("")}},x=d=>{i(a.filter(y=>y!==d))},g=d=>{d.key==="Enter"&&(d.preventDefault(),w())};if(l)return e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(k,{className:"h-6 w-6 animate-spin text-muted-foreground"})});const C=d=>{switch(d){case"completed":return"default";case"pending":return"secondary";case"expired":return"outline";default:return"secondary"}};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Referrals"}),e.jsxs(Y,{variant:"secondary",className:"gap-1",children:[e.jsx(xn,{className:"h-3 w-3"}),(o==null?void 0:o.reward_per_referral)??0," credits per referral"]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:[e.jsxs(F,{children:[e.jsxs(R,{className:"flex flex-row items-center justify-between pb-2",children:[e.jsx(I,{className:"text-sm font-medium text-muted-foreground",children:"Invites Sent"}),e.jsx(We,{className:"h-5 w-5 text-muted-foreground"})]}),e.jsx(B,{children:e.jsx("p",{className:"text-3xl font-bold",children:(o==null?void 0:o.total_invited)??0})})]}),e.jsxs(F,{children:[e.jsxs(R,{className:"flex flex-row items-center justify-between pb-2",children:[e.jsx(I,{className:"text-sm font-medium text-muted-foreground",children:"Friends Joined"}),e.jsx(es,{className:"h-5 w-5 text-muted-foreground"})]}),e.jsx(B,{children:e.jsx("p",{className:"text-3xl font-bold",children:(o==null?void 0:o.total_completed)??0})})]}),e.jsxs(F,{children:[e.jsxs(R,{className:"flex flex-row items-center justify-between pb-2",children:[e.jsx(I,{className:"text-sm font-medium text-muted-foreground",children:"Credits Earned"}),e.jsx(ge,{className:"h-5 w-5 text-muted-foreground"})]}),e.jsx(B,{children:e.jsx("p",{className:"text-3xl font-bold",children:(o==null?void 0:o.total_credits_earned)??0})})]})]}),e.jsxs(F,{children:[e.jsxs(R,{children:[e.jsxs(I,{className:"text-base flex items-center gap-2",children:[e.jsx(ts,{className:"h-4 w-4"}),"Invite Friends"]}),e.jsx(Q,{children:"Share your link or send an invite. When they sign up, you both earn bonus credits."})]}),e.jsxs(B,{className:"space-y-4",children:[(o==null?void 0:o.referral_url)&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(q,{className:"text-xs text-muted-foreground",children:"Your referral link"}),e.jsx(ln,{url:o.referral_url,code:o.referral_code})]}),e.jsx(H,{})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(q,{className:"text-xs text-muted-foreground",children:"Or inv
29ite by email"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(G,{type:"email",placeholder:"[email protected]",value:s,onChange:d=>r(d.target.value),onKeyDown:g,className:"flex-1"}),e.jsxs(E,{variant:"outline",onClick:w,children:[e.jsx(ns,{className:"h-4 w-4 mr-1"}),"Add"]})]})]}),a.length>0&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"flex flex-wrap gap-2",children:a.map(d=>e.jsxs(Y,{variant:"secondary",className:"gap-1 pr-1",children:[d,e.jsx("button",{onClick:()=>x(d),className:"ml-1 rounded-full hover:bg-muted-foreground/20 p-0.5",children:e.jsx(tn,{className:"h-3 w-3"})})]},d))}),e.jsxs(E,{onClick:()=>m.mutate(a),disabled:m.isPending,className:"gap-2",children:[m.isPending?e.jsx(k,{className:"h-4 w-4 animate-spin"}):e.jsx(We,{className:"h-4 w-4"}),"Send ",a.length," Invite",a.length!==1?"s":""]})]})]})]}),(o==null?void 0:o.referral_url)&&e.jsx(Na,{url:o.referral_url,code:o.referral_code}),o&&o.referrals.length>0&&e.jsxs(F,{children:[e.jsx(R,{children:e.jsx(I,{className:"text-base",children:"Referral History"})}),e.jsxs(B,{children:[e.jsx("div",{className:"rounded-md border hidden md:block",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b bg-muted/50",children:[e.jsx("th",{className:"text-left p-3 font-medium",children:"Email"}),e.jsx("th",{className:"text-left p-3 font-medium",children:"Status"}),e.jsx("th",{className:"text-left p-3 font-medium",children:"Credits"}),e.jsx("th",{className:"text-left p-3 font-medium",children:"Date"}),e.jsx("th",{className:"text-right p-3 font-medium",children:"Actions"})]})}),e.jsx("tbody",{children:o.referrals.map(d=>e.jsxs("tr",{className:"border-b",children:[e.jsx("td",{className:"p-3",children:d.referred_email}),e.jsx("td",{className:"p-3",children:e.jsx(Y,{variant:C(d.status),children:d.status.charAt(0).toUpperCase()+d.status.slice(1)})}),e.jsx("td",{className:"p-3",children:d.credits_awarded>0?`+${d.credits_awarded}`:"â"}),e.jsx("td",{className:"p-3 text-muted-foreground",children:new Date(d.created_at).toLocaleDateString()}),e.jsx("td",{className:"p-3 text-right",children:e.jsxs("div",{className:"flex items-center justify-end gap-1",children:[(d.status==="pending"||d.status==="expired")&&e.jsx(E,{variant:"ghost",size:"icon",className:"h-7 w-7",title:"Resend invite",disabled:h.isPending,onClick:()=>h.mutate(d.id),children:e.jsx(It,{className:"h-3.5 w-3.5"})}),d.status!=="completed"&&e.jsx(E,{variant:"ghost",size:"icon",className:"h-7 w-7 text-destructive hover:text-destructive",title:"Delete invite",disabled:c.isPending,onClick:()=>c.mutate(d.id),children:e.jsx(Ae,{className:"h-3.5 w-3.5"})})]})})]},d.id))})]})}),e.jsx("div",{className:"space-y-3 md:hidden",children:o.referrals.map(d=>e.jsxs("div",{className:"rounded-lg border p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"text-sm font-medium truncate mr-2",children:d.referred_email}),e.jsx(Y,{variant:C(d.status),children:d.status.charAt(0).toUpperCase()+d.status.slice(1)})]}),e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:new Date(d.created_at).toLocaleDateString()}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-muted-foreground",children:d.credits_awarded>0?`+${d.credits_awarded} credits`:"â"}),(d.status==="pending"||d.status==="expired")&&e.jsx(E,{variant:"ghost",size:"icon",className:"h-7 w-7",title:"Resend invite",disabled:h.isPending,onClick:()=>h.mutate(d.id),children:e.jsx(It,{className:"h-3.5 w-3.5"})}),d.status!=="completed"&&e.jsx(E,{variant:"ghost",size:"icon",className:"h-7 w-7 text-destructive hover:text-destructive",title:"Delete invite",disabled:c.isPending,onClick:()=>c.mutate(d.id),children:e.jsx(Ae,{className:"h-3.5 w-3.5"})})]})]})]},d.id))})]})]})]})}const ar=[{key:"transactional",title:"Transactional",description:"Guide processing, uploads, and study material generation",emailField:"email_transactional",inappField:"inapp_transactional"},{key:"policy_changes",title:"Policy Changes",description:"Terms of service, privacy policy, and platform updates",emailField:"email_policy_changes",inappField:"inapp_policy_changes"},{key:"billing",title:"Billing & Payment",description:"Invoices, payment confirmations, and plan changes",emailField:"email_billing",inappField:"inapp_billing"},{key:"engagement",title:"Study Reminders",description:"Nudges about guides you haven't opened, weekly recaps, and unused credits",emailField:"email_engagement",inappField:"inapp_engagement"}];function rr(){const t=X(),n=W(),{data:s,isLoading:r}=U({queryKey:["notification-preferences"],queryFn:()=>T.notifications().then(o=>o.data)}),a=O({mutationFn:o=>T.updateNotifications(o),onSuccess:()=>{t.invalidateQueries({queryKey:["notification-preferences"]})},onError:o=>{var l,c;n.error(((c=(l=o==null?void 0:o.response)==null?void 0:l.data)==null?void 0:c.error)||"Failed to update notification preferences"),t.invalidateQueries({queryKey:["notification-preferences"]})}}),i=(o,l)=>
29{t.setQueryData(["notification-preferences"],c=>c&&{...c,[o]:l}),a.mutate({[o]:l})};return r?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(k,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):e.jsxs("div",{className:"space-y-6",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Notifications"}),ar.map(o=>e.jsxs(F,{children:[e.jsxs(R,{children:[e.jsx(I,{className:"text-base",children:o.title}),e.jsx(Q,{children:o.description})]}),e.jsxs(B,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(wn,{className:"h-4 w-4 text-muted-foreground"}),e.jsx(q,{className:"text-sm font-normal",children:"Email"})]}),e.jsx(Me,{checked:(s==null?void 0:s[o.emailField])??!0,onCheckedChange:l=>i(o.emailField,l)})]}),e.jsx(H,{}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(rs,{className:"h-4 w-4 text-muted-foreground"}),e.jsx(q,{className:"text-sm font-normal",children:"In-App"})]}),e.jsx(Me,{checked:(s==null?void 0:s[o.inappField])??!0,onCheckedChange:l=>i(o.inappField,l)})]})]})]},o.key))]})}function ir(){const[t,n]=v.useState(""),[s,r]=v.useState(!1),{toast:a}=W(),i=O({mutationFn:o=>T.submitFeedback(o),onSuccess:()=>{n(""),r(!0),a({title:"Feedback submitted",description:"Thank you for your feedback!"})},onError:()=>{a({title:"Error",description:"Failed to submit feedback. Please try again.",variant:"destructive"})}});return e.jsx("div",{className:"space-y-6",children:e.jsxs(F,{children:[e.jsxs(R,{children:[e.jsxs(I,{className:"flex items-center gap-2",children:[e.jsx(ht,{className:"h-5 w-5"}),"Send Us Feedback"]}),e.jsx(Q,{children:"We appreciate any feedback or feature requests! Your input helps us improve the app for everyone."})]}),e.jsx(B,{className:"space-y-4",children:s?e.jsxs("div",{className:"flex flex-col items-center gap-3 py-8 text-center",children:[e.jsx("div",{className:"rounded-full bg-green-100 p-3",children:e.jsx(ft,{className:"h-6 w-6 text-green-600"})}),e.jsx("p",{className:"text-lg font-medium",children:"Thank you for your feedback!"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"We'll review it carefully."}),e.jsx(E,{variant:"outline",onClick:()=>r(!1),className:"mt-2",children:"Send More Feedback"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(q,{htmlFor:"feedback-message",children:"Your feedback or feature request"}),e.jsx("textarea",{id:"feedback-message",className:"flex min-h-[150px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm r
29ing-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",placeholder:"Tell us what you think, report a bug, or suggest a feature...",value:t,onChange:o=>n(o.target.value),maxLength:5e3}),e.jsxs("p",{className:"text-xs text-muted-foreground text-right",children:[t.length,"/5000"]})]}),e.jsx(E,{onClick:()=>i.mutate(t),disabled:!t.trim()||i.isPending,children:i.isPending?e.jsxs(e.Fragment,{children:[e.jsx(k,{className:"mr-2 h-4 w-4 animate-spin"}),"Submitting..."]}):e.jsxs(e.Fragment,{children:[e.jsx(We,{className:"mr-2 h-4 w-4"}),"Submit Feedback"]})})]})})]})})}export{Rr as default,Wa as selectHistoryRows};
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.