import{r as t,j as e}from"./vendor-react-Dp9pL_Wn.js";import{C as i,a as r,L as s,B as o,S as a,b as n,c as l,d as c,P as d,e as m,f as u,p,g as x,h as y}from"./c6a992d55-B2WBjPbg.js";import{u as f}from"./vendor-intl-D2wGIp4M.js";import{Q as v,aF as g}from"./c6eedc03a-CsEFTfjy.js";import{_ as j,aS as h,aT as b,aU as _,a1 as A}from"./index-CBEPphRm.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-zod-0xcuG3aM.js";import"./vendor-zustand-BeF8W8xk.js";import"./vendor-icons-CokWnmlw.js";import"./vendor-lodash-BvMLws5K.js";import"./vendor-router-qG5OCEmI.js";import"./vendor-query-BwvgHhJ1.js";import"./vendor-zod-v3-CZy0YPWu.js";import"./vendor-motion-EDlUw66k.js";import"./vendor-luxon-CZxT8ieM.js";import"./vendor-growthbook-C66YtMMX.js";import"./vendor-infra-DayZK7Ds.js";import"./caf7c7e06-DJYXCm3T.js";import"./c5669b8e4-DFSq88jr.js";import"./c5f4e1303-CiyIFgnl.js";import"./cbaad2c48-DaP34LG2.js";const k=2e3,M=["line","bar","scatter"];function w(t){return"string"==typeof t?t:void 0}function C(t){return"number"==typeof t&&Number.isFinite(t)?t:void 0}const F=/^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;function z(t){if(!t||"object"!=typeof t)return null;const e=t,i=C(e.x),r=C(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(C).filter(t=>void 0!==t).slice(0,k):void 0,r=Array.isArray(e.points)?e.points.map(z).filter(t=>null!==t).slice(0,k):void 0;return i&&i.length>0||r&&r.length>0?{values:i,points:r,name:w(e.name),color:(s=e.color,"string"==typeof s&&F.test(s)?s:void 0)}:null;var s}function N(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:w(e.title),min:C(e.min),max:C(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,o,a,n,l,c,d,m,u,p,x,y);const S=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})]})})}),B=t.memo(function({input:r,isStreaming:s,conversationUuid:o,disableAnalytics:a}){const n=f(),{shownRef:l,trackRender:c}=j("chart_display",o,a),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:w(i.title),x_axis:N(i.x_axis),y_axis:N(i.y_axis)}}(r),[r]),m=function(){const e=g("chart-categorical-1"),i=g("chart-categorical-2"),r=g("chart-categorical-3"),s=g("chart-categorical-4"),o=g("chart-categorical-5"),a=g("chart-categorical-6");return t.useMemo(()=>[e,i,r,s,o,a],[e,i,r,s,o,a])}(),u=g("text-secondary"),p=g("chart-grid"),x=g("text-primary"),y=t.useMemo(()=>({tick:u,grid:p,text:x}),[u,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,m):null,[d,m]),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(S,{}):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(h,{})});export{B as ChartDisplayToolUseCell};
