1import{r as i,j as e,L as K}from"./react-vendor-CwEQiQ6L.js";import{dD as Y,ab as H,B as N,a6 as Q,ah as q,ae as W,ad as X,dE as J,t as x,dF as Z}from"./index-Cj9vsnc-.js";import{S as k}from"./skeleton-JU1CSfJW.js";import{S as D,a as P,b as _,c as A,d as y}from"./select-CPb0mHJk.js";import{I as ee}from"./input-evLa4T-_.js";import{A as se}from"./arrow-left-DHkQ-b7T.js";import{R as te}from"./refresh-cw-BG-M-l2o.js";import{C as L}from"./circle-alert-zSijk-A1.js";import{C as re}from"./circle-check-mIMkFoGf.js";import{C as ae}from"./circle-x-DKHRJ1d6.js";import"./radix-vendor-Ceih12To.js";import"./chevron-down-C8hO_PUB.js";import"./chevron-up-vBwmE_tK.js";const ne=["public_school","private_school","charter","homeschool_coop","after_school_program"],oe=["church_youth"],E={target:"",role:"child",grade:""};function Ne(){const n=Q(),[r,j]=i.useState([]),[c,m]=i.useState([]),[u,h]=i.useState(!0),[g,o]=i.useState(null),[d,G]=i.useState("all"),[l,F]=i.useState("pending"),[R,w]=i.useState({}),[z,f]=i.useState(null),[M,T]=i.useState(0),v=()=>T(s=>s+1);i.useEffect(()=>{if(!n){h(!1);return}let s=!0;return h(!0),Promise.all([Y({status:l==="resolved"?null:"pending",limit:250}),H()]).then(([t,a])=>{s&&(j(t),m(a))}).catch(t=>{s&&o(t instanceof Error?t.message:String(t))}).finally(()=>{s&&h(!1)}),()=>{s=!1}},[n,l,M]);const S=i.useMemo(()=>{const s=t=>d==="all"?!0:t.kind===d;return r.filter(t=>!(!s(t)||l==="resolved"&&t.status==="pending"||l==="pending"&&t.status!=="pending"))},[r,d,l]),b=i.useMemo(()=>{const s=new Set(ne),t=new Set(oe);return{school:c.filter(a=>s.has(a.group_type)).sort((a,p)=>a.name.localeCompare(p.name)),church:c.filter(a=>t.has(a.group_type)).sort((a,p)=>a.name.localeCompare(p.name))}},[c]),C=s=>{const t=R[s.id];return t||{...E,target:s.suggestedSchoolGroupId??""}},B=(s,t)=>w(a=>({...a,[s]:{...a[s]??E,...t}})),$=async s=>{const t=C(s);if(!t.target){x.error('Pick a target group or "Create new" first.');return}f(s.id);try{await Z(s.id,{targetSchoolGroupId:t.target==="new"?null:t.target,role:t.role,grade:t.grade||void 0}),x.success(t.target==="new"?`Created "${s.rawName}" and linked ${s.personFirstName??"contact"}.`:`Linked ${s.personFirstName??"contact"}.`),w(a=>{const{[s.id]:p,...U}=a;return U}),v()}catch(a){x.error(`Promote failed: ${a instanceof Error?a.message:String(a)}`)}finally{f(null)}},O=async s=>{f(s.id);try{await J(s.id),x.success("Dismissed."),v()}catch(t){x.error(`Dismiss failed: ${t instanceof Error?t.message:String(t)}`)}finally{f(null)}},V=r.filter(s=>s.status==="pending").length;return e.jsxs("div",{className:"p-6 space-y-6",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{children:[e.jsxs(K,{to:"/settings/integrations/mycyt",className:"text-sm text-gray-500 hover:text-gray-900 inline-flex items-center gap-1",children:[e.jsx(se,{size:14})," MyCYT ingest"]}),e.jsx("h1",{className:"text-2xl font-semibold text-gray-900 mt-1",children:"Group Sales affiliation queue"}),e.jsxs("p",{className:"text-sm text-gray-600 mt-1 max-w-2xl",children:["Roster rows whose ",e.jsx("code",{children:"School"})," or ",e.jsx("code",{children:"Place of Worship"})," ","didn't fuzzy-match an existing school or church-youth group in Group Sales. Promote each row to link the contact to an existing group (or create a new one), or dismiss if it's noise. Promoted affiliations land ",e.jsx("em",{children:"verified=true"}),"; auto-linked rows from name matches land"," ",e.jsx("em",{children:"verified=false"})," and appear on the school's Linked Families tab either way."]})]}),e.jsxs(N,{variant:"outline",onClick:v,disabled:!n||u,children:[e.jsx(te,{size:14,className:"mr-2"})," Refresh"]})]}),!n&&e.jsxs("div",{className:"rounded-md border border-amber-200 bg-amber-50 p-4 text-sm text-amber-900",children:[e.jsx(L,{size:14,className:"inline mr-2"}),"Connect Supabase (",e.jsx("code",{children:"VITE_USE_DB=true"}),") to work the queue."]}),g&&e.jsxs("div",{className:"rounded-md border border-red-200 bg-red-50 p-4 text-sm text-red-800",children:[e.jsx(L,{size:14,className:"inline mr-2"}),g]}),e.jsxs("div",{className:"flex flex-wrap gap-4 items-center",children:[e.jsx(I,{value:l,options:[{value:"pending",label:`Pending (${V})`},{value:"resolved",label:"Resolved"}],onChange:s=>F(s)}),e.jsx(I,{value:d,options:[{value:"all",label:"All"},{value:"school",label:"Schools"},{value:"church",label:"Churches"}],onChange:s=>G(s)})]}),e.jsx("div",{className:"rounded-lg border border-gray-200 bg-white overflow-hidden",children:u?e.jsxs("div",{className:"p-6 space-y-3",children:[e.jsx(k,{className:"h-6 w-1/3"}),e.jsx(k,{className:"h-6 w-1/2"})]}):S.length===0?e.jsxs("div",{className:"p-8 text-center",children:[e.jsx("div",{className:"text-sm text-gray-900 font-medium",children:l==="pending"?"Nothing pending":"Nothing resolved yet"}),e.jsx("div",{className:"text-sm text-gray-500 mt-1",children:l==="pending"?"Upload a MyCYT roster to see unmatched schools and churches land here.":"Promoted and dismissed rows will show up in this view."})]}):e.jsx("ul",{className:"divide-y divide-gray-100",children:S.map(s=>e.jsx(ie,{item:s,schoolGroups:s.kind==="church"?b.church:b.school,draft:C(s),onDraft:t=>B(s.id,t),onPromote:()=>$(s),onDismiss:()=>O(s),busy:z===s.id},s.id))})})]})}function I(n){return e.jsx("div",{className:"inline-flex rounded-md border border-gray-200 bg-gray-50 p-0.5",children:n.options.map(r=>e.jsx("button",{type:"button",className:"px-3 py-1 text-sm rounded "+(n.value===r.value?"bg-white text-gray-900 shadow-sm":"text-gray-600 hover:text-gray-900"),onClick:()=>n.onChange(r.value),children:r.label},r.value))})}function ie(n){const{item:r,schoolGroups:j,draft:c,busy:m}=n,u=r.status==="pending",h=[r.personFirstName,r.personLastName].filter(
1Boolean).join(" ")||"Unknown contact",g=r.kind==="church"?"Place of worship":"School";return e.jsx("li",{className:"p-4",children:e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"text-sm font-medium text-gray-900 truncate",children:[h,e.jsx("span",{className:"ml-2 text-xs uppercase tracking-wide text-gray-500",children:g})]}),e.jsxs("div",{className:"text-sm text-gray-600 mt-0.5",children:[e.jsxs("span",{className:"font-medium",children:['"',r.rawName,'"']}),r.sourceFilename&&e.jsxs("span",{className:"text-gray-400",children:[" · from ",r.sourceFilename]})]}),u&&r.suggestedSchoolGroupName&&e.jsxs("div",{className:"mt-1.5 inline-flex items-center gap-1.5 rounded-md bg-violet-50 text-violet-800 border border-violet-200 px-2 py-0.5 text-xs",children:[e.jsx(q,{size:11}),"Suggested: ",r.suggestedSchoolGroupName,r.similarityScore!==null&&e.jsxs("span",{className:"text-violet-600",children:["(",Math.round(r.similarityScore*100),"%)"]})]}),r.status!=="pending"&&e.jsx("div",{className:"text-xs text-gray-500 mt-1",children:r.status==="promoted"?e.jsxs("span",{className:"inline-flex items-center gap-1 text-emerald-700",children:[e.jsx(re,{size:12})," Promoted"," ",r.resolvedAt&&`on ${new Date(r.resolvedAt).toLocaleDateString()}`]}):e.jsxs("span",{className:"inline-flex items-center gap-1 text-gray-600",children:[e.jsx(ae,{size:12})," Dismissed"," ",r.resolvedAt&&`on ${new Date(r.resolvedAt).toLocaleDateString()}`]})})]}),u&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(D,{value:c.target||void 0,onValueChange:o=>n.onDraft({target:o}),children:[e.jsx(P,{className:"w-64",children:e.jsx(_,{placeholder:"Match or createâ¦"})}),e.jsxs(A,{children:[e.jsxs(y,{value:"new",children:['+ Create "',r.rawName,'" as new'," ",r.kind==="church"?"church-youth":"school"]}),j.map(o=>e.jsxs(y,{value:o.id,children:[o.name," ",e.jsxs("span",{className:"text-xs text-gray-500",children:["· ",W[o.group_type]]})]},o.id))]})]}),e.jsxs(D,{value:c.role,onValueChange:o=>n.onDraft({role:o}),children:[e.jsx(P,{className:"w-40",children:e.jsx(_,{})}),e.jsx(A,{children:Object.entries(X).map(([o,d])=>e.jsx(y,{value:o,children:d},o))})]}),e.jsx(ee,{placeholder:"Grade",value:c.grade,onChange:o=>n.onDraft({grade:o.target.value}),className:"w-20"}),e.jsx(N,{size:"sm",onClick:n.onPromote,disabled:m,children:m?"Workingâ¦":"Promote"}),e.jsx(N,{size:"sm",variant:"outline",onClick:n.onDismiss,disabled:m,children:"Dismiss"})]})]})})}export{Ne as SettingsGroupSalesQueue};
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.