1import{r as n,B as T,C as K,E as X,j as e,F as Y,z as Q,x as Z,q as w,G as ee,H as te,I as S,y as re,J as ae,K as se,o as ie}from"./index-BMxCD0ng.js";import{u as ne,O as R,M as F,c as D,p as M}from"./OrganizationLayout-DK39yyAj.js";import{P as de}from"./ProfileNav-BkYQFvsy.js";import{S as ce}from"./Spinner-BXpcrF0E.js";import{V as le,R as oe}from"./ViewScopeNotices-CU9EYRhs.js";import{T as me}from"./TrialCardGate-hahwm86I.js";import{u as ue,m as xe}from"./motion-uOwSnPxf.js";import"./Reef-CFkswW2i.js";import"./SiteNav-DLVknHGG.js";function fe(){const x=n.useId(),m=ue(),{data:k}=T(),a=K(k?.id),b=a.status==="ready";n.useEffect(()=>{b&&X()},[b]);const l=a.status==="ready"&&a.optIn===!0,z=a.status!=="ready"||a.saving;return e.jsxs("div",{className:"rounded-xl border border-zinc-200 bg-white p-6 shadow-sm dark:border-zinc-800 dark:bg-zinc-900 dark:shadow-black/30",children:[e.jsx("h2",{className:"mb-6 text-lg font-semibold text-zinc-900 dark:text-zinc-100",children:"Email preferences"}),e.jsxs("div",{className:"flex items-start justify-between gap-6",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:x,className:"text-sm font-medium text-zinc-900 dark:text-zinc-200",children:"Coral Learn newsletter"}),e.jsx("p",{className:"mt-0.5 max-w-md text-sm text-zinc-500 dark:text-zinc-400",children:"New articles, experiments and practical guides from the CoralBricks team. One email per article. Account and billing emails aren't affected."}),a.status==="unavailable"&&e.jsx("p",{className:"mt-2 text-sm text-zinc-500 dark:text-zinc-400",children:"Email preferences aren't available right now. Try again later."}),a.status==="ready"&&a.error&&e.jsx("p",{role:"alert",className:"mt-2 text-sm text-red-600 dark:text-red-400",children:a.error})]}),e.jsxs("button",{id:x,type:"button",role:"switch","aria-checked":l,disabled:z,onClick:()=>{Y(!l)},className:`relative mt-0.5 inline-flex h-7 w-12 shrink-0 items-center rounded-full border transition-[background-color,border-color] duration-200 active:scale-[0.97] disabled:cursor-not-allowed disabled:opacity-60 ${l?"border-cb-coral bg-cb-coral":"border-zinc-300 bg-zinc-200 dark:border-zinc-700 dark:bg-zinc-800"}`,children:[e.jsx("span",{className:"sr-only",children:l?"Subscribed":"Not subscribed"}),e.jsx(xe.span,{"aria-hidden":!0,className:"ml-[3px] block h-5 w-5 rounded-full bg-white shadow-[0_1px_3px_rgb(10_12_17/30%)]",initial:!1,animate:{x:l?20:0},transition:m?{duration:0}:{type:"spring",stiffness:700,damping:40}})]})]})]})}function ye(){const{scopeUserId:x,isViewingOther:m,viewerIsCoralAdmin:k}=ne(),a=m,b=m&&!k,l=n.useRef(0),[z,O]=n.useState(void 0),[B,U]=n.useState(!1),[E,A]=n.useState(!1),[N,o]=n.useState(""),[P,d]=n.useState(""),[C,L]=n.useState(!1),[i,f]=n.useState({firstName:"",lastName:"",email:"",emailVerified:!1,isActive:!0,createdAt:"",pictureUrl:null}),[v,g]=n.useState(!1),[V,h]=n.useState(""),I=n.useRef(null),{data:p}=T();n.useEffect(()=>{b||Q()&&G()},[x,b]),n.useEffect(()=>{!p||m||f(t=>({...t,firstName:p.firstName??t.firstName,lastName:p.lastName??t.lastName,pictureUrl:p.pictureUrl??t.pictureUrl,emailVerified:p.emailVerified??t.emailVerified}))},[p,m]);const G=async()=>{const t=++l.current,s=x;U(!0),o("");try{const r=await Z(w.user.profile(x??void 0));if(t!==l.current)return;if(r.error)o(r.error||"Failed to load user data");else{const c=r.data?.data?.user||r.data?.user||r.data?.data||r.data;f({firstName:c.firstName||"",lastName:c.lastName||"",email:c.email||"",emailVerified:c.emailVerified||!1,isActive:c.isActive!==!1,createdAt:c.createdAt||"",pictureUrl:c.pictureUrl??null}),O(s)}}catch(r){if(t!==l.current)return;o(r instanceof Error?r.message:"Failed to load user data")}finally{t===l.current&&U(!1)}},_=async t=>{if(t.preventDefault(),a)return;const s=D(i.firstName),r=D(i.lastName),c=M(s,"First name")??M(r,"Last name",{required:!1});if(c){o(c),d("");return}A(!0),o(""),d("");try{const u=await se(w.user.update(),{firstName:s,lastName:r});u.error?o(u.error):(S({firstName:s||null,lastName:r||null}),d("Profile updated successfully!"),setTimeout(()=>d(""),3e3))}catch(u){o(u instanceof Error?u.message:"Failed to update profile")}finally{A(!1)}},$=async t=>{const s=t.target.files?.[0];if(t.target.value="",!!s){if(s.size>5*1024*1024){h("Image must be smaller than 5 MB.");return}h(""),g(!0);try{const r=await ee()||te(),c="",u=new FormData;u.append("picture",s);const j=await fetch(`${c}/marketplace/v1/user/profile-picture`,{method:"PUT",body:u,headers:r?{Authorization:`Bearer ${r}`}:{}}),y=await j.json().catch(()=>({}));if(!j.ok)throw new Error(y.error||`Upload failed (${j.status})`);f(J=>({...J,pictureUrl:y.pictureUrl??null})),S({pictureUrl:y.pictureUrl??null}),d("Profile picture updated."),setTimeout(()=>d(""),3e3)}catch(r){h(r instanceof Error?r.message:"Upload failed")}finally{g(!1)}}},q=async()=>{h(""),g(!0);try{const t=await re("/marketplace/v1/user/profile-picture");
1if(t.error)throw new Error(t.error);f(s=>({...s,pictureUrl:null})),S({pictureUrl:null}),ae(),d("Profile picture removed."),setTimeout(()=>d(""),3e3)}catch(t){h(t instanceof Error?t.message:"Remove failed")}finally{g(!1)}},W=async()=>{L(!0),o(""),d("");try{const t=await ie(w.marketplace.resendAuth0Verification(),{});t.error?o(t.error||"Failed to resend verification email"):(t.data?.data?.verified?(d("Your email is already verified."),f(s=>({...s,emailVerified:!0}))):d("Verification email sent! Please check your inbox."),setTimeout(()=>d(""),5e3))}catch(t){o(t instanceof Error?t.message:"Failed to resend verification email")}finally{L(!1)}},H=t=>{try{return new Date(t).toLocaleDateString("en-US",{year:"numeric",month:"long",day:"numeric",hour:"2-digit",minute:"2-digit"})}catch{return t}};return b?e.jsx(R,{children:e.jsx(le,{page:"Settings"})}):e.jsx(R,{children:e.jsxs("div",{className:"mx-auto max-w-4xl space-y-8",children:[e.jsxs("div",{children:[e.jsx("p",{className:"mb-2 text-[11px] font-semibold uppercase tracking-[0.08em] text-cb-coral-600 dark:text-cb-coral-400",children:"Account"}),e.jsx("h1",{className:"text-[30px] font-semibold leading-tight tracking-[-0.02em] text-zinc-900 dark:text-zinc-50 md:text-[34px]",children:"Account Settings"})]}),a&&e.jsx(oe,{}),e.jsx(me,{isViewingOther:m}),P&&e.jsx("div",{className:"rounded-lg border border-emerald-200 bg-emerald-50 p-4 text-sm text-emerald-700 dark:border-emerald-900/60 dark:bg-emerald-950/40 dark:text-emerald-300",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("svg",{className:"h-4 w-4 text-emerald-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}),P]})}),N&&e.jsx("div",{className:"rounded-lg border border-red-200 bg-red-50 p-4 text-sm text-red-700 dark:border-red-900/60 dark:bg-red-950/40 dark:text-red-300",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("svg",{className:"h-4 w-4 text-red-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),N]})}),B||z!==x?N?null:e.jsx("div",{className:"rounded-xl border border-zinc-200 bg-white p-12 text-center shadow-sm dark:border-zinc-800 dark:bg-zinc-900",children:e.jsx(ce,{size:"lg",label:"Loading account informationâ¦"})}):e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{className:"rounded-xl border border-zinc-200 bg-white p-6 shadow-sm dark:border-zinc-800 dark:bg-zinc-900 dark:shadow-black/30",children:[e.jsx("h2",{className:"mb-6 text-lg font-semibold text-zinc-900 dark:text-zinc-100",children:"Profile Information"}),e.jsxs("div",{className:"mb-6 flex items-center gap-6",children:[e.jsx("div",{className:"h-20 w-20 flex-shrink-0 overflow-hidden rounded-full bg-cb-coral flex items-center justify-center",children:e.jsx(de,{pictureUrl:i.pictureUrl,className:"h-10 w-10 text-white"})}),!a&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("input",{ref:I,type:"file",accept:"image/jpeg,image/png,image/webp",className:"hidden",onChange:$}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",onClick:()=>I.current?.click(),disabled:v,className:"rounded-lg border border-zinc-300 bg-white px-3 py-1.5 text-sm font-medium text-zinc-700 hover:bg-zinc-50 disabled:opacity-50 dark:border-zinc-700 dark:bg-zinc-800 dark:text-zinc-200 dark:hover:bg-zinc-700",children:v?"Uploadingâ¦":i.pictureUrl?"Change picture":"Upload picture"}),i.pictureUrl&&e.jsx("button",{type:"button",onClick:q,disabled:v,className:"rounded-lg border border-zinc-300 bg-white px-3 py-1.5 text-sm font-medium text-zinc-700 hover:bg-zinc-50 disabled:opacity-50 dark:border-zinc-700 dark:bg-zinc-800 dark:text-zinc-200 dark:hover:bg-zinc-700",children:"Remove"})]}),e.jsx("p",{className:"text-xs text-zinc-500 dark:text-zinc-400",children:"JPEG, PNG, or WebP. Max 5 MB. Custom picture overrides your Google avatar."}
1),V&&e.jsx("p",{className:"text-xs text-cb-coral-600 dark:text-rose-400",children:V})]})]}),e.jsxs("form",{onSubmit:_,className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-6 md:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"mb-2 block text-sm font-medium text-zinc-900 dark:text-zinc-200",children:"First Name"}),e.jsx("input",{type:"text",value:i.firstName,onChange:t=>f(s=>({...s,firstName:t.target.value})),disabled:a,maxLength:F,className:"w-full rounded-lg border border-zinc-300 bg-white px-4 py-3 text-sm text-zinc-900 placeholder:text-zinc-500 focus:border-cb-coral focus:outline-none focus:ring-1 focus:ring-cb-coral dark:border-zinc-700 dark:bg-zinc-800 dark:text-zinc-100 dark:placeholder:text-zinc-500",placeholder:"Enter your first name"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-2 block text-sm font-medium text-zinc-900 dark:text-zinc-200",children:"Last Name"}),e.jsx("input",{type:"text",value:i.lastName,onChange:t=>f(s=>({...s,lastName:t.target.value})),disabled:a,maxLength:F,className:"w-full rounded-lg border border-zinc-300 bg-white px-4 py-3 text-sm text-zinc-900 placeholder:text-zinc-500 focus:border-cb-coral focus:outline-none focus:ring-1 focus:ring-cb-coral dark:border-zinc-700 dark:bg-zinc-800 dark:text-zinc-100 dark:placeholder:text-zinc-500",placeholder:"Enter your last name"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-2 block text-sm font-medium text-zinc-900 dark:text-zinc-200",children:"Email Address"}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("input",{type:"email",value:i.email,readOnly:!0,className:"flex-1 rounded-lg border border-zinc-300 bg-zinc-50 px-4 py-3 text-sm text-zinc-700 cursor-not-allowed dark:border-zinc-700 dark:bg-zinc-800/60 dark:text-zinc-400"}),e.jsx("span",{className:`inline-flex rounded-full px-3 py-1 text-xs font-medium ${i.emailVerified?"bg-emerald-100 text-emerald-800 dark:bg-emerald-950/40 dark:text-emerald-300":"bg-amber-100 text-amber-800 dark:bg-amber-950/40 dark:text-amber-300"}`,children:i.emailVerified?"Verified":"Unverified"}),!i.emailVerified&&!a&&e.jsx("button",{type:"button",onClick:W,disabled:C,className:"text-sm text-cb-coral-600 hover:text-cb-coral-400 font-medium disabled:opacity-50 disabled:cursor-not-allowed whitespace-nowrap dark:text-cb-coral-400 dark:hover:text-cb-coral-400",children:C?"Sending...":"Resend Email"})]}),e.jsx("p",{className:"mt-1 text-sm text-zinc-500 dark:text-zinc-400",children:"Email address cannot be changed. Contact support if you need to update it."})]}),!a&&e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"submit",disabled:E,className:"rounded-lg bg-cb-coral px-6 py-3 text-sm font-medium text-white hover:shadow-lg transition-all duration-200 disabled:opacity-50 disabled:cursor-not-allowed",children:E?"Saving...":"Save Changes"})})]})]}),e.jsxs("div",{className:"rounded-xl border border-zinc-200 bg-white p-6 shadow-sm dark:border-zinc-800 dark:bg-zinc-900 dark:shadow-black/30",children:[e.jsx("h2",{className:"mb-6 text-lg font-semibold text-zinc-900 dark:text-zinc-100",children:"Account Information"}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-zinc-200 dark:border-zinc-800",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-zinc-900 dark:text-zinc-200",children:"Account Status"}),e.jsx("div",{className:"text-sm text-zinc-500 dark:text-zinc-400",children:"Current status of your account"})]}),e.jsx("span",{className:`inline-flex rounded-full px-3 py-1 text-xs font-medium ${i.isActive?"bg-emerald-100 text-emerald-800 dark:bg-emerald-950/40 dark:text-emerald-300":"bg-red-100 text-red-800 dark:bg-red-950/40 dark:text-red-300"}`,children:i.isActive?"Active":"Inactive"})]}),e.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-zinc-200 dark:border-zinc-800",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-zinc-900 dark:text-zinc-200",children:"Member Since"}),e.jsx("div",{className:"text-sm text-zinc-500 dark:text-zinc-400",children:"When you joined CoralBricks"})]}),e.jsx("div",{className:"text-sm text-zinc-900 dark:text-zinc-200",children:i.createdAt?H(i.createdAt):"N/A"})]})]})]}),!m&&e.jsx(fe,{})]})]})})}export{ye as OrganizationSettings};
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.