1import{r as j,j as e,D as q,o as V,q as B,t as M,a0 as F,Q as G,B as d,P as _,g as T,K as H,v as K,$ as p,O as U,w as o}from"./index-KkoT--wm.js";import{P as Z}from"./PageContainer-Bxab-5a3.js";import{T as $}from"./textarea-Z1pEoW_D.js";import{S as J}from"./slider-CEghE_8P.js";import{S as D}from"./switch-7Cwm30HW.js";import{S as E,a as P,b as I,c as A,f as R}from"./select-K_8a4ryX.js";import{C as X}from"./confirm-dialog-BuKstdy4.js";import{I as w,u as ee,a as te,b as se,c as ae,d as re,e as ie,f as ne,D as y}from"./dynamic-icon-BtjScOyx.js";import{E as ce}from"./EmptyState-D5lFsQzT.js";import{P as le}from"./pencil-DpDilPJh.js";import{T as oe}from"./trash-2-CfOovbRE.js";import"./arrow-left-CpRyp-pH.js";import"./index-BdQq_4o_.js";import"./index-CnIxGKKI.js";import"./alert-dialog-BMYpiwIq.js";import"./shield-alert-D6Ti0A4t.js";import"./trending-down-CYjIzZTL.js";import"./wrench-D39ghaUN.js";import"./sliders-horizontal-cEzMtVlh.js";import"./quote-D8JQu-6c.js";import"./book-open---3vDKgc.js";import"./info-DbIeIJia.js";import"./chevron-left-Dr3AwD3s.js";import"./chevrons-up-down-CRL3gPiE.js";import"./circle-check-DjE7jGMK.js";import"./circle-dot-BlLmkUzY.js";import"./circle-x-BrJ9N7rR.js";import"./stethoscope-CzjPsELY.js";import"./pause-BPG9eYGv.js";import"./code-xml-bmL4QdCu.js";import"./copy-Cbl3ZEBs.js";import"./database-Ce8eNmxd.js";import"./dollar-sign-D3ToKbx4.js";import"./download-B6kWJwAI.js";import"./ellipsis-vertical-DqF18IUj.js";import"./tags-CrQQVXqY.js";import"./external-link-D34Xclo7.js";import"./eye-off-QrYYfk1R.js";import"./eye-BCAv9Spf.js";import"./file-spreadsheet-BTjy5Mv5.js";import"./network-CtEYqIta.js";import"./globe-BSm6UBCL.js";import"./image-down-BTHVyceR.js";import"./inbox-DaMbAO59.js";import"./layers-DYZ8uuRC.js";import"./layout-grid-DGKnB2Ht.js";import"./list-checks-iqwd179Q.js";import"./list-C7uG4AGB.js";import"./mail-check-ClgtKfFj.js";import"./mail-plus-D7jgAIa2.js";import"./target-G1puX8Bi.js";import"./octagon-alert-Cj6xlvHk.js";import"./paperclip-BHO66JCA.js";import"./play-BXnzWYBL.js";import"./plug-CWJ2SLuN.js";import"./printer-X7AuoaLY.js";import"./rotate-ccw-C2hFst9s.js";import"./save-CIZE3nGU.js";import"./search-BqhjmT-E.js";import"./server-gnoR--BF.js";import"./square-pen-Dua2CVis.js";import"./square-DRHjAEtQ.js";import"./star-BJcOMCil.js";import"./triangle-alert-CCIOhGK3.js";import"./unplug-Bdiy5LPB.js";import"./user-Dlqsy3_q.js";import"./zap-C4n2AZrt.js";const L=Object.keys(w).filter(r=>/^[A-Z]/.test(r)&&!r.endsWith("Icon")&&r!=="createLucideIcon").filter(r=>{const n=w[r];return typeof n=="object"||typeof n=="function"});function me({open:r,onOpenChange:n,value:l,onChange:g}){const[c,x]=j.useState(""),m=j.useMemo(()=>{const i=c.trim().toLowerCase();return(i?L.filter(s=>s.toLowerCase().includes(i)):L).slice(0,600)},[c]);return e.jsx(q,{open:r,onOpenChange:n,children:e.jsxs(V,{className:"max-w-2xl",children:[e.jsx(B,{children:e.jsx(M,{children:"Choose an icon"})}),e.jsx(F,{autoFocus:!0,placeholder:"Search iconsâ¦",value:c,onChange:i=>x(i.target.value)}),e.jsx("div",{className:"max-h-[60vh] overflow-y-auto rounded border p-2",children:e.jsx("div",{className:"grid grid-cols-8 gap-1.5 sm:grid-cols-10",children:m.map(i=>{const s=w[i];return s?e.jsx("button",{type:"button",title:i,onClick:()=>{g(i),n(!1)},className:G("flex h-10 w-10 items-center justify-center rounded border text-muted-foreground hover:bg-accent hover:text-accent-foreground",l===i&&"border-primary text-primary"),children:e.jsx(s,{className:"h-4 w-4"})},i):null})})})]})})}const de=["news","events","customers","other"],pe=["company","contact"];function O(){return{name:"",icon:"Search",target_type:"company",element_type:"news",context:"",serp_pages:3,scrape_per_result:2,follow_links:1,is_active:!0}}function kt(){const{data:r,isLoading:n}=ee(),{data:l}=te(),{data:g}=se(),c=ae(),x=re(),m=ie(),i=ne(),[s,a]=j.useState(null),[z,b]=j.useState(!1),[f,v]=j.useState(null),C=s!==null,S=C&&!(s!=null&&s.id),k=new Map((g??[]).map(t=>[t.system_template_id,t]));async function Q(t,u){try{if(u)await c.mutateAsync(t),o({title:"Template activated",description:"An editable copy was added to your templates."});else{const h=k.get(t.id);if(!h)return;await x.mutateAsync(h),o({title:"Template deactivated"})}}catch(h){o({title:"Action failed",description:h.message,variant:"destructive"})}}async function W(){var t;if(!((t=s==null?void 0:s.name)!=null&&t.trim())){o({title:"Name required",variant:"destructive"});return}try{await m.mutateAsync(s),o({title:S?"Template created":"Template updated"}),a(null)}catch(u){o({title:"Save failed",description:u.message,variant:"destructive"})}}async function Y(){if(f)try{await i.mutateAsync(f),o({title:"Template deleted"})}catch(t){o({title:"Delete failed",description:t.message,variant:"destructive"})}finally{v(null)}}return e.jsxs(Z,{title:"Research templates",description:"Define reusable research recipes that plan SERP searches, scrape sources, and extract structured items.",action:e.jsxs(d,{onClick:()=>a(O()),children:[e.jsx(_,{className:"mr-2 h-4 w-4"})," New template"]}),children:[!!(l!=null&&l.length)&&e.jsxs("section",{className:"mb-8 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("h2",{className:"shrink-0 text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:"System templates"}),e.jsx("div",{className:"h-px flex-1 bg-border"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Toggle on to add an editable copy to your workspace."}),e.jsx("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3",children:l.map(t=>{const u=k.has(t.id);return e.jsxs(T,{className:"flex items-start gap-3 p-4",children:[e.jsx("div",{className:"grid h-10 w-10 shrink-0 place-items-center rounded-md bg-accent text-accent-foreground",children:e.jsx(y,{name:t.icon,
1className:"h-5 w-5"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate font-medium",children:t.name}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[t.target_type," · ",t.element_type]}),t.context&&e.jsx("p",{className:"mt-2 line-clamp-2 text-xs text-muted-foreground",children:t.context})]}),e.jsx(D,{checked:u,disabled:c.isPending||x.isPending,onCheckedChange:h=>Q(t,h),"aria-label":u?"Deactivate":"Activate"})]},t.id)})})]}),n?e.jsx(H,{}):r!=null&&r.length?e.jsxs("section",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("h2",{className:"shrink-0 text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:"Workspace templates"}),e.jsx("div",{className:"h-px flex-1 bg-border"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Editable copies and custom templates for your workspace."}),e.jsx("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3",children:r.map(t=>e.jsxs(T,{className:"flex items-start gap-3 p-4",children:[e.jsx("div",{className:"grid h-10 w-10 shrink-0 place-items-center rounded-md bg-accent text-accent-foreground",children:e.jsx(y,{name:t.icon,className:"h-5 w-5"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"truncate font-medium",children:t.name}),!t.is_active&&e.jsx("span",{className:"rounded bg-muted px-1.5 py-0.5 text-[10px] uppercase text-muted-foreground",children:"Inactive"})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[t.target_type," · ",t.element_type," · ",t.serp_pages," pages"]}),t.context&&e.jsx("p",{className:"mt-2 line-clamp-2 text-xs text-muted-foreground",children:t.context})]}),e.jsxs("div",{className:"flex shrink-0 flex-col gap-1",children:[e.jsx(d,{size:"icon",variant:"ghost",onClick:()=>a(t),"aria-label":"Edit",children:e.jsx(le,{className:"h-4 w-4"})}),e.jsx(d,{size:"icon",variant:"ghost",onClick:()=>v(t.id),"aria-label":"Delete",children:e.jsx(oe,{className:"h-4 w-4"})})]})]},t.id))})]}):e.jsx(ce,{title:"No research templates yet",description:"Create your first template to run structured research on companies or contacts.",action:e.jsxs(d,{onClick:()=>a(O()),children:[e.jsx(_,{className:"mr-2 h-4 w-4"})," New template"]})}),e.jsx(q,{open:C,onOpenChange:t=>!t&&a(null),children:e.jsxs(V,{className:"max-w-2xl",children:[e.jsx(B,{children:e.jsx(M,{children:S?"New research template":"Edit research template"})}),s&&e.jsxs(K,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-end gap-3",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx(p,{children:"Name"}),e.jsx(F,{value:s.name??"",onChange:t=>a({...s,name:t.target.value}),placeholder:"e.g. Recent funding news"})]}),e.jsxs("div",{children:[e.jsx(p,{children:"Icon"}),e.jsxs(d,{type:"button",variant:"outline",onClick:()=>b(!0),className:"w-full justify-start gap-2",children:[e.jsx(y,{name:s.icon,className:"h-4 w-4"}),e.jsx("span",{className:"truncate",children:s.icon||"Pick icon"})]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(p,{children:"Target type"}),e.jsxs(E,{value:s.target_type,onValueChange:t=>a({...s,target_type:t}),children:[e.jsx(P,{children:e.jsx(I,{})}),e.jsx(A,{children:pe.map(t=>e.jsx(R,{value:t,children:t},t))})]})]}),e.jsxs("div",{children:[e.jsx(p,{children:"Element type"}),e.jsxs(E,{value:s.element_type,onValueChange:t=>a({...s,element_type:t}),children:[e.jsx(P,{children:e.jsx(I,{})}),e.jsx(A,{children:de.map(t=>e.jsx(R,{value:t,children:t},t))})]})]})]}),e.jsxs("div",{children:[e.jsx(p,{children:"Context prompt"}),e.jsx($,{rows:5,value:s.context??"",onChange:t=>a({...s,context:t.target.value}),placeholder:"Describe what to research and any guardrails. Variables like {{company.name}} will be substituted."})]}),e.jsxs("div",{className:"space-y-3 rounded-md border p-3",children:[e.jsx(N,{label:"SERP pages",hint:"Number of search queries to run (1â10)",min:1,max:10,value:s.serp_pages??3,onChange:t=>a({...s,serp_pages:t})}),e.jsx(N,{label:"Pages scraped per query",hint:"Top results scraped per query (1â5)",min:1,max:5,value:s.scrape_per_result??2,onChange:t=>a({...s,scrape_per_result:t})}),e.jsx(N,{label:"Follow-up links",hint:"Extra links followed from each scraped page (0â4)",min:0,max:4,value:s.follow_links??1,onChange:t=>a({...s,follow_links:t})})]}),e.jsxs("div",{className:"flex items-center justify-between rounded-md border p-3",children:[e.jsxs("div",{children:[e.jsx(p,{className:"text-sm",children:"Active"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Inactive templates are hidden from run pickers."})]}),e.jsx(D,{checked:s.is_active??!0,onCheckedChange:t=>a({...s,is_active:t})})]})]}),e.jsxs(U,{children:[e.jsx(d,{variant:"ghost",onClick:()=>a(null),children:"Cancel"}),e.jsx(d,{onClick:W,disabled:m.isPending,children:m.isPending?"Savingâ¦":"Save"})]})]})}),e.jsx(me,{open:z,onOpenChange:b,value:s==null?void 0:s.icon,onChange:t=>s&&a({...s,icon:t})}),e.jsx(X,{open:!!f,onOpenChange:t=>!t&&v(null),title:"Delete template?",description:"This will permanently remove the template. Existing research runs will be kept.",confirmLabel:"Delete",onConfirm:Y})]})}function N({label:r,hint:n,min:l,max:g,value:c,onChange:x}){return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(p,{className:"text-sm",children:r}),e.jsx("span",{className:"text-sm font-medium tabular-nums",children:c})]}),e.jsx(J,{min:l,max:g,step:1,value:[c],onValueChange:([m])=>x(m)}),n&&e.jsx("p",{className:"text-xs text-muted-foreground",children:n})]})}export{kt 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.