1import{bL as _,u as A,j as e,C as m,c as u,e as h,f as N,b as x,L as n,I as o,M as S,ai as w,B as i,F,ab as E,ac as I,ad as k,ae as O,af as L,ag as M,s as y}from"./index-fS1BCwCY.js";import{r as l}from"./vendor-stripe-BdjWyUwJ.js";import{A as B}from"./AffiliatePortalLayout-DbtVCZtc.js";import{U as P}from"./user-D3tsdJNv.js";import{B as R}from"./building-5UVZ94uT.js";import"./badge-D8V3NF8j.js";import"./copy-BvRO_3a_.js";import"./log-out-Bc4tCTHy.js";import"./link-2-Cu5-1_8A.js";import"./users-D_jN0jQo.js";import"./dollar-sign-CAfdm_PJ.js";import"./credit-card-CpuE2u6q.js";import"./settings-BF2MJbE0.js";function W(){const{affiliate:s,logout:f}=_(),{toast:r}=A(),[t,c]=l.useState({name:(s==null?void 0:s.name)||"",email:(s==null?void 0:s.email)||"",phone:(s==null?void 0:s.phone)||"",company_name:(s==null?void 0:s.company_name)||""}),[p,j]=l.useState(!1),[C,d]=l.useState(!1),[g,v]=l.useState(!1),D=async()=>{if(s){j(!0);try{const{error:a}=await y.from("affiliates").update({name:t.name,phone:t.phone||null,company_name:t.company_name||null}).eq("id",s.id);if(a)throw a;r({title:"Settings saved successfully"})}catch(a){console.error("Error saving settings:",a),r({title:"Error saving settings",variant:"destructive"})}finally{j(!1)}}},b=async()=>{if(s){v(!0);try{const{error:a}=await y.from("affiliates").update({status:"suspended"}).eq("id",s.id);if(a)throw a;r({title:"Account deactivated"}),f()}catch(a){console.error("Error deleting account:",a),r({title:"Error deactivating account",variant:"destructive"})}finally{v(!1)}}};return e.jsx(B,{children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold",children:"Settings"}),e.jsx("p",{className:"text-muted-foreground",children:"Manage your account settings"})]}),e.jsxs(m,{children:[e.jsxs(u,{children:[e.jsx(h,{className:"text-lg",children:"Profile Information"}),e.jsx(N,{children:"Update your personal information"})]}),e.jsxs(x,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(n,{htmlFor:"name",children:"Full Name"}),e.jsxs("div",{className:"relative",children:[e.jsx(P,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(o,{id:"name",value:t.name,onChange:a=>c({...t,name:a.target.value}),className:"pl-10"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(n,{htmlFor:"email",children:"Email Address"}),e.jsxs("div",{className:"relative",children:[e.jsx(S,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(o,{id:"email",type:"email",value:t.email,disabled:!0,className:"pl-10 bg-muted"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Contact support to change your email address"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(n,{htmlFor:"phone",children:"Phone Number"}),e.jsxs("div",{className:"relative",children:[e.jsx(w,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(o,{id:"phone",value:t.phone,onChange:a=>c({...t,phone:a.target.value}),className:"pl-10",placeholder:"Optional"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(n,{htmlFor:"company",children:"Company Name"}),e.jsxs("div",{className:"relative",children:[e.jsx(R,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(o,{id:"company",value:t.company_name,onChange:a=>c({...t,company_name:a.target.value}),className:"pl-10",placeholder:"Optional"})]})]})]}),e.jsx(i,{onClick:D,disabled:p,children:p?"Saving...":"Save Changes"})]})]}),e.jsxs(m,{children:[e.jsx(u,{children:e.jsx(h,{className:"text-lg",children:"Account Information"})}),e.jsx(x,{children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-muted-foreground",children:"Affiliate Code"}),e.jsx("p",{className:"font-mono font-medium",children:s==null?void 0:s.affiliate_code})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-muted-foreground",children:"Account Status"}),e.jsx("p",{className:"font-medium capitalize",children:s==null?void 0:s.status})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-muted-foreground",children:"One-time Commission Rate"}),e.jsxs("p",{className:"font-medium",children:[s==null?void 0:s.commission_rate_onetime,"%"]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-muted-foreground",children:"Recurring Commission Rate"}),e.jsxs("p",{className:"font-medium",children:[s==null?void 0:s.commission_rate_recurring,"%",s!=null&&s.recurring_duration_months?` for ${s.recurring_duration_months} months`:" (lifetime)"]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-muted-foreground",children:"Cookie Duration"}),e.jsxs("p",{className:"font-medium",children:[s==null?void 0:s.cookie_duration_days," days"]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-muted-foreground",children:"Member Since"}),e.jsx("p",{className:"font-medium",children:s!=null&&s.created_at?new Date(s.created_at).toLocaleDateString():"-"})]})]})})]}),e.jsxs(m,{className:"border-destructive/50",children:[e.jsxs(u,{children:[e.jsx(h,{className:"text-lg text-destructive",children:"Danger Zone"}),e.jsx(N,{children:"Irreversible account actions"})]}),e.jsx(x,{children:e.jsxs(i,{variant:"destructive",onClick:()=>d(!0),children:[e.jsx(F,{className:"mr-2 h-4 w-4"}),"Deactivate My Account"]})})]}),e.jsx(E,{open:C,onOpenChange:d,children:e.jsxs(I,{children:[e.jsxs(k,{children:[e.jsx(O,{children:"Deactivate Account"}),e.jsx(L,{children:"Are you sure you want to deactivate your affiliate account? You will no longer be able to access the affiliate portal or earn commissions. Any pending payouts will still be processed."})]}),e.jsxs(M,{children:[e.jsx(i,{variant:"outline",onClick:()=>d(!1),children:"Cancel"}),e.jsx(i,{variant:"destructive",onClick:b,disabled:g,children:g?"Deactivating...":"Yes, Deactivate"})]})]})})]})})}export{W 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.