1import{r as h,j as e}from"./animation-CddyXVCz.js";import{s as J,D as B,u as U,m as Y,bz as M,p as G,h as x,bA as H,B as i,ae as W,T as D,aH as _,bB as $,bC as K}from"./index-CGKNpi9E.js";import{P as q}from"./PageWrapper-BunOBjUW.js";import{S as u}from"./SectionHeader-HhrOkJ88.js";import{t as Q}from"./calendarDate-C5srIsuk.js";import"./react-vendor-CbN3pvl2.js";import"./supabase-iKSPld20.js";import"./docgen-Bp8WKBAE.js";import"./query-DPqpbKNH.js";const V=async()=>{var n,t;const s=await((n=J)==null?void 0:n.auth.getSession()),o=(t=s==null?void 0:s.data.session)==null?void 0:t.access_token;if(!o)throw new Error("You need to be signed in to delete your account.");const c=await fetch("/api/user/account",{method:"DELETE",headers:{Authorization:`Bearer ${o}`}});if(!c.ok){const d=await c.json().catch(()=>({})),y=typeof d.error=="string"?d.error:typeof d.message=="string"?d.message:null;throw new Error(y||`Account deletion failed (${c.status})`)}},C="DELETE",X=s=>s===C,Z=(s=new Date)=>`careerdiary-export-${Q(s)}.json`,ee=(s,o=new Date)=>({format:"careerdiary-export",version:1,exportedAt:o.toISOString(),account:{id:s.userId,email:s.email??null},profile:s.profile??null,appliedJobs:[...s.appliedJobs??[]],tailoredResumes:[...s.tailoredResumes??[]]}),se=s=>JSON.stringify(s,null,2),ae=(s,o)=>{const c=new Blob([s],{type:"application/json;charset=utf-8"}),n=URL.createObjectURL(c),t=document.createElement("a");t.href=n,t.download=o,document.body.appendChild(t),t.click(),document.body.removeChild(t),setTimeout(()=>URL.revokeObjectURL(n),0)},xe=()=>{const s=B(),{state:o,actions:c,toast:n}=U(),{session:t,isGuest:d,signOut:y}=Y(),{handleSignOut:S,handleClearCareerDiary:A}=c,[E,j]=h.useState(!1),[O,b]=h.useState(!1),[g,f]=h.useState(!1),[w,p]=h.useState(""),[m,v]=h.useState(!1),{reset:T}=M(),N=X(w);G({title:"Settings | CareerDiary",description:"Manage your CareerDiary account, theme, and data preferences.",canonical:"https://careerdiary.io/app/settings"});const z=async()=>{if(window.confirm("Are you sure you want to clear all your Career Diary data? This action cannot be undone.")){j(!0);try{await A(),n.success("Data Cleared","All Career Diary data has been cleared.")}catch(r){const l=r;n.error("Clear Failed",(l==null?void 0:l.message)||"Failed to clear data. Please try again.")}finally{j(!1)}}},I=async()=>{if(t){b(!0);try{const a=t.user.id,[r,l]=await Promise.all([$(a),K(a)]),L=ee({userId:a,email:t.user.email,profile:o.profile,appliedJobs:r,tailoredResumes:l});ae(se(L),Z()),n.success("Download Started","Your CareerDiary data is saved as a JSON file.")}catch(a){const r=a;n.error("Download Failed",(r==null?void 0:r.message)||"Failed to download your data. Please try again.")}finally{b(!1)}}},R=()=>{p(""),f(!0)},k=()=>{m||(f(!1),p(""))};h.useEffect(()=>{if(!g)return;const a=r=>{r.key==="Escape"&&!m&&(f(!1),p(""))};return window.addEventListener("keydown",a),()=>window.removeEventListener("keydown",a)},[g,m]);const P=async a=>{if(a==null||a.preventDefault(),!(!N||m)){v(!0);try{await V()}catch(r){const l=r;n.error("Account Not Deleted",(l==null?void 0:l.message)||"Failed to delete your account. Please try again."),v(!1);return}await y(),s("/")}},F=async()=>{try{await S(),s("/")}catch(a){const r=a;n.error("Sign Out Failed",(r==null?void 0:r.message)||"Failed to sign out. Please try again.")}};return e.jsxs(q,{title:"Settings",description:"Manage your account preferences and settings",maxWidth:"2xl",children:[e.jsxs("div",{className:"space-y-6 pb-24 sm:pb-28",children:[e.jsxs(x,{children:[e.jsx(u,{title:"Account"}),e.jsx("div",{className:"space-y-4",children:t?e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-gray-900 dark:text-white",children:H(t.user.email)}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:"Signed in"})]}),e.jsx(i,{onClick:F,variant:"outline",size:"sm",children:"Sign Out"})]}):d?e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-gray-900 dark:text-white",children:"Guest Mode"}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:"Your data is stored locally"})]}),e.jsx(i,{onClick:()=>s("/"),variant:"primary",size:"sm",children:"Create Account"})]}):e.jsxs("div",{className:"text-center py-4",children:[e.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:"Not signed in"}),e.jsx(i,{onClick:()=>s("/"),variant:"primary",size:"sm",className:"mt-2",children:"Sign In"})]})})]}
1),e.jsxs(x,{children:[e.jsx(u,{title:"Appearance"}),e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-gray-900 dark:text-white",children:"Theme"}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:"Choose your preferred color scheme"})]}),e.jsx(W,{})]})})]}),e.jsxs(x,{children:[e.jsx(u,{title:"Billing & Usage"}),e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-gray-900 dark:text-white",children:"Review your credits and plan"}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:"See your daily AI credits, plan tier, and billing options in one place."})]}),e.jsx(i,{onClick:()=>s("/app/settings/billing"),variant:"primary",size:"sm",children:"Billing & Usage"})]})})]}),e.jsxs(x,{children:[e.jsx(u,{title:"Onboarding"}),e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-gray-900 dark:text-white",children:"Replay the new-user setup guide"}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:"Re-open the 5-step onboarding flow from your dashboard if you want the guided checklist again."})]}),e.jsx(i,{onClick:()=>{T(),s("/dashboard")},variant:"secondary",size:"sm",children:"Restart Onboarding"})]})})]}),e.jsxs(x,{children:[e.jsx(u,{title:"Data Management"}),e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-gray-900 dark:text-white",children:"Clear Career Diary"}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:"Remove all your profile data, experiences, and accomplishments"})]}),e.jsx(i,{onClick:z,loading:E,variant:"danger",size:"sm",leftIcon:e.jsx(D,{className:"h-4 w-4"}),children:"Clear Data"})]})})]}),t&&!d&&e.jsxs(x,{children:[e.jsx(u,{title:"Your Data"}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-gray-900 dark:text-white",children:"Download my data"}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:"Save your profile, Career Diary, tracked applications, and tailored resumes as a JSON file."})]}),e.jsx(i,{onClick:I,loading:O,variant:"secondary",size:"sm",leftIcon:e.jsx(_,{className:"h-4 w-4"}),children:"Download"})]}),e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-gray-900 dark:text-white",children:"Delete account"}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:"Permanently delete your account and everything in it. This cannot be undone."})]}),e.jsx(i,{onClick:R,variant:"danger",size:"sm",leftIcon:e.jsx(D,{className:"h-4 w-4"}),children:"Delete Account"})]})]})]}),e.jsxs(x,{children:[e.jsx(u,{title:"Help & Support"}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(i,{onClick:()=>s("/guide"),variant:"ghost",size:"sm",className:"w-full justify-start",children:"User Guide"}),e.jsx(i,{onClick:()=>s("/privacy"),variant:"ghost",size:"sm",className:"w-full justify-start",children:"Privacy Policy"}),e.jsx(i,{onClick:()=>s("/terms"),variant:"ghost",size:"sm",className:"w-full justify-start",children:"Terms of Service"})]})]})]}),g&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm p-4",onClick:k,role:"dialog","aria-modal":"true","aria-labelledby":"delete-account-title",children:e.jsxs("form",{onSubmit:P,onClick:a=>a.stopPropagation(),className:"bg-white dark:bg-slate-800 rounded-2xl shadow-xl max-w-md w-full p-5 sm:p-6 border border-red-200 dark:border-red-500/40",children:[e.jsx("h3",{id:"delete-account-title",className:"text-lg font-semibold text-gray-900 dark:text-white",children:"Delete your account?"}),e.jsxs("div",{className:"mt-2 space-y-3 text-sm text-gray-600 dark:text-slate-300",children:[e.jsx("p",{children:"This permanently deletes your CareerDiary account and everything in it:"}),e.jsxs("ul",{className:"list-disc pl-5 space-y-1",children:[e.jsx("li",{children:"Your profile and Career Diary"}),e.jsx("li",{children:"Tracked applications and saved jobs"}),e.jsx("li",{children:"Tailored resumes, cover letters, and uploaded documents"}),e.jsx("li",{children:"Your portfolio"})]}),e.jsx("p",{children:"A web subscription is canceled for you. One bought in the App Store is billed by Apple, so cancel it in your Ap
1ple account settings."}),e.jsx("p",{children:"This cannot be undone. Download your data first if you want a copy."})]}),e.jsxs("div",{className:"mt-4",children:[e.jsxs("label",{htmlFor:"delete-account-confirm",className:"block text-sm font-medium text-gray-900 dark:text-white",children:["Type ",C," to confirm"]}),e.jsx("input",{id:"delete-account-confirm",type:"text",value:w,onChange:a=>p(a.target.value),disabled:m,autoComplete:"off",autoCapitalize:"characters",spellCheck:!1,className:"iconic-input mt-2"})]}),e.jsxs("div",{className:"mt-6 flex flex-col-reverse sm:flex-row sm:justify-end gap-3",children:[e.jsx(i,{type:"button",onClick:k,disabled:m,variant:"secondary",size:"sm",className:"w-full sm:w-auto",children:"Cancel"}),e.jsx(i,{type:"submit",loading:m,disabled:!N,variant:"danger",size:"sm",className:"w-full sm:w-auto",children:"Delete Account"})]})]})})]})};export{xe as SettingsPage};
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.