import{o as n}from"./rolldown-runtime-iuO8RvI4.js";import{Mi as e,ki as s}from"./vendor-frame-CwiylG4Y.js";import{Dh as l,lv as t,ov as i,ph as r}from"./shared-1-3-6x7RKF.js";import{Ao as a,qi as o}from"./shared-6-Cf_fMhRZ.js";import{Ol as c}from"./shared-2-CMUBhYOn.js";import{An as m,Mn as u,On as p,Tn as f,in as d,jn as h}from"./shared-8-C1HP2d2B.js";import{t as x}from"./ca1ce32a0-IlirXYWw.js";var j=n(e()),k=s(),g=(0,j.memo)(function({link:n,onLinkOpen:e}){t();const s=l(n.url);if(null===s)return null;const r=n.domain??x(s);return(0,k.jsxs)(o,{href:s,linkTarget:"_blank",target:"_blank",onLinkClick:e,className:`group/link relative flex min-w-0 flex-col overflow-hidden bg-surface-2 px-lg pb-lg pt-lg decoration-transparent ${f}`,children:[(0,k.jsx)("span",{className:`line-clamp-1 group-hover/link:underline group-focus-visible/link:underline ${u}`,children:n.title}),n.snippet&&(0,k.jsx)("span",{className:"line-clamp-2 pt-2 text-body text-secondary",children:n.snippet}),r&&(0,k.jsxs)("span",{className:"flex min-w-0 items-center gap-1.5 pt-md text-footnote text-muted",children:[(0,k.jsx)("span",{className:"flex shrink-0",children:(0,k.jsx)(c,{url:i(s,16),size:16},s)}),(0,k.jsx)("span",{className:"truncate",children:r})]}),(0,k.jsx)(p,{})]})}),v=(0,j.memo)(function({data:n,onLinkOpen:e}){const s=(0,j.useCallback)(()=>e?.(),[e]);return(0,k.jsx)("div",{className:"flex flex-col gap-sm font-ui",children:n.links.map((n,e)=>(0,k.jsx)(g,{link:n,onLinkOpen:s},`${n.url}-${e}`))})});function b(n){return"string"==typeof n?n:void 0}function y(n){if(!n||"object"!=typeof n)return null;const e=n,s=b(e.title),t=l(b(e.url));return t&&s?{url:t,title:s,snippet:b(e.snippet),domain:b(e.domain)}:null}var N=(0,j.memo)(function(){return(0,k.jsxs)("div",{className:"flex flex-col gap-sm font-ui",children:[(0,k.jsx)(d,{width:"100%",height:88,className:f}),(0,k.jsx)(d,{width:"100%",height:88,className:f}),(0,k.jsx)(d,{width:"100%",height:88,className:f})]})}),w=(0,j.memo)(function({input:n,isStreaming:e,partialJson:s,conversationUuid:l,disableAnalytics:t}){const{shownRef:i,trackRender:o,trackClick:c}=a("link_preview",l,t),m=(0,j.useMemo)(()=>function(n){let e;if("string"==typeof n)try{e=r(n)}catch{return null}else{if(!n||"object"!=typeof n)return null;e=n}if(!e||"object"!=typeof e)return null;const s=e,l=Array.isArray(s.links)?s.links.map(y).filter(n=>null!==n).slice(0,6):[];return 0===l.length?null:{links:l,summary:b(s.summary)}}(s??n),[s,n]);(0,j.useEffect)(()=>{e||o(m?"rendered":"blank")},[e,m,o]);const u=(0,j.useCallback)(()=>c("link_open"),[c]);return m?(0,k.jsx)("div",{ref:i,children:(0,k.jsx)(v,{data:m,onLinkOpen:u})}):e?(0,k.jsx)(N,{}):null});export{w as default};