1import{h as Q,u as T,a as z,r as i,t as v,j as e,P as H}from"./index-DJAHnywQ.js";function J(){var I;const{q:t}=Q.useSearch(),l=T(),p=z(),[r,d]=i.useState(t??""),[a,c]=i.useState(!1),[g,f]=i.useState(0),F=i.useRef(null),[j,k]=i.useState(""),[h,S]=i.useState(""),[C,A]=i.useState(""),[m,P]=i.useState(null),{data:b,isFetching:w}=v.searchCompanies.useQuery({query:r.trim()},{enabled:a&&r.trim().length>0}),n=v.webSearchCompany.useMutation();i.useEffect(()=>{if(t&&t.trim()&&!a){const s=t.trim();d(t),c(!0),n.mutate({query:s})}},[t]);const N=v.addCompanyFromSearch.useMutation({onSuccess:s=>{l({to:"/info/$projectId",params:{projectId:s.id}})}}),x=v.addCompanyFromSearch.useMutation({onSuccess:(s,o)=>{P({id:s.id,name:o.name})}}),R=()=>{const s=r.trim();s&&(c(!0),f(0),n.reset(),n.mutate({query:s}))},y=i.useMemo(()=>{var M;const s=(b??[]).map(u=>({kind:"db",id:u.id,name:u.name,caption:u.caption??void 0,logo:u.logo})),o=(((M=n.data)==null?void 0:M.results)??[]).map((u,O)=>({kind:"web",index:O,result:u}));return[...s,...o]},[b,n.data]),D=y[g]??null;i.useEffect(()=>{f(0)},[b,n.data]);const $=s=>{N.mutate({name:s.name,website:s.website,caption:s.caption,overview:s.overview,tags:s.tags,foundedDate:s.foundedDate,description:s.description})},E=s=>{if(s.preventDefault(),!j.trim()||!h.trim())return;const o=h.trim();x.mutate({name:j.trim(),website:C.trim(),caption:o,overview:o,tags:[],foundedDate:"",description:h.trim(),type:"user-co"})},W=()=>{m&&(p.hasProject(m.id)||p.addProject(m.id),l({to:"/remix/$projectId",params:{projectId:m.id}}))},L=()=>{P(null),k(""),S(""),A(""),x.reset()},q=a&&!w&&b!==void 0&&b.length===0&&(!n.data||n.data.results.length===0)&&!n.isPending,B=e.jsxs("form",{onSubmit:s=>{s.preventDefault(),R()},className:"flex items-center gap-2 flex-1 min-w-0",children:[e.jsxs("div",{className:"relative flex-1 min-w-0",children:[e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"absolute left-3 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none",children:[e.jsx("circle",{cx:"11",cy:"11",r:"8"}),e.jsx("path",{d:"m21 21-4.3-4.3"})]}),e.jsx("input",{ref:F,type:"text",value:r,onChange:s=>d(s.target.value),placeholder:"Find or add a companyâ¦",className:"w-full bg-gray-100 rounded-full pl-9 pr-3 py-1.5 text-sm outline-none focus:ring-2 focus:ring-black/20 transition-shadow"})]}),e.jsx("button",{type:"submit",disabled:!r.trim(),className:"shrink-0 p-2 rounded-full bg-black text-white hover:bg-gray-800 transition-colors disabled:opacity-40","aria-label":"Search",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"m22 2-7 20-4-9-9-4Z"}),e.jsx("path",{d:"M22 2 11 13"})]})})]});return e.jsxs(H,{topCenter:B,wide:!0,children:[e.jsxs("div",{className:"relative",children:[e.jsxs("ul",{role:"list",className:"divide-y divide-border",children:[y.length===0&&!w&&!n.isPending&&e.jsx("li",{className:"px-4 py-10 text-center text-sm text-gray-400",children:a?q?`No results for "${r}"`:"Searchingâ¦":"Enter a company name to get started"}),(w||n.isPending)&&y.length===0&&e.jsxs("li",{className:"px-4 py-10 flex items-center justify-center text-gray-400",children:[e.jsx("div",{className:"w-5 h-5 border-2 border-gray-200 border-t-gray-500 rounded-full animate-spin mr-2"}),e.jsx("span",{className:"text-sm",children:"Searchingâ¦"})]}),y.map((s,o)=>e.jsx(V,{row:s,index:o,isFocused:o===g,onFocus:()=>f(o),onOpen:()=>{s.kind==="db"&&l({to:"/info/$projectId",params:{projectId:s.id}})}},s.kind==="db"?`db-${s.id}`:`web-${s.index}`))]}),e.jsx("div",{className:"hidden md:block absolute top-0 right-0 w-1/2 h-full bg-white border-l border-gray-200 pointer-events-none",children:e.jsx("div",{className:"sticky top-0 max-h-screen overflow-y-auto p-6 pointer-events-auto",children:D?e.jsx(Z,{row:D,onOpenDb:s=>l({to:"/info/$projectId",params:{projectId:s}}),onAddWeb:$,isAddingWeb:N.isPending,webError:(I=N.error)==null?void 0:I.message}):e.jsx(_,{})})})]}),e.jsx("div",{className:"border-t border-border mt-6 px-4 py-6",children:m?e.jsxs("div",{className:"space-y-3 rounded-xl border-2 border-teal-400 bg-teal-50/30 p-4 max-w-md",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-xs font-medium text-teal-700 uppercase tracking-wide",children:"Added to Database"}),e.jsx("div",{className:"font-bold text-base",children:m.name})]}),e.jsxs("div",{className:"flex gap-2 pt-1",children:[e.jsx("button",{onClick:()=>l({to:"/info/$projectId",params:{projectId:m.id}}),className:"flex-1 px-4 py-2.5 rounded-lg text-sm font-medium border border-gray-300 text-gray-700 hover:bg-gray-100 transition-colors",children:"View Details"}),e.jsx("button",{onClick:W,className:"flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-black text-white hover:bg-gray-800 transition-colors",children:"+ Remix this Company"})]}),e.jsx("button",{onClick:L,className:"w-full px-4 py-2 rounded-lg text-xs font-medium text-gray-500 hover:text-black transition-colors",children:"Add another"})]}):e.jsxs("form",{onSubmit:E,className:"space-y-5 max-w-md",children:[e.jsxs("div",{children:[e.jsx("span",{className:"swiss-eyebrow swiss-eyebrow-accent",children:"§ Manual"}),e.jsx("h2",{className:"swiss-display-md text-[1.4rem] mt-2",children:"Or describe a company idea"})]}),e.jsxs("label",{className:"block space-y-1.5",children:[e.jsx("span",{className:"swiss-eyebrow",children:"Name"}),e.jsx("input",{type:"text",value:j,onChange:s=>k(s.target.value),placeholder:"Acme Co.",className:"w-full bg-transparent border-0 border-b border-[color:var(--swiss-rule-strong)] px-0 py-2 text-[1rem] outline-none focus:border-[color:var(--swiss-ink)] transition-colors"})]}),e.jsxs("label",{className:"block space-y-1.5",children:[e.jsx("span",{className:"swiss-eyebrow",children:"Description"}),e.jsx("textarea",{value:h,onChange:s=>S(s.target.value),placeholder:"A one- or two-sentence pitch.",rows:3,className:"w-full bg-transparent border-0 border-b border-[color:var(--swiss-rule-strong)] px-0 py-2 text-[1rem] outline-none focus:border-[color:var(--swiss-ink)] transition-colors resize-y"})]}),e.jsxs("label",{className:"block space-y-1.5",children:[e.jsxs("span",{className:"swiss-eyebrow",children:["Website ",e.jsx("span",{className:"opacity-50",children:"(optional)"})]}),e.jsx("input",{type:"url",value:C,onChange:s=>A(s.target.value),placeholder:"https://...",className:"w-full bg-transparent border-0 border-b border-[color:var(--swiss-rule-strong)] px-0 py-2 text-[1rem] outline-none focus:border-[color:var(--swiss-ink)] transition-colors"})]}),x.isError&&e.jsxs("p",{className:"text-xs text-[color:var(--swiss-accent)]",children:["Failed to add: ",x.error.message]}),e.jsx("button",{type:"submit",disabled:!j.trim()||!h.trim()||x.isPending,className:"w-full px-4 py-3 text-[0.85rem] font-mono uppercase tracking-[0.18em] bg-[color:var(--swiss-ink)] text-white hover:bg-[color:var(--swiss-accent)] transition-colors disabled:opacity-40 disabled:cursor-not-allowed",children:x.isPending?"Addingâ¦":"Add to Database"})]})})]})}function V({row:t,index:l,isFocused:p,onFocus:r,onOpen:d}){const a=t.kind==="db"?t.name:t.result.name,c=t.kind==="db"?t.caption:t.result.caption,g=t.kind==="db"?"DB":"Web";return e.jsx("li",{className:`relative cursor-pointer transition-colors ${p?"bg-[color:var(--swiss-paper-warm)]":"hover:bg-[color:var(--swiss-paper-warm)]/60"}`,onMouseEnter:r,onClick:d,children:e.jsxs("div",{className:"flex items-center gap-3 px-4 py-4 md:w-1/2",children:[e.jsx("span",{className:"swiss-eyebrow shrink-0 tabular-nums w-7",children:String(l+1).padStart(2,"0")}),t.kind==="db"&&t.logo&&e.jsx("img",{src:t.logo,alt:"",className:"w-9 h-9 object-contain bg-[color:var(--swiss-paper-warm)] p-0.5 shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-baseline gap-2",children:[e.jsx("div",{className:"swiss-display-md text-[1.05rem] truncate",children:a}),e.jsx("span",{className:"swiss-eyebrow shrink-0",children:g})]}),c&&e.jsx("div",{className:"text-[0.82rem] text-[color:var(--swiss-muted)] mt-0.5 truncate",children:c})]})]})})}function Z({row:t,onOpenDb:l,onAddWeb:p,isAddingWeb:r,webError:d}){if(t.kind==="db")return e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wider text-gray-400",children:"Already in database"}),e.jsx("div",{className:"font-bold text-lg",children:t.name}),t.caption&&e.jsx("p",{className:"text-sm text-gray-700",children:t.caption}),e.jsx("button",{onClick:()=>l(t.id),className:"w-full px-4 py-2.5 rounded-lg text-sm font-medium bg-black text-white hover:bg-gray-800 transition-colors",children:"Open Details"})]});const a=t.result;return e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wider text-gray-400",children:"Web result"}),e.jsx("div",{className:"font-bold text-lg",children:a.name}),a.caption&&e.jsx("p",{className:"text-sm text-gray-700",children:a.caption}),a.website&&e.jsx("a",{href:a.website,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-blue-600 hover:underline block break-all",children:a.website}),a.tags.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5",children:a.tags.map(c=>e.jsx("span",{className:"px-2.5 py-1 rounded-full bg-gray-100 text-xs text-gray-700",children:c},c))}),a.description&&e.jsxs("p",{className:"text-sm text-gray-700 leading-relaxed whitespace-pre-wrap",children:[a.description.slice(0,500),a.description.length>500?"â¦":""]}),d&&e.jsxs("p",{className:"text-xs text-red-600",children:["Failed to add: ",d]}),e.jsx("button",{onClick:()=>p(a),disabled:r,className:"w-full px-4 py-2.5 rounded-lg text-sm font-medium bg-black text-white hover:bg-gray-800 transition-colors disabled:opacity-50",children:r?"Addingâ¦":"Add to Database"})]})}function _(){return e.jsxs("div",{className:"text-center py-12",children:[e.jsx("span",{className:"swiss-eyebrow",children:"§ Preview"}),e.jsx("p",{className:"mt-2 text-sm text-[color:var(--swiss-muted)]",children:"Select a result on the left"})]})}
1export{J as component};
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.