import{r as n,j as e}from"./vendor-react-Dp9pL_Wn.js";import{aa as s,a6 as r,a7 as t,a8 as i,a9 as o,_ as a,a1 as l}from"./index-DhMXk6CR.js";import{R as c,U as m,V as p,W as d,Q as u}from"./c6eedc03a-CsEFTfjy.js";import{d as f}from"./caf7c7e06-DJYXCm3T.js";import"./vendor-infra-DayZK7Ds.js";import"./vendor-zod-0xcuG3aM.js";import"./vendor-router-qG5OCEmI.js";import"./vendor-intl-D2wGIp4M.js";import"./vendor-base-5_f7mmWg.js";import"./vendor-ant-cds-bBedrtIN.js";import"./vendor-base-ui-DNypCIlh.js";import"./vendor-radix-Ch96tRrt.js";import"./vendor-virtual-DRz8lJfQ.js";import"./vendor-query-BwvgHhJ1.js";import"./vendor-zustand-BeF8W8xk.js";import"./vendor-lodash-BvMLws5K.js";import"./vendor-icons-CokWnmlw.js";import"./vendor-motion-EDlUw66k.js";import"./c5669b8e4-DFSq88jr.js";import"./vendor-luxon-CZxT8ieM.js";import"./c5f4e1303-CiyIFgnl.js";import"./cbaad2c48-DaP34LG2.js";import"./vendor-growthbook-C66YtMMX.js";import"./vendor-zod-v3-CZy0YPWu.js";const j=n.memo(function({link:n,onLinkOpen:a}){const l=c(n.url);if(null===l)return null;const u=n.domain??f(l);return e.jsxs(m,{href:l,linkTarget:"_blank",target:"_blank",onLinkClick:a,className:`group/link relative flex min-w-0 flex-col overflow-hidden bg-surface-2 px-lg pb-lg pt-lg decoration-transparent ${s}`,children:[e.jsx("span",{className:`line-clamp-1 group-hover/link:underline group-focus-visible/link:underline ${r}`,children:n.title}),n.snippet&&e.jsx("span",{className:`line-clamp-2 ${t} ${i}`,children:n.snippet}),u&&e.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 pt-md text-footnote text-muted",children:[e.jsx("span",{className:"flex shrink-0",children:e.jsx(p,{url:d(l,16),size:16},l)}),e.jsx("span",{className:"truncate",children:u})]}),e.jsx(o,{})]})}),x=n.memo(function({data:s,onLinkOpen:r}){const t=n.useCallback(()=>r?.(),[r]);return e.jsx("div",{className:"flex flex-col gap-sm font-ui",children:s.links.map((n,s)=>e.jsx(j,{link:n,onLinkOpen:t},`${n.url}-${s}`))})});function v(n){return"string"==typeof n?n:void 0}function k(n){if(!n||"object"!=typeof n)return null;const e=n,s=v(e.title),r=c(v(e.url));return r&&s?{url:r,title:s,snippet:v(e.snippet),domain:v(e.domain)}:null}const h=n.memo(function(){return e.jsxs("div",{className:"flex flex-col gap-sm font-ui",children:[e.jsx(l,{width:"100%",height:88,className:s}),e.jsx(l,{width:"100%",height:88,className:s}),e.jsx(l,{width:"100%",height:88,className:s})]})}),g=n.memo(function({input:s,isStreaming:r,partialJson:t,conversationUuid:i,disableAnalytics:o}){const{shownRef:l,trackRender:c,trackClick:m}=a("link_preview",i,o),p=n.useMemo(()=>function(n){let e;if("string"==typeof n)try{e=u(n)}catch{return null}else{if(!n||"object"!=typeof n)return null;e=n}if(!e||"object"!=typeof e)return null;const s=e,r=Array.isArray(s.links)?s.links.map(k).filter(n=>null!==n).slice(0,6):[];return 0===r.length?null:{links:r,summary:v(s.summary)}}(t??s),[t,s]);n.useEffect(()=>{r||c(p?"rendered":"blank")},[r,p,c]);const d=n.useCallback(()=>m("link_open"),[m]);return p?e.jsx("div",{ref:l,children:e.jsx(x,{data:p,onLinkOpen:d})}):r?e.jsx(h,{}):null});export{g as default};
