1import{_ as w,r as c,s as p,j as e,a as n,I as l,S as x,z as g,D as j,F as _,G as f,B as v,C as A}from"./index-BemFr6U8.js";import{A as F,K as P,U as E}from"./AdminLayout-Dif4Acnh.js";import{T}from"./textarea-eJFy0uxF.js";import{C as D,b as G,c as L,d as I,a as M}from"./card-iKiACmKy.js";import{A as V,a as B,b as K}from"./alert-DQCgfafG.js";import{C as O}from"./copy-Db2qsttD.js";import"./shield-DrTblTXN.js";import"./layout-dashboard-5_jWpvNj.js";import"./use-mobile-1PH3TLH6.js";import"./building-2-BRDLqZIF.js";import"./user-check-DDbWgRZD.js";import"./graduation-cap-CEbVvphc.js";import"./trending-up-fLbaVcUG.js";import"./star-EoZPPjN6.js";import"./users-DkGVXX12.js";import"./calendar-days-DDxMstXA.js";import"./users-round-CXGFpdCx.js";import"./download-zkv6R0-2.js";import"./bell-BsQvpV9Y.js";import"./index-mIuwLVBy.js";import"./zap-BGiY2302.js";import"./circle-check-big-pdnR18S4.js";import"./isAfter-CagysP8H.js";import"./en-US-Ca8fhmg7.js";import"./subDays-C8JG4QrU.js";import"./formatDistanceToNow-CSEz7yxR.js";import"./endOfMonth-j36o3Juj.js";const y=[{value:"clarity",label:"Clarity (2 sessions)",defaultSessions:2},{value:"confidence",label:"Confidence (4 sessions)",defaultSessions:4},{value:"career-change",label:"Career Change (6 sessions)",defaultSessions:6}];function xe(){const{toast:d}=w(),[C,b]=c.useState([]),[m,u]=c.useState(!1),[i,h]=c.useState(null),[a,r]=c.useState({email:"",first_name:"",last_name:"",package_type:"career-change",coach_user_id:"",duration_days:120,sessions_total:6,notes:""});c.useEffect(()=>{p.rpc("get_approved_coach_names").then(({data:s})=>{s&&b(s)})},[]);const k=s=>{const t=y.find(o=>o.value===s);r(o=>({...o,package_type:s,sessions_total:(t==null?void 0:t.defaultSessions)??o.sessions_total}))},N=async s=>{s.preventDefault(),u(!0),h(null);try{const{data:t,error:o}=await p.functions.invoke("admin-grant-manual-access",{body:{email:a.email.trim(),first_name:a.first_name.trim(),last_name:a.last_name.trim(),package_type:a.package_type,coach_user_id:a.coach_user_id||null,duration_days:Number(a.duration_days),sessions_total:Number(a.sessions_total),notes:a.notes||void 0}});if(o)throw o;if(t!=null&&t.error)throw new Error(typeof t.error=="string"?t.error:JSON.stringify(t.error));h({magic_link:t.magic_link,was_created:t.was_created,expires_at:t.expires_at}),d({title:"Access granted",description:`${a.email} is set up.`})}catch(t){d({title:"Failed",description:t.message||"Could not grant access",variant:"destructive"})}finally{u(!1)}},S=()=>{i!=null&&i.magic_link&&(navigator.clipboard.writeText(i.magic_link),d({title:"Copied",description:"Magic link copied to clipboard."}))};return e.jsx(F,{children:e.jsxs("div",{className:"max-w-3xl mx-auto py-8 px-4 space-y-6",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-3xl font-bold text-foreground flex items-center gap-2",children:[e.jsx(P,{className:"w-7 h-7 text-primary"}),"Grant Manual Access"]}),e.jsx("p",{className:"text-muted-foreground mt-1",children:"Provision an account for off-platform purchases and send a magic link straight into onboarding."})]}),e.jsxs(D,{children:[e.jsxs(G,{children:[e.jsx(L,{children:"Member details"}),e.jsx(I,{children:"Used to create or update the account."})]}),e.jsx(M,{children:e.jsxs("form",{onSubmit:N,className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(n,{htmlFor:"first_name",children:"First name"}),e.jsx(l,{id:"first_name",required:!0,value:a.first_name,onChange:s=>r({...a,first_name:s.target.value})})]}),e.jsxs("div",{children:[e.jsx(n,{htmlFor:"last_name",children:"Last name"}),e.jsx(l,{id:"last_name",value:a.last_name,onChange:s=>r({...a,last_name:s.target.value})})]})]}),e.jsxs("div",{children:[e.jsx(n,{htmlFor:"email",children:"Email"}),e.jsx(l,{id:"email",type:"email",required:!0,value:a.email,onChange:s=>r({...a,email:s.target.value})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(n,{htmlFor:"package",children:"Package"}),e.jsxs(x,{value:a.package_type,onValueChange:k,children:[e.jsx(g,{id:"package",children:e.jsx(j,{})}),e.jsx(_,{children:y.map(s=>e.jsx(f,{value:s.value,children:s.label},s.value))})]})]}),e.jsxs("div",{children:[e.jsx(n,{htmlFor:"coach",children:"Assigned co
1ach"}),e.jsxs(x,{value:a.coach_user_id,onValueChange:s=>r({...a,coach_user_id:s}),children:[e.jsx(g,{id:"coach",children:e.jsx(j,{placeholder:"Select coach (optional)"})}),e.jsx(_,{children:C.map(s=>e.jsxs(f,{value:s.id,children:[s.first_name," ",s.last_name]},s.id))})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(n,{htmlFor:"sessions",children:"Coaching sessions"}),e.jsx(l,{id:"sessions",type:"number",min:1,max:100,value:a.sessions_total,onChange:s=>r({...a,sessions_total:Number(s.target.value)})})]}),e.jsxs("div",{children:[e.jsx(n,{htmlFor:"duration",children:"Package record duration (days)"}),e.jsx(l,{id:"duration",type:"number",min:1,max:3650,value:a.duration_days,onChange:s=>r({...a,duration_days:Number(s.target.value)})})]})]}),e.jsxs("div",{children:[e.jsx(n,{htmlFor:"notes",children:"Internal notes (optional)"}),e.jsx(T,{id:"notes",rows:3,value:a.notes,onChange:s=>r({...a,notes:s.target.value}),placeholder:"e.g. paid by bank transfer 1 Jun 2026, 2 extra sessions with Claudia for CV/interview prep"})]}),e.jsxs(v,{type:"submit",disabled:m,className:"w-full",children:[e.jsx(E,{className:"w-4 h-4 mr-2"}),m?"Provisioning...":"Grant access & generate link"]})]})})]}),i&&e.jsxs(V,{children:[e.jsx(A,{className:"h-4 w-4"}),e.jsx(B,{children:i.was_created?"Account created":"Existing account updated"}),e.jsxs(K,{children:[e.jsxs("p",{className:"mt-1",children:["Package record expires ",new Date(i.expires_at).toLocaleDateString("en-GB"),"."]}),i.magic_link?e.jsxs("div",{className:"mt-3 space-y-2",children:[e.jsx("p",{className:"font-medium",children:"Send this magic link to the member:"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(l,{readOnly:!0,value:i.magic_link,className:"font-mono text-xs"}),e.jsx(v,{type:"button",variant:"outline",size:"icon",onClick:S,children:e.jsx(O,{className:"w-4 h-4"})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Opens onboarding for this account."})]}):e.jsx("p",{className:"mt-2 text-muted-foreground",children:"No magic link generated â ask the member to sign in with their email."})]})]})]})})}export{xe 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.