1import{af as O,ah as l,x as Y,i as J,r as m,e as X,a6 as A,l as B,j as e,n as g,H as j,I as f,M as N,B as x,o as y,J as i,X as _,v as C,ar as W,a1 as w,a3 as k,a7 as q,m as F,q as U}from"./index-Bfoo6lbk.js";import{I as d}from"./input-BvivHdOb.js";import{C as $,a as G,b as Z}from"./collapsible-B-itdNUr.js";import{S as D}from"./switch-CisT3l6U.js";import{P as ee}from"./ProfessionalLayout-CqCXJb_i.js";import{U as L}from"./user-D1OWNgL1.js";import{S as se}from"./square-pen-CF6vQ602.js";import{S as ae}from"./save-CMs8Aa8P.js";import{S as re}from"./search-BalJhKxo.js";import{C as te}from"./chevron-down-BH329--v.js";import{a as ie}from"./avatar-B92vVn88.js";import{B as ne}from"./building-2-BTi_Exg2.js";import{S as de}from"./shield-CUA3tUqT.js";import{C as H}from"./circle-check-Cv177cdU.js";import"./index-BEiALmq1.js";import"./TopNavbar-DvPKrLLY.js";import"./select-DsRXan1i.js";import"./index-CxjCBplK.js";import"./index-Dnn2g0iV.js";import"./upload-CgMeD-w4.js";import"./popover-CaialJOY.js";import"./briefcase-Dt5Cn-ST.js";import"./log-out-B-OiC1sU.js";import"./refresh-cw-DZ5EF0zJ.js";import"./arrow-right-Dpazjd0u.js";const le=O({firstName:l().optional(),surname:l().optional(),email:l().email("Invalid email address"),mobile:l().optional()}),oe=O({currentPassword:l().min(1,"Current password is required"),newPassword:l().min(8,"Password must be at least 8 characters"),confirmPassword:l().min(1,"Please confirm your password")}).refine(a=>a.newPassword===a.confirmPassword,{message:"Passwords don't match",path:["confirmPassword"]});function We(){var M,T;const{user:a}=Y(),{toast:o}=J(),[c,b]=m.useState(!1),[S,h]=m.useState(!1),[R,P]=m.useState(!1),[I,E]=m.useState(!1),{data:s}=X({queryKey:["/api/billing/me"]}),t=A({resolver:q(le),defaultValues:{firstName:"",surname:"",email:"",mobile:""}});m.useEffect(()=>{a&&t.reset({firstName:a.firstName||"",surname:a.surname||"",email:a.email||"",mobile:a.mobile||""})},[a,t]),m.useEffect(()=>{if(a!==void 0){const r=s!=null&&s.team?s.team.defaultWebSearchInNormal:void 0,v=(a==null?void 0:a.webSearchInNormalMode)??r??!1;P(v)}},[a,s]);const n=A({resolver:q(oe),defaultValues:{currentPassword:"",newPassword:"",confirmPassword:""}}),p=B({mutationFn:async r=>await F("PATCH","/api/users/me",r),onSuccess:()=>{U.invalidateQueries({queryKey:["/api/auth/me"]}),b(!1),o({title:"Success",description:"Your personal information has been updated"})},onError:r=>{o({title:"Error",description:r.message||"Failed to update personal information",variant:"destructive"})}}),u=B({mutationFn:async r=>await F("POST","/api/users/me/change-password",{currentPassword:r.currentPassword,newPassword:r.newPassword}),onSuccess:()=>{n.reset(),h(!1),o({title:"Success",description:"Your password has been changed successfully"})},onError:r=>{o({title:"Error",description:r.message||"Failed to change password",variant:"destructive"})}}),V=r=>{p.mutate(r)},K=r=>{u.mutate(r)},Q=()=>{t.reset({firstName:(a==null?void 0:a.firstName)||"",surname:(a==null?void 0:a.surname)||"",email:(a==null?void 0:a.email)||"",mobile:(a==null?void 0:a.mobile)||""}),b(!1)},z=async r=>{E(!0);try{await F("PATCH","/api/users/me",{webSearchInNormalMode:r}),P(r),U.invalidateQueries({queryKey:["/api/auth/me"]}),o({title:"Preference Updated",description:`Web search in Normal mode has been ${r?"enabled":"disabled"}`})}catch(v){o({title:"Error",description:v.message||"Failed to update web search preference",variant:"destructive"}),P(!r)}finally{E(!1)}};return e.jsx(ee,{menuStructure:[],selectedMenuItem:null,onMenuItemSelect:()=>{},children:e.jsxs("div",{className:"space-y-6 max-w-4xl",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold text-gray-900 dark:text-white","data-testid":"text-page-title",children:"Account Settings"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mt-1",children:"Manage your account information and security settings"})]}),e.jsxs(g,{className:"border border-gray-200 dark:border-gray-700",children:[e.jsxs(j,{className:"flex flex-row items-center justify-between space-y-0 pb-4",children:[e.jsxs("div",{children:[e.jsxs(f,{className:"text-xl font-semibold flex items-center gap-2",children:[e.jsx(L,{className:"w-5 h-5 text-primary"}),"Personal Information"]}),e.jsx(N,{children:"Update your personal details and contact information"})]}),!c&&e.jsxs(x,{variant:"outline",size:"sm",onClick:()=>b(!0),"data-testid":"button-edit-personal-info",children:[e.jsx(se,{className:"w-4 h-4 mr-2"}),"Edit"]})]}),e.jsx(y,{children:e.jsxs("form",{onSubmit:t.handleSubmit(V),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(i,{htmlFor:"firstName",children:"First Name"}),e.jsx(d,{id:"firstName",...t.register("firstName"),disabled:!c,"data-testid":"input-firstName"}),t.formState.errors.firstName&&e.jsx("p",{className:"text-sm text-red-500",children:t.formState.errors.firstName.message})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(i,{htmlFor:"surname",children:"Surname"}),e.jsx(d,{id:"surname",...t.register("surname"),disabled:!c,"data-testid":"input-surname"}),t.formState.errors.surname&&e.jsx("p",{className:"text-sm text-red-500",children:t.formState.errors.surname.message})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(i,{htmlFor:"username",children:"Username"}),e.jsx(d,{id:"username",value:(a==null?void 0:a.username)||"",disabled:!0,className:"bg-gray-50 dark:bg-gray-900","data-testid":"input-username"}),e.jsx("p",{className:"text-xs text-gray-500",children:"Username cannot be changed"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(i,{htmlFor:"email",children:"Email Address"}),e.jsx(d,{id:"email",type:"email",...t.register("email"),disabled:!c,"data-testid":"input-email"}),t.formState.errors.email&&e.jsx("p",{className:"text-sm text-red-500",children:t.formState.errors.email.message})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(i,{htmlFor:"mobile",children:"Mobile Number"}),e.jsx(d,{id:"mobile",...t.register("mobile"),disabled:!c,placeholder:"+1 234 567 8900","data-testid":"input-mobile"}),t.formState.errors.mobile&&e.jsx("p",{className:"text-sm text-red-500",children:t.formState.errors.mobile.message})]})]}),c&&e.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[e.jsxs(x,{type:"button",variant:"outline",onClick:Q,disabled:p.isPending,"data-testid":"button-cancel-edit",children:[e.jsx(_,{className:"w-4 h-4 mr-2"}),"Cancel"]}),e.jsx(x,{type:"submit",disabled:p.isPending,"data-testid":"button-save-personal-info",children:p.isPending?e.jsxs(e.Fragment,{children:[e.jsx(C,{className:"w-4 h-4 mr-2 animate-spin"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(ae,{className:"w-4 h-4 mr-2"}),"Save Changes"]})})]})]})})]}),e.jsxs(g,{className:"border border-gray-200 dark:border-gray-700",children:[e.jsxs(j,{children:[e.jsxs(f,{className:"text-xl font-semibold flex items-center gap-2",children:[e.jsx(re,{className:"w-5 h-5 text-primary"}),"Search Preferences"]}),e.jsx(N,{children:"Customise how AI searches for information in Normal mode"})]}),e.jsx(y,{children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"flex items-center gap-2 mb-2",children:e.jsx(i,{htmlFor:"web-search-toggle",className:"text-base font-medium cursor-pointer",children:"Enable Web Search in Normal Mode"})}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:"When enabled, Normal mode will search the web for current information. This provides up-to-date results but uses additional API quota."}),(a==null?void 0:a.webSearchInNormalMode)===null&&(s==null?void 0:s.team)&&s.team.defaultWebSearchInNormal!==void 0&&e.jsxs("p",{className:"text-xs text-gray-500 dark:text-gray-500 mt-2",children:["Currently using team default: ",s.team.defaultWebSearchInNormal?"Enabled":"Disabled"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[I&&e.jsx(C,{className:"w-4 h-4 animate-spin text-gray-500"}),e.jsx(D,{id:"web-search-toggle",checked:R,onCheckedChange:z,disabled:I,"data-testid":"switch-web-search-normal-mode"})]})]})})]}),e.jsx(g,{className:"border border-gray-200 dark:border-gray-700",children:e.jsxs($,{open:S,onOpenChange:h,children:[e.jsx(j,{className:"cursor-pointer",onClick:()=>h(!S),children:e.jsxs(G,{className:"flex items-center justify-between w-full",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(W,{className:"w-5 h-5 text-primary"}),e.jsxs("div",{className:"text-left",children:[e.jsx(f,{className:"text-xl font-semibold",children:"Password & Security"}),e.jsx(N,{children:"Change your password to keep your account secure"})]})]}),S?e.jsx(te,{className:"w-5 h-5"}):e.jsx(ie,{className:"w-5 h-5"})]})}),e.jsx(Z,{children:e.jsx(y,{children:e.jsxs("form",{onSubmit:n.handleSubmit(K),className:"space-y-4",children:[e.jsxs("div",{className:"space-y-4 max-w-md",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(i,{htmlFor:"currentPassword",children:"Current Password"}),e.jsx(d,{id:"currentPassword",type:"password",...n.register("currentPassword"),"data-testid":"input-currentPassword"}),n.formState.errors.currentPassword&&e.jsx("p",{className:"text-sm text-red-500",children:n.formState.errors.currentPassword.message})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(i,{htmlFor:"newPassword",children:"New Password"}),e.jsx(d,{id:"newPassword",type:"password",...n.register("newPassword"),"data-testid":"input-newPassword"}),n.formState.errors.newPassword&&e.jsx("p",{className:"text-sm text-red-500",children:n.formState.errors.newPassword.message}),e.jsx("p",{className:"text-xs text-gray-500",children:"Password must be at least 8 characters long"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(i,{htmlFor:"confirmPassword",children:"Confirm New Password"}),e.jsx(d,{id:"confirmPassword",type:"password",...n.register("confirmPassword"),"data-testid":"input-confirmPassword"}),n.formState.errors.confirmPassword&&e.jsx("p",{className:"text-sm text-red-500",children:n.formState.errors.confirmPassword.message})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[e.jsx(x,{type:"button",variant:"outline",onClick:()=>{n.reset(),h(!1)},disabled:u.isPending,"data-testid":"button-cancel-password",children:"Cancel"}),e.jsx(x,{type:"submit",disabled:u.isPending,"data-testid":"button-change-password",children:u.isPending?e.jsxs(e.Fragment,{children:[e.jsx(C,{className:"w-4 h-4 mr-2 animate-spin"}),"Changing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(W,{className:"w-4 h-4 mr-2"}),"Change Password"]})})]})]})})})]})}),e.jsxs(g,{className:"border border-gray-200 dark:border-gray-700",children:[e.jsxs(j,{children:[e.jsxs(f,{className:"text-xl font-semibold flex items-center gap-2",children:[e.jsx(w,{className:"w-5 h-5 text-primary"}),"Account & Billing"]}),e.jsx(N,{children:"View your subscription and billing information"})]}),e.jsx(y,{children:e.jsxs("div",{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(i,{className:"text-gray-600 dark:text-gray-400",children:"Team Name"}),e.jsxs("div",{className:"flex items-center gap-2 p-3 bg-gray-50 dark:bg-gray-900 rounded-md",children:[e.jsx(ne,{className:"w-4 h-4 text-gray-500"}),e.jsx("span",{className:"font-medium","data-testid":"text-team-name",children:((M=s==null?void 0:s.team)==null?void 0:M.name)||(a==null?void 0:a.name)||"No team"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(i,{className:"text-gray-600 dark:text-gray-400",children:"Current Package"}),e.jsxs("div",{className:"flex items-center gap-2 p-3 bg-gray-50 dark:bg-gray-900 rounded-md",children:[e.jsx(de,{className:"w-4 h-4 text-gray-500"}),e.jsx("span",{className:"font-medium","data-testid":"text-package-name",children:((T=s==null?void 0:s.currentPackage)==null?void 0:T.name)||"No package"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(i,{className:"text-gray-600 dark:text-gray-400",children:"Billing Status"}),e.jsx("div",{className:"flex items-center gap-2 p-3 bg-gray-50 dark:bg-gray-900 rounded-md",children:(s==null?void 0:s.stripeSubscriptionStatus)==="active"?e.jsxs(e.Fragment,{children:[e.jsx(H,{className:"w-4 h-4 text-green-500"}),e.jsx("span",{className:"font-medium text-green-600 dark:text-green-400","data-testid":"text-billing-status",children:"Active"})]}):(s==null?void 0:s.stripeSubscriptionStatus)==="trialing"?e.jsxs(e.Fragment,{children:[e.jsx(H,{className:"w-4 h-4 text-blue-500"}
1),e.jsx("span",{className:"font-medium text-blue-600 dark:text-blue-400","data-testid":"text-billing-status",children:"Trial"})]}):(s==null?void 0:s.stripeSubscriptionStatus)==="past_due"?e.jsxs(e.Fragment,{children:[e.jsx(k,{className:"w-4 h-4 text-orange-500"}),e.jsx("span",{className:"font-medium text-orange-600 dark:text-orange-400","data-testid":"text-billing-status",children:"Past Due"})]}):s!=null&&s.stripeSubscriptionStatus?e.jsxs(e.Fragment,{children:[e.jsx(k,{className:"w-4 h-4 text-gray-500"}),e.jsx("span",{className:"font-medium text-gray-600 dark:text-gray-400","data-testid":"text-billing-status",children:s.stripeSubscriptionStatus})]}):e.jsxs(e.Fragment,{children:[e.jsx(k,{className:"w-4 h-4 text-gray-500"}),e.jsx("span",{className:"font-medium text-gray-600 dark:text-gray-400","data-testid":"text-billing-status",children:"No active subscription"})]})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(i,{className:"text-gray-600 dark:text-gray-400",children:"Account Role"}),e.jsxs("div",{className:"flex items-center gap-2 p-3 bg-gray-50 dark:bg-gray-900 rounded-md",children:[e.jsx(L,{className:"w-4 h-4 text-gray-500"}),e.jsx("span",{className:"font-medium capitalize","data-testid":"text-role",children:(a==null?void 0:a.role)||"user"})]})]}),(s==null?void 0:s.nextBillingDate)&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(i,{className:"text-gray-600 dark:text-gray-400",children:"Next Billing Date"}),e.jsxs("div",{className:"flex items-center gap-2 p-3 bg-gray-50 dark:bg-gray-900 rounded-md",children:[e.jsx(w,{className:"w-4 h-4 text-gray-500"}),e.jsx("span",{className:"font-medium","data-testid":"text-next-billing",children:new Date(s.nextBillingDate).toLocaleDateString()})]})]}),(s==null?void 0:s.paymentMethodLast4)&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(i,{className:"text-gray-600 dark:text-gray-400",children:"Payment Method"}),e.jsxs("div",{className:"flex items-center gap-2 p-3 bg-gray-50 dark:bg-gray-900 rounded-md",children:[e.jsx(w,{className:"w-4 h-4 text-gray-500"}),e.jsxs("span",{className:"font-medium","data-testid":"text-payment-method",children:["â¢â¢â¢â¢ ",s.paymentMethodLast4]})]})]})]}),(s==null?void 0:s.stripeSubscriptionStatus)&&e.jsx("div",{className:"mt-6 pt-6 border-t border-gray-200 dark:border-gray-700",children:e.jsx(x,{asChild:!0,className:"w-full","data-testid":"button-manage-billing",children:e.jsxs("a",{href:"/account-settings",children:[e.jsx(w,{className:"w-4 h-4 mr-2"}),"Manage Billing & Invoices"]})})})]})})]})]})})}export{We as UserProfile};
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.