1import{r as l,u as te,i as H,K as re,s as m,j as e,L as d,e as ne,A as le,N as ie,C as j,k as N,l as y,O as I,n as v,o as b,Q as ce,B as S,R as oe,U as de,V as me,M as ue,W as he,Y as xe,Z as pe,_ as ge,v as w,I as C,$ as fe}from"./index-Dob99ouq.js";import{P as K}from"./progress-D57Wx3P5.js";import{u as je,E as Ne,C as ye}from"./useDealsLimit-Cno5IV9O.js";import{u as ve}from"./useChatUsage-CWwYTuxW.js";import{u as be}from"./useFeatureAccess-oyZdtZ4q.js";import{g as J}from"./error-messages-CW8TISq_.js";import{f as _}from"./format-dVXnaPEj.js";import{S as we}from"./save-BxGlV3Zp.js";import{E as Ce}from"./external-link-PQTUSwyN.js";import"./auth-validation-IwN_320M.js";import"./eye-off-z-zX4PrH.js";import"./eye-BXFW7iUP.js";import"./en-US-wfBU2YNu.js";const Se=({userId:a})=>{const[u,M]=l.useState(!1),[o,P]=l.useState(null),{toast:D}=H();l.useEffect(()=>{if(!a)return;(async()=>{const{data:s,error:U}=await m.from("subscriptions").select("id, user_id, tier_key, status, current_period_start, current_period_end, cancel_at_period_end, trial_end, organization_id, quantity, created_at, updated_at").eq("user_id",a).single();!U&&s&&P(s)})()},[a]);const g=async()=>{M(!0);try{const{data:n,error:s}=await m.functions.invoke("stripe-portal");if(s)throw s;if(n!=null&&n.error)throw new Error(n.error);if(n!=null&&n.url)window.open(n.url,"_blank");else throw new Error("No portal URL returned")}catch(n){console.error("Portal error:",n),D({title:"Couldn't open settings",description:J(n,"We couldn't open your subscription settings. Please try again."),variant:"destructive"})}finally{M(!1)}};return e.jsxs("div",{className:"pt-4 border-t space-y-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"You have full access to all DealOrb features."}),(o==null?void 0:o.current_period_end)&&e.jsx("p",{className:"text-sm text-muted-foreground",children:o.cancel_at_period_end?`Your subscription ends on ${_(new Date(o.current_period_end),"MMM d, yyyy")}`:`Next billing date: ${_(new Date(o.current_period_end),"MMM d, yyyy")}`}),e.jsxs(S,{variant:"outline",size:"sm",onClick:g,disabled:u,children:[u?e.jsx(d,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(Ce,{className:"h-4 w-4 mr-2"}),"Manage Subscription"]})]})},Re=()=>{const[a,u]=l.useState(null),[M,o]=l.useState(null),[P,D]=l.useState(!0),[g,n]=l.useState(!1),[s,U]=l.useState(null),[A,F]=l.useState(""),[k,L]=l.useState(""),[O,$]=l.useState(""),[Q,R]=l.useState(!1),[V,Y]=l.useState(!1),h=te(),{toast:q}=H(),{tier:i,isPro:x,loading:f,upgradedAt:B}=re((a==null?void 0:a.id)||null),{responseCount:T,loading:z}=ve((a==null?void 0:a.id)||null),{getChatResponseLimit:Z}=be((a==null?void 0:a.id)||null),{dealCount:E,maxDeals:p,loading:G}=je((a==null?void 0:a.id)||null),W=Z();l.useEffect(()=>{const{data:{subscription:r}}=m.auth.onAuthStateChange((t,c)=>{o(c),u((c==null?void 0:c.user)??null),c!=null&&c.user&&c.user.email_confirmed_at||h("/portal/auth")});return m.auth.getSession().then(({data:{session:t}})=>{o(t),u((t==null?void 0:t.user)??null),t!=null&&t.user&&t.user.email_confirmed_at?X(t.user.id):h("/portal/auth")}),()=>r.unsubscribe()},[h]);const X=async r=>{try{const{data:t,error:c}=await m.from("profiles").select("*").eq("id",r).single();if(c)throw c;U(t),F(t.full_name||""),L(t.company_name||""),$(t.phone||"")}catch(t){console.error("Error loading profile:",t)}finally{D(!1)}},ee=async()=>{if(a){n(!0);try{const{error:r}=await m.from("profiles").update({full_name:A.trim()||null,company_name:k.trim()||null,phone:O.trim()||null,updated_at:new Date().toISOString()}).eq("id",a.id);if(r)throw r;q({title:"Profile updated",description:"Your profile has been saved successfully."})}catch(r){q({title:"Couldn't save profile",description:J(r,"We couldn't save your profile. Please try again."),variant:"destructive"})}finally{n(!1)}}},ae=(r,t)=>r?r.split(" ").map(c=>c[0]).join("").toUpperCase().slice(0,2):t?t[0].toUpperCase():"U",se=()=>{const r=new Date,t=new Date(r.getFullYear(),r.getMonth()+1,1);return _(t,"MMM d, yyyy")};return P?e.jsx("div",{className:"min-h-screen bg-background flex items-center justify-center",children:e.jsx(d,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):e.jsx(ne,{children:e.jsxs("div",{className:"min-h-screen flex w-full bg-background",children:[e.jsx(le,{userId:(a==null?void 0:a.id)||null}),e.jsxs("div",{className:"flex-1 flex flex-col",children:[e.jsx(ie,{userId:(a==null?void 0:a.id)||null}),e.jsx("main",{className:"flex-1 overflow-auto pt-28 p-6",children:e.jsxs("div",{className:"max-w-2xl mx-auto
1space-y-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold",children:"Profile Settings"}),e.jsx("p",{className:"text-muted-foreground",children:"Manage your account information"})]}),e.jsxs(j,{children:[e.jsxs(N,{children:[e.jsxs(y,{className:"flex items-center gap-2",children:[e.jsx(I,{className:"h-5 w-5"}),"Plan & Subscription"]}),e.jsx(v,{children:"Your current DealOrb subscription and usage"})]}),e.jsxs(b,{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"flex items-center gap-3",children:f?e.jsx(d,{className:"h-4 w-4 animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsxs(ce,{variant:i==="free"?"secondary":"default",className:`gap-1 text-sm px-3 py-1 ${i==="pro"?"bg-amber-500 hover:bg-amber-600":i==="growth"?"bg-emerald-500 hover:bg-emerald-600":i==="starter"?"bg-blue-500 hover:bg-blue-600":""}`,children:[e.jsx(I,{className:"h-4 w-4"}),"DealOrb ",i==="pro"?"Pro":i==="growth"?"Growth":i==="starter"?"Starter":"Free"]}),i!=="free"&&B&&e.jsxs("span",{className:"text-sm text-muted-foreground",children:["Since ",_(new Date(B),"MMM d, yyyy")]})]})}),i!=="pro"&&!f&&e.jsxs(S,{variant:"default",className:"gap-2 bg-amber-500 hover:bg-amber-600",onClick:()=>Y(!0),children:[e.jsx(I,{className:"h-4 w-4"}),"Upgrade"]})]}),e.jsxs("div",{className:"space-y-4 pt-4 border-t",children:[e.jsx("h4",{className:"text-sm font-medium",children:"Usage This Month"}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(oe,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:"AI Chat Responses"})]}),e.jsx("span",{className:"font-medium",children:z?e.jsx(d,{className:"h-4 w-4 animate-spin"}):x?"Unlimited":`${T} / ${W}`})]}),!x&&!z&&e.jsx(K,{value:T/W*100,className:"h-2"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(de,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:"Active Deals"})]}),e.jsx("span",{className:"font-medium",children:G?e.jsx(d,{className:"h-4 w-4 animate-spin"}):x||p===1/0?`${E} (Unlimited)`:`${E} / ${p}`})]}),!x&&p!==1/0&&!G&&e.jsx(K,{value:E/(p===1/0?1:p)*100,className:"h-2"})]}),!x&&e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground pt-2",children:[e.jsx(me,{className:"h-3 w-3"}),e.jsxs("span",{children:["Chat usage resets on ",se()]})]})]}),i!=="pro"&&!f&&e.jsx("p",{className:"text-sm text-muted-foreground pt-4 border-t",children:"Upgrade to DealOrb Pro for unlimited AI chats, unlimited deals, Market Deals access, Knowledge Base, CIM Analyzer, and more."}),i!=="free"&&!f&&e.jsx(Se,{userId:(a==null?void 0:a.id)||null})]})]}),e.jsxs(j,{children:[e.jsxs(N,{children:[e.jsxs(y,{className:"flex items-center gap-2",children:[e.jsx(ue,{className:"h-5 w-5"}),"Email Connection"]}),e.jsx(v,{children:"Connect your Gmail to send emails to sellers directly from your deals. Replies arrive in your Gmail inbox."})]}),e.jsx(b,{children:e.jsx(Ne,{userId:a==null?void 0:a.id})})]}),e.jsxs(j,{children:[e.jsxs(N,{children:[e.jsxs(y,{className:"flex items-center gap-2",children:[e.jsx(he,{className:"h-5 w-5"}),"Personal Information"]}),e.jsx(v,{children:"Update your personal details and contact information"})]}),e.jsxs(b,{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs(xe,{className:"h-20 w-20",children:[e.jsx(pe,{src:(s==null?void 0:s.avatar_url)||void 0}),e.jsx(ge,{className:"text-lg",children:ae(s==null?void 0:s.full_name,s==null?void 0:s.email)})]}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:(s==null?void 0:s.full_name)||"No name set"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s==null?void 0:s.email})]})]}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(w,{htmlFor:"email",children:"Email"}),e.jsx(C,{id:"email",type:"email",value:(s==null?void 0:s.email)||"",disabled:!0,className:"bg-muted"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Email cannot be changed"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(w,{htmlFor:"fullName",children:"Full Name"}),e.jsx(C,{id:"fullName",type:"text",placeholder:"John Doe",value:A,onChange:r=>F(r.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(w,{htmlFor:"companyName",children:"Company Name"}),e.jsx(C,{id:"companyName",type:"text",placeholder:"Acme Inc.",value:k,onChange:r=>L(r.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(w,{htmlFor:"phone",children:"Phone Number"}),e.jsx(C,{id:"phone",type:"tel",placeholder:"+1 (555) 123-4567",value:O,onChange:r=>$(r.target.value)})]})]}),e.jsx(S,{onClick:ee,disabled:g,children:g?e.jsxs(e.Fragment,{children:[e.jsx(d,{className:"mr-2 h-4 w-4 animate-spin"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(we,{className:"mr-2 h-4 w-4"}),"Save Changes"]})})]})]}),e.jsxs(j,{children:[e.jsxs(N,{children:[e.jsx(y,{children:"Account Security"}),e.jsx(v,{children:"Manage your password and security settings"})]}),e.jsx(b,{children:e.jsx(S,{variant:"outline",onClick:()=>R(!0),children:"Change Password"})})]}),e.jsx(ye,{open:Q,onOpenChange:R}),e.jsx(fe,{open:V,onOpenChange:Y,currentTier:i==="deal_sourcing"?"free":i})]})})]})]})})};export{Re as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.