1import{a as n,j as e}from"./vendor-query-BxlSJxfF.js";import{d as x,a$ as k,I as j,B as v,L as N,s as S,e as c}from"./index-DO0aGFYL.js";import{L as b}from"./label-Lh_RHPfV.js";import{A as w}from"./AdminPage-Bk0BX7la.js";import{A as y}from"./AdminCard-BSBYnc2T.js";import{E as A}from"./eye-zwjnFLuE.js";import{S as C}from"./send-C6vNENnO.js";import"./vendor-react-DdNhUK9-.js";import"./vendor-supabase-Csx7YFID.js";const E=k("relative w-full rounded-lg border p-4 [&>svg~*]:pl-7 [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground",{variants:{variant:{default:"bg-background text-foreground",destructive:"border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive"}},defaultVariants:{variant:"default"}}),m=n.forwardRef(({className:t,variant:r,...l},o)=>e.jsx("div",{ref:o,role:"alert",className:x(E({variant:r}),t),...l}));m.displayName="Alert";const L=n.forwardRef(({className:t,...r},l)=>e.jsx("h5",{ref:l,className:x("mb-1 font-medium leading-none tracking-tight",t),...r}));L.displayName="AlertTitle";const u=n.forwardRef(({className:t,...r},l)=>e.jsx("div",{ref:l,className:x("text-sm [&_p]:leading-relaxed",t),...r}));u.displayName="AlertDescription";const R="https://knuckl.com";function $(t="/"){const r=t.startsWith("/")?t:`/${t}`;return`${R}${r}`}function G(){const[t,r]=n.useState(50),[l,o]=n.useState($("/worker?addEmail=1")),[d,p]=n.useState(null),[a,h]=n.useState(null),f=async s=>{p(s?"dry":"send"),h(null);try{const{data:i,error:g}=await S.functions.invoke("email-capture-sms-backfill",{body:{limit:t,link:l,dryRun:s}});if(g)throw g;h(i),s?c.success(`Found ${i.candidateCount} candidates`):c.success(`Sent ${i.sent}, failed ${i.failed}`)}catch(i){c.error(i.message)}finally{p(null)}};return e.jsxs(w,{title:"Email Capture SMS Backfill",subtitle:"Send a one-time TCPA-compliant SMS to phone-only users inviting them to add an email. Already-messaged users are skipped.",children:[e.jsxs(y,{className:"p-4 space-y-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-semibold text-foreground",children:"Run options"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Throttled per cycle. Start with a dry run to preview."})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(b,{htmlFor:"limit",children:"Batch limit (max 500)"}),e.jsx(j,{id:"limit",type:"number",min:1,max:500,value:t,onChange:s=>r(Math.max(1,Math.min(500,Number(s.target.value)||0)))})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(b,{htmlFor:"link",children:"Deep link"}),e.jsx(j,{id:"link",value:l,onChange:s=>o(s.target.value)})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(v,{variant:"outline",onClick:()=>f(!0),disabled:d!==null,children:[d==="dry"?e.jsx(N,{className:"h-4 w-4 animate-spin mr-2"}):e.jsx(A,{className:"h-4 w-4 mr-2"}),"Dry run"]}),e.jsxs(v,{onClick:()=>f(!1),disabled:d!==null,children:[d==="send"?e.jsx(N,{className:"h-4 w-4 animate-spin mr-2"}):e.jsx(C,{className:"h-4 w-4 mr-2"}),"Send batch"]})]})]}),a&&e.jsxs(y,{className:"p-4 space-y-3",children:[e.jsx("h2",{className:"text-sm font-semibold text-foreground",children:"Result"}),a.dryRun?e.jsx(m,{children:e.jsxs(u,{children:[e.jsxs("div",{className:"font-medium",children:[a.candidateCount," candidate(s) would receive SMS"]}),a.sample&&a.sample.length>0&&e.jsx("ul",{className:"mt-2 text-xs space-y-1 font-mono",children:a.sample.map(s=>e.jsxs("li",{children:[s.phone," â ",s.full_name??"â"]},s.user_id))})]})}):e.jsx(m,{children:e.jsxs(u,{children:["Sent: ",e.jsx("strong",{children:a.sent})," · Failed: ",e.jsx("strong",{children:a.failed})," · Total: ",e.jsx("strong",{children:a.totalCandidates})]})}),a.errors&&a.errors.length>0&&e.jsxs("div",{className:"text-xs",children:[e.jsx("div",{className:"font-medium mb-1",children:"First errors:"}),e.jsx("ul",{className:"space-y-1 font-mono",children:a.errors.map((s,i)=>e.jsxs("li",{className:"text-destructive",children:[s.user_id.slice(0,8),": ",s.error]},i))})]})]})]})}export{G 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.