import{o as t}from"./rolldown-runtime-iuO8RvI4.js";import{Mi as e,ki as i}from"./vendor-frame-CwiylG4Y.js";import{ph as s}from"./shared-1-3-6x7RKF.js";import{Ao as a}from"./shared-6-Cf_fMhRZ.js";import{rn as r}from"./vendor-all-2-BJdkbLSj.js";import{Is as o}from"./shared-5-UQAFGbWu.js";import{in as n,ln as l,on as c,sn as d}from"./shared-8-C1HP2d2B.js";import{_ as u,c as m,d as y,f as p,h as x,l as f,m as h,n as g,o as v,p as b,s as j,u as _,v as A,y as k}from"./c2a6d07ee-z_SX0ju5.js";var M=t(e()),w=2e3,C=["line","bar","scatter"];function F(t){return"string"==typeof t?t:void 0}function R(t){return"number"==typeof t&&Number.isFinite(t)?t:void 0}var N=/^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;function O(t){if(!t||"object"!=typeof t)return null;const e=t,i=R(e.x),s=R(e.y);return void 0!==i&&void 0!==s?{x:i,y:s}:null}function E(t){if(!t||"object"!=typeof t)return null;const e=t,i=Array.isArray(e.values)?e.values.map(R).filter(t=>void 0!==t).slice(0,w):void 0,s=Array.isArray(e.points)?e.points.map(O).filter(t=>null!==t).slice(0,w):void 0;return i&&i.length>0||s&&s.length>0?{values:i,points:s,name:F(e.name),color:(a=e.color,"string"==typeof a&&N.test(a)?a:void 0)}:null;var a}function H(t){if(!t||"object"!=typeof t)return;const e=t,i=Array.isArray(e.data)?e.data.filter(t=>"string"==typeof t||"number"==typeof t&&Number.isFinite(t)).slice(0,w):void 0,s={data:i&&i.length>0?i:void 0,title:F(e.title),min:R(e.min),max:R(e.max),scale:(a=e.scale,"linear"===a||"log"===a?a:void 0)};var a;return Object.values(s).some(t=>void 0!==t)?s:void 0}var S=i();f.register(_,v,x,m,p,b,h,y,j,A,k,u);var W=(0,M.memo)(function(){return(0,S.jsx)(l,{children:(0,S.jsxs)("div",{className:"space-y-3",children:[(0,S.jsx)(n,{height:16,width:"40%"}),(0,S.jsx)(n,{height:280})]})})}),z=(0,M.memo)(function({input:t,isStreaming:e,conversationUuid:i,disableAnalytics:n}){const l=r(),{shownRef:u,trackRender:m}=a("chart_display",i,n),y=(0,M.useMemo)(()=>function(t){let e;if("string"==typeof t)try{e=s(t)}catch{return null}else{if(!t||"object"!=typeof t)return null;e=t}if(!e||"object"!=typeof e)return null;const i=e,a=C.find(t=>t===i.style)??"line",r=Array.isArray(i.series)?i.series.map(E).filter(t=>null!==t).slice(0,12):[];return 0===r.length?null:{style:a,series:r,title:F(i.title),x_axis:H(i.x_axis),y_axis:H(i.y_axis)}}(t),[t]),p=function(){const t=o("chart-categorical-1"),e=o("chart-categorical-2"),i=o("chart-categorical-3"),s=o("chart-categorical-4"),a=o("chart-categorical-5"),r=o("chart-categorical-6");return(0,M.useMemo)(()=>[t,e,i,s,a,r],[t,e,i,s,a,r])}(),x=o("text-secondary"),f=o("chart-grid"),h=o("text-primary"),v=(0,M.useMemo)(()=>({tick:x,grid:f,text:h}),[x,f,h]),b=(0,M.useMemo)(()=>y?function(t,e){const i=t.series.reduce((t,e)=>Math.max(t,e.values?.length??e.points?.length??0),0);return{labels:"scatter"!==t.style?t.x_axis?.data??Array.from({length:i},(t,e)=>String(e+1)):void 0,datasets:t.series.map((i,s)=>{const a=i.color??e[s%e.length];return{label:i.name??"",data:"scatter"===t.style?i.points??i.values?.map((t,e)=>({x:e,y:t}))??[]:i.values??i.points?.map(t=>t.y)??[],borderColor:a,backgroundColor:a,pointRadius:"line"===t.style?0:3,pointHoverRadius:4,borderWidth:2,tension:.2}})}}(y,p):null,[y,p]),j=(0,M.useMemo)(()=>y?function(t,e){const i=t=>"log"===t?"logarithmic":"linear";return{responsive:!0,maintainAspectRatio:!1,interaction:{mode:"index",intersect:!1},plugins:{legend:{display:t.series.some(t=>!!t.name),position:"bottom",labels:{color:e.text,boxWidth:12,boxHeight:12}},title:{display:!!t.title,text:t.title??"",color:e.text,font:{size:14,weight:"bold"},padding:{bottom:12}},tooltip:{enabled:!0}},scales:{x:{type:"scatter"===t.style?i(t.x_axis?.scale):"category",..."scatter"===t.style?{min:t.x_axis?.min,max:t.x_axis?.max}:{},title:{display:!!t.x_axis?.title,text:t.x_axis?.title??"",color:e.tick},ticks:{color:e.tick},grid:{color:e.grid}},y:{type:i(t.y_axis?.scale),min:t.y_axis?.min,max:t.y_axis?.max,title:{display:!!t.y_axis?.title,text:t.y_axis?.title??"",color:e.tick},ticks:{color:e.tick},grid:{color:e.grid}}}}}(y,v):null,[y,v]);return(0,M.useEffect)(()=>{e||m(y?"rendered":"blank")},[e,y,m]),e&&!y?(0,S.jsx)(W,{}):y&&b&&j?(0,S.jsx)(c,{ref:u,children:(0,S.jsx)("div",{"data-testid":"chart-display-canvas",style:{height:280},className:"w-full",children:(0,S.jsx)(g,{type:y.style,data:b,options:j,"aria-label":y.title||l.formatMessage({defaultMessage:"Chart",id:"nFVuBOECC+"})})})}):(0,S.jsx)(d,{})});export{z as ChartDisplayToolUseCell};