import{r as t,j as e}from"./vendor-react-Dp9pL_Wn.js";import{e as i,C as r,f as s,g as a,S as o,a as n,L as l,h as c,P as d,b as u,B as m,p,c as x,d as y}from"./c6a992d55-c5W_gcW7.js";import{u as f}from"./vendor-intl-BDR1NhN_.js";import{aK as v,aL as g,at as h,aM as j,aN as b,aO as _,aP as A}from"./c4b350ac1-KLFM4jkb.js";import"./vendor-base-5_f7mmWg.js";import"./vendor-ant-cds-DvTmcYA1.js";import"./vendor-base-ui-CdQU4JQh.js";import"./vendor-radix-D3USJ4lr.js";import"./vendor-virtual-DRz8lJfQ.js";import"./vendor-zod-DIcz3Rbr.js";import"./vendor-zustand-CI9omAwJ.js";import"./vendor-icons-BBStP_8q.js";import"./vendor-lodash-CIro4mst.js";import"./vendor-router-qG5OCEmI.js";import"./vendor-query-DgCRID2b.js";import"./vendor-motion-D7Z1qgzM.js";import"./vendor-luxon-Y8l99kBI.js";import"./vendor-infra-DayZK7Ds.js";import"./vendor-growthbook-C66YtMMX.js";const k=2e3,M=["line","bar","scatter"];function C(t){return"string"==typeof t?t:void 0}function w(t){return"number"==typeof t&&Number.isFinite(t)?t:void 0}const F=/^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;function N(t){if(!t||"object"!=typeof t)return null;const e=t,i=w(e.x),r=w(e.y);return void 0!==i&&void 0!==r?{x:i,y:r}:null}function R(t){if(!t||"object"!=typeof t)return null;const e=t,i=Array.isArray(e.values)?e.values.map(w).filter(t=>void 0!==t).slice(0,k):void 0,r=Array.isArray(e.points)?e.points.map(N).filter(t=>null!==t).slice(0,k):void 0;return i&&i.length>0||r&&r.length>0?{values:i,points:r,name:C(e.name),color:(s=e.color,"string"==typeof s&&F.test(s)?s:void 0)}:null;var s}function z(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,k):void 0,r={data:i&&i.length>0?i:void 0,title:C(e.title),min:w(e.min),max:w(e.max),scale:(s=e.scale,"linear"===s||"log"===s?s:void 0)};var s;return Object.values(r).some(t=>void 0!==t)?r:void 0}r.register(s,a,o,n,l,c,d,u,m,p,x,y);const O=t.memo(function(){return e.jsx(_,{children:e.jsxs("div",{className:"space-y-3",children:[e.jsx(A,{height:16,width:"40%"}),e.jsx(A,{height:280})]})})}),S=t.memo(function({input:r,isStreaming:s,conversationUuid:a,disableAnalytics:o}){const n=f(),{shownRef:l,trackRender:c}=g("chart_display",a,o),d=t.useMemo(()=>function(t){let e;if("string"==typeof t)try{e=v(t)}catch{return null}else{if(!t||"object"!=typeof t)return null;e=t}if(!e||"object"!=typeof e)return null;const i=e,r=M.find(t=>t===i.style)??"line",s=Array.isArray(i.series)?i.series.map(R).filter(t=>null!==t).slice(0,12):[];return 0===s.length?null:{style:r,series:s,title:C(i.title),x_axis:z(i.x_axis),y_axis:z(i.y_axis)}}(r),[r]),u=function(){const e=h("chart-categorical-1"),i=h("chart-categorical-2"),r=h("chart-categorical-3"),s=h("chart-categorical-4"),a=h("chart-categorical-5"),o=h("chart-categorical-6");return t.useMemo(()=>[e,i,r,s,a,o],[e,i,r,s,a,o])}(),m=h("text-secondary"),p=h("chart-grid"),x=h("text-primary"),y=t.useMemo(()=>({tick:m,grid:p,text:x}),[m,p,x]),_=t.useMemo(()=>d?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,r)=>{const s=i.color??e[r%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:s,backgroundColor:s,pointRadius:"line"===t.style?0:3,pointHoverRadius:4,borderWidth:2,tension:.2}})}}(d,u):null,[d,u]),A=t.useMemo(()=>d?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}}}}}(d,y):null,[d,y]);return t.useEffect(()=>{s||c(d?"rendered":"blank")},[s,d,c]),s&&!d?e.jsx(O,{}):d&&_&&A?e.jsx(b,{ref:l,children:e.jsx("div",{"data-testid":"chart-display-canvas",style:{height:280},className:"w-full",children:e.jsx(i,{type:d.style,data:_,options:A,"aria-label":d.title||n.formatMessage({defaultMessage:"Chart",id:"nFVuBOECC+"})})})}):e.jsx(j,{})});export{S as ChartDisplayToolUseCell};
