1import{a3 as B,r,W as Q,a4 as K,j as e,a5 as F,C as j,a as I,b as q,a6 as O,d as f,I as i,B as R,L as S,P as T,a7 as G,q as x,h as k,E as M,s as t,k as m}from"./index-UvnNizN9.js";import{T as W,a as z,b as D,c,d as J,e as d}from"./table-ft49Ub_C.js";function Y(){const N=B(),[v,y]=r.useState(""),[w,L]=r.useState(""),[l,b]=r.useState(""),[u,_]=r.useState(""),[n,C]=r.useState(""),[U,E]=r.useState(!1),{data:h=[],isLoading:P}=Q({queryKey:["social-leads"],queryFn:async()=>{const{data:s,error:a}=await t.from("social_leads").select("*").order("created_at",{ascending:!1}).limit(50);if(a)throw a;return s}}),p=K({mutationFn:async()=>{if(!l.trim())throw new Error("External URL is required");const{data:s,error:a}=await t.from("social_leads").insert({platform:"instagram",instagram_handle:v.trim()||null,instagram_post_url:w.trim()||null,external_call_url:l.trim(),tags:u.trim()?u.split(",").map(o=>o.trim()):[],status:"processing"}).select("id").single();if(a)throw a;const{error:g}=await t.functions.invoke("discover-opportunities",{body:{ingest_url:l.trim()}});if(g)throw g;await t.from("social_leads").update({status:"processed"}).eq("id",s.id)},onSuccess:()=>{m.success("Lead ingested and queued for enrichment"),y(""),L(""),b(""),_(""),N.invalidateQueries({queryKey:["social-leads"]})},onError:s=>m.error(s.message)}),H=async()=>{if(n.trim()){E(!0);try{const{data:s,error:a}=await t.from("social_leads").insert({platform:"direct",external_call_url:n.trim(),status:"processing",tags:[]}).select("id").single();if(a)throw a;const{data:g,error:o}=await t.functions.invoke("discover-opportunities",{body:{ingest_url:n.trim()}});if(o)throw o;await t.from("social_leads").update({status:"processed"}).eq("id",s.id),m.success("URL ingested and queued for enrichment"),C(""),N.invalidateQueries({queryKey:["social-leads"]})}catch(s){m.error(s.message)}finally{E(!1)}}},A=s=>s==="processed"||s==="verified"?"default":s==="error"||s==="failed"?"destructive":"secondary";return e.jsxs("div",{className:"p-6 max-w-5xl mx-auto space-y-6",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl font-bold text-foreground flex items-center gap-2",children:[e.jsx(F,{className:"h-6 w-6"})," Lead Ingestion"]}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Add opportunities via Instagram or direct URL. External URLs will be scraped and enriched."})]}),e.jsxs(j,{children:[e.jsx(I,{children:e.jsxs(q,{className:"text-base flex items-center gap-2",children:[e.jsx(O,{className:"h-4 w-4"})," Add Opportunity URL Directly"]})}),e.jsxs(f,{children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(i,{placeholder:"https://example.com/open-call-details",value:n,onChange:s=>C(s.target.value),className:"flex-1"}),e.jsxs(R,{onClick:H,disabled:U||!n.trim(),children:[U?e.jsx(S,{className:"h-4 w-4 animate-spin mr-1"}):e.jsx(T,{className:"h-4 w-4 mr-1"}),"Ingest"]})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:"Paste any opportunity URL. It will go through the full pipeline: scrape â extract â classify â verified."})]})]}),e.jsxs(j,{children:[e.jsx(I,{children:e.jsxs(q,{className:"text-base flex items-center gap-2",children:[e.jsx(G,{className:"h-4 w-4"})," Add Instagram Lead"]})}),e.jsxs(f,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:"Instagram Handle"}),e.jsx(i,{placeholder:"@opencallfinder",value:v,onChange:s=>y(s.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:"Instagram Post URL"}),e.jsx(i,{placeholder:"https://instagram.com/p/...",value:w,onChange:s=>L(s.target.value)})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:"External Call URL *"}),e.jsx(i,{placeholder:"https://example.com/open-call-details",value:l,onChange:s=>b(s.target.value),required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:"Tags (comma-separated)"}),e.jsx(i,{placeholder:"Dance, Open Call, Europe",value:u,onChange:s=>_(s.target.value)})]}),e.jsxs(R,{onClick:()=>p.mutate(),disabled:p.isPending||!l.trim(),className:"gap-2",children:[p.isPending?e.jsx(S,{className:"h-4 w-4 animate-spin"}):e.jsx(T,{className:"h-4 w-4"}),"Add Lead"]})]})]}),e.jsxs("div",{children:[e.jsxs("h2",{className:"text-lg font-semibold mb-3",children:["Recent Leads (",h.length,")"]}),P?e.jsx("p",{className:"text-muted-foreground",children:"Loadingâ¦"}):h.length===0?e.jsx("p",{className:"text-muted-foreground",children:"No leads yet."}):e.jsx(j,{children:e.jsx(f,{className:"p-0",children:e.jsxs(W,{children:[e.jsx(z,{children:e.jsxs(D,{children:[e.jsx(c,{children:"Date"}),e.jsx(c,{children:"Source"}),e.jsx(c,{children:"URL"}),e.jsx(c,{children:"Status"}),e.jsx(c,{children:"Handle"})]})}),e.jsx(J,{children:h.map(s=>e.jsxs(D,{children:[e.jsx(d,{className:"text-xs text-muted-foreground whitespace-nowrap",children:new Date(s.created_at).toLocaleDateString()}),e.jsx(d,{children:e.jsx(k,{variant:"outline",className:"text-xs",children:s.platform})}),e.jsx(d,{className:"max-w-[300px]",children:e.jsxs("a",{href:s.external_call_url,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-primary hover:underline flex items-center gap-1 truncate",children:[s.external_call_url.slice(0,50),"â¦",e.jsx(M,{className:"h-3 w-3 shrink-0"})]})}),e.jsx(d,{children:e.jsx(k,{variant:A(s.status),className:"text-xs",children:s.status})}),e.jsx(d,{className:"text-xs text-muted-foreground",children:s.instagram_handle||"â"})]},s.id))})]})})})]})]})}export{Y 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.