"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[6714],{46714($,y,a){a.d(y,{GenAISuggestionsDrawer:()=>L});var i=a(74848),n=a(22803),f=a(67458),g=a(92745),v=a(63142),h=a(8207),u=a(41654),b=a(8073),j=a(66404),C=a(47931),N=a(45861),S=a(50992);const w=s=>{if(!s)return[];const c=[];return s.split(/```/).forEach((r,o)=>{if(o%2===0)r.trim()&&c.push({type:"text",content:r.trim()});else{const l=r.split(`
`);let e="sql",t=r;if(l[0]&&l[0].trim()&&!l[0].includes(" ")&&(e=l[0].trim().toLowerCase(),t=l.slice(1).join(`
`)),t=t.replace(/\n+$/,""),t.trim()){const p=e==="mysql"||e==="sql"?"mysql":e;c.push({type:"code",content:t.trim(),language:p})}}}),c},L=({isOpen:s,onApplySuggestion:c,onClose:m,suggestions:r})=>{const o=(0,v.of)(k);return s?(0,i.jsx)(h._,{onClose:m,size:"lg",title:(0,i.jsx)(g.x6,{i18nKey:"sql-expressions.sql-suggestion-history",children:"SQL Suggestion History"}),children:(0,i.jsx)("div",{className:o.content,"data-testid":"suggestions-drawer",children:(0,i.jsx)(u.B,{direction:"column",gap:3,children:(0,i.jsxs)("div",{className:o.timelineContainer,children:[(0,i.jsx)("div",{className:o.timelineLine}),(0,i.jsx)("div",{className:o.suggestionsList,children:r.map((l,e)=>{const t=w(l),p=e===0;return(0,i.jsxs)("div",{className:o.timelineItem,children:[(0,i.jsx)("div",{className:`${o.timelineNode} ${p?o.timelineNodeActive:o.timelineNodeInactive}`}),(0,i.jsx)(b.Z,{noMargin:!0,className:p?o.latestSuggestion:"",children:(0,i.jsx)("div",{className:o.suggestionContent,children:t.map(({type:I,content:d,language:x},B)=>(0,i.jsx)("div",{className:o.suggestionPart,children:I==="code"?(0,i.jsxs)("div",{className:o.codeBlock,children:[(0,i.jsx)("div",{className:o.codeHeader,children:(0,i.jsxs)(u.B,{direction:"row",justifyContent:"space-between",alignItems:"center",children:[(0,i.jsx)(j.E,{variant:"bodySmall",weight:"bold",children:(0,i.jsx)(g.x6,{i18nKey:"sql-expressions.code-label",values:{language:x?.toUpperCase()||"CODE"},children:"{{ language }}"})}),(0,i.jsxs)(u.B,{direction:"row",gap:1,children:[(0,i.jsx)(C.b,{size:"sm",icon:"copy",variant:"secondary",getText:()=>d,children:(0,i.jsx)(g.x6,{i18nKey:"sql-expressions.copy",children:"Copy"})}),(0,i.jsx)(N.$n,{size:"sm",variant:"primary",icon:"ai-sparkle",onClick:()=>c(d),children:(0,i.jsx)(g.x6,{i18nKey:"sql-expressions.apply",children:"Apply"})})]})]})}),(0,i.jsx)(S.B,{value:d,language:x==="sql"||x==="mysql"?"mysql":"sql",width:"100%",height:Math.max(80,Math.min(300,(d.split(`
`).length+1)*20)),readOnly:!0,showMiniMap:!1,showLineNumbers:!0,monacoOptions:{lineNumbers:"on",folding:!1,minimap:{enabled:!1},scrollBeyondLastLine:!1,renderLineHighlight:"none",wordWrap:"on",readOnly:!0,contextmenu:!1,padding:{top:8,bottom:8},automaticLayout:!0,fontSize:13,lineHeight:20}})]}):(0,i.jsx)("div",{className:"markdown-html",dangerouslySetInnerHTML:{__html:(0,f.G)(d)}})},B))})},e)]},e)})})]})})})}):null},k=s=>({content:(0,n.css)({height:"100%",display:"flex",flexDirection:"column"}),emptyState:(0,n.css)({display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",height:"100%",textAlign:"center",gap:s.spacing(2)}),timelineContainer:(0,n.css)({position:"relative",display:"flex",flexDirection:"column",overflow:"auto",flex:1,paddingLeft:s.spacing(4.5)}),timelineLine:(0,n.css)({position:"absolute",left:`calc(${s.spacing(1)} + 2px)`,top:s.spacing(1),bottom:0,width:"2px",backgroundColor:s.colors.border.strong,zIndex:1}),suggestionsList:(0,n.css)({display:"flex",flexDirection:"column",gap:s.spacing(2),position:"relative"}),timelineItem:(0,n.css)({position:"relative",display:"flex",alignItems:"flex-start",gap:s.spacing(2)}),timelineNode:(0,n.css)({position:"absolute",left:s.spacing(-4.5),top:s.spacing(1),width:s.spacing(3),height:s.spacing(3),borderRadius:s.shape.radius.pill,border:`2px solid ${s.colors.primary.main}`,backgroundColor:s.colors.background.primary,zIndex:2,flexShrink:0}),timelineNodeActive:(0,n.css)({backgroundColor:s.colors.primary.main,boxShadow:`0 0 0 4px ${s.colors.background.primary}`}),timelineNodeInactive:(0,n.css)({backgroundColor:s.colors.background.primary,boxShadow:`0 0 0 4px ${s.colors.background.primary}`}),latestSuggestion:(0,n.css)({border:`2px solid ${s.colors.primary.main}`,position:"relative","&::before":{content:'"Latest"',position:"absolute",top:s.spacing(-.5),right:s.spacing(1),backgroundColor:s.colors.primary.main,color:s.colors.primary.contrastText,padding:s.spacing(.25,1),borderRadius:s.shape.radius.default,fontSize:s.typography.bodySmall.fontSize,fontWeight:s.typography.fontWeightMedium}}),suggestionContent:(0,n.css)({display:"flex",flexDirection:"column",gap:s.spacing(1.5),width:"100%",overflowX:"auto"}),suggestionPart:(0,n.css)({display:"block",width:"100%"}),codeBlock:(0,n.css)({border:`1px solid ${s.colors.border.medium}`,borderRadius:s.shape.radius.default,overflow:"hidden",marginBottom:s.spacing(1),width:"100%",minWidth:"600px"}),codeHeader:(0,n.css)({backgroundColor:s.colors.background.secondary,padding:s.spacing(1,1.5),borderBottom:`1px solid ${s.colors.border.weak}`})})}}]);

//# sourceMappingURL=6714.00e143e2b34ff8d2f22e.js.map