@devtable/dashboard 14.3.4 → 14.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -89,7 +89,7 @@ React keys must be passed directly to JSX without using spread:
89
89
  ${Object.entries(t).map(([s,i])=>`const ${s} = '${i}';`).join(`
90
90
  `)}
91
91
  return ${e};
92
- `)(r)}catch(s){return console.error(s),console.log(e),e}}function fs(e,t,r,s){const i=dy(t,s);return e.replaceAll(/(\{\{([^{\}]+(?=}))\}\})/g,(...l)=>{const c=l[2];if(!c)return c;const u=i[c];if(u)return u;const d=py(c);return hy(d,i,r)})}function gy(e,t){const r=Sl.decode(t);r!==e&&(console.error("Inconsistent sql"),console.groupCollapsed("Inconsistent sql"),console.table({before:e,after:t,v:r}),console.groupEnd())}async function fy({query:e,name:t,payload:r,additionals:s},i){if(!e.sql)return[];const{type:o,key:l,sql:c,pre_process:u,post_process:d}=e,p=Xs(c,r),h=tx({sql:p,pre_process:u}),x=Sl.encode(h);gy(h,x);let b=await gt.query(i)({type:o,key:l,query:x,...s},{params:{name:t}});return b=nx(d,b,ba(r)),b}async function xy({type:e,key:t,configString:r,name:s,additionals:i},o){try{return await gt.httpDataSourceQuery(o)({type:e,key:t,query:r,...i},{params:{name:s}})}catch(l){if(pt.isCancel(l))throw l;return console.error(l),l}}async function my({key:e,configString:t,name:r,additionals:s},i){try{return await gt.mericoMetricQuery(i)({type:"merico_metric_system",key:e,query:t,...s},{params:{name:r}})}catch(o){throw o}}async function ya(){try{return(await gt.post()("/datasource/list",{filter:{},sort:[{field:"create_time",order:"ASC"}],pagination:{page:1,pagesize:100}},{})).data}catch(e){return console.error(e),[]}}async function vd(){try{return(await gt.post()("/sql_snippet/list",{filter:{},sort:[{field:"id",order:"ASC"}],pagination:{page:1,pagesize:1e3}},{})).data}catch(e){return console.error(e),[]}}class _d{constructor(t){N(this,"rootRef");this.rootRef=te.observable({current:t})}async deleteItem(t){te.runInAction(()=>{v.unset(this.rootRef.current,[t])})}getItem(t){const r=this.getValueFromRoot(t);return Promise.resolve(r)}getValueFromRoot(t){return t===null?te.toJS(this.rootRef.current):v.get(this.rootRef.current,[t])}setItem(t,r){if(t===null)if(v.isObject(r))te.runInAction(()=>{this.rootRef.current=r});else throw new Error("Cannot set root value to non-object");else te.runInAction(()=>{v.set(this.rootRef.current,[t],r)});return Promise.resolve(this.getItem(t))}watchItem(t,r,s){return te.reaction(()=>this.getValueFromRoot(t),(i,o)=>{r(i,o)},{requiresObservable:!0,fireImmediately:v.get(s,"fireImmediately",!1)})}}class by{constructor(){N(this,"channels",new Map);N(this,"globalChannel",new Tl)}getChannel(t){const r=this.channels.get(t);if(r)return r;const s=new Tl;return this.channels.set(t,s),s}}class yy{constructor(t){N(this,"instances",new Map);this.pluginManager=t}get availableVizList(){return this.pluginManager.installedPlugins.flatMap(t=>t.manifest.viz)}resolveComponent(t){return this.pluginManager.factory.viz(t)}getOrCreateInstance(t){const r=this.instances.get(t.id);if(r)return r;const s={id:t.id,name:t.viz.type,type:t.viz.type,messageChannels:new by,instanceData:new _d(t.viz.conf)};return this.instances.set(t.id,s),s}}function jd(e,t,r,s){return{vizManager:r,locale:"zh",msgChannels:e.messageChannels,instanceData:e.instanceData,pluginData:new _d({}),colorPalette:{getColor(){return()=>""}},data:t,variables:s}}const vy=e=>{const{panel:t,measure:r,vizManager:s,data:i,variables:o}=e,l=s.resolveComponent(t.viz.type),c=s.getOrCreateInstance(t),u={...jd(c,i,s,o),viewport:{width:r.w,height:r.h}},d=l.viewRender;return n.jsx(d,{context:u,instance:c,...v.omit(e,["panel","vizManager","data"])})},_y=e=>{const{vizManager:t,panel:r,data:s,variables:i}=e,o=t.resolveComponent(r.viz.type),l=t.getOrCreateInstance(r),c={...jd(l,s,t,i)},u=o.configRender;return n.jsx(u,{context:c,instance:l,...v.omit(e,["panel","vizManager","data"])})},wd=(e,t)=>{const r=Dt.bezier(e),s=Dt.bezier(t);return function(i){return i<50?r(i*2/100).hex():s((i-50)*2/100).hex()}},xs=e=>{const t=Dt.bezier(e);return function(r){return t(r/100).hex()}},jy={type:"interpolation",displayName:"style.color.interpolation.palette.red_green",getColor:wd(["darkred","deeppink","lightyellow"],["lightyellow","lightgreen","teal"]),name:"red-green",category:"diverging"},wy={type:"interpolation",displayName:"style.color.interpolation.palette.yellow_blue",getColor:wd(["#8f531d","#ffd347","#e3efe3"],["#eefaee","#4ecbbf","#003f94"]),name:"yellow-blue",category:"diverging"},Cy={type:"interpolation",displayName:"style.color.interpolation.palette.red",getColor:xs(["#fff7f1","darkred"]),name:"red",category:"sequential"},Sy={type:"interpolation",displayName:"style.color.interpolation.palette.green",getColor:xs(["#f0ffed","darkgreen"]),name:"green",category:"sequential"},Ty={type:"interpolation",displayName:"style.color.interpolation.palette.blue",getColor:xs(["#f9fcff","#48b3e9","darkblue"]),name:"blue",category:"sequential"},ky={type:"interpolation",displayName:"style.color.interpolation.palette.orange",getColor:xs(["#fff7f1","darkorange","#b60000"]),name:"orange",category:"sequential"};class Dy{constructor(t){N(this,"symbol");this.symbol=Symbol(t)}}function Jt(e){return new Dy(e)}class va{constructor(){N(this,"parent");N(this,"factoryRegistry",new Map);N(this,"instanceRegistry",new Map)}createScoped(){const t=new va;return t.parent=this,t}getRequired(t){return this.get(t)}get(t){if(this.instanceRegistry.has(t.symbol))return this.instanceRegistry.get(t.symbol);const r=this.factoryRegistry.get(t.symbol);if(r){const s=r(this);return this.instanceRegistry.set(t.symbol,s),s}if(this.parent)return this.parent.get(t)}provideFactory(t,r){return this.factoryRegistry.has(t.symbol)?console.warn(`Token ${t.symbol.toString()} is already registered`):this.factoryRegistry.set(t.symbol,r),this}provideValue(t,r){return this.factoryRegistry.has(t.symbol)?console.warn(`Token ${t.symbol.toString()} is already registered`):this.factoryRegistry.set(t.symbol,()=>r),this}dispose(){this.instanceRegistry.forEach(t=>{const r=v.get(t,"dispose");v.isFunction(r)&&r.bind(t)()}),this.instanceRegistry.clear(),this.factoryRegistry.clear()}}const Cd="14.3.4",zy=Object.freeze(Object.defineProperty({__proto__:null,version:Cd},Symbol.toStringTag,{value:"Module"}));class Iy{constructor(t){N(this,"staticColors",new Map);N(this,"interpolations",new Map);t.installedPlugins.forEach(r=>{r.manifest.color.forEach(s=>{this.register(s)})})}getStaticColors(){return Array.from(this.staticColors.values())}register(t){const r=this.encodeColor(t);t.type==="single"?(this.staticColors.has(r)&&console.warn(`the color '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`),this.staticColors.set(r,t)):t.type==="interpolation"&&(this.interpolations.has(r)&&console.warn(`the interpolation '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`,`the interpolation '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`),this.interpolations.set(r,t))}decodeStaticColor(t){return this.staticColors.get(t)}encodeColor(t){return`\${${t.category}}.{${t.name}}`}decodeInterpolation(t){return this.interpolations.get(t)}getColorInterpolations(){return Array.from(this.interpolations.values())}}class My{constructor(){N(this,"plugins",new Map);N(this,"vizComponents",new Map);N(this,"factory",{viz:t=>{const r=this.vizComponents.get(t);if(r)return r;throw new Error(`Viz Component (${t}) not found`)}})}install(t){if(this.plugins.has(t.id))throw new Error(`Plugin (${t.id}) has been installed before`);this.plugins.set(t.id,t);for(const r of t.manifest.viz){if(this.vizComponents.has(r.name))throw new Error(`Viz Component (${r.name}) has been installed before`);this.vizComponents.set(r.name,r)}}get installedPlugins(){return Array.from(this.plugins.values())}}class Ey{constructor(){N(this,"migrations",[])}version(t,r){return this.migrations.push({version:t,handler:r}),this}run(t,r,s){var l;if(t.from===t.to)return r;if(t.from>t.to)throw new Error(`Can not downgrade from version '${t.from}' to (${t.to})`);const i=this.migrations.filter(c=>c.version>t.from&&c.version<=t.to),o=v.orderBy(i,"version","asc");if(((l=v.last(o))==null?void 0:l.version)!==t.to)throw new Error(`Migration to version ${t.to} not found`);return o.reduce((c,u)=>u.handler(c,s),r)}}class ke extends Ey{constructor(){super(),this.configVersions()}version(t,r){return super.version(t,(s,i)=>({version:t,...r(s,i)}))}async migrate({configData:t,panelModel:r}){const s=await t.getItem(null),i=v.get(s,"version",0),o=this.run({from:i,to:this.VERSION},s,{panelModel:r});await t.setItem(null,o)}async needMigration({configData:t}){const r=await t.getItem(null);return v.get(r,"version",0)<this.VERSION}}const W=(e,t)=>{const[r,{setFalse:s}]=U.useBoolean(!0),[i,o]=f.useState();f.useEffect(()=>(e.getItem(t).then(c=>{o(c),s()}),e.watchItem(t,c=>{o(c)})));const l=f.useCallback(async c=>{await e.setItem(t,c),o(c)},[e,t]);return{loading:r,value:i,set:l}},st={top:16,right:16,bottom:16,left:16},Et=e=>Math.max(0,e-st.left-st.right),Pt=e=>Math.max(0,e-st.top-st.bottom),zr=(e,t)=>({width:Et(e),height:Pt(t)}),at=({width:e,height:t,children:r})=>n.jsx(a.Box,{pt:st.top,pr:st.right,pb:st.bottom,pl:st.left,sx:{width:e,height:t,overflow:"hidden",position:"relative"},children:r}),_a={x_axis_data_key:"",y_axis_data_key:"",z_axis_data_key:"",xAxis3D:{type:"value",name:"X Axis Name"},yAxis3D:{type:"value",name:"Y Axis Name"},zAxis3D:{type:"value",name:"Z Axis Name"}};function Py({context:e}){const{value:t}=W(e.instanceData,"config"),r=e.data,{width:s,height:i}=e.viewport,{x_axis_data_key:o,y_axis_data_key:l,z_axis_data_key:c,xAxis3D:u,yAxis3D:d,zAxis3D:p}=v.defaults({},t,_a),h=f.useMemo(()=>qr(r,o),[r,o]),{x,y:b,z:m}=f.useMemo(()=>({x:O(o),y:O(l),z:O(c)}),[o,l,c]),{min:j,max:D}=f.useMemo(()=>{const z=v.minBy(h,M=>M[m.columnKey]),I=v.maxBy(h,M=>M[m.columnKey]);return{min:v.get(z,m.columnKey),max:v.get(I,m.columnKey)}},[h,m]),T={tooltip:{},backgroundColor:"#fff",visualMap:{show:!0,dimension:2,min:j,max:D,inRange:{color:["#313695","#4575b4","#74add1","#abd9e9","#e0f3f8","#ffffbf","#fee090","#fdae61","#f46d43","#d73027","#a50026"]}},xAxis3D:u,yAxis3D:d,zAxis3D:p,grid3D:{viewControl:{projection:"orthographic",autoRotate:!1},light:{main:{shadow:!0,quality:"ultra",intensity:1.5}}},series:[{type:"bar3D",wireframe:{},data:h.map(z=>[z[x.columnKey],z[b.columnKey],z[m.columnKey]])}]};return t?n.jsx(at,{width:s,height:i,children:n.jsx(Qe,{echarts:Fe,option:T,style:zr(s,i),notMerge:!0,theme:"merico-light"})}):null}const R=k.observer(f.forwardRef(({label:e,required:t,description:r,value:s,onChange:i,queryID:o,clearable:l=!1,sx:c,...u},d)=>{const{panel:p}=Pe(),h=f.useMemo(()=>p.dataFieldOptionGroups(s,l,o),[s,l,o]);if(h.length===0){const x=p.explainDataKey(s);return n.jsxs(a.HoverCard,{shadow:"md",position:"bottom-start",withinPortal:!0,zIndex:320,children:[n.jsx(a.HoverCard.Target,{children:n.jsx(a.Box,{children:n.jsx(a.TextInput,{label:e,required:t,defaultValue:x.columnKey,readOnly:!0,disabled:!0})})}),n.jsx(a.HoverCard.Dropdown,{children:n.jsxs(a.Group,{justify:"flex-start",gap:0,children:[n.jsx(a.Text,{size:"xs",c:x.queryName?"black":"red",ff:"monospace",children:x.queryName??x.queryID}),n.jsx(a.Text,{size:"xs",c:"black",ff:"monospace",children:"."}),n.jsx(a.Text,{size:"xs",c:"red",ff:"monospace",children:x.columnKey})]})})]})}return n.jsx(a.Select,{ref:d,label:e,description:r,data:h,value:s,onChange:Se(i),required:t,sx:c,maxDropdownHeight:500,...u})}));function Ay({context:e}){const{value:t,set:r}=W(e.instanceData,"config"),s=v.defaults({},t,_a),{control:i,handleSubmit:o,reset:l}=y.useForm({defaultValues:s});return f.useEffect(()=>{l(s)},[t]),t?n.jsx(a.Stack,{gap:"xs",children:n.jsxs("form",{onSubmit:o(r),children:[n.jsx(a.Text,{size:"sm",children:"X Axis"}),n.jsxs(a.Group,{justify:"space-between",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[n.jsx(y.Controller,{name:"x_axis_data_key",control:i,render:({field:c})=>n.jsx(R,{label:"Data Field",required:!0,...c})}),n.jsx(y.Controller,{name:"xAxis3D.name",control:i,render:({field:c})=>n.jsx(a.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...c})})]}),n.jsx(a.Text,{mt:"lg",size:"sm",children:"Y Axis"}),n.jsxs(a.Group,{justify:"space-between",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[n.jsx(y.Controller,{name:"y_axis_data_key",control:i,render:({field:c})=>n.jsx(R,{label:"Data Field",required:!0,...c})}),n.jsx(y.Controller,{name:"yAxis3D.name",control:i,render:({field:c})=>n.jsx(a.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...c})})]}),n.jsx(a.Text,{mt:"lg",size:"sm",children:"Z Axis"}),n.jsxs(a.Group,{justify:"space-between",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[n.jsx(y.Controller,{name:"z_axis_data_key",control:i,render:({field:c})=>n.jsx(R,{label:"Data Field",required:!0,...c})}),n.jsx(y.Controller,{name:"zAxis3D.name",control:i,render:({field:c})=>n.jsx(a.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...c})})]}),n.jsx(a.Group,{justify:"center",mt:"xl",grow:!0,sx:{width:"60%"},mx:"auto",children:n.jsxs(a.Button,{color:"blue",type:"submit",children:[n.jsx(C.IconDeviceFloppy,{size:20}),n.jsx(a.Text,{ml:"md",size:"sm",children:"Save"})]})})]})}):null}const Ly=[{lang:"en",resources:{bar_chart_3d:{viz_name:"Bar Chart(3D)"}}},{lang:"zh",resources:{bar_chart_3d:{viz_name:"柱图(3D)"}}}];function Oy(e,{panelModel:t}){try{const r=t.queryIDs[0];if(!r)throw new Error("cannot migrate when queryID is empty");const s=u=>u&&`${r}.${u}`,{x_axis_data_key:i,y_axis_data_key:o,z_axis_data_key:l,...c}=e;return{...c,x_axis_data_key:s(i),y_axis_data_key:s(o),z_axis_data_key:s(l)}}catch(r){throw console.error("[Migration failed]",r),r}}class Vy extends ke{constructor(){super(...arguments);N(this,"VERSION",2)}configVersions(){this.version(1,r=>({version:1,config:r})),this.version(2,(r,s)=>{const{config:i}=r;return{...r,version:2,config:Oy(i,s)}})}}const By={displayName:"viz.bar_chart_3d.viz_name",displayGroup:"chart.groups.echarts_based_charts",migrator:new Vy,name:"bar-3d",viewRender:Py,configRender:Ay,createConfig(){return{version:2,config:v.cloneDeep(_a)}},translation:Ly},qy=({disabled:e,value:t,onChange:r})=>{const s=i=>{i&&r(i)};return n.jsxs(a.Box,{sx:{position:"relative"},children:[e&&n.jsx(a.Overlay,{backgroundOpacity:.6,color:"#fff",zIndex:5,blur:2}),n.jsx(ht,{height:"500px",defaultLanguage:"javascript",value:t,onChange:s,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})};function ot({enabled:e,func_content:t}){return(r,s)=>{if(!e)return r;try{return new Function(`return ${t}`)()(r,s)}catch(i){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${i.message}`),r}}}function Xe(){return{enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
92
+ `)(r)}catch(s){return console.error(s),console.log(e),e}}function fs(e,t,r,s){const i=dy(t,s);return e.replaceAll(/(\{\{([^{\}]+(?=}))\}\})/g,(...l)=>{const c=l[2];if(!c)return c;const u=i[c];if(u)return u;const d=py(c);return hy(d,i,r)})}function gy(e,t){const r=Sl.decode(t);r!==e&&(console.error("Inconsistent sql"),console.groupCollapsed("Inconsistent sql"),console.table({before:e,after:t,v:r}),console.groupEnd())}async function fy({query:e,name:t,payload:r,additionals:s},i){if(!e.sql)return[];const{type:o,key:l,sql:c,pre_process:u,post_process:d}=e,p=Xs(c,r),h=tx({sql:p,pre_process:u}),x=Sl.encode(h);gy(h,x);let b=await gt.query(i)({type:o,key:l,query:x,...s},{params:{name:t}});return b=nx(d,b,ba(r)),b}async function xy({type:e,key:t,configString:r,name:s,additionals:i},o){try{return await gt.httpDataSourceQuery(o)({type:e,key:t,query:r,...i},{params:{name:s}})}catch(l){if(pt.isCancel(l))throw l;return console.error(l),l}}async function my({key:e,configString:t,name:r,additionals:s},i){try{return await gt.mericoMetricQuery(i)({type:"merico_metric_system",key:e,query:t,...s},{params:{name:r}})}catch(o){throw o}}async function ya(){try{return(await gt.post()("/datasource/list",{filter:{},sort:[{field:"create_time",order:"ASC"}],pagination:{page:1,pagesize:100}},{})).data}catch(e){return console.error(e),[]}}async function vd(){try{return(await gt.post()("/sql_snippet/list",{filter:{},sort:[{field:"id",order:"ASC"}],pagination:{page:1,pagesize:1e3}},{})).data}catch(e){return console.error(e),[]}}class _d{constructor(t){N(this,"rootRef");this.rootRef=te.observable({current:t})}async deleteItem(t){te.runInAction(()=>{v.unset(this.rootRef.current,[t])})}getItem(t){const r=this.getValueFromRoot(t);return Promise.resolve(r)}getValueFromRoot(t){return t===null?te.toJS(this.rootRef.current):v.get(this.rootRef.current,[t])}setItem(t,r){if(t===null)if(v.isObject(r))te.runInAction(()=>{this.rootRef.current=r});else throw new Error("Cannot set root value to non-object");else te.runInAction(()=>{v.set(this.rootRef.current,[t],r)});return Promise.resolve(this.getItem(t))}watchItem(t,r,s){return te.reaction(()=>this.getValueFromRoot(t),(i,o)=>{r(i,o)},{requiresObservable:!0,fireImmediately:v.get(s,"fireImmediately",!1)})}}class by{constructor(){N(this,"channels",new Map);N(this,"globalChannel",new Tl)}getChannel(t){const r=this.channels.get(t);if(r)return r;const s=new Tl;return this.channels.set(t,s),s}}class yy{constructor(t){N(this,"instances",new Map);this.pluginManager=t}get availableVizList(){return this.pluginManager.installedPlugins.flatMap(t=>t.manifest.viz)}resolveComponent(t){return this.pluginManager.factory.viz(t)}getOrCreateInstance(t){const r=this.instances.get(t.id);if(r)return r;const s={id:t.id,name:t.viz.type,type:t.viz.type,messageChannels:new by,instanceData:new _d(t.viz.conf)};return this.instances.set(t.id,s),s}}function jd(e,t,r,s){return{vizManager:r,locale:"zh",msgChannels:e.messageChannels,instanceData:e.instanceData,pluginData:new _d({}),colorPalette:{getColor(){return()=>""}},data:t,variables:s}}const vy=e=>{const{panel:t,measure:r,vizManager:s,data:i,variables:o}=e,l=s.resolveComponent(t.viz.type),c=s.getOrCreateInstance(t),u={...jd(c,i,s,o),viewport:{width:r.w,height:r.h}},d=l.viewRender;return n.jsx(d,{context:u,instance:c,...v.omit(e,["panel","vizManager","data"])})},_y=e=>{const{vizManager:t,panel:r,data:s,variables:i}=e,o=t.resolveComponent(r.viz.type),l=t.getOrCreateInstance(r),c={...jd(l,s,t,i)},u=o.configRender;return n.jsx(u,{context:c,instance:l,...v.omit(e,["panel","vizManager","data"])})},wd=(e,t)=>{const r=Dt.bezier(e),s=Dt.bezier(t);return function(i){return i<50?r(i*2/100).hex():s((i-50)*2/100).hex()}},xs=e=>{const t=Dt.bezier(e);return function(r){return t(r/100).hex()}},jy={type:"interpolation",displayName:"style.color.interpolation.palette.red_green",getColor:wd(["darkred","deeppink","lightyellow"],["lightyellow","lightgreen","teal"]),name:"red-green",category:"diverging"},wy={type:"interpolation",displayName:"style.color.interpolation.palette.yellow_blue",getColor:wd(["#8f531d","#ffd347","#e3efe3"],["#eefaee","#4ecbbf","#003f94"]),name:"yellow-blue",category:"diverging"},Cy={type:"interpolation",displayName:"style.color.interpolation.palette.red",getColor:xs(["#fff7f1","darkred"]),name:"red",category:"sequential"},Sy={type:"interpolation",displayName:"style.color.interpolation.palette.green",getColor:xs(["#f0ffed","darkgreen"]),name:"green",category:"sequential"},Ty={type:"interpolation",displayName:"style.color.interpolation.palette.blue",getColor:xs(["#f9fcff","#48b3e9","darkblue"]),name:"blue",category:"sequential"},ky={type:"interpolation",displayName:"style.color.interpolation.palette.orange",getColor:xs(["#fff7f1","darkorange","#b60000"]),name:"orange",category:"sequential"};class Dy{constructor(t){N(this,"symbol");this.symbol=Symbol(t)}}function Jt(e){return new Dy(e)}class va{constructor(){N(this,"parent");N(this,"factoryRegistry",new Map);N(this,"instanceRegistry",new Map)}createScoped(){const t=new va;return t.parent=this,t}getRequired(t){return this.get(t)}get(t){if(this.instanceRegistry.has(t.symbol))return this.instanceRegistry.get(t.symbol);const r=this.factoryRegistry.get(t.symbol);if(r){const s=r(this);return this.instanceRegistry.set(t.symbol,s),s}if(this.parent)return this.parent.get(t)}provideFactory(t,r){return this.factoryRegistry.has(t.symbol)?console.warn(`Token ${t.symbol.toString()} is already registered`):this.factoryRegistry.set(t.symbol,r),this}provideValue(t,r){return this.factoryRegistry.has(t.symbol)?console.warn(`Token ${t.symbol.toString()} is already registered`):this.factoryRegistry.set(t.symbol,()=>r),this}dispose(){this.instanceRegistry.forEach(t=>{const r=v.get(t,"dispose");v.isFunction(r)&&r.bind(t)()}),this.instanceRegistry.clear(),this.factoryRegistry.clear()}}const Cd="14.3.5",zy=Object.freeze(Object.defineProperty({__proto__:null,version:Cd},Symbol.toStringTag,{value:"Module"}));class Iy{constructor(t){N(this,"staticColors",new Map);N(this,"interpolations",new Map);t.installedPlugins.forEach(r=>{r.manifest.color.forEach(s=>{this.register(s)})})}getStaticColors(){return Array.from(this.staticColors.values())}register(t){const r=this.encodeColor(t);t.type==="single"?(this.staticColors.has(r)&&console.warn(`the color '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`),this.staticColors.set(r,t)):t.type==="interpolation"&&(this.interpolations.has(r)&&console.warn(`the interpolation '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`,`the interpolation '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`),this.interpolations.set(r,t))}decodeStaticColor(t){return this.staticColors.get(t)}encodeColor(t){return`\${${t.category}}.{${t.name}}`}decodeInterpolation(t){return this.interpolations.get(t)}getColorInterpolations(){return Array.from(this.interpolations.values())}}class My{constructor(){N(this,"plugins",new Map);N(this,"vizComponents",new Map);N(this,"factory",{viz:t=>{const r=this.vizComponents.get(t);if(r)return r;throw new Error(`Viz Component (${t}) not found`)}})}install(t){if(this.plugins.has(t.id))throw new Error(`Plugin (${t.id}) has been installed before`);this.plugins.set(t.id,t);for(const r of t.manifest.viz){if(this.vizComponents.has(r.name))throw new Error(`Viz Component (${r.name}) has been installed before`);this.vizComponents.set(r.name,r)}}get installedPlugins(){return Array.from(this.plugins.values())}}class Ey{constructor(){N(this,"migrations",[])}version(t,r){return this.migrations.push({version:t,handler:r}),this}run(t,r,s){var l;if(t.from===t.to)return r;if(t.from>t.to)throw new Error(`Can not downgrade from version '${t.from}' to (${t.to})`);const i=this.migrations.filter(c=>c.version>t.from&&c.version<=t.to),o=v.orderBy(i,"version","asc");if(((l=v.last(o))==null?void 0:l.version)!==t.to)throw new Error(`Migration to version ${t.to} not found`);return o.reduce((c,u)=>u.handler(c,s),r)}}class ke extends Ey{constructor(){super(),this.configVersions()}version(t,r){return super.version(t,(s,i)=>({version:t,...r(s,i)}))}async migrate({configData:t,panelModel:r}){const s=await t.getItem(null),i=v.get(s,"version",0),o=this.run({from:i,to:this.VERSION},s,{panelModel:r});await t.setItem(null,o)}async needMigration({configData:t}){const r=await t.getItem(null);return v.get(r,"version",0)<this.VERSION}}const W=(e,t)=>{const[r,{setFalse:s}]=U.useBoolean(!0),[i,o]=f.useState();f.useEffect(()=>(e.getItem(t).then(c=>{o(c),s()}),e.watchItem(t,c=>{o(c)})));const l=f.useCallback(async c=>{await e.setItem(t,c),o(c)},[e,t]);return{loading:r,value:i,set:l}},st={top:16,right:16,bottom:16,left:16},Et=e=>Math.max(0,e-st.left-st.right),Pt=e=>Math.max(0,e-st.top-st.bottom),zr=(e,t)=>({width:Et(e),height:Pt(t)}),at=({width:e,height:t,children:r})=>n.jsx(a.Box,{pt:st.top,pr:st.right,pb:st.bottom,pl:st.left,sx:{width:e,height:t,overflow:"hidden",position:"relative"},children:r}),_a={x_axis_data_key:"",y_axis_data_key:"",z_axis_data_key:"",xAxis3D:{type:"value",name:"X Axis Name"},yAxis3D:{type:"value",name:"Y Axis Name"},zAxis3D:{type:"value",name:"Z Axis Name"}};function Py({context:e}){const{value:t}=W(e.instanceData,"config"),r=e.data,{width:s,height:i}=e.viewport,{x_axis_data_key:o,y_axis_data_key:l,z_axis_data_key:c,xAxis3D:u,yAxis3D:d,zAxis3D:p}=v.defaults({},t,_a),h=f.useMemo(()=>qr(r,o),[r,o]),{x,y:b,z:m}=f.useMemo(()=>({x:O(o),y:O(l),z:O(c)}),[o,l,c]),{min:j,max:D}=f.useMemo(()=>{const z=v.minBy(h,M=>M[m.columnKey]),I=v.maxBy(h,M=>M[m.columnKey]);return{min:v.get(z,m.columnKey),max:v.get(I,m.columnKey)}},[h,m]),T={tooltip:{},backgroundColor:"#fff",visualMap:{show:!0,dimension:2,min:j,max:D,inRange:{color:["#313695","#4575b4","#74add1","#abd9e9","#e0f3f8","#ffffbf","#fee090","#fdae61","#f46d43","#d73027","#a50026"]}},xAxis3D:u,yAxis3D:d,zAxis3D:p,grid3D:{viewControl:{projection:"orthographic",autoRotate:!1},light:{main:{shadow:!0,quality:"ultra",intensity:1.5}}},series:[{type:"bar3D",wireframe:{},data:h.map(z=>[z[x.columnKey],z[b.columnKey],z[m.columnKey]])}]};return t?n.jsx(at,{width:s,height:i,children:n.jsx(Qe,{echarts:Fe,option:T,style:zr(s,i),notMerge:!0,theme:"merico-light"})}):null}const R=k.observer(f.forwardRef(({label:e,required:t,description:r,value:s,onChange:i,queryID:o,clearable:l=!1,sx:c,...u},d)=>{const{panel:p}=Pe(),h=f.useMemo(()=>p.dataFieldOptionGroups(s,l,o),[s,l,o]);if(h.length===0){const x=p.explainDataKey(s);return n.jsxs(a.HoverCard,{shadow:"md",position:"bottom-start",withinPortal:!0,zIndex:320,children:[n.jsx(a.HoverCard.Target,{children:n.jsx(a.Box,{children:n.jsx(a.TextInput,{label:e,required:t,defaultValue:x.columnKey,readOnly:!0,disabled:!0})})}),n.jsx(a.HoverCard.Dropdown,{children:n.jsxs(a.Group,{justify:"flex-start",gap:0,children:[n.jsx(a.Text,{size:"xs",c:x.queryName?"black":"red",ff:"monospace",children:x.queryName??x.queryID}),n.jsx(a.Text,{size:"xs",c:"black",ff:"monospace",children:"."}),n.jsx(a.Text,{size:"xs",c:"red",ff:"monospace",children:x.columnKey})]})})]})}return n.jsx(a.Select,{ref:d,label:e,description:r,data:h,value:s,onChange:Se(i),required:t,sx:c,maxDropdownHeight:500,...u})}));function Ay({context:e}){const{value:t,set:r}=W(e.instanceData,"config"),s=v.defaults({},t,_a),{control:i,handleSubmit:o,reset:l}=y.useForm({defaultValues:s});return f.useEffect(()=>{l(s)},[t]),t?n.jsx(a.Stack,{gap:"xs",children:n.jsxs("form",{onSubmit:o(r),children:[n.jsx(a.Text,{size:"sm",children:"X Axis"}),n.jsxs(a.Group,{justify:"space-between",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[n.jsx(y.Controller,{name:"x_axis_data_key",control:i,render:({field:c})=>n.jsx(R,{label:"Data Field",required:!0,...c})}),n.jsx(y.Controller,{name:"xAxis3D.name",control:i,render:({field:c})=>n.jsx(a.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...c})})]}),n.jsx(a.Text,{mt:"lg",size:"sm",children:"Y Axis"}),n.jsxs(a.Group,{justify:"space-between",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[n.jsx(y.Controller,{name:"y_axis_data_key",control:i,render:({field:c})=>n.jsx(R,{label:"Data Field",required:!0,...c})}),n.jsx(y.Controller,{name:"yAxis3D.name",control:i,render:({field:c})=>n.jsx(a.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...c})})]}),n.jsx(a.Text,{mt:"lg",size:"sm",children:"Z Axis"}),n.jsxs(a.Group,{justify:"space-between",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[n.jsx(y.Controller,{name:"z_axis_data_key",control:i,render:({field:c})=>n.jsx(R,{label:"Data Field",required:!0,...c})}),n.jsx(y.Controller,{name:"zAxis3D.name",control:i,render:({field:c})=>n.jsx(a.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...c})})]}),n.jsx(a.Group,{justify:"center",mt:"xl",grow:!0,sx:{width:"60%"},mx:"auto",children:n.jsxs(a.Button,{color:"blue",type:"submit",children:[n.jsx(C.IconDeviceFloppy,{size:20}),n.jsx(a.Text,{ml:"md",size:"sm",children:"Save"})]})})]})}):null}const Ly=[{lang:"en",resources:{bar_chart_3d:{viz_name:"Bar Chart(3D)"}}},{lang:"zh",resources:{bar_chart_3d:{viz_name:"柱图(3D)"}}}];function Oy(e,{panelModel:t}){try{const r=t.queryIDs[0];if(!r)throw new Error("cannot migrate when queryID is empty");const s=u=>u&&`${r}.${u}`,{x_axis_data_key:i,y_axis_data_key:o,z_axis_data_key:l,...c}=e;return{...c,x_axis_data_key:s(i),y_axis_data_key:s(o),z_axis_data_key:s(l)}}catch(r){throw console.error("[Migration failed]",r),r}}class Vy extends ke{constructor(){super(...arguments);N(this,"VERSION",2)}configVersions(){this.version(1,r=>({version:1,config:r})),this.version(2,(r,s)=>{const{config:i}=r;return{...r,version:2,config:Oy(i,s)}})}}const By={displayName:"viz.bar_chart_3d.viz_name",displayGroup:"chart.groups.echarts_based_charts",migrator:new Vy,name:"bar-3d",viewRender:Py,configRender:Ay,createConfig(){return{version:2,config:v.cloneDeep(_a)}},translation:Ly},qy=({disabled:e,value:t,onChange:r})=>{const s=i=>{i&&r(i)};return n.jsxs(a.Box,{sx:{position:"relative"},children:[e&&n.jsx(a.Overlay,{backgroundOpacity:.6,color:"#fff",zIndex:5,blur:2}),n.jsx(ht,{height:"500px",defaultLanguage:"javascript",value:t,onChange:s,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})};function ot({enabled:e,func_content:t}){return(r,s)=>{if(!e)return r;try{return new Function(`return ${t}`)()(r,s)}catch(i){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${i.message}`),r}}}function Xe(){return{enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
93
93
  `)}}const At=f.forwardRef(({value:e,onChange:t,triggerButtonText:r},s)=>{const{t:i}=_.useTranslation(),[o,{setTrue:l,setFalse:c}]=U.useBoolean(),[u,d]=f.useState(e);f.useEffect(()=>{d(e)},[e]);const p=D=>{d({...u,enabled:D})},h=()=>{c();const{enabled:D,func_content:T}=u,z={enabled:D,func_content:T};d(z),t(z)},x=()=>{c(),d(e)},b=D=>{d(T=>({...T,func_content:D}))},m=()=>{b(Xe().func_content)},j=r??i("chart.axis.customize_label");return n.jsxs(n.Fragment,{children:[n.jsx(a.Button,{variant:"filled",color:"grape",leftSection:n.jsx(C.IconMathFunction,{size:16}),mt:24,onClick:l,sx:{flexGrow:0},children:j}),n.jsx(a.Modal,{size:800,title:j,opened:o,onClose:c,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:o&&n.jsxs(a.Stack,{children:[n.jsx(a.Checkbox,{mt:10,label:i("common.enabled"),checked:u.enabled,onChange:D=>p(D.currentTarget.checked)}),n.jsx(qy,{value:u.func_content,onChange:b,disabled:!u.enabled}),n.jsxs(a.Group,{justify:"space-between",children:[n.jsx(a.Button,{onClick:m,color:"red",leftSection:n.jsx(C.IconRecycle,{size:20}),children:i("common.actions.reset_to_default")}),n.jsxs(a.Group,{justify:"flex-end",children:[n.jsx(a.Button,{onClick:x,variant:"subtle",children:i("common.actions.cancel")}),n.jsx(a.Button,{color:"green",leftSection:n.jsx(C.IconDeviceFloppy,{size:16}),onClick:h,children:i("common.actions.save")})]})]})]})})]})}),Tn={x_axis_scroll:!1,y_axis_scroll:!1,x_axis_slider:!1,y_axis_slider:!1};function Sd(){return v.cloneDeep(Tn)}const Ny=[{lang:"en",resources:{boxplot:{viz_name:"Boxplot Chart",box:"Box",outlier:"Outlier",scatter:"Scatter",click_series:{label:"Click box, scatter or outlier"}}}},{lang:"zh",resources:{boxplot:{viz_name:"箱线图",box:"箱体",outlier:"异常点",scatter:"散点",click_series:{label:"点击箱体、散点或异常点"}}}}],Td={id:"builtin:echarts:click-echart:series",displayName:"viz.boxplot.click_series.label",nameRender:Gy,configRender:$y,payload:[{name:"type",description:"Always 'click'",valueType:"string"},{name:"seriesType",description:"'boxplot'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"Record of 'name', 'min', 'q1', 'median', 'q3', 'max'",valueType:"object"},{name:"rowData",description:"Data of the row",valueType:"object"}]};function $y(e){return n.jsx(n.Fragment,{})}function Gy(e){const{t}=_.useTranslation();return n.jsx(a.Text,{size:"sm",children:t("viz.boxplot.click_series.label")})}const ms=f.forwardRef(({sectionTitle:e,value:t,onChange:r},s)=>{const{t:i,i18n:o}=_.useTranslation(),l=u=>d=>{const p=v.cloneDeep(t);v.set(p,u,d),r(p)},c=f.useMemo(()=>[{label:i("chart.axis.overflow.truncate"),value:"truncate"},{label:i("chart.axis.overflow.break_line"),value:"break"},{label:i("chart.axis.overflow.break_word"),value:"breakAll"}],[o.language]);return n.jsxs(a.Stack,{gap:0,children:[e&&n.jsx(a.Divider,{mb:-5,mt:5,variant:"dotted",label:e,labelPosition:"right",styles:{label:{color:"dimmed"}}}),n.jsxs(a.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(a.NumberInput,{label:i("chart.axis.overflow.max_width"),hideControls:!0,value:t.width,onChange:l("width")}),n.jsx(a.Select,{label:i("chart.axis.overflow.label"),data:c,value:t.overflow,onChange:l("overflow")}),n.jsx(a.TextInput,{label:i("chart.axis.overflow.ellipsis"),value:t.ellipsis,disabled:!0})]})]})}),Lt=f.forwardRef(({value:e,onChange:t},r)=>{const{t:s}=_.useTranslation(),i=l=>{t({...e,on_axis:l})},o=l=>{t({...e,in_tooltip:l})};return n.jsxs(a.Stack,{ref:r,gap:0,children:[n.jsx(ms,{sectionTitle:s("chart.axis.overflow.section_title.on_axis"),value:e.on_axis,onChange:i}),n.jsx(ms,{sectionTitle:s("chart.axis.overflow.section_title.in_tooltip"),value:e.in_tooltip,onChange:o})]})});function lt(){return{on_axis:{width:80,overflow:"truncate",ellipsis:"..."},in_tooltip:{width:200,overflow:"break",ellipsis:"..."}}}function Ct({overflow:e,width:t}){const r={truncate:"initial",break:"break-all",breakAll:"break-word"}[e],s=e==="truncate"?"nowrap":"initial",i={truncate:"ellipsis",break:"clip",breakAll:"clip"}[e];return`
94
94
  max-width: ${t}px;
95
95
  word-break: ${r};
@@ -494,7 +494,7 @@ React keys must be passed directly to JSX without using spread:
494
494
  }
495
495
  `,th=()=>{const{t:e}=_.useTranslation(),[t,r]=f.useState(!1);return n.jsxs(n.Fragment,{children:[n.jsx(a.Button,{variant:"subtle",size:"compact-sm",onClick:()=>r(s=>!s),children:e(t?"common.actions.close":"filter.widget.common.see_data_structure")}),n.jsx(a.Collapse,{in:t,children:n.jsx(zt.CodeHighlight,{language:"typescript",withCopyButton:!1,code:m3})})]})},b3={[Q.Checkbox]:"true",[Q.DateRange]:"[new Date('2023-01-01 00:00:00'), new Date('2024-01-01 00:00:00')]",[Q.MultiSelect]:"[]",[Q.Select]:'""',[Q.TreeSelect]:"[]",[Q.TreeSingleSelect]:'""',[Q.TextInput]:'""'},y3=e=>["function getDefaultValue(filter, utils, context) {",` return ${b3[e]};`,"}"].join(`
496
496
  `),Dn=k.observer(({filter:e})=>{const{t}=_.useTranslation();return n.jsx(fa,{label:"",title:t("filter.field.custom_default_value.title"),triggerLabel:t("filter.field.custom_default_value.trigger"),value:e.default_value_func,onChange:e.setDefaultValueFunc,defaultValue:y3(e.type),triggerButtonProps:{size:"xs",color:"grape",sx:{flexGrow:0,alignSelf:"flex-start"},leftSection:n.jsx(C.IconMathFunction,{size:16})},description:n.jsx(a.Alert,{title:t("filter.field.custom_default_value.tips"),color:"gray",mb:16,children:n.jsxs(a.List,{size:"xs",type:"ordered",children:[n.jsx(a.List.Item,{children:t("filter.field.custom_default_value.tip_1")}),n.jsx(a.List.Item,{children:t("filter.field.custom_default_value.tip_2")})]})})})}),Es=k.observer(({value:e,onChange:t})=>{const{t:r}=_.useTranslation(),s=se(),i=re(),o=f.useMemo(()=>i.queries.options,[i.queries.current]),l=o.length===0,c=u=>{s.editor.setPath(["_QUERIES_",u])};return n.jsx(a.Select,{label:n.jsxs(a.Group,{justify:"space-between",children:[n.jsx(a.Text,{fw:500,size:"sm",children:r("filter.widget.common.use_query_data_as_options")}),e&&n.jsx(a.Button,{size:"xs",leftSection:n.jsx(C.IconArrowCurveRight,{size:16}),variant:"subtle",color:"blue",onClick:()=>c(e),children:r("query.open")})]}),data:o,value:e,onChange:Se(t),allowDeselect:!1,clearable:!0,sx:{flexGrow:1},disabled:l,error:l?"You need to add a query in Data Settings":void 0,styles:{label:{display:"block"}}})}),v3=k.observer(function({filter:t}){const{t:r}=_.useTranslation(),s=t.config;return n.jsxs(n.Fragment,{children:[n.jsxs(a.Group,{justify:"space-between",children:[n.jsx(a.Checkbox,{checked:s.required,onChange:i=>s.setRequired(i.currentTarget.checked),label:r("filter.widget.select.required")}),n.jsx(Dn,{filter:t})]}),n.jsx(a.TextInput,{label:r("filter.widget.common.min_width"),value:s.min_width,onChange:i=>s.setMinWidth(i.currentTarget.value),placeholder:"200px"}),n.jsx(a.Divider,{label:r("filter.widget.common.fetch_options_from_datasource"),labelPosition:"center"}),n.jsx(a.Checkbox,{checked:s.treeCheckStrictly,onChange:i=>s.setTreeCheckStrictly(i.currentTarget.checked),label:r("filter.widget.tree_select.strictly")}),n.jsx(a.NumberInput,{value:s.default_selection_count,onChange:s.setDefaultSelectionCount,label:r("filter.widget.common.default_selection_count")}),n.jsx(Es,{value:s.options_query_id,onChange:s.setOptionsQueryID}),n.jsx(th,{})]})}),mo=({errorMessage:e})=>{const{t}=_.useTranslation();return e?n.jsx(a.Text,{c:"red",size:"12px",children:e}):n.jsx(a.Text,{c:"dimmed",size:"12px",children:t("filter.widget.common.selector_option_empty")})},_3=({rotate:e,onClick:t})=>n.jsx("svg",{onClick:t,className:"caret-icon",viewBox:"0 0 1024 1024",focusable:"false","data-icon":"caret-down",width:"14px",height:"14px",fill:"currentColor","aria-hidden":"true",transform:`rotate(${e})`,children:n.jsx("path",{d:"M840.4 300H183.6c-19.7 0-30.7 20.8-18.5 35l328.4 380.8c9.4 10.9 27.5 10.9 37 0L858.9 335c12.2-14.2 1.2-35-18.5-35z"})}),nh=({expanded:e,isLeaf:t,value:r,onClick:s,...i})=>t?n.jsx("span",{style:{width:"14px",display:"inline-block"}}):n.jsx(_3,{rotate:e?"0":"-90",onClick:s,...i}),j3=({onClick:e})=>n.jsxs("svg",{onClick:e,className:"checkbox-icon",width:"16",height:"16",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),n.jsx("rect",{className:"border",x:"4",y:"4",width:"16",height:"16",rx:"2"}),n.jsx("rect",{className:"checkmark-indeterminate",x:"8",y:"8",width:"8",height:"8",rx:"2",stroke:"none"}),n.jsx("path",{className:"checkmark-checked",d:"M9 12l2 2l4 -4"})]}),rh=({onClick:e,...t})=>n.jsx(j3,{onClick:e,...t}),w3=on.createStyles((e,{radius:t=4,width:r,name:s})=>({root:{borderRadius:a.getRadius(t),display:"flex",flexWrap:"nowrap",border:"1px solid #ced4da",paddingLeft:"0px",paddingRight:"30px",backgroundColor:"#fff",transition:"border-color 100ms ease",borderColor:"#e9ecef","&.rc-tree-select.rc-tree-select-open":{borderColor:"#228be6 !important",".rc-tree-select-selection-overflow-item-rest":{display:"none"},".rc-tree-select-selection-overflow-item-suffix":{display:"block"}},".rc-tree-select-selector":{height:"auto",lineHeight:1.55,paddingLeft:"12px",resize:"none",boxSizing:"border-box",fontSize:"14px",width:"100%",color:"#000",display:"block",textAlign:"left",minHeight:"36px",cursor:"pointer",flexGrow:1},".rc-tree-select-selection-search-mirror":{display:"none"},".rc-tree-select-selection-search":{flexGrow:1,width:"auto !important"},".rc-tree-select-selection-overflow":{display:"flex",minHeight:"34px",alignItems:"center",flexWrap:"nowrap",marginLeft:"calc(-10px / 2)",boxSizing:"border-box"},".rc-tree-select-selection-overflow-item":{display:"flex",alignItems:"center",backgroundColor:"#f1f3f5",color:"#495057",height:"24px",paddingLeft:"12px",paddingRight:"12px",fontWeight:500,fontSize:"12px",borderRadius:"4px",cursor:"default",userSelect:"none",maxWidth:"calc(100% - 20px)",margin:"calc(10px / 2 - 2px) calc(10px / 2)"},".rc-tree-select-selection-overflow-item-rest":{cursor:"pointer"},".rc-tree-select-selection-overflow-item-suffix":{display:"none",backgroundColor:"transparent",width:"100%",maxWidth:"100%",height:"28px",margin:0,paddingLeft:0,paddingRight:0},input:{flex:1,minWidth:"60px",backgroundColor:"transparent",border:0,outline:0,fontSize:"14px",padding:0,marginLeft:0,color:"inherit",height:"28px",lineHeight:"32px",cursor:"pointer",width:"100%","&::-webkit-search-decoration, &::-webkit-search-cancel-button, &::-webkit-search-results-button, &::-webkit-search-results-decoration":{display:"none"}},".rc-tree-select-clear":{marginRight:"-24px",alignSelf:"center",cursor:"pointer"},"&.rc-tree-select-disabled":{backgroundColor:"rgb(241, 243, 245)",color:"rgb(144, 146, 150)",opacity:.6,"&, .rc-tree-select-selector, input":{cursor:"not-allowed"}}},label:{fontSize:e.fontSizes.sm,fontWeight:500,color:"#212529"},required:{color:"#fa5252",paddingLeft:"3px"},dropdown:{fontSize:e.fontSizes.xs,zIndex:300,paddingTop:"6px",position:"absolute",width:`${r} !important`,"&.rc-tree-select-dropdown-slide-up-leave-active":{display:"none"},".rc-tree-select-tree-list .rc-tree-select-tree-list-holder":{},".rc-tree-select-tree-list, .rc-tree-select-empty":{backgroundColor:"#fff",border:"1px solid #e9ecef",padding:0,boxShadow:"0 1px 3px rgb(0 0 0 / 5%), rgb(0 0 0 / 5%) 0px 10px 15px -5px, rgb(0 0 0 / 4%) 0px 7px 7px -5px",borderRadius:"4px"},".rc-tree-select-empty":{padding:"8px 12px"},".rc-tree-select-tree-treenode":{boxSizing:"border-box",textAlign:"left",width:"100%",padding:"0px 12px",cursor:"pointer",fontSize:"14px",color:"#000",borderRadius:"4px",display:"flex",flexWrap:"nowrap",overflow:"hidden","&:hover":{backgroundColor:"#f1f3f5"},"&.rc-tree-select-tree-treenode-checkbox-checked":{".rc-tree-select-tree-iconEle .checkbox-icon .checkmark-checked":{stroke:"rgb(64, 192, 87)",animation:"check 200ms linear forwards"}},"&.rc-tree-select-tree-treenode-checkbox-indeterminate":{".rc-tree-select-tree-iconEle .checkbox-icon .checkmark-indeterminate":{fill:"rgb(64, 192, 87)"}},"&.rc-tree-select-tree-treenode-disabled":{color:"#aaa",".rc-tree-select-tree-title, .rc-tree-select-tree-iconEle":{cursor:"not-allowed"},".rc-tree-select-tree-iconEle":{"svg .border":{fill:"#ced4da"}}},".rc-tree-select-tree-switcher":{height:"16px",alignSelf:"center",paddingRight:"2px",transition:"color 200ms ease","&:hover":{color:"#228be6","svg.caret-icon":{color:"#228be6"}},"svg.caret-icon":{color:"#ced4da",transition:"all 200ms ease"}},".rc-tree-select-tree-node-content-wrapper":{display:"flex",flexWrap:"nowrap",overflow:"hidden",alignItems:"center",gap:"8px",width:"100%",padding:"8px 0",transition:"color 200ms ease","&:hover":{color:"#228be6"}},".rc-tree-select-tree-iconEle":{height:"16px","svg .border":{stroke:"#ced4da"},".checkbox-icon .checkmark-indeterminate":{fill:"transparent",transition:"fill 200ms ease"},".checkbox-icon .checkmark-checked":{transform:"scale(1.2)",transformOrigin:"center center",strokeDasharray:10,strokeDashoffset:-10},"@keyframes check":{"0%":{strokeDashoffset:10},"100%":{strokeDashoffset:0}}},".rc-tree-select-tree-title":{textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden",".rc-tree-select-tree-title-desc":{fontSize:"12px",maxWidth:"100%",textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden"}},".rc-tree-select-tree-indent":{flexGrow:0,height:0,verticalAlign:"bottom"},".rc-tree-select-tree-indent-unit":{display:"inline-block",width:"1em"}}}})),C3=({disabled:e,radius:t,style:r,label:s,value:i,onChange:o,treeData:l,errorMessage:c,required:u,treeCheckStrictly:d})=>{const{t:p}=_.useTranslation(),{classes:h,cx:x}=w3({radius:t,width:r.width,name:"FilterTreeSelectWidget"}),[b,m]=f.useState(!1),j=T=>{m(T)},D=b&&(i==null?void 0:i.length)>0;return n.jsxs(a.Stack,{gap:3,children:[n.jsxs(a.Group,{justify:"space-between",children:[n.jsxs(a.Text,{className:h.label,size:"sm",children:[s,u&&n.jsx("span",{className:h.required,"aria-hidden":"true",children:"*"})]}),D&&n.jsx(a.Tooltip,{label:p("filter.widget.common.x_selected",{count:i.length}),children:n.jsx(a.Badge,{variant:"light",children:i.length})})]}),n.jsx(Ys,{disabled:e,allowClear:{clearIcon:n.jsx(a.CloseButton,{size:"sm"})},treeCheckStrictly:d,labelInValue:!0,className:x(h.root,"check-select"),dropdownClassName:x(h.dropdown,""),onDropdownVisibleChange:j,transitionName:"rc-tree-select-dropdown-slide-up",choiceTransitionName:"rc-tree-select-selection__choice-zoom",style:r,listHeight:510,treeLine:!0,switcherIcon:nh,treeIcon:rh,maxTagTextLength:10,value:i,treeData:l,notFoundContent:n.jsx(mo,{errorMessage:c}),treeNodeFilterProp:"filterBasis",treeCheckable:!0,showCheckedStrategy:Ys.SHOW_PARENT,onChange:o,onSelect:console.log,maxTagCount:0,maxTagPlaceholder:()=>p("filter.widget.common.x_selected",{count:i.length})})]})},S3=k.observer(({label:e,config:t,value:r,onChange:s})=>{const{treeData:i,treeDataLoading:o,errorMessage:l}=t,c=x=>{const b=x.map(m=>m.value);s(b,!1)},u=f.useMemo(()=>t.initialSelection(r),[r,t.initialSelection,o]),d=t.min_width?t.min_width:"200px",h=!!t.options_query_id?o:!1;return n.jsx(C3,{disabled:h,style:{minWidth:"160px",width:d,maxWidth:h?d:"unset",borderColor:"#e9ecef"},value:[...u],onChange:c,treeData:i,errorMessage:l,label:e,required:t.required,treeCheckStrictly:t.treeCheckStrictly})}),T3=k.observer(({filter:e})=>{const{t}=_.useTranslation(),r=e.config;return n.jsxs(n.Fragment,{children:[n.jsxs(a.Group,{justify:"space-between",children:[n.jsx(a.Checkbox,{checked:r.required,onChange:s=>r.setRequired(s.currentTarget.checked),label:t("filter.widget.select.required")}),n.jsx(Dn,{filter:e})]}),n.jsx(a.TextInput,{label:t("filter.widget.common.min_width"),value:r.min_width,onChange:s=>r.setMinWidth(s.currentTarget.value),placeholder:"200px"}),n.jsx(a.Divider,{label:t("filter.widget.common.fetch_options_from_datasource"),labelPosition:"center"}),n.jsx(a.Checkbox,{checked:r.default_selection_count===1,onChange:s=>r.setDefaultSelectionCount(s.currentTarget.checked?1:0),label:t("filter.widget.tree_single_select.select_first_option_by_default")}),n.jsx(Es,{value:r.options_query_id,onChange:r.setOptionsQueryID}),n.jsx(th,{})]})}),k3=on.createStyles((e,{radius:t=4,width:r,name:s})=>({root:{borderRadius:a.getRadius(t),display:"flex",flexWrap:"nowrap",border:"1px solid #ced4da",paddingLeft:"0px",paddingRight:"30px",backgroundColor:"#fff",transition:"border-color 100ms ease",borderColor:"#e9ecef","&.rc-tree-select.rc-tree-select-open":{borderColor:"#228be6 !important",".rc-tree-select-selection-overflow-item-rest":{display:"none"},".rc-tree-select-selection-overflow-item-suffix":{display:"block"}},"&.rc-tree-select-focused":{".rc-tree-select-selection-item":{color:"#aaa"}},".rc-tree-select-selector":{height:"auto",lineHeight:1.55,paddingLeft:"calc(2.25rem / 3)",resize:"none",boxSizing:"border-box",fontSize:"14px",width:"100%",color:"#000",display:"block",textAlign:"left",minHeight:"36px",cursor:"pointer",position:"relative"},".rc-tree-select-selection-search":{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:1,".rc-tree-select-selection-search-input":{height:"36px",paddingLeft:"calc(2.25rem / 3)",textOverflow:"ellipsis"}},".rc-tree-select-selection-item":{position:"absolute",top:0,bottom:0,left:0,paddingLeft:"calc(2.25rem / 3)",color:"#000",lineHeight:"36px",fontSize:"0.875rem",cursor:"default",userSelect:"none",maxWidth:"calc(100% - 20px)",transition:"color 200ms ease"},input:{flex:1,minWidth:"60px",backgroundColor:"transparent",border:0,outline:0,fontSize:"14px",padding:0,marginLeft:0,color:"inherit",height:"28px",lineHeight:"32px",cursor:"pointer",width:"100%","&::-webkit-search-decoration, &::-webkit-search-cancel-button, &::-webkit-search-results-button, &::-webkit-search-results-decoration":{display:"none"}},".rc-tree-select-clear":{marginRight:"-24px",alignSelf:"center",cursor:"pointer"},"&.rc-tree-select-disabled":{backgroundColor:"rgb(241, 243, 245)",color:"rgb(144, 146, 150)",opacity:.6,"&, .rc-tree-select-selector, input":{cursor:"not-allowed"}}},label:{fontSize:e.fontSizes.sm,fontWeight:500,color:"#212529"},required:{color:"#fa5252",paddingLeft:"3px"},dropdown:{fontSize:e.fontSizes.xs,zIndex:300,paddingTop:"6px",position:"absolute",width:`${r} !important`,"&.rc-tree-select-dropdown-slide-up-leave-active":{display:"none"},".rc-tree-select-tree-list .rc-tree-select-tree-list-holder":{},".rc-tree-select-tree-list, .rc-tree-select-empty":{backgroundColor:"#fff",border:"1px solid #e9ecef",padding:0,boxShadow:"0 1px 3px rgb(0 0 0 / 5%), rgb(0 0 0 / 5%) 0px 10px 15px -5px, rgb(0 0 0 / 4%) 0px 7px 7px -5px",borderRadius:"4px"},".rc-tree-select-empty":{padding:"8px 12px"},".rc-tree-select-tree-treenode":{boxSizing:"border-box",textAlign:"left",width:"100%",padding:"0px 12px",cursor:"pointer",fontSize:"14px",color:"#000",borderRadius:"4px",display:"flex",flexWrap:"nowrap",overflow:"hidden",transition:"background-color 200ms ease","&:hover":{backgroundColor:"#f1f3f5"},"&.rc-tree-select-tree-treenode-selected":{".rc-tree-select-tree-iconEle .checkbox-icon .checkmark-checked":{stroke:"rgb(64, 192, 87)",animation:"check 200ms linear forwards"}},"&.rc-tree-select-tree-treenode-disabled":{color:"#aaa",".rc-tree-select-tree-title, .rc-tree-select-tree-iconEle":{cursor:"not-allowed"},".rc-tree-select-tree-iconEle":{"svg .border":{fill:"#ced4da"}}},".rc-tree-select-tree-switcher":{height:"16px",alignSelf:"center",paddingRight:"2px",transition:"color 200ms ease","&:hover":{color:"#228be6","svg.caret-icon":{color:"#228be6"}},"svg.caret-icon":{color:"#ced4da",transition:"all 200ms ease"}},".rc-tree-select-tree-node-content-wrapper":{display:"flex",flexWrap:"nowrap",overflow:"hidden",alignItems:"center",gap:"8px",transition:"color 200ms ease",width:"100%",padding:"8px 0","&:hover":{color:"#228be6"}},".rc-tree-select-tree-iconEle":{height:"16px","svg .border":{stroke:"#ced4da"},".checkbox-icon .checkmark-indeterminate":{fill:"transparent",transition:"fill 200ms ease"},".checkbox-icon .checkmark-checked":{transform:"scale(1.2)",transformOrigin:"center center",strokeDasharray:10,strokeDashoffset:-10},"@keyframes check":{"0%":{strokeDashoffset:10},"100%":{strokeDashoffset:0}}},".rc-tree-select-tree-title":{textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden",".rc-tree-select-tree-title-desc":{fontSize:"12px",maxWidth:"100%",textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden"}},".rc-tree-select-tree-indent":{flexGrow:0,height:0,verticalAlign:"bottom"},".rc-tree-select-tree-indent-unit":{display:"inline-block",width:"1em"}}}})),D3=({disabled:e,radius:t,style:r,label:s,value:i,onChange:o,treeData:l,errorMessage:c,required:u})=>{_.useTranslation();const{classes:d,cx:p}=k3({radius:t,width:r.width,name:"FilterTreeSelectWidget"});return n.jsxs(a.Stack,{gap:3,children:[n.jsx(a.Group,{justify:"space-between",children:n.jsxs(a.Text,{className:d.label,size:"sm",children:[s,u&&n.jsx("span",{className:d.required,"aria-hidden":"true",children:"*"})]})}),n.jsx(Ys,{disabled:e,allowClear:{clearIcon:n.jsx(a.CloseButton,{size:"sm"})},multiple:!1,labelInValue:!0,className:p(d.root,"check-select"),dropdownClassName:p(d.dropdown,""),transitionName:"rc-tree-select-dropdown-slide-up",choiceTransitionName:"rc-tree-select-selection__choice-zoom",style:r,listHeight:510,treeLine:!0,switcherIcon:nh,treeIcon:rh,value:i,treeData:l,notFoundContent:n.jsx(mo,{errorMessage:c}),treeNodeFilterProp:"filterBasis",treeCheckable:!1,onChange:o,onSelect:console.log,showSearch:!0})]})},z3=k.observer(({label:e,config:t,value:r,onChange:s})=>{const{treeData:i,treeDataLoading:o,errorMessage:l}=t,c=x=>{s(x?x.value:null,!1)},u=f.useMemo(()=>t.initialSelection(r),[r,t.initialSelection,t.treeDataLoading]),d=t.min_width?t.min_width:"200px",h=!!t.options_query_id?o:!1;return n.jsx(D3,{disabled:h,style:{width:d,maxWidth:h?d:"unset",borderColor:"#e9ecef"},value:u,onChange:c,treeData:i,errorMessage:l,label:e,required:t.required})});function I3(e){return df.arrayToTree(e,{id:"value",parentId:"parent_value",childrenField:"children",dataField:null})}function M3(e){return e.map(t=>{const{label:r,description:s,...i}=t,o={...i,filterBasis:`${r}___${s??""}`,description:s,label:r};return s&&(o.label=f.createElement("div",{},[f.createElement(a.Text,{key:0,title:t.label},t.label),f.createElement(a.Text,{key:1,className:"rc-tree-select-tree-title-desc",color:"dimmed",title:t.description},t.description)])),o})}const sh=g.types.compose("FilterConfigModel_BaseTreeSelect",g.types.model({min_width:g.types.optional(g.types.string,"")}),po).views(e=>({get plainData(){const{data:t}=e.contentModel.getDataStuffByID(e.options_query_id);return t},get treeData(){const t=this.plainData,r=M3(t);return I3(r)},get errorMessage(){const{error:t}=e.contentModel.getDataStuffByID(e.options_query_id);return t},get treeDataLoading(){const{state:t}=e.contentModel.getDataStuffByID(e.options_query_id);return t==="loading"}})).actions(e=>({setMinWidth(t){e.min_width=t}})),bo=g.types.compose("FilterTreeSelectConfigMeta",g.types.model({_name:g.types.literal("tree-select"),default_value:g.types.optional(g.types.array(g.types.string),[]),treeCheckStrictly:g.types.optional(g.types.boolean,!1)}),sh).views(e=>({get json(){const{_name:t,default_value:r,required:s,min_width:i,static_options:o,options_query_id:l,default_selection_count:c,treeCheckStrictly:u}=e;return{_name:t,required:!!s,min_width:i,default_value:r,static_options:o,options_query_id:l,treeCheckStrictly:u,default_selection_count:c}},get defaultSelection(){const t=e.filter.formattedDefaultValue;if(Array.isArray(t)&&t.length>0)return t;const{default_selection_count:r}=e;return r?e.treeData.slice(0,r).map(i=>i.value):[]},valueObjects(t){const r=new Set(t);return e.plainData.filter(s=>r.has(s.value))},initialSelection(t){return t?this.valueObjects(t):this.valueObjects(this.defaultSelection)},truthy(t){return Array.isArray(t)&&t.length>0}})).actions(e=>({setDefaultValue(t){e.default_value=g.cast(t)},setTreeCheckStrictly(t){e.treeCheckStrictly=t},applyDefaultSelection(){if(e.optionsLoading)return;const t=e.filter.value,r=new Set(e.plainData.map(i=>i.value)),s=(t??[]).filter(i=>r.has(i));s.length>0?e.filter.setValue(s):e.filter.setValue(e.defaultSelection)},afterCreate(){g.addDisposer(e,te.reaction(()=>JSON.stringify(e.defaultSelection),this.applyDefaultSelection,{fireImmediately:!1,delay:0}))}})),ih=()=>bo.create({_name:"tree-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),yo=g.types.compose("FilterTreeSingleSelectConfigMeta",g.types.model({_name:g.types.literal("tree-single-select"),default_value:g.types.optional(g.types.string,"")}),sh).views(e=>({get json(){const{_name:t,default_value:r,required:s,min_width:i,static_options:o,options_query_id:l,default_selection_count:c}=e;return{_name:t,required:!!s,min_width:i,default_value:r,static_options:o,options_query_id:l,default_selection_count:c}},get selectFirstByDefault(){return e.default_selection_count===1},get defaultSelection(){if(e.treeDataLoading)return"";const t=e.filter.formattedDefaultValue;return t||(this.selectFirstByDefault&&e.treeData.length>0?e.treeData[0].value:"")},valueObject(t){if(t)return e.plainData.find(r=>r.value===t)},initialSelection(t){if(t)return this.valueObject(t)},truthy(t){return typeof t=="string"&&t!==""}})).actions(e=>({setDefaultValue(t){e.default_value=t},applyDefaultSelection(){if(e.treeDataLoading)return;const t=e.filter.value;e.optionValuesSet.has(t)?e.filter.setValue(t):e.filter.setValue(e.defaultSelection)},afterCreate(){g.addDisposer(e,te.reaction(()=>te.toJS(e.defaultSelection),this.applyDefaultSelection,{fireImmediately:!1,delay:0}))}})),ah=()=>yo.create({_name:"tree-single-select",default_value:"",static_options:[],options_query_id:"",default_selection_count:0}),vo=g.types.model("FilterMeta",{id:g.types.identifier,key:g.types.string,label:g.types.string,order:g.types.number,visibleInViewsIDs:g.types.array(g.types.string),auto_submit:g.types.optional(g.types.boolean,!1),default_value_func:g.types.optional(g.types.string,""),type:g.types.enumeration("DashboardFilterType",[Q.Select,Q.MultiSelect,Q.TreeSelect,Q.TreeSingleSelect,Q.TextInput,Q.Checkbox,Q.DateRange]),config:g.types.union(go,ho,bo,yo,fo,lo,uo)}).views(e=>({get contentModel(){return g.getRoot(e).content},get filters(){return this.contentModel.filters},get value(){return this.filters.values[e.key]},get plainDefaultValue(){const t=e.config.default_value;return Array.isArray(t)?[...t]:t},get usingDefaultValue(){return e.type!==Q.TreeSelect&&e.type!==Q.TreeSingleSelect},get usingDefaultValueFunc(){return!!e.default_value_func},get formattedDefaultValue(){return this.filters.formattedDefaultValues[e.key]},get auto_submit_supported(){return[Q.Select,Q.Checkbox,Q.DateRange].includes(e.type)}})).views(e=>({get json(){const{id:t,key:r,label:s,order:i,visibleInViewsIDs:o,default_value_func:l,auto_submit:c,type:u,config:d}=e;return{id:t,key:r,type:u,label:s,order:i,config:d.json,auto_submit:c,visibleInViewsIDs:te.toJS(o),default_value_func:l}},get visibleInViewsIDSet(){return new Set(e.visibleInViewsIDs)},get should_auto_submit(){return e.auto_submit_supported&&e.auto_submit},requiredAndPass(t){return v.get(e.config,"required",!1)?v.get(e.config,"truthy",()=>!0)(t):!1}})).actions(e=>({setKey(t){e.key=t},setValue(t){e.filters.setValueByKey(e.key,t)},setLabel(t){e.label=t},setOrder(t){const r=Number(t);Number.isFinite(r)&&(e.order=r)},setType(t){switch(t){case Q.Select:e.config=eh();break;case Q.MultiSelect:e.config=Jp();break;case Q.TreeSelect:e.config=ih();break;case Q.TreeSingleSelect:e.config=ah();break;case Q.TextInput:e.config=xo();break;case Q.Checkbox:e.config=Rp();break;case Q.DateRange:e.config=Hp();break;default:return}e.type=t},setVisibleInViewsIDs(t){e.visibleInViewsIDs.length=0,e.visibleInViewsIDs.push(...t)},setAutoSubmit(t){e.auto_submit=e.auto_submit_supported&&t},setDefaultValueFunc(t){e.default_value_func=t}}));var F=(e=>(e.Division="div",e.Modal="modal",e.Tabs="tabs",e))(F||{});const _o=g.types.model("ViewDivisionConfig",{_name:g.types.literal(F.Division)}).views(e=>({get json(){const{_name:t}=e;return{_name:t}}})),oh=()=>_o.create({_name:F.Division}),E3=g.types.model("CustomModalTitleModel",{enabled:g.types.optional(g.types.boolean,!1),func_content:g.types.optional(g.types.string,"")}).views(e=>({get json(){const{enabled:t,func_content:r}=e;return{enabled:t,func_content:r}},get value(){const{enabled:t,func_content:r}=e,s=g.getParent(e,2),i=g.getRoot(e);if(!t)return s.name;try{const o={filters:i.content.filters.valuesForPayload,context:i.context.current};return new Function(`return ${r}`)()(o)}catch(o){return console.error(o),s.name}}})).actions(e=>({setEnabled(t){e.enabled=t},setFuncContent(t){e.func_content=t},replace({enabled:t,func_content:r}){e.enabled=t,e.func_content=r}})),Ps={enabled:!1,func_content:["function text({ filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
497
- `)},jo=g.types.model("ViewModalConfig",{_name:g.types.literal(F.Modal),width:g.types.string,height:g.types.string,custom_modal_title:g.types.optional(E3,Ps)}).views(e=>({get json(){const{_name:t,width:r,height:s,custom_modal_title:i}=e;return{_name:t,width:r,height:s,custom_modal_title:i.json}}})).actions(e=>({setWidth(t){e.width=t},setHeight(t){e.height=t}})),lh=()=>jo.create({_name:F.Modal,width:"90vw",height:"90vh"}),P3=g.types.model("ViewTabsTabModel",{id:g.types.identifier,name:g.types.string,view_id:g.types.string,color:g.types.optional(g.types.string,""),order:g.types.optional(g.types.number,0)}).views(e=>({get json(){const{id:t,name:r,view_id:s,color:i,order:o}=e;return{id:t,name:r,color:i,order:o,view_id:s}}})).actions(e=>({setName(t){e.name=t},setViewID(t){t&&(e.view_id=t)},setColor(t){e.color=t},setOrder(t){typeof t!="string"&&(e.order=t)}})),wo=g.types.model("ViewTabsConfig",{_name:g.types.literal(F.Modal),tabs:g.types.optional(g.types.array(P3),[]),variant:g.types.optional(g.types.enumeration("variant",["default","outline","pills"]),"default"),orientation:g.types.optional(g.types.enumeration("orientation",["horizontal","vertical"]),"horizontal"),grow:g.types.optional(g.types.boolean,!1)}).views(e=>({get json(){const{_name:t,variant:r,orientation:s,tabs:i,grow:o}=e;return{grow:o,tabs:i.map(l=>l.json),_name:t,variant:r,orientation:s}},get tabsInOrder(){return v.sortBy(e.tabs,"order")}})).actions(e=>({setVariant(t){t&&(e.variant=t)},setOrientation(t){t&&(e.orientation=t)},setGrow(t){e.grow=t},setTabs(t){e.tabs.length=0,e.tabs=g.cast(t)},addTab(){const t=ze.randomId(),r={id:t,name:t,view_id:""};e.tabs.push(r)},removeTab(t){e.tabs.splice(t,1)}})),ch=()=>wo.create({_name:F.Modal,tabs:[]}),uh=g.types.model({id:g.types.identifier,name:g.types.string,type:g.types.enumeration("EViewComponentType",[F.Division,F.Modal,F.Tabs]),config:g.types.union(_o,jo,wo),panelIDs:g.types.optional(g.types.array(g.types.string),[])}).views(e=>({get json(){const{id:t,name:r,type:s,config:i}=e;return{id:t,name:r,type:s,config:i.json,panelIDs:e.panelIDs.map(o=>o)}}})).actions(e=>({setName(t){e.name=t},setType(t){if(e.type!==t){switch(t){case F.Division:e.config=oh();break;case F.Modal:e.config=lh();break;case F.Tabs:e.config=ch();break;default:return}e.type=t}},appendPanelID(t){e.panelIDs.push(t)},appendPanelIDs(t){e.panelIDs.push(...t)},removePanelID(t){const r=e.panelIDs.filter(s=>s!==t);e.panelIDs.length=0,e.panelIDs.push(...r)}})),nn="13.45.0",A3={definition:{sqlSnippets:[],queries:[],mock_context:{}},views:[{id:"Main",name:"Main",type:F.Division,config:{},panelIDs:[]}],panels:[],filters:[],version:nn,layouts:[{id:"basis",name:"basis",list:[],breakpoint:0}]},Co=g.types.model("DataSourceMetaModel",{id:g.types.string,type:g.types.enumeration("DataSourceType",[J.HTTP,J.MySQL,J.Postgresql,J.MericoMetricSystem]),key:g.types.string,config:g.types.frozen()}),dh=g.types.model("DataSourcesMetaModel",{list:g.types.optional(g.types.array(Co),[])}).views(e=>({find({type:t,key:r}){return e.list.find(s=>s.key===r&&s.type===t)},get options(){return e.list.map(t=>({value:t.key,label:t.key}))}})).actions(e=>({replace(t){e.list.length=0,e.list.push(...t)}})),ph=g.types.model({id:g.types.string,content:g.types.string,create_time:g.types.string,update_time:g.types.string,is_preset:g.types.boolean}),So=g.types.model("GlobalSQLSnippetsMeta",{list:g.types.optional(g.types.array(ph),[])}).views(e=>({find(t){return e.list.find(r=>r.id===t)},get options(){return e.list.map(t=>({value:t.id,label:t.id}))}})).actions(e=>({replace(t){e.list.length=0,e.list.push(...t)}})),As=g.types.model("ContextMeta",{current:g.types.optional(g.types.frozen(),{})}).views(e=>({get keys(){return Object.keys(e.current)},get entries(){return Object.entries(e.current)}})).actions(e=>({replace(t){e.current=t},get(t){return e.current[t]},set(t,r){e.current[t]=r}}));function To(e){return As.create({current:e})}const ko=g.types.compose("ViewRenderModel",uh,g.types.model({tab:g.types.optional(g.types.string,"")})).views(e=>({get tabs(){return e.config.tabs},get tabInfo(){const t=this.tabs.find(r=>r.id===e.tab);return t?{id:t.id,name:t.name}:null},get tabView(){return e.type!==F.Tabs?null:this.tabs.find(t=>t.id===e.tab)},get tabViewID(){return this.tabView?this.tabView.view_id??"":""},get contentModel(){return g.getParent(e,3)},get panels(){if(e.type!==F.Tabs)return this.contentModel.panels.panelsByIDs(e.panelIDs);const t=this.tabViewID,r=this.contentModel.views.findByID(t);return(r==null?void 0:r.panels)??[]},get renderViewIDs(){const t=[e.id];return e.type===F.Tabs&&t.push(this.tabViewID),t},async downloadScreenshot(t){const r=t.offsetWidth*2+10,s=t.offsetHeight*2+10,i=new Dl,o=new Date().getTime(),l=await kl.toBlob(t,{bgcolor:"white",width:r,height:s,style:{transformOrigin:"0 0",transform:"scale(2)"}});i.file(`${e.name}_${o}.png`,l),i.file(`dashboard_state_${o}.json`,JSON.stringify(this.contentModel.dashboardState,null,4)),i.generateAsync({type:"blob"}).then(c=>{Vr.saveAs(c,`${e.name}_${o}.zip`)}).catch(c=>{console.error(c),$t.notifications.show({color:"red",title:"Failed to download screenshot with dashboard state",message:c.message})})}})).actions(e=>({setTab(t){e.tab=t??""},setTabByTabInfo(t){e.tab=t.id??""}})),Do=g.types.model("ViewsRenderModel",{current:g.types.optional(g.types.array(ko),[]),visibleViewIDs:g.types.array(g.types.string)}).views(e=>({get json(){return e.current.map(t=>Zt(t.json))},get idMap(){const t=new Map;return e.current.forEach(r=>{t.set(r.id,r)}),t},findByID(t){return e.current.find(r=>r.id===t)},get firstVisibleView(){const[t]=e.visibleViewIDs;return e.current.find(({id:r})=>r===t)},get visibleViews(){const t=new Set(e.visibleViewIDs);return e.current.filter(({id:r})=>t.has(r))},get firstVisibleTabsView(){return this.visibleViews.find(t=>t.type===F.Tabs)},get firstVisibleTabsViewActiveTab(){const t=this.firstVisibleTabsView;return t?t.tabInfo:null},get firstVisibleTabsViewActiveTabStr(){return JSON.stringify(this.firstVisibleTabsViewActiveTab)}})).actions(e=>({appendToVisibles(t){new Set(e.visibleViewIDs.map(s=>s)).has(t)||e.visibleViewIDs.push(t)},rmVisibleViewID(t){const r=e.visibleViewIDs.findIndex(s=>s===t);r!==-1&&e.visibleViewIDs.splice(r,1)},setFirstVisibleTabsViewActiveTab(t){if(!t)return;const r=e.firstVisibleTabsView;r==null||r.setTabByTabInfo(t)}}));function hh(e,t){const r=e.length>0?[e[0].id]:[],s=e.map(i=>{const{_name:o=i.type}=i.config,l={...i,tab:"",config:{...i.config,_name:o},panelIDs:i.panelIDs};if(i.type===F.Tabs){let c=v.minBy(i.config.tabs,u=>u.order);!c&&i.config.tabs.length>0&&(c=i.config.tabs[0]),l.tab=(c==null?void 0:c.id)??""}return l});return t&&(s[0].tab=t.id),{current:s,visibleViewIDs:r}}const L3=new uf.AsyncParser({withBOM:!0});async function gh(e){return!Array.isArray(e)||e.length===0?"":await L3.parse(e).promise()}async function fh(e,t){const r=await gh(t),s=new Blob([r],{type:"text/csv"});Vr.saveAs(s,`${e}.csv`)}function xh(e){const t=new Dl,r=e.map(async({id:s,data:i})=>{const o=await gh(i);t.file(`${s}.csv`,o)});Promise.all(r).then(()=>{t.generateAsync({type:"blob"}).then(s=>{Vr.saveAs(s,"dashboard_data.zip")})}).catch(s=>{console.error(s),$t.notifications.show({color:"red",title:"Failed to download data",message:s.message})})}function er(e,t){const r=new Blob([t],{type:"application/json"});Vr.saveAs(r,`${e}.json`)}const zo=Op.views(e=>({get contentModel(){return g.getRoot(e).content}})).views(e=>({get queries(){return e.contentModel.queries.findByIDSet(e.queryIDSet)},get firstQuery(){return this.queries.length>0?this.queries[0]:null},get firstQueryData(){return this.firstQuery?this.firstQuery.data:[]},queryByID(t){return this.queries.find(r=>r.id===t)},get data(){return this.queries.reduce((t,r)=>(t[r.id]=r.data,t),{})},get variableStrings(){return xd(e.variables,this.data)},get variableAggValueMap(){const t={},r=this.data;return e.variables.reduce((s,i)=>(s[i.name]=Rt(i,r),s),t),t},get variableValueMap(){const t={},r=this.variableAggValueMap;return e.variables.reduce((s,i)=>(s[i.name]=wt(i,r[i.name]),s),t),t},get variableStyleMap(){const t=this.variableValueMap,r={};return e.variables.reduce((s,i)=>{const o=lx(i.color,t[i.name]);return s[i.name]={color:o,"font-size":i.size,"font-weight":i.weight,variable:i},s},r),r},get dataLoading(){return this.queries.some(t=>t.state==="loading")},get queryStateMessages(){const t=this.queries.filter(o=>!o.runByConditionsMet);if(t.length===0)return"";const r=new Set,s=new Set;t.forEach(o=>{const l=o.conditionNames;l.context.forEach(c=>r.add(c)),l.filters.forEach(c=>s.add(c))});const i=[];return r.size>0&&i.push(`context: ${Array.from(r).join(", ")}`),s.size>0&&i.push(`filter${s.size>1?"s":""}: ${Array.from(s).join(", ")}`),i.length===2&&i.splice(1,0,"and"),i.unshift("Waiting for"),i.join(" ")},get queryErrors(){return this.queries.map(t=>t.error??t.metricQueryPayloadErrorString).filter(t=>!!t)},get canRenderViz(){return this.queryErrors.length===0&&this.queryStateMessages===""&&!this.dataLoading}})).actions(e=>({refreshData(){e.queries.forEach(t=>t.fetchData(!0))},downloadData(){e.contentModel.queries.downloadDataByQueryIDs(e.queryIDs)},getSchema(){const t=e.json;return t.viz.conf={...t.viz.conf,__INTERACTIONS:{},__OPERATIONS:{},__TRIGGERS:{}},{panel:t,queries:e.queries.map(r=>r.json),layouts:e.contentModel.layouts.jsonByPanelIDSet(new Set([e.id]))}},downloadSchema(){const{panel:t,queries:r,layouts:s}=this.getSchema(),o=JSON.stringify({panels:[t],definition:{queries:r},layouts:s,version:nn},null,2),l=e.name;er(l,o)}}));function mh(e){return{id:e,name:"Panel",title:{show:!0},description:"<p></p>",queryIDs:[],viz:{type:Ra.name,conf:Ra.createConfig()},style:{border:{enabled:!0}}}}const Io=g.types.model("PanelsRenderModel",{list:g.types.optional(g.types.array(zo),[])}).views(e=>({get json(){return e.list.map(t=>t.json)},findByID(t){return e.list.find(r=>r.id===t)},get idMap(){const t=new Map;return e.list.forEach(r=>{t.set(r.id,r)}),t}})).views(e=>({panelsByIDs(t){const r=[];return t.forEach(s=>{const i=e.idMap.get(s);i?r.push(i):console.warn(`Panel is not found, id:${s}`)}),r}}));function bh(e){const t=e.config,r=t.default_value;return r===void 0?r:t._name==="date-range"?Kp(t):r}function O3(e,t){const r=e.default_value_func;try{const s=new Function(`return ${r}`)()(e,It,t);return e.config._name==="date-range"&&Array.isArray(s)?{value:s,shortcut:null}:s}catch(s){return console.error(s),bh(e)}}function yh(e,t){var r;return(r=e.default_value_func)!=null&&r.trim()?O3(e,t):bh(e)}function vh(e,t){return e.reduce((r,s)=>(r[s.key]=yh(s,t),r),{})}function _h(e,t){const r={};return Object.entries(t).forEach(([s,i])=>{const o=e[s];return typeof i=="object"&&"shortcut"in i&&Array.isArray(o)?r[s]={value:o,shortcut:null}:r[s]=o??i,r}),r}const Mo=g.types.model("FiltersRenderModel",{current:g.types.optional(g.types.array(vo),[]),values:g.types.optional(g.types.frozen(),{})}).views(e=>({get json(){return e.current.map(t=>t.json)},get valuesString(){return JSON.stringify(e.values)},get filter(){return g.getParent(e)},get valuesForPayload(){const t={};return Object.entries(e.values).forEach(([r,s])=>{t[r]=s;const i=this.findByKey(r);i&&i.config._name==="date-range"&&(t[r]=i.config.dateStringsValue)}),t},get contentModel(){return g.getRoot(e).content},get context(){return this.contentModel.payloadForSQL.context},get initialValuesDep(){return JSON.stringify({filters:e.current.map(({default_value_func:t,config:r})=>({default_value_func:t,config:r})),context:this.contentModel.payloadForSQL.context})},get formattedDefaultValues(){return vh(this.json,this.contentModel.context)},get firstID(){if(e.current.length!==0)return e.current[0].id},findByID(t){return e.current.find(r=>r.id===t)},findByKey(t){return e.current.find(r=>r.key===t)},findByIDSet(t){return e.current.filter(r=>t.has(r.id))},get inOrder(){return v.sortBy(e.current,"order")},get empty(){return e.current.length===0},visibleInView(t){return v.sortBy(e.current.filter(r=>r.visibleInViewsIDSet.has(t)),"order")},get firstFilterValueKey(){return Object.keys(e.values)[0]??""},get keySet(){return new Set(e.current.map(t=>t.key))},get keyLabelMap(){return e.current.reduce((t,r)=>(t[r.key]=r.label,t),{})},getSelectOption(t){const r=this.findByID(t);if(!r||!("getSelectOption"in r.config))return null;const s=e.values[r.key];return r.config.getSelectOption(s)}})).actions(e=>({setValues(t){console.debug("⚪️ setting filter values: ",JSON.stringify(t)),e.values=t},patchValues(t){console.debug("⚪️ patching filter values: ",JSON.stringify(t)),e.values=_h(t,e.values)},setValueByKey(t,r){console.debug(`⚪️ setting filter[${t}] to value: `,JSON.stringify(r)),e.values={...e.values,[t]:r}},applyValuesPatch(t){e.values={...e.values,...t}},getValueByKey(t){return e.values[t]},getSchema(t,r){return{filters:e.findByIDSet(new Set(t)).map(o=>({...o.json,visibleInViewsIDs:r?o.json.visibleInViewsIDs:[]})),version:nn}},downloadSchema(t){const r=JSON.stringify(this.getSchema(t,!1),null,2);er("Filters",r)}}));function Eo(e,t,r,s){const i={...r,...t},o=vh(e,i),l=_h(s,o);return{current:e,values:l}}const jh=Gp.views(e=>({get rootModel(){return g.getRoot(e)},get contentModel(){return this.rootModel.content},get conditionOptions(){if(!g.isAlive(e))return{optionGroups:[],validValues:new Set};const t=new Set,{context:r}=this.contentModel.payloadForSQL,s={group:"context.label",items:Object.keys(r).map(l=>{const c=`context.${l}`;return t.add(c),{label:l,value:c,description:void 0,type:"context"}})},i={group:"filter.labels",items:this.contentModel.filters.keyLabelOptions.map(l=>{const c=`filters.${l.value}`;return t.add(c),{label:l.label,value:c,description:l.value,type:"filter",widget:l.widget}})};return{optionGroups:[s,i],validValues:t}},getConditionOptionsWithInvalidValue(t){const{optionGroups:r,validValues:s}=this.conditionOptions;if(!t||s.has(t))return this.conditionOptions;const i={group:"common.invalid",items:[{label:t,value:t}]};return{optionGroups:[...r,i],validValues:s}},get conditionOptionsWithInvalidRunbys(){const{optionGroups:t,validValues:r}=this.conditionOptions,s={group:"common.invalid",items:[]};return e.run_by.forEach(i=>{r.has(i)||s.items.push({label:i,value:i})}),{optionGroups:[...t,s],validValues:r}},get unmetRunByConditions(){if(!g.isAlive(e))return[];const{run_by:t}=e;if(t.length===0)return[];const r=this.contentModel.payloadForSQL;return t.filter(s=>{const i=v.get(r,s);return Array.isArray(i)?i.length===0:typeof i=="number"?Number.isNaN(i):!i})}})).views(e=>({get payload(){return e.contentModel.payloadForSQL},get formattedSQL(){const t=v.get(e,"config.sql","");return Hs(t,this.payload)},get httpConfigString(){const{context:t,filters:r}=this.payload,{name:s,pre_process:i}=e.json,o=uy(i,t,r);return console.groupCollapsed(`Request config for: ${s}`),console.log(o),console.groupEnd(),JSON.stringify(o)},get typedAsSQL(){return[J.Postgresql,J.MySQL].includes(e.type)},get typedAsHTTP(){return[J.HTTP].includes(e.type)},get isMericoMetricQuery(){return e.type===J.MericoMetricSystem},get isTransform(){return e.type===J.Transform},get reQueryKey(){const t=v.get(e,"config.react_to",[]);if(t.length===0)return"";const r=e.contentModel.payloadForSQL,s=[...t].reduce((i,o)=>(i[o]=v.get(r,o),i),{});return JSON.stringify(s)},get runByConditionsMet(){return e.unmetRunByConditions.length===0},get conditionNames(){if(e.unmetRunByConditions.length===0)return{context:[],filters:[]};const{keyLabelMap:t}=e.contentModel.filters,r=e.unmetRunByConditions.filter(i=>i.startsWith("context.")).map(i=>i.replace("context.","")),s=e.unmetRunByConditions.filter(i=>i.startsWith("filters.")).map(i=>v.get({filters:t},i,i.replace("filters.",""))).filter(i=>!!i);return{context:r,filters:s}},get queries(){return g.getParent(e,2)},get inUse(){return this.queries.isQueryInUse(e.id)},get dependencies(){if(!this.typedAsSQL)return[];const t=v.get(e,"config.sql","");if(!t)return[];const r=v.uniq(t.match(gs.sqlSnippet)),s=v.uniq(t.match(gs.filter)),i=v.uniq(t.match(gs.context)),o=[];return r.forEach(l=>{o.push({type:"sql_snippet",key:l,valid:e.contentModel.sqlSnippets.keySet.has(l)})}),s.forEach(l=>{o.push({type:"filter",key:l,valid:e.contentModel.filters.keySet.has(l)})}),i.forEach(l=>{o.push({type:"context",key:l,valid:e.contentModel.mock_context.keySet.has(l)})}),o},get metricQueryPayload(){if(e.type!==J.MericoMetricSystem)return null;const t=this.payload,r=e.config,s=r.filters.reduce((p,h)=>(p[h.dimension]={eq:v.get(t,h.variable)},p),{}),i={id:r.id,type:r.type,filters:s,groupBys:r.groupBys};if(!r.timeQuery.enabled)return i;const{range_variable:o,unit_variable:l}=r.timeQuery,c="YYYY-MM-DD",u="PRC",d={start:"",end:"",unitOfTime:v.get(t,l,""),unitNumber:1,timezone:"PRC",stepKeyFormat:c};if(o){const p=v.get(t,o);Array.isArray(p)&&p.length===2&&(d.start=A(p[0]).tz(u).format(c),d.end=A(p[1]).tz(u).format(c))}return i.timeQuery=d,i},get metricQueryPayloadString(){return this.metricQueryPayload?JSON.stringify(this.metricQueryPayload,null,2):""},get metricQueryPayloadError(){const t=[];if(!this.metricQueryPayload)return t;const r=e.config,{timeQuery:s}=this.metricQueryPayload;if(!s)return r.groupByValues.length>2&&t.push("分组聚合维度:最多支持两个维度的聚合计算"),t;r.groupByValues.length>1&&t.push("分组聚合维度:按时间序列展示时,仅可选择一个聚合维度");const{start:i,end:o,unitOfTime:l}=s;return(!i||!o)&&t.push("时间维度:时间范围不完整"),l||t.push("步长:必选"),t},get metricQueryPayloadErrorString(){return this.metricQueryPayloadError.join(`
497
+ `)},jo=g.types.model("ViewModalConfig",{_name:g.types.literal(F.Modal),width:g.types.string,height:g.types.string,custom_modal_title:g.types.optional(E3,Ps)}).views(e=>({get json(){const{_name:t,width:r,height:s,custom_modal_title:i}=e;return{_name:t,width:r,height:s,custom_modal_title:i.json}}})).actions(e=>({setWidth(t){e.width=t},setHeight(t){e.height=t}})),lh=()=>jo.create({_name:F.Modal,width:"90vw",height:"90vh"}),P3=g.types.model("ViewTabsTabModel",{id:g.types.identifier,name:g.types.string,view_id:g.types.string,color:g.types.optional(g.types.string,""),order:g.types.optional(g.types.number,0)}).views(e=>({get json(){const{id:t,name:r,view_id:s,color:i,order:o}=e;return{id:t,name:r,color:i,order:o,view_id:s}}})).actions(e=>({setName(t){e.name=t},setViewID(t){t&&(e.view_id=t)},setColor(t){e.color=t},setOrder(t){typeof t!="string"&&(e.order=t)}})),wo=g.types.model("ViewTabsConfig",{_name:g.types.literal(F.Modal),tabs:g.types.optional(g.types.array(P3),[]),variant:g.types.optional(g.types.enumeration("variant",["default","outline","pills"]),"default"),orientation:g.types.optional(g.types.enumeration("orientation",["horizontal","vertical"]),"horizontal"),grow:g.types.optional(g.types.boolean,!1)}).views(e=>({get json(){const{_name:t,variant:r,orientation:s,tabs:i,grow:o}=e;return{grow:o,tabs:i.map(l=>l.json),_name:t,variant:r,orientation:s}},get tabsInOrder(){return v.sortBy(e.tabs,"order")}})).actions(e=>({setVariant(t){t&&(e.variant=t)},setOrientation(t){t&&(e.orientation=t)},setGrow(t){e.grow=t},setTabs(t){e.tabs.length=0,e.tabs=g.cast(t)},addTab(){const t=ze.randomId(),r={id:t,name:t,view_id:""};e.tabs.push(r)},removeTab(t){e.tabs.splice(t,1)}})),ch=()=>wo.create({_name:F.Modal,tabs:[]}),uh=g.types.model({id:g.types.identifier,name:g.types.string,type:g.types.enumeration("EViewComponentType",[F.Division,F.Modal,F.Tabs]),config:g.types.union(_o,jo,wo),panelIDs:g.types.optional(g.types.array(g.types.string),[])}).views(e=>({get json(){const{id:t,name:r,type:s,config:i}=e;return{id:t,name:r,type:s,config:i.json,panelIDs:e.panelIDs.map(o=>o)}}})).actions(e=>({setName(t){e.name=t},setType(t){if(e.type!==t){switch(t){case F.Division:e.config=oh();break;case F.Modal:e.config=lh();break;case F.Tabs:e.config=ch();break;default:return}e.type=t}},appendPanelID(t){e.panelIDs.push(t)},appendPanelIDs(t){e.panelIDs.push(...t)},removePanelID(t){const r=e.panelIDs.filter(s=>s!==t);e.panelIDs.length=0,e.panelIDs.push(...r)}})),nn="13.45.0",A3={definition:{sqlSnippets:[],queries:[],mock_context:{}},views:[{id:"Main",name:"Main",type:F.Division,config:{},panelIDs:[]}],panels:[],filters:[],version:nn,layouts:[{id:"basis",name:"basis",list:[],breakpoint:0}]},Co=g.types.model("DataSourceMetaModel",{id:g.types.string,type:g.types.enumeration("DataSourceType",[J.HTTP,J.MySQL,J.Postgresql,J.MericoMetricSystem]),key:g.types.string,config:g.types.frozen()}),dh=g.types.model("DataSourcesMetaModel",{list:g.types.optional(g.types.array(Co),[])}).views(e=>({find({type:t,key:r}){return e.list.find(s=>s.key===r&&s.type===t)},get options(){return e.list.map(t=>({value:t.key,label:t.key}))}})).actions(e=>({replace(t){e.list.length=0,e.list.push(...t)}})),ph=g.types.model({id:g.types.string,content:g.types.string,create_time:g.types.string,update_time:g.types.string,is_preset:g.types.boolean}),So=g.types.model("GlobalSQLSnippetsMeta",{list:g.types.optional(g.types.array(ph),[])}).views(e=>({find(t){return e.list.find(r=>r.id===t)},get options(){return e.list.map(t=>({value:t.id,label:t.id}))}})).actions(e=>({replace(t){e.list.length=0,e.list.push(...t)}})),As=g.types.model("ContextMeta",{current:g.types.optional(g.types.frozen(),{})}).views(e=>({get keys(){return Object.keys(e.current)},get entries(){return Object.entries(e.current)}})).actions(e=>({replace(t){e.current=t},get(t){return e.current[t]},set(t,r){e.current[t]=r}}));function To(e){return As.create({current:e})}const ko=g.types.compose("ViewRenderModel",uh,g.types.model({tab:g.types.optional(g.types.string,"")})).views(e=>({get tabs(){return e.config.tabs},get tabInfo(){const t=this.tabs.find(r=>r.id===e.tab);return t?{id:t.id,name:t.name}:null},get tabView(){return e.type!==F.Tabs?null:this.tabs.find(t=>t.id===e.tab)},get tabViewID(){return this.tabView?this.tabView.view_id??"":""},get contentModel(){return g.getParent(e,3)},get panels(){if(e.type!==F.Tabs)return this.contentModel.panels.panelsByIDs(e.panelIDs);const t=this.tabViewID,r=this.contentModel.views.findByID(t);return(r==null?void 0:r.panels)??[]},get renderViewIDs(){const t=[e.id];return e.type===F.Tabs&&t.push(this.tabViewID),t},async downloadScreenshot(t){const r=t.offsetWidth*2+10,s=t.offsetHeight*2+10,i=new Dl,o=new Date().getTime(),l=await kl.toBlob(t,{bgcolor:"white",width:r,height:s,style:{transformOrigin:"0 0",transform:"scale(2)"}});i.file(`${e.name}_${o}.png`,l),i.file(`dashboard_state_${o}.json`,JSON.stringify(this.contentModel.dashboardState,null,4)),i.generateAsync({type:"blob"}).then(c=>{Vr.saveAs(c,`${e.name}_${o}.zip`)}).catch(c=>{console.error(c),$t.notifications.show({color:"red",title:"Failed to download screenshot with dashboard state",message:c.message})})}})).actions(e=>({setTab(t){e.tab=t??""},setTabByTabInfo(t){e.tab=t.id??""}})),Do=g.types.model("ViewsRenderModel",{current:g.types.optional(g.types.array(ko),[]),visibleViewIDs:g.types.array(g.types.string)}).views(e=>({get json(){return e.current.map(t=>Zt(t.json))},get idMap(){const t=new Map;return e.current.forEach(r=>{t.set(r.id,r)}),t},findByID(t){return e.current.find(r=>r.id===t)},get firstVisibleView(){const[t]=e.visibleViewIDs;return e.current.find(({id:r})=>r===t)},get visibleViews(){const t=new Set(e.visibleViewIDs);return e.current.filter(({id:r})=>t.has(r))},get firstVisibleTabsView(){return this.visibleViews.find(t=>t.type===F.Tabs)},get firstVisibleTabsViewActiveTab(){const t=this.firstVisibleTabsView;return t?t.tabInfo:null},get firstVisibleTabsViewActiveTabStr(){return JSON.stringify(this.firstVisibleTabsViewActiveTab)}})).actions(e=>({appendToVisibles(t){new Set(e.visibleViewIDs.map(s=>s)).has(t)||e.visibleViewIDs.push(t)},rmVisibleViewID(t){const r=e.visibleViewIDs.findIndex(s=>s===t);r!==-1&&e.visibleViewIDs.splice(r,1)},setFirstVisibleTabsViewActiveTab(t){if(!t)return;const r=e.firstVisibleTabsView;r==null||r.setTabByTabInfo(t)}}));function hh(e,t){const r=e.length>0?[e[0].id]:[],s=e.map(i=>{const{_name:o=i.type}=i.config,l={...i,tab:"",config:{...i.config,_name:o},panelIDs:i.panelIDs};if(i.type===F.Tabs){let c=v.minBy(i.config.tabs,u=>u.order);!c&&i.config.tabs.length>0&&(c=i.config.tabs[0]),l.tab=(c==null?void 0:c.id)??""}return l});return t&&(s[0].tab=t.id),{current:s,visibleViewIDs:r}}const L3=new uf.AsyncParser({withBOM:!0});async function gh(e){return!Array.isArray(e)||e.length===0?"":await L3.parse(e).promise()}async function fh(e,t){const r=await gh(t),s=new Blob([r],{type:"text/csv"});Vr.saveAs(s,`${e}.csv`)}function xh(e){const t=new Dl,r=e.map(async({id:s,data:i})=>{const o=await gh(i);t.file(`${s}.csv`,o)});Promise.all(r).then(()=>{t.generateAsync({type:"blob"}).then(s=>{Vr.saveAs(s,"dashboard_data.zip")})}).catch(s=>{console.error(s),$t.notifications.show({color:"red",title:"Failed to download data",message:s.message})})}function er(e,t){const r=new Blob([t],{type:"application/json"});Vr.saveAs(r,`${e}.json`)}const zo=Op.views(e=>({get contentModel(){return g.getRoot(e).content}})).views(e=>({get queries(){return e.contentModel.queries.findByIDSet(e.queryIDSet)},get firstQuery(){return this.queries.length>0?this.queries[0]:null},get firstQueryData(){return this.firstQuery?this.firstQuery.data:[]},queryByID(t){return this.queries.find(r=>r.id===t)},get data(){return this.queries.reduce((t,r)=>(t[r.id]=r.data,t),{})},get variableStrings(){return xd(e.variables,this.data)},get variableAggValueMap(){const t={},r=this.data;return e.variables.reduce((s,i)=>(s[i.name]=Rt(i,r),s),t),t},get variableValueMap(){const t={},r=this.variableAggValueMap;return e.variables.reduce((s,i)=>(s[i.name]=wt(i,r[i.name]),s),t),t},get variableStyleMap(){const t=this.variableValueMap,r={};return e.variables.reduce((s,i)=>{const o=lx(i.color,t[i.name]);return s[i.name]={color:o,"font-size":i.size,"font-weight":i.weight,variable:i},s},r),r},get dataLoading(){return this.queries.some(t=>t.state==="loading")},get queryStateMessages(){const t=this.queries.filter(o=>!o.runByConditionsMet);if(t.length===0)return"";const r=new Set,s=new Set;t.forEach(o=>{const l=o.conditionNames;l.context.forEach(c=>r.add(c)),l.filters.forEach(c=>s.add(c))});const i=[];return r.size>0&&i.push(`context: ${Array.from(r).join(", ")}`),s.size>0&&i.push(`filter${s.size>1?"s":""}: ${Array.from(s).join(", ")}`),i.length===2&&i.splice(1,0,"and"),i.unshift("Waiting for"),i.join(" ")},get queryErrors(){return this.queries.map(t=>t.error??t.metricQueryPayloadErrorString).filter(t=>!!t)},get canRenderViz(){return this.queryErrors.length===0&&this.queryStateMessages===""&&!this.dataLoading}})).actions(e=>({refreshData(){e.queries.forEach(t=>t.fetchData(!0))},downloadData(){e.contentModel.queries.downloadDataByQueryIDs(e.queryIDs)},getSchema(){const t=e.json;return t.viz.conf={...t.viz.conf,__INTERACTIONS:{},__OPERATIONS:{},__TRIGGERS:{}},{panel:t,queries:e.queries.map(r=>r.json),layouts:e.contentModel.layouts.jsonByPanelIDSet(new Set([e.id]))}},downloadSchema(){const{panel:t,queries:r,layouts:s}=this.getSchema(),o=JSON.stringify({panels:[t],definition:{queries:r},layouts:s,version:nn},null,2),l=e.name;er(l,o)}}));function mh(e){return{id:e,name:"Panel",title:{show:!0},description:"<p></p>",queryIDs:[],viz:{type:Ra.name,conf:Ra.createConfig()},style:{border:{enabled:!0}}}}const Io=g.types.model("PanelsRenderModel",{list:g.types.optional(g.types.array(zo),[])}).views(e=>({get json(){return e.list.map(t=>t.json)},findByID(t){return e.list.find(r=>r.id===t)},get idMap(){const t=new Map;return e.list.forEach(r=>{t.set(r.id,r)}),t}})).views(e=>({panelsByIDs(t){const r=[];return t.forEach(s=>{const i=e.idMap.get(s);i?r.push(i):console.warn(`Panel is not found, id:${s}`)}),r}}));function bh(e){const t=e.config,r=t==null?void 0:t.default_value;return r===void 0?r:t._name==="date-range"?Kp(t):r}function O3(e,t){const r=e.default_value_func;try{const s=new Function(`return ${r}`)()(e,It,t);return e.config._name==="date-range"&&Array.isArray(s)?{value:s,shortcut:null}:s}catch(s){return console.error(s),bh(e)}}function yh(e,t){var r;return(r=e.default_value_func)!=null&&r.trim()?O3(e,t):bh(e)}function vh(e,t){return e.reduce((r,s)=>(r[s.key]=yh(s,t),r),{})}function _h(e,t){const r={};return Object.entries(t).forEach(([s,i])=>{const o=e[s];return typeof i=="object"&&"shortcut"in i&&Array.isArray(o)?r[s]={value:o,shortcut:null}:r[s]=o??i,r}),r}const Mo=g.types.model("FiltersRenderModel",{current:g.types.optional(g.types.array(vo),[]),values:g.types.optional(g.types.frozen(),{})}).views(e=>({get json(){return e.current.map(t=>t.json)},get valuesString(){return JSON.stringify(e.values)},get filter(){return g.getParent(e)},get valuesForPayload(){const t={};return Object.entries(e.values).forEach(([r,s])=>{t[r]=s;const i=this.findByKey(r);i&&i.config._name==="date-range"&&(t[r]=i.config.dateStringsValue)}),t},get contentModel(){return g.getRoot(e).content},get context(){return this.contentModel.payloadForSQL.context},get initialValuesDep(){return JSON.stringify({filters:e.current.map(({default_value_func:t,config:r})=>({default_value_func:t,config:r})),context:this.contentModel.payloadForSQL.context})},get formattedDefaultValues(){return vh(this.json,this.contentModel.context)},get firstID(){if(e.current.length!==0)return e.current[0].id},findByID(t){return e.current.find(r=>r.id===t)},findByKey(t){return e.current.find(r=>r.key===t)},findByIDSet(t){return e.current.filter(r=>t.has(r.id))},get inOrder(){return v.sortBy(e.current,"order")},get empty(){return e.current.length===0},visibleInView(t){return v.sortBy(e.current.filter(r=>r.visibleInViewsIDSet.has(t)),"order")},get firstFilterValueKey(){return Object.keys(e.values)[0]??""},get keySet(){return new Set(e.current.map(t=>t.key))},get keyLabelMap(){return e.current.reduce((t,r)=>(t[r.key]=r.label,t),{})},getSelectOption(t){const r=this.findByID(t);if(!r||!("getSelectOption"in r.config))return null;const s=e.values[r.key];return r.config.getSelectOption(s)}})).actions(e=>({setValues(t){console.debug("⚪️ setting filter values: ",JSON.stringify(t)),e.values=t},patchValues(t){console.debug("⚪️ patching filter values: ",JSON.stringify(t)),e.values=_h(t,e.values)},setValueByKey(t,r){console.debug(`⚪️ setting filter[${t}] to value: `,JSON.stringify(r)),e.values={...e.values,[t]:r}},applyValuesPatch(t){e.values={...e.values,...t}},getValueByKey(t){return e.values[t]},getSchema(t,r){return{filters:e.findByIDSet(new Set(t)).map(o=>({...o.json,visibleInViewsIDs:r?o.json.visibleInViewsIDs:[]})),version:nn}},downloadSchema(t){const r=JSON.stringify(this.getSchema(t,!1),null,2);er("Filters",r)}}));function Eo(e,t,r,s){const i={...r,...t},o=vh(e,i),l=_h(s,o);return{current:e,values:l}}const jh=Gp.views(e=>({get rootModel(){return g.getRoot(e)},get contentModel(){return this.rootModel.content},get conditionOptions(){if(!g.isAlive(e))return{optionGroups:[],validValues:new Set};const t=new Set,{context:r}=this.contentModel.payloadForSQL,s={group:"context.label",items:Object.keys(r).map(l=>{const c=`context.${l}`;return t.add(c),{label:l,value:c,description:void 0,type:"context"}})},i={group:"filter.labels",items:this.contentModel.filters.keyLabelOptions.map(l=>{const c=`filters.${l.value}`;return t.add(c),{label:l.label,value:c,description:l.value,type:"filter",widget:l.widget}})};return{optionGroups:[s,i],validValues:t}},getConditionOptionsWithInvalidValue(t){const{optionGroups:r,validValues:s}=this.conditionOptions;if(!t||s.has(t))return this.conditionOptions;const i={group:"common.invalid",items:[{label:t,value:t}]};return{optionGroups:[...r,i],validValues:s}},get conditionOptionsWithInvalidRunbys(){const{optionGroups:t,validValues:r}=this.conditionOptions,s={group:"common.invalid",items:[]};return e.run_by.forEach(i=>{r.has(i)||s.items.push({label:i,value:i})}),{optionGroups:[...t,s],validValues:r}},get unmetRunByConditions(){if(!g.isAlive(e))return[];const{run_by:t}=e;if(t.length===0)return[];const r=this.contentModel.payloadForSQL;return t.filter(s=>{const i=v.get(r,s);return Array.isArray(i)?i.length===0:typeof i=="number"?Number.isNaN(i):!i})}})).views(e=>({get payload(){return e.contentModel.payloadForSQL},get formattedSQL(){const t=v.get(e,"config.sql","");return Hs(t,this.payload)},get httpConfigString(){const{context:t,filters:r}=this.payload,{name:s,pre_process:i}=e.json,o=uy(i,t,r);return console.groupCollapsed(`Request config for: ${s}`),console.log(o),console.groupEnd(),JSON.stringify(o)},get typedAsSQL(){return[J.Postgresql,J.MySQL].includes(e.type)},get typedAsHTTP(){return[J.HTTP].includes(e.type)},get isMericoMetricQuery(){return e.type===J.MericoMetricSystem},get isTransform(){return e.type===J.Transform},get reQueryKey(){const t=v.get(e,"config.react_to",[]);if(t.length===0)return"";const r=e.contentModel.payloadForSQL,s=[...t].reduce((i,o)=>(i[o]=v.get(r,o),i),{});return JSON.stringify(s)},get runByConditionsMet(){return e.unmetRunByConditions.length===0},get conditionNames(){if(e.unmetRunByConditions.length===0)return{context:[],filters:[]};const{keyLabelMap:t}=e.contentModel.filters,r=e.unmetRunByConditions.filter(i=>i.startsWith("context.")).map(i=>i.replace("context.","")),s=e.unmetRunByConditions.filter(i=>i.startsWith("filters.")).map(i=>v.get({filters:t},i,i.replace("filters.",""))).filter(i=>!!i);return{context:r,filters:s}},get queries(){return g.getParent(e,2)},get inUse(){return this.queries.isQueryInUse(e.id)},get dependencies(){if(!this.typedAsSQL)return[];const t=v.get(e,"config.sql","");if(!t)return[];const r=v.uniq(t.match(gs.sqlSnippet)),s=v.uniq(t.match(gs.filter)),i=v.uniq(t.match(gs.context)),o=[];return r.forEach(l=>{o.push({type:"sql_snippet",key:l,valid:e.contentModel.sqlSnippets.keySet.has(l)})}),s.forEach(l=>{o.push({type:"filter",key:l,valid:e.contentModel.filters.keySet.has(l)})}),i.forEach(l=>{o.push({type:"context",key:l,valid:e.contentModel.mock_context.keySet.has(l)})}),o},get metricQueryPayload(){if(e.type!==J.MericoMetricSystem)return null;const t=this.payload,r=e.config,s=r.filters.reduce((p,h)=>(p[h.dimension]={eq:v.get(t,h.variable)},p),{}),i={id:r.id,type:r.type,filters:s,groupBys:r.groupBys};if(!r.timeQuery.enabled)return i;const{range_variable:o,unit_variable:l}=r.timeQuery,c="YYYY-MM-DD",u="PRC",d={start:"",end:"",unitOfTime:v.get(t,l,""),unitNumber:1,timezone:"PRC",stepKeyFormat:c};if(o){const p=v.get(t,o);Array.isArray(p)&&p.length===2&&(d.start=A(p[0]).tz(u).format(c),d.end=A(p[1]).tz(u).format(c))}return i.timeQuery=d,i},get metricQueryPayloadString(){return this.metricQueryPayload?JSON.stringify(this.metricQueryPayload,null,2):""},get metricQueryPayloadError(){const t=[];if(!this.metricQueryPayload)return t;const r=e.config,{timeQuery:s}=this.metricQueryPayload;if(!s)return r.groupByValues.length>2&&t.push("分组聚合维度:最多支持两个维度的聚合计算"),t;r.groupByValues.length>1&&t.push("分组聚合维度:按时间序列展示时,仅可选择一个聚合维度");const{start:i,end:o,unitOfTime:l}=s;return(!i||!o)&&t.push("时间维度:时间范围不完整"),l||t.push("步长:必选"),t},get metricQueryPayloadErrorString(){return this.metricQueryPayloadError.join(`
498
498
  `)},get metricQueryPayloadValid(){return this.metricQueryPayload?this.metricQueryPayloadError.length===0:!1}})),Po=g.types.compose("QueryRenderModel",jh,g.types.model({state:g.types.optional(g.types.enumeration(["idle","loading","error"]),"idle"),data:g.types.optional(g.types.frozen([]),[]),error:g.types.frozen()})).views(e=>({get datasource(){const{key:t,type:r}=e;return e.rootModel.datasources.find({type:r,key:t})},get additionalQueryInfo(){return e.contentModel.getAdditionalQueryInfo(e.id)},get depQueryModels(){const t=v.get(e,"config.dep_query_ids",[]);return e.contentModel.queries.findByIDSet(new Set(t))},get depQueryModelStates(){return this.depQueryModels.map(t=>t.state)},get depQueryModelStatesString(){return this.depQueryModelStates.toString()}})).views(e=>({get stateMessage(){if(e.state!=="idle")return"";if(!e.runByConditionsMet){const{context:t,filters:r}=e.conditionNames;if(t.length===0&&r.length===0)return"Waiting";const s=[];return t.length>0&&s.push(`context: ${t.join(", ")}`),r.length>0&&s.push(`filter${r.length>1?"s":""}: ${r.join(", ")}`),s.length===2&&s.splice(1,0,"and"),s.unshift("Waiting for"),s.join(" ")}return e.data.length>0?"":"data.empty_data"}})).volatile(()=>({controller:new AbortController})).actions(e=>({runSQL:g.flow(function*(){var t;if(e.valid&&((t=e.controller)==null||t.abort(),!!e.runByConditionsMet)){e.controller=new AbortController,e.state="loading";try{const r=e.payload,s=e.config;e.data=yield*g.toGenerator(fy({payload:r,name:e.name,query:{type:e.type,key:e.key,sql:s.sql,pre_process:e.pre_process,post_process:e.post_process},additionals:e.additionalQueryInfo},e.controller.signal)),e.state="idle",e.error=null}catch(r){if(pt.isCancel(r))console.debug(`🟡 Query[${e.name}] is cancelled`),e.data=[],e.state="idle";else{e.data=[];const s=v.get(r,"message","unkown error");e.error=v.get(r,"response.data.detail.message",s),e.state="error"}}}}),runHTTP:g.flow(function*(){var t;if(!(!e.valid||!e.datasource)&&((t=e.controller)==null||t.abort(),!!e.runByConditionsMet)){e.controller=new AbortController,e.state="loading";try{const{type:r,key:s,post_process:i}=e.json;let o=JSON.parse(e.httpConfigString);o=ps(e.datasource,o);const l=yield*g.toGenerator(xy({type:r,key:s,configString:JSON.stringify(o),name:e.name,additionals:e.additionalQueryInfo},e.controller.signal)),c=hs(e.datasource,l),u=bd(i,c,e.contentModel.dashboardState);e.data=u,e.state="idle",e.error=null}catch(r){if(console.error(r),pt.isCancel(r))console.debug(`🟡 Query[${e.name}] is cancelled`),e.data=[],e.state="idle";else{e.data=[];const s=v.get(r,"message","unkown error");e.error=v.get(r,"response.data.detail.message",s),e.state="error"}}}}),runMericoMetricQuery:g.flow(function*(){var t;if(!(!e.valid||!e.datasource)&&((t=e.controller)==null||t.abort(),!!e.runByConditionsMet&&e.metricQueryPayloadValid)){e.controller=new AbortController,e.state="loading";try{const{type:r,key:s,post_process:i}=e.json;let o={url:"/buffet/api/metric_management/query",method:"POST",data:e.metricQueryPayload};o=ps(e.datasource,o);const l=yield*g.toGenerator(my({key:s,configString:JSON.stringify(o),name:e.name,additionals:e.additionalQueryInfo},e.controller.signal)),c=hs(e.datasource,l),u=bd(i,c,e.contentModel.dashboardState);e.data=u.data,e.state="idle",e.error=null}catch(r){if(console.error(r),pt.isCancel(r))console.debug(`🟡 Query[${e.name}] is cancelled`),e.data=[],e.state="idle";else{e.data=[];const s=v.get(r,"message","unkown error");e.error=v.get(r,"response.data.detail.message",s),e.state="error"}}}}),runTransformation(){e.state="loading";try{const t=e.depQueryModels.map(o=>({id:o.id,name:o.name,data:v.cloneDeep(o.data)})),r=e.contentModel.dashboardState,s=e.pre_process,i=new Function(`return ${s}`)()(t,r,It);e.data=i,e.state="idle",e.error=null}catch(t){e.data=[],e.error=t.message,e.state="error"}}})).actions(e=>({fetchData:t=>{if(!e.inUse&&!t){console.debug(`🟡 Skipping query[${e.name}]`);return}return console.debug(`🔵 Running query[${e.name}]`),e.isTransform?e.runTransformation():e.typedAsHTTP?e.runHTTP():e.isMericoMetricQuery?e.runMericoMetricQuery():e.runSQL()},beforeDestroy(){var t;(t=e.controller)==null||t.abort()}})).actions(e=>({afterCreate(){g.addDisposer(e,te.reaction(()=>{var r,s;if(e.isTransform){const i=e.config;return[e.inUse,e.id,e.key,i.dep_query_ids.toString(),e.pre_process,e.depQueryModelStatesString].join("--")}return e.typedAsHTTP?`${e.inUse}--${e.id}--${e.key}--${e.reQueryKey}--${(r=e.datasource)==null?void 0:r.id}`:e.isMericoMetricQuery?`${e.inUse}--${e.id}--${e.key}--${e.reQueryKey}--${(s=e.datasource)==null?void 0:s.id}`:[e.inUse,e.id,e.key,e.formattedSQL,e.pre_process,e.post_process].join("--")},()=>e.fetchData(!1),{fireImmediately:!0,delay:0}))}})),Ao=g.types.model("QueriesRenderModel",{current:g.types.optional(g.types.array(Po),[])}).views(e=>({get idSet(){return new Set(e.current.map(t=>t.id))},get firstID(){if(e.current.length!==0)return e.current[0].id},findByID(t){return e.current.find(r=>r.id===t)},findByIDSet(t){return e.current.filter(r=>t.has(r.id))},get json(){return e.current.filter(t=>t.id&&t.key).map(t=>t.json)},get contentModel(){return g.getParent(e,1)},get visibleQueryIDSet(){const{views:t,filters:r,queries:s}=this.contentModel,i=[];t.visibleViews.forEach(c=>{c.panels.forEach(u=>{i.push(...u.queryIDs)})});const o=v.uniq(t.visibleViews.map(c=>c.renderViewIDs).flat());r.current.forEach(c=>{const u=v.get(c,"config.options_query_id");if(!u)return;o.some(p=>c.visibleInViewsIDSet.has(p))&&i.push(u)}),s.findByIDSet(new Set(i)).forEach(c=>{const u=c.config;!c.isTransform||u.dep_query_ids.length===0||i.push(...u.dep_query_ids)});const l=new Set(i);return console.debug("QueryIDs:",l),l},isQueryInUse(t){return this.visibleQueryIDSet.has(t)}})).actions(e=>({downloadAllData(){const t=e.current.map(({name:r,data:s})=>({id:r,data:s}));xh(t)},downloadDataByQueryIDs(t){const r=new Set(t),s=e.current.filter(i=>r.has(i.id)).map(({name:i,data:o})=>({id:i,data:o}));xh(s)},downloadDataByQueryID(t){const r=e.findByID(t);if(!r){console.log("[downloadDataByQueryID] query not found");return}const{name:s,data:i}=r;fh(s,i)},refetchDataByQueryID(t){const r=e.findByID(t);if(!r){console.error(new Error(`[downloadDataByQueryID] query by ID[${t}] not found`));return}return r.fetchData(!0)},getSchema(t){return{definition:{queries:e.findByIDSet(new Set(t)).map(i=>i.json)},version:nn}},downloadSchema(t){const r=JSON.stringify(this.getSchema(t),null,2);er("Queries",r)}}));function wh(e){return{current:e}}function Ch({min:e,max:t}){const r=`${e}px`,s=Number.isFinite(t)?`${t}px`:"∞";return`[${r}, ${s})`}const Lo=g.types.model("LayoutsRenderModel",{list:g.types.array(Qp),currentBreakpoint:g.types.string}).views(e=>({get json(){return e.list.map(t=>t.json)},jsonByPanelIDSet(t){return e.list.map(r=>r.jsonByPanelIDSet(t))},get root(){return g.getRoot(e)},get contentModel(){return this.root.content},get basisLayoutSet(){return e.list.find(t=>t.id==="basis")},get currentLayoutSet(){return e.list.find(t=>t.id===e.currentBreakpoint)},get currentLayoutRange(){return this.breakpointRanges.find(t=>t.id===e.currentBreakpoint)},get currentRangeText(){const t=this.currentLayoutRange;return Ch(t)},get cols(){const t={};return e.list.forEach(r=>{t[r.id]=36}),t},get breakpoints(){const t={};return e.list.forEach(r=>{t[r.id]=r.breakpoint}),t},get breakpointNameRecord(){const t={};return e.list.forEach(r=>{t[r.name]=r.breakpoint}),t},get breakpointRanges(){const t=e.list.map(r=>({id:r.id,name:r.name,min:r.breakpoint,max:1/0,text:""}));return t.sort((r,s)=>r.min-s.min).forEach((r,s)=>{s!==t.length-1&&(r.max=t[s+1].min)}),t.forEach(r=>{r.text=Ch(r)}),t},get breakpointsInfo(){return e.list.map(t=>({id:t.id,name:t.name,breakpoint:t.breakpoint})).sort((t,r)=>t.breakpoint-r.breakpoint)},get currentBreakpointRange(){return this.breakpointRanges.find(t=>t.id===e.currentBreakpoint)},get currentLayoutPreviewWidth(){const t=this.currentBreakpointRange;if(t)return t.max===1/0?t.min===0?void 0:t.min+1:t.max},items(t){const r=new Set(t);return this.currentLayoutSet.list.filter(i=>r.has(i.panelID))},gridLayouts(t){const r=new Set(t),s={};return e.list.forEach(i=>{s[i.id]=i.list.filter(o=>r.has(o.panelID)).map(o=>o.layoutProperies)}),s},findItemByPanelID(t){return this.currentLayoutSet.findByPanelID(t)}})).actions(e=>({setCurrentBreakpoint(t){console.log("🔴 onBreakpointChange:",t),e.currentBreakpoint=t},afterCreate(){g.addDisposer(e,te.reaction(()=>e.currentBreakpoint,()=>{setTimeout(()=>{window.dispatchEvent(new Event("resize"))},32)},{fireImmediately:!1,delay:0}))}})),Sh=Wp.views(e=>({isADuplicatedKey(t){return!t||t===e.key?!1:!!g.getParent(e,2).findByKey(t)}})),Oo=g.types.model("SQLSnippetsRenderModel",{current:g.types.optional(g.types.array(Sh),[])}).views(e=>({get json(){return e.current.map(t=>t.json)},get record(){return e.current.reduce((t,r)=>(t[r.key]=r.value,t),{})},get keySet(){return new Set(e.current.map(t=>t.key))},get firstKey(){if(e.current.length!==0)return e.current[0].key},findByKey(t){return e.current.find(r=>r.key===t)},findByKeySet(t){return e.current.filter(r=>t.has(r.key))}})).actions(e=>({getSchema(t){return{definition:{sqlSnippets:e.findByKeySet(new Set(t)).map(i=>i.json)},version:nn}},downloadSchema(t){const r=JSON.stringify(this.getSchema(t),null,2);er("SQL Snippets",r)}}));function Th(e){return{current:e}}function Er(e,t,r,s){return e.reduce((i,o)=>{try{i[o[t]]=Xs(o[r],s)}catch(l){i[o[t]]=l.message}return i},{})}class kh{constructor(t){N(this,"origin");N(this,"copy");this.origin=t,this.copy=g.clone(t),te.makeAutoObservable(this,{},{autoBind:!0,deep:!1})}get changed(){return!v.isEqual(g.getSnapshot(this.origin),g.getSnapshot(this.copy))}commit(){g.applySnapshot(this.origin,g.getSnapshot(this.copy))}reset(){g.applySnapshot(this.copy,g.getSnapshot(this.origin))}update(t){g.applySnapshot(this.copy,t)}}const Dh=e=>new kh(e),V3=({description:e,isDescriptionEmpty:t})=>t?null:n.jsx(a.Tooltip,{color:"white",label:n.jsx(Yn,{value:e,styles:{root:{border:"none"},content:{padding:0}}}),styles:{tooltip:{border:"0.0625rem solid rgb(233, 236, 239)",boxShadow:"rgb(0 0 0 / 5%) 0px 0.0625rem 0.1875rem, rgb(0 0 0 / 5%) 0px 1.25rem 1.5625rem -0.3125rem, rgb(0 0 0 / 4%) 0px 0.625rem 0.625rem -0.3125rem"}},withArrow:!0,children:n.jsx(a.Box,{sx:{height:"16px",alignSelf:"center"},children:n.jsx(C.IconInfoCircle,{size:16,color:"gray"})})}),B3=k.observer(({label:e,config:{default_value:t,description:r,isDescriptionEmpty:s,...i},value:o,onChange:l})=>n.jsxs(a.Box,{children:[n.jsx(a.Text,{size:"sm",children:" "}),n.jsx(a.Checkbox,{label:n.jsxs(a.Group,{wrap:"nowrap",justify:"space-between",align:"middle",gap:6,children:[n.jsx(a.Box,{sx:{flexGrow:1},children:e}),n.jsx(V3,{description:r,isDescriptionEmpty:s})]}),checked:o||!1,onChange:c=>l(c.currentTarget.checked),...i,pt:".4em",styles:{input:{borderColor:"#e9ecef"}}})]})),q3=({value:e,onChange:t,close:r,max_days:s,allowSingleDateInRange:i})=>{const{i18n:o}=_.useTranslation(),l=e.value,[c,u]=l,d=f.useMemo(()=>c||new Date,[c]),p=f.useMemo(()=>{if(c&&!u)return c},[c,u]),h=f.useMemo(()=>{if(c&&!u&&s>0)return A(c).add(s-1,"days").toDate()},[c,u,s]),x=b=>{const[m,j]=b;t({value:b,shortcut:null}),m&&j&&r()};return n.jsx(jl.DatePicker,{defaultDate:d,numberOfColumns:2,type:"range",value:l,onChange:x,onNextMonth:console.log,minDate:p,maxDate:h,allowSingleDateInRange:i,locale:o.language})},N3=({begin:e,end:t})=>{const{t:r}=_.useTranslation(),s=f.useMemo(()=>!t&&!e?Number.NaN:A(t).diff(A(e),"days")+1,[e,t]);if(Number.isNaN(s))return n.jsx("span",{style:{userSelect:"none",opacity:0,visibility:"hidden"},children:"."});const i=s===1?r("filter.widget.date_range.one_day"):r("filter.widget.date_range.x_days",{count:s});return n.jsx(a.Tooltip,{label:i,children:n.jsx(a.Badge,{size:"sm",variant:"light",children:s})})},$3=({max_days:e})=>{const{t}=_.useTranslation();return e?n.jsxs(n.Fragment,{children:[n.jsx(a.Group,{justify:"flex-end",children:n.jsx(a.Badge,{size:"xs",variant:"light",children:t("filter.widget.date_range.x_max_days",{max_days:e})})}),n.jsx(a.Divider,{variant:"dashed",my:10})]}):null},G3=({onChange:e})=>{const{t,i18n:r}=_.useTranslation(),s=l=>()=>{const c=l();e(c)},i=f.useMemo(()=>Yp(),[]),o=r.language==="zh";return n.jsxs(n.Fragment,{children:[n.jsx(a.Divider,{variant:"dashed",my:10}),n.jsx(a.Table,{withTableBorder:!1,sx:{"tbody > tr":{border:"none"},"tbody > tr > th, tbody > tr > td":{borderTop:"none",padding:"2px 6px"},"tbody > tr > th":{cursor:"default",userSelect:"none"},td:{paddingLeft:"1px"}},children:n.jsx(a.Table.Tbody,{children:Object.entries(i).map(([l,c])=>n.jsxs(a.Table.Tr,{children:[n.jsx(a.Table.Th,{children:n.jsx(a.Text,{size:"xs",c:"#555",fw:500,sx:{textAlignLast:"justify"},children:t(`filter.widget.date_range.shortcut.${l}.label`)})}),c.map(({key:u,value:d,getRange:p})=>n.jsx(a.Table.Td,{children:n.jsx(a.Button,{size:"compact-xs",variant:"subtle",onClick:s(p),children:t(`filter.widget.date_range.shortcut.${l}.${o?"full.":""}${u}`)})},u))]},l))})})]})},zh=e=>({label:{display:"block",height:"21.7px"},input:{borderColor:e?"#228be6":"#e9ecef"}}),F3=({label:e,required:t,value:r,onChange:s,max_days:i,allowSingleDateInRange:o,inputFormat:l,disabled:c})=>{const{t:u}=_.useTranslation(),[d,{open:p,close:h}]=ze.useDisclosure(!1),[x,b]=r.value,m=x?A(x).format(l):"",j=b?A(b).format(l):"";return n.jsxs(a.Popover,{opened:d,onClose:h,position:"bottom-start",shadow:"md",children:[n.jsxs(a.Group,{justify:"flex-start",grow:!0,wrap:"nowrap",gap:0,w:"288px",sx:{marginTop:"3px"},children:[n.jsx(a.Popover.Target,{children:n.jsx(a.TextInput,{label:e,labelProps:{title:e},required:t,leftSection:n.jsx(C.IconCalendar,{size:16}),placeholder:u("filter.widget.date_range.start_date"),readOnly:!0,disabled:c,value:m,onFocus:p,styles:zh(d),sx:{".mantine-TextInput-label":{textOverflow:"ellipsis",overflow:"hidden",whiteSpace:"nowrap",width:"calc(240px)",position:"relative",zIndex:1},".mantine-Input-input":{borderRight:"none",borderTopRightRadius:0,borderBottomRightRadius:0},".mantine-Input-input[data-disabled]":{backgroundColor:"transparent",backgroundImage:"linear-gradient(to left, #fff 0%, #f1f3f5 30%)",opacity:1},".mantine-Input-input[data-disabled]::placeholder":{opacity:.6}}})}),n.jsx(a.TextInput,{label:n.jsx(a.Group,{justify:"flex-end",children:n.jsx(N3,{begin:x,end:b})}),leftSection:n.jsx(C.IconMinus,{size:16}),placeholder:u("filter.widget.date_range.end_date"),readOnly:!0,disabled:!x||c,value:j,onFocus:p,styles:zh(d),sx:{".mantine-Input-section":{transform:"translateX(-18px)"},".mantine-Input-input":{borderLeft:"none",borderTopLeftRadius:0,borderBottomLeftRadius:0},".mantine-Input-input[data-disabled]":{backgroundColor:"transparent",backgroundImage:"linear-gradient(to right, #fff 0%, #f1f3f5 30%)",opacity:1},".mantine-Input-input[data-disabled]::placeholder":{opacity:.6}}})]}),n.jsxs(a.Popover.Dropdown,{p:"sm",children:[n.jsx($3,{max_days:i}),n.jsx(q3,{value:r,onChange:s,close:h,allowSingleDateInRange:o,max_days:i}),n.jsx(G3,{onChange:s})]})]})},Ih={value:[null,null],shortcut:null},Mh=k.observer(({label:e,config:t,value:r=Ih,onChange:s,disabled:i})=>{const{inputFormat:o,required:l,max_days:c,allowSingleDateInRange:u}=t,d=f.useMemo(()=>{const p=co(r.shortcut);return p||(Array.isArray(r.value)?r:Ih)},[r]);return n.jsx(F3,{label:e,value:d,onChange:s,inputFormat:o,allowSingleDateInRange:u,max_days:c,required:l,disabled:i})}),Q3=on.createStyles((e,{radius:t=4,name:r,...s})=>({root:{borderRadius:a.getRadius(t),display:"flex",flexWrap:"nowrap",border:"1px solid #ced4da",paddingLeft:"0px",paddingRight:"30px",backgroundColor:"#fff",transition:"border-color 100ms ease",borderColor:"#e9ecef",...s,"&.rc-select.rc-select-open":{borderColor:"#228be6 !important",".rc-select-selection-overflow-item-rest":{display:"none"},".rc-select-selection-overflow-item-suffix":{display:"block"}},".rc-select-selector":{height:"auto",lineHeight:1.55,paddingLeft:"12px",resize:"none",boxSizing:"border-box",fontSize:"14px",width:"100%",color:"#000",display:"block",textAlign:"left",minHeight:"36px",cursor:"pointer",flexGrow:1},".rc-select-selection-search-mirror":{display:"none"},".rc-select-selection-search":{flexGrow:1,width:"auto !important"},".rc-select-selection-overflow":{display:"flex",minHeight:"34px",alignItems:"center",flexWrap:"nowrap",marginLeft:"calc(-10px / 2)",boxSizing:"border-box"},".rc-select-selection-overflow-item":{display:"flex",alignItems:"center",backgroundColor:"#f1f3f5",color:"#495057",height:"24px",paddingLeft:"12px",paddingRight:"12px",fontWeight:500,fontSize:"12px",borderRadius:"4px",cursor:"default",userSelect:"none",maxWidth:"calc(100% - 20px)",margin:"calc(10px / 2 - 2px) calc(10px / 2)"},".rc-select-selection-overflow-item-rest":{cursor:"pointer"},".rc-select-selection-overflow-item-suffix":{display:"none",backgroundColor:"transparent",width:"100%",maxWidth:"100%",height:"28px",margin:0,paddingLeft:0,paddingRight:0},input:{flex:1,minWidth:"60px",backgroundColor:"transparent",border:0,outline:0,fontSize:"14px",padding:0,marginLeft:0,color:"inherit",height:"28px",lineHeight:"32px",cursor:"pointer",width:"100%","&::-webkit-search-decoration, &::-webkit-search-cancel-button, &::-webkit-search-results-button, &::-webkit-search-results-decoration":{display:"none"}},".rc-select-clear":{marginRight:"-24px",alignSelf:"center",cursor:"pointer"},"&.rc-select-disabled":{backgroundColor:"rgb(241, 243, 245)",color:"rgb(144, 146, 150)",opacity:.6,"&, .rc-select-selector, input":{cursor:"not-allowed"}}},label:{fontSize:e.fontSizes.sm,fontWeight:500,color:"#212529"},required:{color:"#fa5252",paddingLeft:"3px"},dropdown:{fontSize:e.fontSizes.xs,zIndex:300,backgroundColor:"#fff",border:"1px solid #e9ecef",marginTop:6,padding:0,boxShadow:"0 1px 3px rgb(0 0 0 / 5%), rgb(0 0 0 / 5%) 0px 10px 15px -5px, rgb(0 0 0 / 4%) 0px 7px 7px -5px",borderRadius:"4px","&.rc-select-dropdown-slide-up-leave-active":{display:"none"},".rc-select-item-empty":{padding:"8px 12px"},".rc-select-item-option":{boxSizing:"border-box",textAlign:"left",width:"100%",padding:"8px 12px 8px 2px",cursor:"pointer",fontSize:"14px",color:"#000",borderRadius:"4px",display:"flex",flexWrap:"nowrap",overflow:"hidden","&:hover":{backgroundColor:"#f1f3f5"},flexDirection:"row-reverse",".rc-select-item-option-state":{flexGrow:0,flexShrink:0,width:"30px",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center"},".rc-select-item-option-content":{width:"calc(100% - 30px)",overflow:"hidden",'div[data-role="label"]':{overflowWrap:"break-word"}}},".rc-virtual-list-holder-inner":{alignItems:"flex-start"}}})),W3=({disabled:e,radius:t,style:r,label:s,value:i,onChange:o,options:l,errorMessage:c,required:u})=>{const{t:d}=_.useTranslation(),{classes:p,cx:h}=Q3({radius:t,name:"MultiSelectWidget"}),[x,b]=f.useState(!1),m=I=>{b(I)},j=x&&(i==null?void 0:i.length)>0,[D,T]=f.useState(""),z=f.useMemo(()=>{if(!D)return l;const I=D.toLowerCase(),M=P=>{var ae;return((ae=P.description)==null?void 0:ae.toLowerCase().includes(I))||P.label.toLowerCase().includes(I)};return l.filter(M)},[D,l]);return n.jsxs(a.Stack,{gap:3,children:[n.jsxs(a.Group,{justify:"space-between",children:[n.jsxs(a.Text,{className:p.label,size:"sm",children:[s,u&&n.jsx("span",{className:p.required,"aria-hidden":"true",children:"*"})]}),j&&n.jsx(a.Tooltip,{label:d("filter.widget.common.x_selected",{count:i.length}),children:n.jsx(a.Badge,{variant:"light",children:i.length})})]}),n.jsx(zl,{disabled:e,allowClear:!0,className:h(p.root,"check-select"),dropdownClassName:h(p.dropdown,""),onDropdownVisibleChange:m,transitionName:"rc-select-dropdown-slide-up",choiceTransitionName:"rc-select-selection__choice-zoom",style:r,clearIcon:()=>n.jsx(a.CloseButton,{size:"sm"}),value:i,onChange:o,onSelect:console.log,mode:"multiple",maxTagCount:0,notFoundContent:n.jsx(mo,{errorMessage:c}),maxTagTextLength:10,maxTagPlaceholder:I=>d("filter.widget.common.x_selected",{count:I.length}),searchValue:D,onSearch:T,filterOption:!1,children:z.map(I=>n.jsxs(zl.Option,{title:I.label,children:[n.jsx(a.Text,{size:"sm","data-role":"label",children:I.label}),I.description&&n.jsx(a.Text,{size:"xs",c:"dimmed","data-role":"description",children:I.description})]},I.value))})]})},R3=k.observer(({label:e,config:t,value:r,onChange:s})=>{const i=Te(),o=!!t.options_query_id,{state:l,error:c}=i.getDataStuffByID(t.options_query_id),u=l==="loading",d=t.min_width?t.min_width:"200px",p=o?u:!1,h=f.useMemo(()=>t.initialSelection(r),[r,t.initialSelection]),x=b=>s(b,!1);return n.jsx(W3,{label:e,options:t.options,style:{minWidth:"160px",width:d,maxWidth:p?d:"unset",borderColor:"#e9ecef"},disabled:p,value:[...h],onChange:x,errorMessage:c,required:t.required})}),U3=({option:e,...t})=>{const{label:r,description:s}=e;return n.jsx("div",{...t,children:n.jsx(a.Group,{wrap:"nowrap",children:n.jsxs("div",{children:[n.jsx(a.Text,{size:"sm","data-role":"label",children:r}),n.jsx(a.Text,{size:"xs",c:"dimmed","data-role":"description",children:s})]})})})},Y3=k.observer(({label:e,config:t,value:r,onChange:s})=>{const{t:i}=_.useTranslation(),o=Te(),l=!!t.options_query_id,{state:c,error:u}=o.getDataStuffByID(t.options_query_id),d=c==="loading",p=f.useCallback((h,x)=>{h&&s(h,!1)},[s]);return n.jsx(a.Select,{label:e,data:t.options,disabled:l?d:!1,value:r,onChange:p,maxDropdownHeight:500,styles:{root:{width:t.width?t.width:"200px"},input:{borderColor:"#e9ecef"}},sx:{".mantine-Select-item[data-selected] .mantine-Text-root[data-role=description]":{color:"rgba(255,255,255,.7)"},".mantine-Select-nothingFound":{fontSize:"0.75rem",textAlign:"left",padding:"4px 10px"}},renderOption:U3,searchable:!u,nothingFoundMessage:u||i("filter.widget.common.selector_option_empty"),clearable:t.clearable})});function K3({label:e,config:t,value:r,onChange:s}){return n.jsx(a.TextInput,{label:e,value:r||"",onChange:i=>s(i.currentTarget.value),...t,styles:{input:{borderColor:"#e9ecef"}}})}const X3=k.observer(({filter:{type:e,config:t,key:r,...s},formFieldProps:i})=>{switch(e){case Q.Select:return n.jsx(Y3,{...s,...i,config:t});case Q.MultiSelect:return n.jsx(R3,{...s,...i,config:t});case Q.TreeSelect:return n.jsx(S3,{...s,...i,config:t});case Q.TreeSingleSelect:return n.jsx(z3,{...s,...i,config:t});case Q.TextInput:return n.jsx(K3,{...s,...i,config:t});case Q.DateRange:return n.jsx(Mh,{...s,...i,config:t});case Q.Checkbox:return n.jsx(B3,{...s,...i,config:t});default:return null}}),H3=k.observer(f.forwardRef(({filter:e,...t},r)=>n.jsx("div",{className:"filter-root",ref:r,children:n.jsx(Ie,{children:n.jsx(X3,{filter:e,formFieldProps:t})})}))),Z3=({disabled:e})=>{const{searchButtonProps:t}=$l(),{children:r="Search",...s}=t;return n.jsx(a.Button,{color:"blue",size:"sm",type:"submit",...s,disabled:e||s.disabled,children:r})};function J3(e){const t=re();f.useEffect(()=>{var r,s;(s=(r=t.filters).updatePreviewValues)==null||s.call(r,e)},[e])}const e5=({opened:e,toggle:t})=>{const{t:r}=_.useTranslation();return n.jsx(a.Group,{justify:"flex-end",ml:-4,mt:-4,mb:e?4:0,children:n.jsx(a.Button,{size:"compact-xs",variant:"subtle",color:e?"gray":"blue",leftSection:e?n.jsx(C.IconChevronsUp,{size:14}):n.jsx(C.IconChevronsDown,{size:14}),onClick:t,children:r(e?"filter.hide_filters":"filter.show_filters")})})},Eh=k.observer(function({view:t}){const[r,{toggle:s}]=ze.useDisclosure(!0),i=Te(),{control:o,handleSubmit:l,reset:c}=y.useForm({defaultValues:i.filters.values,reValidateMode:"onBlur"}),u=y.useWatch({control:o});f.useEffect(()=>{c(i.filters.values)},[i.filters.values,c]),J3(u);const d=i.filters.visibleInView(t.id),p=f.useMemo(()=>d.every(m=>m.should_auto_submit),[d]),h=f.useMemo(()=>d.filter(m=>v.get(m,"config.required",!1)),[d]),x=f.useMemo(()=>h.length===0?!1:h.some(m=>!m.requiredAndPass(u[m.key])),[u,h]);if(d.length===0)return null;const b=(m,j)=>(D,T)=>{j(D),(m.should_auto_submit||T)&&i.filters.setValueByKey(m.key,D)};return n.jsxs("form",{onSubmit:l(i.filters.setValues),children:[n.jsx(e5,{opened:r,toggle:s}),n.jsx(a.Collapse,{in:r,children:n.jsxs(a.Group,{className:"dashboard-filters",justify:"space-between",wrap:"nowrap",sx:p?{}:{border:"1px solid #e9ecef",borderRadius:"4px",padding:"16px"},children:[n.jsx(a.Group,{align:"flex-start",children:d.map(m=>n.jsx(y.Controller,{name:m.key,control:o,render:({field:j})=>n.jsx(H3,{filter:m,value:j.value,onChange:b(m,j.onChange)})},m.id))}),!p&&n.jsx(a.Group,{sx:{alignSelf:"flex-end"},children:n.jsx(Z3,{disabled:x})})]})})]})}),t5={viewPanelInFullScreen:v.noop,inFullScreen:!1},Ls=f.createContext(t5),n5=k.observer(({view:e})=>{const{t}=_.useTranslation(),r=se(),{panel:s}=Pe(),i=s.realQueryOptions,o=c=>{r.editor.open(["_QUERIES_",c])},l=()=>{r.editor.open(["_VIEWS_",e.id,"_PANELS_",s.id,"_TABS_","Data"])};return i.length===0?null:n.jsxs(n.Fragment,{children:[n.jsx(a.Divider,{label:t(i.length>1?"query.labels":"query.label"),labelPosition:"center"}),n.jsx(a.Menu.Item,{onClick:l,leftSection:n.jsx(C.IconDatabase,{size:14}),children:t("data.label")}),i.map(c=>n.jsx(a.Menu.Item,{onClick:()=>o(c.value),leftSection:n.jsx(C.IconDatabase,{size:14}),children:c.label},c.value))]})}),r5=k.observer(({view:e,title:t})=>{const{t:r}=_.useTranslation(),s=se(),i=re(),o=dt.useModals(),{panel:l,downloadPanelScreenshot:c}=Pe(),{id:u}=l,{viewPanelInFullScreen:d,inFullScreen:p}=f.useContext(Ls),h=()=>{i.duplicatePanelByID(u,e.id)},x=()=>{s.editor.open(["_VIEWS_",e.id,"_PANELS_",u,"_TABS_","Panel"])},b=()=>{s.editor.open(["_VIEWS_",e.id,"_PANELS_",u,"_TABS_","Variables"])},m=()=>{s.editor.open(["_VIEWS_",e.id,"_PANELS_",u,"_TABS_","Visualization"])},j=()=>{s.editor.open(["_VIEWS_",e.id,"_PANELS_",u,"_TABS_","Interactions"])},D=()=>o.openConfirmModal({title:`${r("panel.delete")}?`,labels:{confirm:r("common.actions.confirm"),cancel:r("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>i.removePanelByID(u,e.id),confirmProps:{color:"red"},zIndex:320}),T=f.useCallback(()=>{d(u)},[u,d]),z=!p&&e.type!==F.Modal;return n.jsx(n.Fragment,{children:n.jsx(a.Box,{sx:{position:"absolute",top:0,left:0,right:0,zIndex:300},title:t,children:n.jsxs(a.Menu,{withinPortal:!0,children:[n.jsx(a.Menu.Target,{children:n.jsx(a.Box,{className:"panel-dropdown-target",sx:{width:"100%"}})}),n.jsxs(a.Menu.Dropdown,{children:[n.jsx(a.Menu.Item,{onClick:l.refreshData,leftSection:n.jsx(C.IconRefresh,{size:14}),children:r("common.actions.refresh")}),n.jsx(a.Menu.Item,{onClick:l.downloadData,leftSection:n.jsx(C.IconDownload,{size:14}),children:r("common.actions.download_data")}),n.jsx(a.Menu.Item,{onClick:l.downloadSchema,leftSection:n.jsx(C.IconCode,{size:14}),children:r("common.actions.download_schema")}),n.jsx(a.Menu.Item,{onClick:c,leftSection:n.jsx(C.IconCamera,{size:14}),children:r("common.actions.download_screenshot")}),z&&n.jsx(a.Menu.Item,{onClick:T,leftSection:n.jsx(C.IconArrowsMaximize,{size:14}),disabled:!0,children:r("common.actions.enter_fullscreen")}),n.jsx(n5,{view:e}),n.jsx(a.Divider,{label:r("common.actions.edit"),labelPosition:"center"}),n.jsx(a.Menu.Item,{onClick:x,leftSection:n.jsx(C.IconAppWindow,{size:14}),children:r("panel.label")}),n.jsx(a.Menu.Item,{onClick:b,leftSection:n.jsx(C.IconVariable,{size:14}),children:r("panel.variable.labels")}),n.jsx(a.Menu.Item,{onClick:m,leftSection:n.jsx(C.IconChartHistogram,{size:14}),children:r("visualization.label")}),n.jsx(a.Menu.Item,{onClick:j,leftSection:n.jsx(C.IconRoute,{size:14}),children:r("interactions.label")}),n.jsx(a.Divider,{label:r("common.actions.actions"),labelPosition:"center"}),n.jsx(a.Menu.Item,{onClick:h,leftSection:n.jsx(C.IconCopy,{size:14}),children:r("common.actions.duplicate")}),n.jsx(a.Menu.Item,{color:"red",onClick:D,leftSection:n.jsx(C.IconTrash,{size:14}),children:r("common.actions.delete")})]})]})})})});function s5(e){return e?["<p><br></p>","<p></p>"].includes(e):!0}const i5=k.observer(()=>{const e=Te(),{panel:t}=He(),r=f.useMemo(()=>fs(t.description,t.json.variables,e.payloadForViz,t.data),[t.data,t.description,t.json.variables,e.payloadForViz]);return n.jsx(Yn,{value:r,styles:{root:{border:"none"},content:{padding:0}},sx:{".mantine-RichTextEditor-content .ProseMirror":{padding:"0 !important"}},dashboardState:e.dashboardState,variableAggValueMap:t.variableAggValueMap})}),Vo=k.observer(()=>{const{t:e}=_.useTranslation(),[t,r]=f.useState(!1),{panel:s}=He();return s5(s.description)?null:n.jsxs(n.Fragment,{children:[n.jsx(a.Modal,{opened:t,onClose:()=>r(!1),title:s.title.show?s.name:"",withCloseButton:!1,withinPortal:!0,zIndex:310,children:n.jsx(i5,{})}),n.jsx(a.Tooltip,{label:e("panel.panel_description_click"),position:"top-start",withinPortal:!0,children:n.jsx(a.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>r(i=>!i),sx:{verticalAlign:"baseline",cursor:"pointer"},children:n.jsx(C.IconInfoCircle,{size:20})})})]})}),SE="",a5=k.observer(function(){const{panel:t}=He(),{name:r,title:s}=t;return s.show?n.jsx(a.Group,{grow:!0,justify:"center",className:"panel-title-wrapper",sx:{flexGrow:1},children:n.jsx(a.Text,{size:"sm",ta:"center",lineClamp:1,className:"panel-title-text",children:r})}):null});function o5(e){const t=f.useRef(null);return{ref:t,downloadPanelScreenshot:()=>{const s=t.current;if(!s)return;const i=s.offsetWidth*2,o=s.offsetHeight*2;kl.toBlob(t.current,{bgcolor:"white",width:i,height:o,style:{border:"none",borderRadius:0,transformOrigin:"0 0",transform:"scale(2)"}}).then(l=>{window.saveAs(l,`${e.name?e.name:e.viz.type}.png`)})}}}var Ph=(e=>(e.migrated="migrated",e.nothingToMigrate="nothingToMigrate",e.checkFailed="checkFailed",e.migrationFailed="migrationFailed",e))(Ph||{}),Os=(e=>(e.notStarted="notStarted",e.inProgress="inProgress",e.done="done",e))(Os||{});class l5{constructor(t){N(this,"vizInstance");N(this,"operationManager");N(this,"triggerManager");N(this,"vizManager");N(this,"runningMigration");N(this,"panelModel");N(this,"status","notStarted");this.panelModel=t.getRequired(Ae.instanceScope.panelModel),this.vizInstance=t.getRequired(Ae.instanceScope.vizInstance),this.operationManager=t.getRequired(Ae.instanceScope.operationManager),this.triggerManager=t.getRequired(Ae.instanceScope.triggerManager),this.vizManager=t.getRequired(Ae.vizManager)}async createMigrationTask(){const t=[];try{await this.instanceNeedMigration()&&t.push(()=>this.runInstanceMigration()),await this.interactionNeedMigration()&&t.push(()=>this.runInteractionMigration())}catch(r){return console.warn("check migration failed",r),"checkFailed"}if(t.length===0)return"nothingToMigrate";try{return await Promise.all(t.map(r=>r())),"migrated"}catch(r){return console.warn("migration failed",r),"migrationFailed"}}async runMigration(){return this.runningMigration||(this.status="inProgress",this.runningMigration=this.createMigrationTask().then(t=>(this.status="done",t))),this.runningMigration}async runInteractionMigration(){await this.operationManager.runMigration(),await this.triggerManager.runMigration()}async runInstanceMigration(){const t=this.vizManager.resolveComponent(this.vizInstance.type),r={configData:this.vizInstance.instanceData,panelModel:this.panelModel};await t.migrator.migrate(r)}async instanceNeedMigration(){const t=this.vizManager.resolveComponent(this.vizInstance.type),r={configData:this.vizInstance.instanceData};return t.migrator.needMigration(r)}async interactionNeedMigration(){return await this.operationManager.needMigration()||await this.triggerManager.needMigration()}}function Ah(e){const{panel:t}=He();return f.useCallback(r=>{const s=r.getRequired(Ae.vizManager),i=s.resolveComponent(e.viz.type);return r.createScoped().provideFactory(Ae.instanceScope.vizInstance,()=>s.getOrCreateInstance(e)).provideFactory(Ae.instanceScope.interactionManager,o=>{const l=o.getRequired(Ae.instanceScope.vizInstance);return new Ca(l,i,bs)}).provideFactory(Ae.instanceScope.operationManager,o=>o.getRequired(Ae.instanceScope.interactionManager).operationManager).provideFactory(Ae.instanceScope.triggerManager,o=>o.getRequired(Ae.instanceScope.interactionManager).triggerManager).provideValue(Ae.instanceScope.panelModel,t).provideFactory(Ae.instanceScope.migrator,o=>new l5(o))},[e.viz.type,e.viz.conf])}function Lh(e){const[t,r]=f.useState(!1),s=Mp().getRequired(Ae.instanceScope.migrator);return U.useAsyncEffect(async()=>{const i=s.status===Os.notStarted;r(s.status===Os.done),s.status===Os.notStarted&&s.runMigration().then(o=>{o===Ph.migrated&&i&&(e==null||e())}).finally(()=>{r(!0)})},[s]),t}function Oh(e,t){const r=Mp().getRequired(Ae.instanceScope.vizInstance);return f.useEffect(()=>(r.instanceData.setItem(null,t.viz.conf),r.instanceData.watchItem(null,s=>{e(s)})),[e,t.viz.type]),r}function c5({setVizConf:e,...t}){const{panel:r}=t,s=Oh(e,r),i=Lh(()=>{$t.showNotification({title:`${r.name} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})});return U.useAsyncEffect(async()=>{await s.instanceData.setItem(null,r.viz.conf)},[s,r.viz.type]),i?n.jsx(_y,{...t}):n.jsx(a.Text,{size:"sm",children:"Checking update..."})}function u5(e){const{panel:t,setVizConf:r}=e;Oh(r,t);const{inEditMode:s}=f.useContext($r);return Lh(()=>{s&&$t.showNotification({title:`${t.name} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})})?n.jsx(vy,{...e}):n.jsx(a.Text,{size:"sm",children:"Checking update"})}const TE="";function d5(e,t){const{vizManager:r}=f.useContext(tn),{panel:{viz:s,title:i,id:o,name:l,description:c,queryIDs:u,variables:d}}=He(),p={id:o,name:l,title:i,description:c,queryIDs:u,viz:s},h=Ah(p);try{return r.resolveComponent(s.type),n.jsx(Ms,{configure:h,children:n.jsx(u5,{setVizConf:s.setConf,panel:p,measure:t,data:e,variables:d,vizManager:r})})}catch(x){return console.info(v.get(x,"message")),null}}const Vh=k.observer(function({data:t}){const{ref:r,width:s,height:i}=ze.useElementSize(),o=d5(t,{w:s,h:i}),l=s>0&&i>0;return n.jsx("div",{className:"viz-root",ref:r,children:n.jsx(a.Box,{sx:{width:s,height:i,overflow:"hidden"},children:l&&n.jsx(Ie,{children:o})})})}),Bh=k.observer(({panel:e})=>n.jsxs(a.Stack,{children:[e.queryErrors.map((t,r)=>n.jsx(a.Text,{c:"red",size:"sm",ta:"center",ff:"monospace",children:t},`${r}-${t}`)),n.jsx(a.Text,{c:"gray",ta:"center",size:"sm",children:e.queryStateMessages})]})),Bo=k.observer(({panel:e})=>n.jsxs(a.Flex,{className:"panel-viz-section",direction:"column",sx:{position:"relative",width:"100%"},children:[n.jsx(a.LoadingOverlay,{visible:e.dataLoading,transitionProps:{exitDuration:0}}),!e.canRenderViz&&n.jsx(Bh,{panel:e}),e.canRenderViz&&n.jsx(Vh,{data:e.data})]})),p5={border:"1px solid #e9ecef"},qh=k.observer(({panel:e,panelStyle:t,dropdownContent:r})=>{const{ref:s,downloadPanelScreenshot:i}=o5(e);return e.title.show,n.jsx(ii,{value:{panel:e,data:e.data,loading:e.dataLoading,errors:e.queryErrors,downloadPanelScreenshot:i},children:n.jsxs(a.Box,{className:`panel-root ${e.title.show?"panel-root--show-title":""}`,ref:s,p:0,sx:{...p5,...t},children:[n.jsx(a.Box,{className:"panel-description-popover-wrapper",children:n.jsx(Vo,{})}),r,n.jsx(a5,{}),n.jsx(Bo,{panel:e})]})})}),h5={border:"1px dashed transparent",transition:"border-color 300ms ease","&:hover":{borderColor:"#e9ecef"}};function g5(e){return e.style.border.enabled?{}:h5}const Nh=k.observer(function({panel:t,view:r}){const s=g5(t);return n.jsx(qh,{panel:t,panelStyle:s,dropdownContent:n.jsx(r5,{view:r,title:t.name})})});function f5(e){return!["richText","button"].includes(e)}const x5=k.observer(({view:e,title:t})=>{const{t:r}=_.useTranslation(),{panel:s,downloadPanelScreenshot:i}=He(),{id:o}=s,{viewPanelInFullScreen:l,inFullScreen:c}=f.useContext(Ls),u=f.useCallback(()=>{l(o)},[o,l]),d=!c&&e.type!==F.Modal;return f5(s.viz.type)?n.jsx(a.Box,{sx:{position:"absolute",top:0,left:0,right:0,zIndex:300},title:t,children:n.jsxs(a.Menu,{withinPortal:!0,children:[n.jsx(a.Menu.Target,{children:n.jsx(a.Box,{className:"panel-dropdown-target"})}),n.jsxs(a.Menu.Dropdown,{children:[n.jsx(a.Menu.Item,{onClick:s.refreshData,leftSection:n.jsx(C.IconRefresh,{size:14}),children:r("common.actions.refresh")}),n.jsx(a.Menu.Item,{onClick:s.downloadData,leftSection:n.jsx(C.IconDownload,{size:14}),children:r("common.actions.download_data")}),n.jsx(a.Menu.Item,{onClick:i,leftSection:n.jsx(C.IconCamera,{size:14}),children:r("common.actions.download_screenshot")}),d&&n.jsx(a.Menu.Item,{onClick:u,leftSection:n.jsx(C.IconArrowsMaximize,{size:14}),children:r("common.actions.enter_fullscreen")})]})]})}):null});function m5(e){return e.style.border.enabled?{}:{border:"1px dashed transparent"}}const qo=k.observer(({panel:e,view:t})=>{const r=m5(e);return n.jsx(qh,{panel:e,panelStyle:r,dropdownContent:n.jsx(x5,{title:e.name,view:t})})}),b5={modal:{display:"flex",flexDirection:"column",flexWrap:"nowrap"},body:{display:"flex",height:"calc(100vh - 88px)"}},$h=k.observer(function({view:t,panel:r,exitFullScreen:s}){return n.jsx(a.Modal,{opened:!0,fullScreen:!0,onClose:s,title:n.jsx(a.Button,{color:"blue",size:"xs",onClick:s,leftSection:n.jsx(C.IconArrowLeft,{size:20}),children:"Exit fullscreen"}),styles:b5,children:n.jsx(a.Group,{grow:!0,sx:{flexGrow:1,flexShrink:0},children:n.jsx(qo,{view:t,panel:r})})})});function Gh(e,t,r){const{panels:s}=Te(),i=e.id==="Main",[o,l]=f.useState(()=>i&&s.findByID(t)?t:null),c=f.useCallback(h=>{l(h),i&&r(h)},[i,r]),u=f.useCallback(()=>{l(null),i&&r("")},[i,r]),d=o?s.findByID(o):null;return{viewPanelInFullScreen:c,exitFullScreen:u,inFullScreen:!!d,fullScreenPanel:d}}const kE="",y5=f.forwardRef(({h:e},t)=>n.jsx(a.ActionIcon,{ref:t,className:"react-grid-customDragHandle",sx:{userSelect:"none",cursor:"grab",position:"absolute",top:5,right:e>38?5:20,zIndex:400,"&:hover":{color:"#228be6"}},variant:"transparent",children:n.jsx(C.IconArrowsMove,{size:16})})),v5=f.forwardRef(({handleAxis:e,...t},r)=>n.jsx(a.ActionIcon,{ref:r,className:"react-grid-customResizeHandle",sx:{userSelect:"none",cursor:"nwse-resize",position:"absolute",bottom:0,right:0,zIndex:400,"&:hover":{color:"#228be6"}},variant:"transparent",...t,children:n.jsx(C.IconChevronDownRight,{size:16})})),_5=Br.WidthProvider(Br.Responsive),j5=k.observer(({view:e,className:t="layout"})=>{const s=re().layouts,i=s.items(e.panelIDs),o=s.gridLayouts(e.panelIDs),l=(d,p,h,x)=>{h.h<30&&(h.h=30,x.h=30),h.w<4&&(h.w=4,x.w=4)},c=(d,p,h)=>{console.log("🔴 onResizeStop",{layouts:d,oldItem:p,newItem:h}),s.updateCurrentLayoutItem(h)},u=(d,p,h)=>{console.log("🔴 onDragStop",{layouts:d,oldItem:p,newItem:h}),s.updateCurrentLayoutItems(d)};return n.jsx(_5,{className:`dashboard-layout ${t}`,rowHeight:1,margin:[0,0],isBounded:!0,isDraggable:!0,isResizable:!0,cols:s.cols,layouts:o,draggableHandle:".react-grid-customDragHandle",resizeHandle:n.jsx(v5,{}),onResize:l,breakpoints:s.breakpoints,onBreakpointChange:s.setCurrentBreakpoint,onResizeStop:c,onDragStop:u,width:s.currentLayoutPreviewWidth,children:i.map(d=>n.jsxs("div",{"data-grid":d.layoutProperies,className:"panel-grid-item",children:[n.jsx(y5,{h:d.h}),n.jsx(Nh,{view:e,panel:d.panel})]},d.id))})}),w5=Br.WidthProvider(Br.Responsive),C5=k.observer(({view:e,className:t="layout"})=>{const r=Te(),s=r.layouts.items(e.panelIDs),i=r.layouts.gridLayouts(e.panelIDs);return n.jsx(w5,{className:`dashboard-layout ${t}`,rowHeight:1,margin:[0,0],isDraggable:!1,isResizable:!1,cols:r.layouts.cols,layouts:i,breakpoints:r.layouts.breakpoints,onBreakpointChange:r.layouts.setCurrentBreakpoint,children:s.map(o=>n.jsx("div",{"data-grid":o.layoutProperies,className:"panel-grid-item",children:n.jsx(qo,{view:e,panel:o.panel})},o.id))})});function No(e){const t=f.useRef(null);return{ref:t,downloadScreenshot:()=>{var i;const s=(i=t.current)==null?void 0:i.querySelector(".react-grid-layout");s&&e.downloadScreenshot(s)}}}const S5=k.observer(({downloadScreenshot:e})=>{const{t}=_.useTranslation(),[r,{setTrue:s,setFalse:i}]=U.useBoolean(!1),o=ql(),l=Te(),c=()=>{const u=JSON.stringify(l.contentJSON,null,2),d=`${o.name}__${l.name}`;er(d,u)};return n.jsxs(a.Menu,{shadow:"md",width:200,trigger:"hover",openDelay:200,closeDelay:400,withinPortal:!0,position:"bottom-end",children:[n.jsx(a.Menu.Target,{children:n.jsx(a.Affix,{position:{bottom:"20px",right:"10px"},zIndex:1,children:n.jsx(a.ActionIcon,{size:"md",variant:"gradient",gradient:{from:"indigo",to:"cyan"},onMouseEnter:s,onMouseLeave:i,sx:{opacity:r?1:.6,transform:`translateX(${r?0:"2px"})`,transition:"all ease 300ms",borderRadius:"50%"},children:n.jsx(C.IconShare3,{size:"1rem"})})})}),n.jsxs(a.Menu.Dropdown,{children:[n.jsx(a.Menu.Item,{leftSection:n.jsx(C.IconCamera,{size:14}),onClick:e,children:t("common.actions.download_screenshot")}),n.jsx(a.Menu.Divider,{}),n.jsx(a.Menu.Item,{leftSection:n.jsx(C.IconDownload,{size:14}),onClick:l.queries.downloadAllData,children:t("common.actions.download_data")}),n.jsx(a.Menu.Item,{leftSection:n.jsx(C.IconCode,{size:14}),onClick:c,children:t("common.actions.download_schema")})]})]})}),Fh=k.observer(({children:e,view:t,sx:r={}})=>{const{ref:s,downloadScreenshot:i}=No(t);return n.jsxs(n.Fragment,{children:[n.jsx(a.Box,{ref:s,pt:10,pb:10,sx:r,children:e}),n.jsx(S5,{downloadScreenshot:i})]})}),Qh=k.observer(({downloadScreenshot:e})=>n.jsx(a.ActionIcon,{className:"download-screenshot-button",color:"blue",variant:"subtle",onClick:e,children:n.jsx(C.IconCamera,{size:14})})),T5=k.observer(({children:e,view:t})=>{const r=Te(),s=t.config,i=r.views.visibleViewIDs.includes(t.id),o=()=>r.views.rmVisibleViewID(t.id),{ref:l,downloadScreenshot:c}=No(t);return n.jsx(a.Modal,{size:s.width,centered:!0,opened:i,onClose:o,withCloseButton:!1,title:n.jsxs(a.Group,{justify:"space-between",px:"1rem",h:"48px",children:[n.jsx(a.Box,{children:s.custom_modal_title.value}),n.jsx(Qh,{downloadScreenshot:c})]}),trapFocus:!0,onDragStart:u=>{u.stopPropagation()},styles:{root:{position:"fixed",zIndex:200,inset:0},overlay:{zIndex:"unset"},inner:{zIndex:"unset",padding:"0 !important"},content:{border:"1px solid #efefef",maxHeight:"unset !important",overflow:"hidden"},body:{maxHeight:s.height,overflow:"auto",position:"relative",paddingBottom:10},header:{padding:0},title:{flexGrow:1}},transitionProps:{duration:0},children:n.jsx(a.Box,{ref:l,children:e})})}),k5=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},D5=k.observer(({view:e})=>{const t=Te(),r=e.config;return n.jsxs(a.Tabs,{className:"render-view-tabs",variant:r.variant,orientation:r.orientation,value:e.tab,onChange:e.setTab,styles:{root:{height:"100%",overflow:r.orientation==="horizontal"?"hidden":"auto"},panel:{padding:r.orientation==="horizontal"?"0px 0px 36px":"0",height:"100%",overflow:"auto"}},keepMounted:!1,children:[n.jsx(a.Tabs.List,{grow:r.grow,children:r.tabsInOrder.map(s=>n.jsx(a.Tabs.Tab,{value:s.id,sx:k5(s),disabled:!s.view_id,children:s.name??s.id},s.id))}),r.tabsInOrder.map(s=>{const i=t.views.findByID(s.view_id);return i?n.jsx(a.Tabs.Panel,{value:s.id,children:n.jsx(Vs,{view:i})},s.id):null})]})}),z5=k.observer(({view:e,children:t})=>{switch(e.type){case F.Modal:return n.jsx(T5,{view:e,children:t});case F.Tabs:return n.jsx(D5,{view:e});case F.Division:default:return n.jsx(Fh,{view:e,children:t})}}),I5=k.observer(({children:e,view:t})=>{const s=re().layouts,[i,o]=ze.useResizeObserver();return f.useEffect(()=>{s.setCurrentLayoutWrapperWidth(o.width)},[o.width]),n.jsx(a.Box,{sx:{height:"100%"},ref:i,children:n.jsx(a.Box,{sx:{paddingBottom:"100px",background:"white",margin:"0 auto",width:s.currentLayoutPreviewWidth??"100%",transform:`scale(${s.divisionPreviewScale})`,transformOrigin:"0 0"},children:n.jsx(Fh,{view:t,sx:{paddingTop:"0px !important",".dashboard-sticky-area > form":{paddingBottom:"5px"},".dashboard-layout":{marginTop:0,marginBottom:0}},children:e})})})});function Wh(e){return e.replace(/(vw|vh)/,"%")}const M5=k.observer(({children:e,view:t})=>{const r=t.config,{width:s,height:i}=f.useMemo(()=>({width:Wh(r.width),height:Wh(r.height)}),[r.width,r.height]),{ref:o,downloadScreenshot:l}=No(t);return n.jsx(a.Box,{sx:{height:"100%","> div:not(.mantine-Modal-root)":{height:"100%"}},children:n.jsx(a.Modal,{size:r.width,opened:!0,onClose:v.noop,withCloseButton:!1,title:n.jsxs(a.Group,{justify:"space-between",px:"1rem",h:"48px",children:[n.jsx(a.Box,{children:r.custom_modal_title.value}),n.jsx(Qh,{downloadScreenshot:l})]}),trapFocus:!0,onDragStart:c=>{c.stopPropagation()},styles:{root:{position:"relative",height:"100%"},overlay:{position:"absolute !important"},inner:{position:"relative",top:"50%",left:"50%",right:"unset",bottom:"unset",transform:"translate(-50%, -50%)",padding:"0 !important",width:s,height:i,maxHeight:i},content:{border:"1px solid #efefef",height:"100%"},body:{maxHeight:"calc(100% - 48px)",overflow:"auto"},header:{padding:0},title:{flexGrow:1}},withinPortal:!1,transitionProps:{duration:0},children:n.jsx(a.Box,{ref:o,children:e})})})}),E5=({variant:e,orientation:t})=>{const r={root:{height:"100%",overflow:"hidden"},list:{backgroundColor:"white"},tab:{},panel:{padding:"16px"}};return e==="pills"&&t==="horizontal"&&(r.tab.paddingTop="6px",r.tab.paddingBottom="6px"),t==="vertical"&&(r.tab["&.add-a-tab"]={paddingTop:"1px",paddingBottom:"1px"},r.tab["&.add-a-tab .mantine-Tabs-tabLabel"]={marginLeft:"auto",marginRight:"auto"}),r},P5=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},A5=k.observer(({view:e})=>{const{t}=_.useTranslation(),r=dt.useModals(),s=re(),i=f.useMemo(()=>s.views.options.filter(d=>d.type===F.Division),[e.id,s.views.options]),o=e.config,l=d=>r.openConfirmModal({title:`${t("view.component.tabs.tab.delete")}?`,labels:{confirm:t("common.actions.confirm"),cancel:t("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>{o.removeTab(d)},confirmProps:{color:"red"},zIndex:320}),c=o.tabs.length===0,u=o.tabsInOrder.length===0?void 0:o.tabsInOrder[0].id;return n.jsxs(a.Tabs,{className:"preview-view-tabs",variant:o.variant,orientation:o.orientation,value:e.tab||u,onChange:e.setTab,styles:E5(o),children:[n.jsxs(a.Tabs.List,{grow:o.grow,children:[o.tabsInOrder.map(d=>n.jsx(a.Tabs.Tab,{value:d.id,sx:P5(d),children:d.name??d.id},d.id)),n.jsx(a.Tabs.Tab,{onClick:o.addTab,value:"add",className:"add-a-tab",children:n.jsx(C.IconPlus,{size:18,color:"#228be6"})})]}),o.tabsInOrder.map((d,p)=>{const h=s.views.findByID(d.view_id);return n.jsxs(a.Tabs.Panel,{value:d.id,sx:{position:"relative"},children:[n.jsxs(a.Box,{sx:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:200},children:[n.jsx(a.Overlay,{backgroundOpacity:.8,color:"#FFF",blur:10,zIndex:100}),n.jsxs(a.Stack,{mx:"auto",mt:100,sx:{width:"300px",position:"relative",zIndex:200},children:[n.jsx(a.TextInput,{label:t("view.component.tabs.tab.name"),required:!0,value:d.name,onChange:x=>d.setName(x.currentTarget.value)}),n.jsx(a.Select,{label:t("view.label"),value:d.view_id,onChange:d.setViewID,data:i}),n.jsx(a.NumberInput,{label:t("view.component.tabs.tab.order"),required:!0,value:d.order,onChange:x=>d.setOrder(x||0),min:0,max:1e3,step:1}),n.jsx(a.ColorInput,{label:t("view.component.tabs.tab.color"),value:d.color,onChange:d.setColor,disabled:o.variant!=="default"}),h&&n.jsx(a.Button,{mt:20,variant:"gradient",leftSection:n.jsx(C.IconArrowsLeftRight,{size:18}),gradient:{from:"cyan",to:"indigo"},onClick:()=>s.views.setIDOfVIE(h.id),children:t("view.component.tabs.tab.switch_to_view",{name:h.name})}),n.jsx(a.Button,{mt:20,variant:"subtle",color:"red",onClick:()=>l(p),disabled:c,leftSection:n.jsx(C.IconTrash,{size:14}),children:t("view.component.tabs.tab.delete")})]})]}),h&&n.jsx(Vs,{view:h})]},d.id)})]})}),L5=k.observer(({view:e,children:t})=>{switch(e.type){case F.Modal:return n.jsx(M5,{view:e,children:t});case F.Tabs:return n.jsx(A5,{view:e});case F.Division:default:return n.jsx(I5,{view:e,children:t})}}),Rh=k.observer(function({view:t}){const s=re().layouts.divisionPreviewScale!==1;return n.jsx(Ls.Provider,{value:{viewPanelInFullScreen:v.noop,inFullScreen:!1},children:n.jsx(a.Box,{className:"dashboard-view","data-enable-scrollbar":!0,sx:{background:s?"transparent":"#efefef"},children:n.jsx(L5,{view:t,children:n.jsxs(a.Box,{sx:{position:"relative"},children:[n.jsx(a.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:n.jsx(Eh,{view:t})}),n.jsx(j5,{view:t})]})})})})}),Vs=k.observer(function({view:t}){const{fullScreenPanelID:r,setFullScreenPanelID:s}=Yl(),{viewPanelInFullScreen:i,exitFullScreen:o,inFullScreen:l,fullScreenPanel:c}=Gh(t,r,s);return n.jsx(Ls.Provider,{value:{viewPanelInFullScreen:i,inFullScreen:l},children:n.jsxs(a.Box,{className:"dashboard-view","data-enable-scrollbar":!0,sx:{height:t.type===F.Modal?"0 !important":"100%"},children:[l&&n.jsx($h,{view:t,panel:c,exitFullScreen:o}),n.jsx(z5,{view:t,children:n.jsxs(a.Box,{sx:{position:"relative"},children:[!l&&n.jsx(a.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:n.jsx(Eh,{view:t})}),!l&&n.jsx(C5,{view:t})]})})]})})});var Uh=(e=>(e.Use="use",e.Edit="edit",e))(Uh||{});const O5={[F.Division]:"Division",[F.Tabs]:"Tabs",[F.Modal]:"Modal"},Yh={[F.Division]:"rgba(255, 0, 0, 0.2)",[F.Modal]:"rgba(0, 0, 0, 0.2)",[F.Tabs]:"rgba(255, 200, 100, 0.4)"},V5={[F.Division]:"#ff4000",[F.Modal]:"#000",[F.Tabs]:"#ffad18"};function B5(e,t,r){g.addDisposer(e,g.addMiddleware(e,(s,i)=>{i(s,()=>{g.getType(s.context)===t&&s.type==="action"&&r(s.name,s.context)})}))}const Kh=g.types.compose("FiltersModel",Mo,g.types.model("FiltersModel",{previewValues:g.types.optional(g.types.frozen(),{})})).views(e=>({get idSet(){return new Set(e.current.map(t=>t.id))},get keySet(){return new Set(e.current.map(t=>t.key))},get options(){return e.current.map(t=>({label:t.label??t.id,value:t.id,_type:"filter"}))},get selects(){return e.current.filter(t=>t.type===Q.Select).map(t=>({label:t.label??t.id,value:t.id}))},get keyLabelOptions(){return e.current.map(t=>({label:t.label??t.key,value:t.key,widget:t.type}))},get sortedList(){return v.sortBy(e.current,t=>t.label.toLowerCase())}})).actions(e=>({replace(t){e.current=g.cast(t)},append(t){e.current.push(t)},appendMultiple(t){if(t.length===0)return;const r=t.filter(s=>!e.idSet.has(s.id));e.current.push(...r)},remove(t){e.current.splice(t,1)},removeByID(t){const r=e.current.findIndex(s=>s.id===t);r>=0&&e.current.splice(r,1)},updatePreviewValues(t){e.previewValues=t}})).actions(e=>{function t(){B5(e.current,vo,(r,s)=>{if(r==="setType"){const i=yh(s.config.default_value,s.config);e.setValueByKey(s.key,i),e.updatePreviewValues({...e.previewValues,[s.key]:i})}})}return{afterCreate(){t()}}}),Xh=Po.views(e=>({get canPreviewData(){return e.isTransform?e.config.dep_query_ids.length>0&&!!e.pre_process:!!e.datasource},get guideToPreviewData(){return e.isTransform?"Need to complete settings in Transform tab":"Need to pick a Data Source first"},get usage(){return e.contentModel.findQueryUsage(e.id)},get runBySet(){return new Set(e.run_by)},keyInRunBy(t){return this.runBySet.has(t)}})).actions(e=>({changeRunByRecord(t,r){const s=new Set(e.run_by);r?s.add(t):s.delete(t),e.run_by.length=0,e.run_by.push(...s)}})),Hh=g.types.compose("QueriesModel",Ao,g.types.model({current:g.types.optional(g.types.array(Xh),[])})).views(e=>({get options(){const t=e.current.map(r=>({value:r.id,label:r.name,_type:"query"}));return v.sortBy(t,r=>r.label.toLowerCase())},get optionsWithoutTransform(){const t=e.current.filter(r=>r.type!==J.Transform).map(r=>({value:r.id,label:r.name,_type:"query"}));return v.sortBy(t,r=>r.label.toLowerCase())},get sortedList(){return v.sortBy(e.current,t=>t.name.toLowerCase())}})).actions(e=>({replace(t){e.current=g.cast(t)},append(t){e.current.push(t)},appendMultiple(t){if(t.length===0)return;const r=t.filter(s=>!e.idSet.has(s.id));e.current.push(...r)},remove(t){e.current.splice(t,1)},replaceByIndex(t,r){e.current.splice(t,1,r)},removeQuery(t){const r=e.current.find(s=>s.id===t);r&&(g.detach(r),e.current.remove(r))},removeQueries(t){const r=new Set(t);e.current.forEach(i=>{r.has(i.id)&&g.detach(i)});const s=[...e.current];v.remove(s,i=>r.has(i.id)),e.current=g.cast(s)}})),Zh=Oo.views(e=>({get sortedList(){return v.sortBy(e.current,t=>t.key.toLowerCase())},get options(){const t=e.current.map(r=>({label:r.key,value:r.key,_type:"sql_snippet"}));return v.sortBy(t,r=>r.label.toLowerCase())}})).actions(e=>({replace(t){e.current=g.cast(t)},append(t){e.current.push(t)},appendMultiple(t){if(t.length===0)return;const r=t.filter(s=>!e.keySet.has(s.key));e.current.push(...r)},remove(t){e.current.splice(t,1)},removeByKey(t){const r=e.current.findIndex(s=>s.key===t);r>=0&&e.current.splice(r,1)},removeByKeys(t){const r=new Set(t);e.current.forEach(i=>{r.has(i.key)&&g.detach(i)});const s=[...e.current];v.remove(s,i=>r.has(i.key)),e.current=g.cast(s)},replaceByIndex(t,r){e.current.splice(t,1,r)}})),q5=g.types.model({data:g.types.optional(g.types.frozen(),[]),state:g.types.optional(g.types.enumeration(["idle","loading","error"]),"idle"),error:g.types.frozen()}).views(e=>({get loading(){return e.state==="loading"},get empty(){return e.data.length===0}})),N5=g.types.model({data:g.types.optional(g.types.frozen(),[]),state:g.types.optional(g.types.enumeration(["idle","loading","error"]),"idle"),error:g.types.frozen()}).views(e=>({get loading(){return e.state==="loading"},get empty(){return e.data.length===0}})),$5=g.types.model({page:g.types.optional(g.types.number,1),limit:g.types.optional(g.types.number,20),data:g.types.optional(g.types.frozen(),[]),total:g.types.optional(g.types.number,0),state:g.types.optional(g.types.enumeration(["idle","loading","error"]),"idle"),error:g.types.frozen()}).views(e=>({get keywords(){return g.getParent(e,1)},get keywordString(){const{table_name:t,table_schema:r}=g.getParent(e,1);return`${r}||${t}`}})).views(e=>({get loading(){return e.state==="loading"},get empty(){return e.data.length===0},get maxPage(){return Math.ceil(e.total/e.limit)},get offset(){return(e.page-1)*e.limit},get countSql(){const{table_name:t,table_schema:r}=e.keywords;return`
499
499
  SELECT count(*) AS total
500
500
  FROM ${r}.${t}
@@ -513,7 +513,7 @@ Variable: {{ your_var }}`,tabs:{guide:"Guide",vars:"Dashboard state & Panel vari
513
513
  value: string;
514
514
  description?: string; // optional
515
515
  }
516
- `,vg=()=>{const{t:e}=_.useTranslation(),[t,r]=f.useState(!1);return n.jsxs(n.Fragment,{children:[n.jsx(a.Button,{variant:"subtle",size:"compact-sm",onClick:()=>r(s=>!s),children:e(t?"common.actions.close":"filter.widget.common.see_data_structure")}),n.jsx(a.Collapse,{in:t,children:n.jsx(zt.CodeHighlight,{language:"typescript",withCopyButton:!1,code:mI})})]})},bI=k.observer(function({filter:t}){const{t:r}=_.useTranslation(),s=t.config,i=()=>{s.addStaticOption({label:"",value:""})},o=s.static_options,l=[...o];return n.jsxs(n.Fragment,{children:[n.jsxs(a.Group,{justify:"space-between",children:[n.jsx(a.Checkbox,{checked:s.required,onChange:c=>s.setRequired(c.currentTarget.checked),label:r("filter.widget.select.required")}),n.jsx(Dn,{filter:t})]}),n.jsx(a.TextInput,{label:r("filter.widget.select.width"),description:r("filter.widget.multi_select.width_description"),value:s.min_width,onChange:c=>s.setMinWidth(c.currentTarget.value),placeholder:"200px"}),n.jsx(a.Divider,{label:r("filter.widget.select.configure_options"),labelPosition:"center"}),n.jsxs(a.Stack,{gap:10,sx:{position:"relative",minHeight:"50px"},children:[s.usingQuery&&n.jsxs(n.Fragment,{children:[n.jsx(a.Overlay,{backgroundOpacity:.8,color:"#000",sx:{left:"-5px",right:"-5px",top:"-5px",bottom:"-5px"}}),n.jsx(a.Center,{sx:{position:"absolute",top:0,left:0,zIndex:200,height:"100%",width:"100%"},children:n.jsx(a.Text,{c:"white",size:"16px",children:r("filter.widget.common.using_query")})})]}),o.length>0&&n.jsx(a.MultiSelect,{label:r("filter.widget.select.default_selection"),data:l,value:[...s.default_value],onChange:s.setDefaultValue}),o.map((c,u)=>n.jsxs(a.Flex,{gap:10,sx:{position:"relative"},pr:"40px",children:[n.jsx(a.TextInput,{label:r("common.label"),required:!0,value:s.static_options[u].label,onChange:d=>{s.static_options[u].setLabel(d.currentTarget.value)},sx:{flexGrow:1}}),n.jsx(a.TextInput,{label:r("common.value"),required:!0,value:s.static_options[u].value,onChange:d=>{s.static_options[u].setValue(d.currentTarget.value)},sx:{flexGrow:1}}),n.jsx(a.ActionIcon,{color:"red",variant:"subtle",onClick:()=>s.removeStaticOption(u),sx:{position:"absolute",top:28,right:5},children:n.jsx(C.IconTrash,{size:16})})]},u)),n.jsx(a.Button,{mt:10,size:"xs",color:"blue",leftSection:n.jsx(C.IconPlaylistAdd,{size:20}),onClick:i,sx:{width:"50%"},mx:"auto",children:r("common.actions.add_an_option")})]}),n.jsx(a.Divider,{label:r("filter.widget.common.or_fetch_options_from_datasource"),labelPosition:"center"}),n.jsx(a.NumberInput,{value:s.default_selection_count,onChange:s.setDefaultSelectionCount,label:r("filter.widget.common.default_selection_count")}),n.jsx(Es,{value:s.options_query_id,onChange:s.setOptionsQueryID}),n.jsx(vg,{})]})}),_g={date_unit:{zh:[{label:"天",value:"day"},{label:"周",value:"week"},{label:"双周",value:"bi-week"},{label:"月",value:"month"},{label:"季度",value:"quarter"},{label:"年",value:"year"}],en:[{label:"Day",value:"day"},{label:"Week",value:"week"},{label:"Bi-Week",value:"bi-week"},{label:"Month",value:"month"},{label:"Quarter",value:"quarter"},{label:"Year",value:"year"}]}},jg=k.observer(({config:e})=>{const{t,i18n:r}=_.useTranslation(),s=()=>{e.addStaticOption({label:"",value:""})},i=f.useMemo(()=>[{label:t("filter.widget.select.preset_options.date_unit"),value:"date_unit"}],[r.language]),o=l=>{if(!l||!(l in _g))return;const c=_g[l][r.language];e.replaceStaticOptions(c),c.length>0&&e.setDefaultValue(c[0].value)};return n.jsxs(a.Group,{justify:"space-between",children:[n.jsx(a.Button,{size:"xs",color:"blue",leftSection:n.jsx(C.IconPlaylistAdd,{size:20}),onClick:s,children:t("common.actions.add_an_option")}),n.jsx(a.Select,{placeholder:t("filter.widget.select.preset_options.apply"),value:null,onChange:o,data:i,size:"xs"})]})}),yI=k.observer(({config:e})=>{const{t,i18n:r}=_.useTranslation(),s=[...e.static_options],i=f.useMemo(()=>[{label:t("filter.widget.select.no_default_selection"),value:""},...s],[r.language,s]);return s.length===0?n.jsx(jg,{config:e}):n.jsxs(n.Fragment,{children:[n.jsx(a.Select,{label:t("filter.widget.select.default_selection"),data:i,value:e.default_value,onChange:e.setDefaultValue}),s.map((o,l)=>n.jsxs(a.Flex,{gap:10,sx:{position:"relative"},pr:"40px",children:[n.jsx(a.TextInput,{label:t("common.label"),required:!0,value:e.static_options[l].label,onChange:c=>{e.static_options[l].setLabel(c.currentTarget.value)},sx:{flexGrow:1}}),n.jsx(a.TextInput,{label:t("common.value"),required:!0,value:e.static_options[l].value,onChange:c=>{e.static_options[l].setValue(c.currentTarget.value)},sx:{flexGrow:1}}),n.jsx(a.ActionIcon,{color:"red",variant:"subtle",onClick:()=>e.removeStaticOption(l),sx:{position:"absolute",top:28,right:5},children:n.jsx(C.IconTrash,{size:16})})]},l)),n.jsx(jg,{config:e})]})}),vI=k.observer(({filter:e})=>{const{t}=_.useTranslation(),r=e.config;return n.jsxs(n.Fragment,{children:[n.jsxs(a.Group,{justify:"space-between",children:[n.jsx(a.Checkbox,{checked:r.required,onChange:s=>r.setRequired(s.currentTarget.checked),label:t("filter.widget.select.required")}),n.jsx(a.Checkbox,{checked:r.clearable,onChange:s=>r.setClearable(s.currentTarget.checked),label:t("filter.widget.select.clearable")}),n.jsx(Dn,{filter:e})]}),n.jsx(a.TextInput,{label:t("filter.widget.select.width"),value:r.width,onChange:s=>r.setWidth(s.currentTarget.value),placeholder:"200px"}),n.jsx(a.Divider,{label:t("filter.widget.select.configure_options"),labelPosition:"center"}),n.jsxs(a.Stack,{gap:10,sx:{position:"relative",minHeight:"50px"},children:[r.usingQuery&&n.jsxs(n.Fragment,{children:[n.jsx(a.Overlay,{backgroundOpacity:.8,color:"#000",sx:{left:"-5px",right:"-5px",top:"-5px",bottom:"-5px"}}),n.jsx(a.Center,{sx:{position:"absolute",top:0,left:0,zIndex:200,height:"100%",width:"100%"},children:n.jsx(a.Text,{c:"white",size:"16px",children:t("filter.widget.common.using_query")})})]}),n.jsx(yI,{config:r})]}),n.jsx(a.Divider,{label:t("filter.widget.common.or_fetch_options_from_datasource"),labelPosition:"center"}),n.jsx(a.Checkbox,{checked:r.default_selection_count===1,onChange:s=>r.setDefaultSelectionCount(s.currentTarget.checked?1:0),label:t("filter.widget.select.select_first_option_by_default")}),n.jsx(Es,{value:r.options_query_id,onChange:r.setOptionsQueryID}),n.jsx(vg,{})]})}),_I=k.observer(function({filter:t}){const{t:r}=_.useTranslation(),s=t.config;return n.jsxs(n.Fragment,{children:[n.jsxs(a.Group,{children:[n.jsx(a.TextInput,{label:r("filter.widget.text_input.default_value"),value:s.default_value,onChange:i=>{s.setDefaultValue(i.currentTarget.value)},sx:{flexGrow:1}}),n.jsx(a.Box,{mt:22,children:n.jsx(Dn,{filter:t})})]}),n.jsx(a.Checkbox,{checked:s.required,onChange:i=>s.setRequired(i.currentTarget.checked),label:r("filter.widget.text_input.required")})]})}),jI=k.observer(function({filter:t}){const{t:r}=_.useTranslation();return n.jsxs(a.Box,{sx:{maxWidth:"480px"},children:[n.jsx(a.Text,{pt:"0",pb:"md",c:"gray",size:"sm",children:r("common.titles.config")}),n.jsx(zt.CodeHighlight,{mt:22,language:"json",withCopyButton:!1,code:JSON.stringify(t,null,4)})]})}),wI={[Q.Select]:vI,[Q.MultiSelect]:bI,[Q.TreeSelect]:v3,[Q.TreeSingleSelect]:T3,[Q.TextInput]:_I,[Q.Checkbox]:gI,[Q.DateRange]:xI},rn={[Q.Select]:"filter.widget.names.select",[Q.MultiSelect]:"filter.widget.names.multi_select",[Q.TreeSelect]:"filter.widget.names.tree_select",[Q.TreeSingleSelect]:"filter.widget.names.tree_single_select",[Q.TextInput]:"filter.widget.names.text_input",[Q.Checkbox]:"filter.widget.names.checkbox",[Q.DateRange]:"filter.widget.names.date_range"},CI=k.observer(function({filter:t}){const{t:r,i18n:s}=_.useTranslation(),i=re(),o=f.useMemo(()=>wI[t.type],[t.type]),l=f.useMemo(()=>[{label:r(rn[Q.Select]),value:"select"},{label:r(rn[Q.MultiSelect]),value:"multi-select"},{label:r(rn[Q.TreeSelect]),value:"tree-select"},{label:r(rn[Q.TreeSingleSelect]),value:"tree-single-select"},{label:r(rn[Q.TextInput]),value:"text-input"},{label:r(rn[Q.Checkbox]),value:"checkbox"},{label:r(rn[Q.DateRange]),value:"date-range"}],[s.language]);return n.jsxs(a.Group,{grow:!0,gap:20,align:"top",children:[n.jsxs(a.Box,{sx:{maxWidth:"600px"},children:[n.jsx(a.Text,{pb:"md",c:"gray",size:"sm",children:r("common.titles.edit")}),n.jsxs(a.Stack,{children:[n.jsxs(a.Group,{wrap:"nowrap",children:[n.jsx(a.NumberInput,{label:r("filter.field.order"),required:!0,value:t.order,onChange:t.setOrder,hideControls:!0,sx:{flexGrow:"1 !important"}}),t.auto_submit_supported&&n.jsx(a.Checkbox,{label:r("filter.field.auto_submit"),checked:t.auto_submit,onChange:c=>t.setAutoSubmit(c.currentTarget.checked),mt:22})]}),n.jsx(a.MultiSelect,{label:r("filter.field.visible_in"),data:i.views.options,value:[...t.visibleInViewsIDs],onChange:t.setVisibleInViewsIDs}),n.jsx(a.TextInput,{label:r("common.key"),placeholder:r("filter.field.key_placeholder"),required:!0,value:t.key,onChange:c=>{t.setKey(c.currentTarget.value)}}),n.jsx(a.TextInput,{label:r("common.label"),placeholder:r("filter.field.label_placeholder"),required:!0,value:t.label,onChange:c=>{t.setLabel(c.currentTarget.value)}}),n.jsx(a.Select,{label:r("filter.field.widget"),data:l,required:!0,value:t.type,onChange:t.setType,maxDropdownHeight:500}),n.jsx(a.Divider,{mb:0,mt:10,variant:"dashed",labelPosition:"center"}),n.jsx(o,{filter:t})]})]}),n.jsx(jI,{filter:t})]})}),SI=k.observer(({id:e})=>{const{t}=_.useTranslation(),r=dt.useModals(),s=se(),i=re();if(e==="")return null;const o=i.filters.findByID(e);if(!o)return n.jsxs(a.Text,{size:"14px",children:["Filter by ID[",e,"] is not found"]});const l=()=>{s.editor.setPath(["_FILTERS_",""])},c=()=>{r.openConfirmModal({title:`${t("filter.delete")}?`,labels:{confirm:t("common.actions.confirm"),cancel:t("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>{i.filters.removeByID(e),l()},confirmProps:{color:"red"},zIndex:320})};return n.jsxs(a.Stack,{sx:{maxWidth:"1100px",height:"100vh"},gap:"sm",pb:30,children:[n.jsx(a.Group,{justify:"flex-end",pt:10,children:n.jsx(a.Button,{size:"xs",color:"red",leftSection:n.jsx(C.IconTrash,{size:16}),onClick:c,children:t("filter.delete")})}),n.jsx(a.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:n.jsx(CI,{filter:o})})]})}),TI=k.observer(()=>{const{t:e}=_.useTranslation(),[t,r]=f.useState([]),s=se(),i=d=>{s.editor.setPath(["_FILTERS_",d])},o=()=>{s.content.filters.downloadSchema(t)},l=f.useMemo(()=>s.content.filters.sortedList.map(d=>d.id),[s.content.filters.sortedList]),c=()=>{r(l)},u=()=>{r([])};return n.jsxs(a.Stack,{sx:{height:"100%"},gap:"sm",pb:"59px",children:[n.jsx(a.Box,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:n.jsx(a.Text,{size:"sm",px:"md",ta:"left",sx:{userSelect:"none",cursor:"default"},children:e("filter.manage")})}),n.jsx(a.Flex,{justify:"space-between",align:"center",px:12,children:n.jsxs(a.Group,{justify:"flex-start",children:[n.jsxs(a.Button.Group,{children:[n.jsx(a.Button,{variant:"default",size:"xs",onClick:c,children:e("common.actions.select_all")}),n.jsx(a.Button,{variant:"default",size:"xs",onClick:u,children:e("common.actions.clear_selection")})]}),n.jsx(a.Button,{size:"xs",color:"blue",leftSection:n.jsx(C.IconCode,{size:14}),disabled:t.length===0,onClick:o,children:e("common.actions.download_schema")})]})}),n.jsx(a.Box,{sx:{flexGrow:1,overflow:"auto"},children:n.jsx(a.Checkbox.Group,{size:"xs",value:t,onChange:r,children:n.jsxs(a.Table,{fz:"sm",highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[n.jsx(a.Table.Thead,{children:n.jsxs(a.Table.Tr,{children:[n.jsx(a.Table.Th,{style:{width:"40px"}}),n.jsx(a.Table.Th,{style:{width:"300px"},children:e("common.label")}),n.jsx(a.Table.Th,{children:e("common.key")}),n.jsx(a.Table.Th,{style:{width:"100px"},children:e("filter.field.widget")}),n.jsx(a.Table.Th,{style:{width:"300px",paddingLeft:"24px"},children:e("common.action")})]})}),n.jsx(a.Table.Tbody,{children:s.content.filters.sortedList.map(d=>n.jsxs(a.Table.Tr,{children:[n.jsx(a.Table.Td,{children:n.jsx(a.Checkbox,{value:d.id,styles:{input:{cursor:"pointer"}}})}),n.jsx(a.Table.Td,{children:d.label}),n.jsx(a.Table.Td,{children:d.key}),n.jsx(a.Table.Td,{children:e(rn[d.type])}),n.jsx(a.Table.Td,{children:n.jsx(a.Button,{variant:"subtle",size:"xs",onClick:()=>i(d.id),children:e("common.actions.open")})})]},d.id))})]})})})]})}),kI=k.observer(()=>{const{t:e}=_.useTranslation(),t=re(),[r,s]=f.useState(()=>JSON.stringify(t.mock_context.current,null,4)),i=()=>{try{t.mock_context.replace(JSON.parse(r))}catch(l){$t.showNotification({title:"Failed",message:l.message,color:"red"})}},o=f.useMemo(()=>{try{return JSON.stringify(JSON.parse(r))!==JSON.stringify(t.mock_context.current)}catch{return!1}},[r,t.mock_context.current]);return n.jsxs(a.Stack,{sx:{border:"1px solid #eee",borderLeft:"none",borderRight:"none",flexGrow:1,maxWidth:"unset"},children:[n.jsx(a.Group,{justify:"flex-start",pl:"md",py:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",flexGrow:0},children:n.jsx(a.Text,{size:"sm",fw:500,children:e("mock_context.label")})}),n.jsx(a.Group,{grow:!0,px:"md",pb:"md",pt:0,sx:{flexGrow:1,position:"relative",alignItems:"flex-start"},children:n.jsxs(a.Stack,{gap:10,sx:{maxWidth:"unset !important"},children:[n.jsxs(a.Group,{justify:"flex-start",children:[n.jsx(a.Text,{size:"sm",children:e("mock_context.hint")}),n.jsx(a.Button,{color:"green",size:"compact-sm",leftSection:n.jsx(C.IconDeviceFloppy,{size:16}),onClick:i,disabled:!o,children:e("common.actions.save")})]}),n.jsx(a.JsonInput,{validationError:"Invalid json",formatOnBlur:!0,autosize:!0,minRows:30,value:r,onChange:s,sx:{flexGrow:1}})]})})]})}),DI=k.observer(()=>{const{t:e}=_.useTranslation(),{panel:t}=Pe();return n.jsx(bn,{label:e("panel.panel_description"),value:t.description,onChange:t.setDescription,styles:{root:{flexGrow:1}}},t.id)}),zI=k.observer(()=>{const{t:e}=_.useTranslation(),{panel:t}=Pe(),r=Te().layouts.findItemByPanelID(t.id),{style:s}=t;return n.jsx(n.Fragment,{children:n.jsxs(a.Stack,{gap:20,children:[n.jsxs(a.Group,{grow:!0,align:"top",children:[n.jsx(a.NumberInput,{label:e("panel.style.width"),min:1,max:36,step:1,decimalScale:0,rightSection:n.jsx(a.Text,{size:"12px",children:e("panel.style.width_postfix")}),styles:{section:{width:"auto",maxWidth:"100px",paddingRight:"14px",justifyContent:"flex-end"}},value:r.w,onChange:i=>{typeof i!="string"&&r.setWidth(i)}}),n.jsx(a.NumberInput,{label:e("panel.style.height"),rightSection:n.jsx(a.Text,{size:"12px",children:e("panel.style.height_postfix")}),styles:{section:{width:"40px"}},value:r.h,onChange:i=>{typeof i!="string"&&r.setHeight(i)}})]}),n.jsx(a.Checkbox,{ml:6,label:e("panel.style.border"),checked:s.border.enabled,onChange:i=>s.border.setEnabled(i.currentTarget.checked)})]})})}),II=()=>n.jsxs("span",{className:"mantine-103svbs mantine-InputWrapper-required mantine-Select-required","aria-hidden":"true",children:[" ","*"]}),MI=k.observer(()=>{const{t:e}=_.useTranslation(),{panel:t}=Pe(),{name:r}=t,[s,i]=ze.useInputState(r),o=r!==s,l=f.useCallback(()=>{o&&t.setName(s)},[o,s]);f.useEffect(()=>{i(r)},[r]);const c=!s.trim();return n.jsxs(a.Stack,{gap:4,children:[n.jsxs(a.Group,{align:"center",children:[n.jsxs(a.Text,{size:"14px",fw:500,children:[e("panel.panel_name"),n.jsx(II,{})]}),n.jsx(a.ActionIcon,{variant:"subtle",color:"blue",disabled:!o||c,onClick:l,children:n.jsx(C.IconDeviceFloppy,{size:18})})]}),n.jsx(a.TextInput,{value:s,onChange:i,required:!0})]})}),EI=k.observer(()=>{const{t:e}=_.useTranslation(),{panel:t}=Pe();return n.jsx(a.Stack,{gap:6,mb:10,children:n.jsxs(a.Group,{pl:6,justify:"flex-start",gap:20,children:[n.jsx(a.Checkbox,{size:"sm",checked:t.title.show,onChange:r=>t.title.setShow(r.currentTarget.checked),label:e("panel.show_title"),sx:{userSelect:"none"}}),n.jsx(a.Checkbox,{size:"sm",checked:!0,disabled:!0,label:e("panel.use_name_as_title")})]})})});function PI(){const{t:e}=_.useTranslation();return n.jsxs(a.Stack,{sx:{height:"100%"},children:[n.jsx(zI,{}),n.jsx(a.Divider,{label:e("common.info"),labelPosition:"center",variant:"dashed"}),n.jsx(MI,{}),n.jsx(EI,{}),n.jsx(DI,{})]})}const AI={width:"fit-content",minWidth:"100%",tableLayout:"fixed",tr:{width:"fit-content"},th:{position:"relative"},"th, td":{wordBreak:"break-word"},".resizer":{position:"absolute",right:0,top:"50%",transform:"translateY(-50%)",cursor:"col-resize",userSelect:"none",touchAction:"none"},".resizer.isResizing":{color:"#228be6",opacity:"1",backgroundColor:"rgb(248, 249, 250)"},"@media (hover: hover)":{".resizer":{opacity:"0"},"*:hover > .resizer":{color:"#228be6",opacity:"1"}}};function wg({data:e}){const t=f.useMemo(()=>{if(!Array.isArray(e)||e.length===0)return[];const s=We.createColumnHelper();return Object.keys(e[0]).map(i=>s.accessor(i,{cell:o=>o.getValue()}))},[e]),r=We.useReactTable({data:e,columns:t,columnResizeMode:"onChange",getCoreRowModel:We.getCoreRowModel()});return e.length===0?n.jsx(a.Box,{sx:{height:"5em"}}):n.jsx(Ie,{children:n.jsxs(a.Table,{sx:AI,children:[n.jsx(a.Table.Thead,{children:r.getHeaderGroups().map(s=>n.jsx(a.Table.Tr,{children:s.headers.map(i=>n.jsxs(a.Table.Th,{style:{width:i.getSize()},children:[i.isPlaceholder?null:We.flexRender(i.column.columnDef.header,i.getContext()),n.jsx(a.ActionIcon,{variant:"subtle",onMouseDown:i.getResizeHandler(),onTouchStart:i.getResizeHandler(),className:`resizer ${i.column.getIsResizing()?"isResizing":""}`,children:n.jsx(C.IconArrowBarToRight,{})})]},i.id))},s.id))}),n.jsx(a.Table.Tbody,{children:r.getRowModel().rows.map(s=>n.jsx(a.Table.Tr,{children:s.getVisibleCells().map(i=>n.jsx(a.Table.Td,{children:n.jsx(Ie,{children:typeof i.getValue()=="object"?n.jsx("pre",{children:JSON.stringify(i.getValue(),null,2)}):We.flexRender(i.column.columnDef.cell,i.getContext())})},i.id))},s.id))})]})})}const LI=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],OI={section:{"&[data-position=left]":{width:"70px",textAlign:"center"}},input:{paddingLeft:"70px"}},VI=({data:e,page:t,setPage:r,limit:s,setLimit:i})=>{const{t:o}=_.useTranslation(),l=e.length,c=Math.ceil(l/s),u=p=>{p&&(r(1),i(Number(p)))};if(l===0)return null;const d=c===1&&l<=10;return n.jsxs(a.Group,{pt:10,px:10,justify:"space-between",children:[n.jsxs(a.Group,{justify:"flex-start",children:[c>1&&n.jsx(a.Pagination,{size:"sm",value:t,onChange:r,total:c,withEdges:c>7,styles:{control:{height:"30px"}}}),!d&&n.jsx(a.Select,{leftSection:n.jsx(a.Text,{ta:"center",c:"dimmed",size:"14px",children:o("common.pagination.page_size")}),size:"xs",styles:OI,data:LI,value:String(s),onChange:u})]}),n.jsx(a.Group,{justify:"flex-end",children:n.jsx(a.Text,{c:"dimmed",my:0,size:"14px",children:o("common.pagination.total_rows",{total:l})})})]})},BI=md(({data:e,loading:t})=>{const[r,s]=f.useState(1),[i,o]=f.useState(20),l=f.useMemo(()=>{const c=(r-1)*i,u=c+i;return e.slice(c,u)},[e,r,i]);return n.jsxs(Ie,{children:[n.jsx(VI,{data:e,page:r,setPage:s,limit:i,setLimit:o}),n.jsxs(a.Box,{py:10,sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[n.jsx(a.LoadingOverlay,{visible:t,overlayProps:{blur:2}}),n.jsx(wg,{data:l})]})]})}),qI=k.observer(({queryID:e})=>{const{t}=_.useTranslation(),r=Te(),s=f.useMemo(()=>r.queries.findByID(e),[r,e]);if(!s||s.state==="loading")return null;const{error:i,metricQueryPayloadErrorString:o,stateMessage:l}=s;return i||o?n.jsx(a.Text,{mt:10,c:"red",size:"md",ta:"center",ff:"monospace",children:i??o}):l?n.jsx(a.Text,{size:"sm",mt:10,c:"gray",ta:"center",children:t(l)}):null}),Uo=k.observer(({id:e,moreActions:t,refreshOnMount:r})=>{const{t:s}=_.useTranslation(),i=Te(),{data:o,state:l}=i.getDataStuffByID(e),c=l==="loading",u=f.useCallback(()=>{i.queries.refetchDataByQueryID(e)},[e,i]),d=()=>{i.queries.downloadDataByQueryID(e)};f.useEffect(()=>{r&&u()},[u,r]);const p=!Array.isArray(o)||o.length===0;return n.jsxs(a.Stack,{gap:0,sx:{height:"100%",border:"1px solid #eee"},children:[n.jsxs(a.Group,{justify:"space-between",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[n.jsx(a.Group,{justify:"flex-start",children:n.jsx(a.Text,{size:"sm",fw:500,children:s("data.preview_data")})}),n.jsxs(a.Group,{pr:15,children:[t,n.jsx(a.ActionIcon,{variant:"subtle",color:"blue",disabled:c,onClick:u,children:n.jsx(C.IconRefresh,{size:16})}),n.jsx(a.ActionIcon,{variant:"subtle",color:"blue",disabled:c||p,onClick:d,children:n.jsx(C.IconDownload,{size:16})})]})]}),n.jsxs(a.Box,{pb:20,sx:{position:"relative",flexGrow:1,overflow:"auto"},children:[n.jsx(qI,{queryID:e}),n.jsx(BI,{data:o,loading:c})]})]})}),NI=k.observer(function(){const{t}=_.useTranslation(),r=se(),s=re(),{panel:i}=Pe(),[o,l]=f.useState(!1),c=d=>{r.editor.setPath(["_QUERIES_",d])},u=i.queryIDs.length;return n.jsxs(n.Fragment,{children:[n.jsx(a.Drawer,{opened:o,onClose:()=>l(!1),title:t("panel.settings.choose_queries"),padding:"xl",size:500,zIndex:320,children:n.jsx(a.Checkbox.Group,{value:[...i.queryIDs],onChange:i.setQueryIDs,children:n.jsx(a.Stack,{gap:"lg",children:s.queries.options.map(d=>n.jsx(a.Checkbox,{label:d.label,value:d.value},d.value))})})}),n.jsxs(a.Stack,{gap:6,children:[n.jsx(a.Group,{justify:"flex-start",children:n.jsx(a.Button,{variant:"light",size:"sm",leftSection:n.jsx(C.IconLine,{size:16}),onClick:()=>l(!0),children:t(u===0?"panel.settings.need_to_choose_queries":"panel.settings.choose_queries")})}),u===1&&n.jsx(Uo,{id:i.queryIDs[0],moreActions:n.jsx(a.Tooltip,{label:t("query.open"),children:n.jsx(a.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>c(i.queryIDs[0]),children:n.jsx(C.IconArrowCurveRight,{size:16})})})}),u>1&&n.jsxs(a.Tabs,{defaultValue:i.queryIDs[0],children:[n.jsx(a.Tabs.List,{children:i.queries.map(d=>n.jsx(a.Tabs.Tab,{value:d.id,children:d.name},d.id))}),i.queries.map(d=>n.jsx(a.Tabs.Panel,{value:d.id,children:n.jsx(Uo,{id:d.id,moreActions:n.jsx(a.Tooltip,{label:t("query.open"),children:n.jsx(a.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>c(d.id),children:n.jsx(C.IconArrowCurveRight,{size:16})})})})},d.id))]})]})]})}),$I=k.observer(()=>{const{panel:e}=He();return e.title.show?n.jsx(a.Group,{grow:!0,justify:"center",className:"panel-title-wrapper",sx:{flexGrow:1},children:n.jsx(a.Text,{size:"sm",ta:"center",lineClamp:1,className:"panel-title-text",children:e.title.show?e.name:""})}):null}),GI=k.observer(()=>{const{panel:e}=He();return n.jsx(Ie,{children:n.jsxs(a.Box,{className:`panel-root ${e.title.show?"panel-root--show-title":""}`,p:0,sx:{border:"1px solid",borderColor:e.style.border.enabled?"#e9ecef":"transparent",flexGrow:0,flexShrink:0,width:"600px !important",height:"450px !important"},children:[n.jsx(a.Box,{className:"panel-description-popover-wrapper",children:n.jsx(Vo,{})}),n.jsx($I,{}),n.jsx(Bo,{panel:e})]})})});function FI(){const{t:e}=_.useTranslation(),{vizManager:t}=f.useContext(tn);return f.useMemo(()=>v.orderBy(Object.entries(v.groupBy(t.availableVizList,"displayGroup")),[i=>i[0]],["asc"]).map(([i,o])=>{const l=o.map(c=>({value:c.name,label:e(c.displayName??it.name)}));return{group:e(i??"ungrouped"),items:v.orderBy(l,[c=>c.label],["asc"])}}),[t])}const QI=k.observer(({value:e,submit:t})=>{const{t:r}=_.useTranslation(),[s,i]=ze.useInputState(e);f.useEffect(()=>{i(e)},[e]);const o=FI(),l=e!==s;return n.jsx(a.Select,{label:r("visualization.component"),value:s,searchable:!0,onChange:i,data:o,rightSection:n.jsx(a.ActionIcon,{variant:"filled",color:"green",disabled:!l,onClick:()=>t(s),styles:{root:{pointerEvents:"all"}},children:n.jsx(C.IconDeviceFloppy,{size:20})}),maxDropdownHeight:600})}),Cg=[];function WI(e,t){try{return e.resolveComponent(t).createConfig()}catch{return null}}function RI(){const{data:e,panel:{variables:t,viz:r,title:s,name:i,queryIDs:o,description:l,id:c}}=Pe(),{vizManager:u}=f.useContext(tn),d={name:i,title:s,description:l,viz:r,queryIDs:o,id:c},p=Ah(d);try{return u.resolveComponent(d.viz.type),n.jsx(Ms,{configure:p,children:n.jsx(c5,{variables:t,setVizConf:r.setConf,panel:d,vizManager:u,data:e})})}catch(h){return console.info(v.get(h,"message")),null}}const UI=k.observer(()=>{const{data:e,panel:{viz:t}}=Pe(),{vizManager:r}=f.useContext(tn),s=f.useCallback(d=>{if(d===t.type)return;const p=WI(r,d);t.setType(d),t.setConf(p||{})},[t.type]),i=d=>{try{t.setConf(JSON.parse(d))}catch(p){console.error(p)}},o=f.useMemo(()=>{var d;return(d=Cg.find(p=>p.value===t.type))==null?void 0:d.Panel},[t.type,Cg]),l=RI(),c=o?f.createElement(o,{data:e,conf:t.conf,setConf:t.setConf}):null,u=l||c;return n.jsxs(a.Stack,{align:"stretch",sx:{height:"100%",overflow:"hidden"},children:[n.jsx(QI,{submit:s,value:t.type}),n.jsxs(Ie,{children:[n.jsx(a.Stack,{pb:10,sx:{flexGrow:1,maxHeight:"100%",overflow:"auto"},children:u}),!u&&n.jsx(a.JsonInput,{minRows:20,label:"Config",value:JSON.stringify(t.conf,null,2),onChange:i})]})]})}),YI=k.observer(({panel:e,sourceViewID:t})=>{const{t:r}=_.useTranslation(),s=re(),[i,o]=f.useState(t);f.useEffect(()=>{o(t)},[t]);const[l,{open:c,close:u}]=ze.useDisclosure(!1),d=()=>{e.moveToView(t,i),u()};return n.jsxs(n.Fragment,{children:[n.jsx(a.Button,{size:"xs",variant:"subtle",color:"blue",onClick:c,leftSection:n.jsx(C.IconBoxMultiple,{size:14}),children:r("panel.settings.change_view")}),n.jsx(a.Modal,{opened:l,onClose:u,title:r("panel.settings.change_view_title"),zIndex:320,children:n.jsxs(a.Stack,{sx:{maxHeight:"calc(100vh - 185px)",overflow:"hidden"},children:[n.jsx(a.Radio.Group,{value:i,onChange:o,pb:10,sx:{flexGrow:1,maxHeight:"calc(100vh - 185px - 30px)",overflow:"auto"},children:n.jsx(a.Stack,{gap:"xs",children:s.views.options.map(p=>n.jsx(a.Radio,{value:p.value,label:p.label},p.value))})}),n.jsxs(a.Group,{wrap:"nowrap",justify:"space-between",sx:{flexGrow:0,flexShrink:0},children:[n.jsx(a.Button,{size:"xs",color:"red",leftSection:n.jsx(C.IconX,{size:14}),onClick:u,children:r("common.actions.cancel")}),n.jsx(a.Button,{size:"xs",color:"blue",leftSection:n.jsx(C.IconDeviceFloppy,{size:14}),onClick:d,disabled:i===t,children:r("common.actions.confirm")})]})]})})]})}),KI=k.observer(({sx:e={}})=>{const{t}=_.useTranslation(),r=Te(),{panel:s}=He(),i=r.dashboardState,o=(()=>{const l={...i,...s.variableStrings};return JSON.stringify(l,null,2)})();return n.jsx(a.Stack,{sx:{overflow:"hidden",...e},children:n.jsxs(a.Tabs,{defaultValue:"vars",keepMounted:!1,children:[n.jsxs(a.Tabs.List,{children:[n.jsx(a.Tabs.Tab,{value:"guide",leftSection:n.jsx(C.IconAlertCircle,{size:14}),children:t("panel.variable.guide.tabs.guide")}),n.jsx(a.Tabs.Tab,{value:"vars",leftSection:n.jsx(C.IconVariable,{size:14}),children:t("panel.variable.guide.tabs.vars")})]}),n.jsx(a.Tabs.Panel,{value:"guide",pt:"xs",children:n.jsx(zt.CodeHighlight,{language:"sql",sx:{width:"100%"},withCopyButton:!1,code:t("panel.variable.guide.text")})}),n.jsx(a.Tabs.Panel,{value:"vars",pt:"xs",children:n.jsx(zt.CodeHighlight,{language:"json",sx:{width:"100%"},withCopyButton:!1,code:o})})]})})}),Yo={name:"new_var",size:"1rem",weight:"initial",color:{type:"static",staticColor:"Red"},data_field:"",aggregation:{type:"sum",config:{},fallback:"0"},formatter:{output:"number",mantissa:0,trimMantissa:!1,average:!1}};class XI{constructor(t){N(this,"panel");N(this,"selected");this.panel=t,t.variables.length>0&&(this.selected=t.variables[0]),te.makeAutoObservable(this,{},{deep:!1,autoBind:!0})}get variables(){return this.panel.variables}get variableOptions(){return this.panel.variables.map(t=>({label:t.name,value:t.name,description:t.aggregation.type}))}addNew(){const t=this.panel.variables.filter(r=>r.name.startsWith(Yo.name)).length;this.panel.addVariable(v.cloneDeep({...Yo,name:`${Yo.name}${t||""}`})),this.selected=v.last(this.panel.variables)}select(t){this.selected=t}selectByName(t){if(!t){console.warn("Unexpected null name when calling selectByName");return}const r=this.variables.find(s=>s.name===t);if(!r){console.error(`Variable by name[${t}] not found`);return}this.selected=r}remove(t){this.selected===t&&(this.selected=void 0);const r=this.panel.variables.indexOf(t);if(this.panel.removeVariable(t),!this.selected&&!v.isEmpty(this.panel.variables)){const s=Math.min(this.panel.variables.length-1,r);this.selected=this.panel.variables[s]}}}function HI(){const{panel:e}=Pe();return U.useCreation(()=>new XI(e),[e])}const ZI=f.forwardRef(function({value:t,onChange:r,remove:s},i){const{t:o}=_.useTranslation(),l=(c,u)=>{const d=v.cloneDeep(t);v.set(d,c,u),r(d)};return n.jsxs(a.Stack,{ref:i,children:[n.jsxs(a.Stack,{gap:"xs",px:"sm",py:"md",sx:{border:"1px solid #e9ecef"},children:[n.jsxs(a.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(a.TextInput,{label:o("common.name"),required:!0,value:t.name,onChange:c=>l("name",c.currentTarget.value)}),n.jsx(R,{label:o("common.data_field"),required:!0,value:t.data_field,onChange:c=>l("data_field",c)})]}),n.jsx(Va,{label:o("panel.variable.aggregation.label"),pt:0,value:t.aggregation,onChange:c=>l("aggregation",c),withFallback:!0}),t.aggregation.type!=="custom"&&n.jsxs(n.Fragment,{children:[n.jsx(a.Divider,{mt:"xl",mb:0,label:o("numbro.format.label"),labelPosition:"center",variant:"dashed"}),n.jsx(Tt,{value:t.formatter,onChange:c=>l("formatter",c)})]})]}),n.jsx(a.Button,{mt:20,leftSection:n.jsx(C.IconTrash,{size:16}),color:"red",variant:"light",onClick:s,children:o("panel.variable.delete")})]})}),JI=k.observer(e=>{const{t}=_.useTranslation(),r=U.useCreation(()=>Dh(e.variable),[e.variable]),s=()=>e.uiModel.remove(e.variable);return n.jsxs(a.Stack,{"data-testid":"variable-editor",align:"stretch",children:[n.jsxs(a.Group,{justify:"space-between",children:[n.jsx(a.Button,{variant:"subtle",size:"xs",disabled:!r.changed,color:"red",onClick:r.reset,leftSection:n.jsx(C.IconRecycle,{size:18}),children:t("common.actions.revert_changes")}),n.jsx(a.Button,{variant:"filled",size:"xs",disabled:!r.changed,color:"green",onClick:r.commit,leftSection:n.jsx(C.IconDeviceFloppy,{size:18}),children:t("common.actions.save_changes")})]}),n.jsx(ZI,{value:g.getSnapshot(r.copy),onChange:r.update,remove:s})]})});k.observer(e=>{const{uiModel:t}=e;return n.jsx(a.Stack,{className:"var-list",children:t.variables.map(r=>n.jsx(a.Button,{variant:t.selected===r?"filled":"subtle",color:"gray",onClick:()=>t.select(r),children:r.name},r.name))})});const eM=k.observer(({model:e})=>{const{t}=_.useTranslation();return n.jsx(a.Overlay,{color:"#fff",backgroundOpacity:1,sx:{position:"absolute"},children:n.jsx(a.Button,{variant:"light",size:"xs",leftSection:n.jsx(C.IconPlus,{size:16}),onClick:e.addNew,sx:{flexGrow:0,flexShrink:0,alignSelf:"flex-end",height:"38px"},children:t("panel.variable.add")})})}),tM=k.observer(()=>{var r;const{t:e}=_.useTranslation(),t=HI();return t.variableOptions.length===0?n.jsx(eM,{model:t}):n.jsxs(a.Stack,{pb:20,children:[n.jsxs(a.Group,{justify:"flex-start",children:[n.jsx(a.Select,{label:e("panel.variable.labels"),data:t.variableOptions,value:(r=t.selected)==null?void 0:r.name,onChange:t.selectByName,maxDropdownHeight:600,sx:{flexGrow:1}}),n.jsx(a.Button,{variant:"light",size:"xs",leftSection:n.jsx(C.IconPlus,{size:16}),onClick:t.addNew,sx:{flexGrow:0,flexShrink:0,alignSelf:"flex-end",height:"38px"},children:e("panel.variable.add")})]}),n.jsx(a.Divider,{variant:"dashed"}),t.selected?n.jsx(JI,{uiModel:t,variable:t.selected}):n.jsx("span",{children:"Select or create a new variable on right side"})]})}),nM={root:{flexGrow:1,width:"100%",minWidth:"1200px",overflow:"hidden"},panel:{width:"100%",minWidth:"1200px",height:"calc(100% - 44px)",padding:10,overflow:"auto"}},Ko=({children:e})=>n.jsxs(a.Group,{wrap:"nowrap",grow:!0,justify:"flex-start",gap:20,sx:{width:"100%",height:"100%",position:"relative"},children:[n.jsx(a.Box,{sx:{maxWidth:"calc(100% - 610px - 10px)",height:"100%",overflow:"auto"},children:e}),n.jsxs(a.Stack,{justify:"flex-start",sx:{alignSelf:"flex-start",width:"600px",flexGrow:0,flexShrink:0},children:[n.jsx(GI,{}),n.jsx(a.Box,{sx:{flexGrow:1},children:n.jsx(KI,{})})]})]});function rM(e){return!["richText","button"].includes(e)}const sM=k.observer(({panel:e})=>{const{t}=_.useTranslation(),r=dt.useModals(),s=se(),i=re(),[o,l]=f.useState(s.editor.panelTab),c=e.queries,d=rM(e.viz.type)&&e.dataLoading,p=d||e.queryErrors.length>0||e.queryStateMessages!==""||c.length===0,h=s.editor.path[1];f.useEffect(()=>{l(j=>p&&j==="Visualization"?"Data":j)},[e.id,p]);const x=f.useCallback(j=>{l(j),s.editor.setPanelTab(o)},[]),b=()=>{s.editor.setPath(["_VIEWS_",h])},m=()=>r.openConfirmModal({title:`${t("panel.delete")}?`,labels:{confirm:t("common.actions.confirm"),cancel:t("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>{i.removePanelByID(e.id,h),b()},confirmProps:{color:"red"},zIndex:320});return n.jsxs(ii,{value:{panel:e,data:e.data,loading:d,errors:e.queryErrors,downloadPanelScreenshot:()=>{}},children:[n.jsxs(a.Group,{px:16,justify:"space-between",sx:{borderBottom:"1px solid #eee"},children:[n.jsx(a.Text,{size:"sm",pt:9,pb:8,children:e.name}),n.jsxs(a.Group,{justify:"flex-end",wrap:"nowrap",children:[n.jsx(YI,{panel:e,sourceViewID:h}),n.jsx(a.Button,{size:"xs",variant:"subtle",color:"red",onClick:m,leftSection:n.jsx(C.IconTrash,{size:14}),children:t("panel.delete")})]})]}),n.jsxs(a.Tabs,{value:o,onChange:x,keepMounted:!1,styles:nM,children:[n.jsxs(a.Tabs.List,{children:[n.jsx(a.Tabs.Tab,{value:"Data",leftSection:n.jsx(C.IconDatabase,{size:14}),disabled:d,children:t("data.label")}),n.jsx(a.Tabs.Tab,{value:"Panel",leftSection:n.jsx(C.IconAppWindow,{size:14}),children:t("panel.label")}),n.jsx(a.Tabs.Tab,{value:"Variables",leftSection:n.jsx(C.IconVariable,{size:14}),disabled:p,children:n.jsx(a.Tooltip,{label:t("data.requires_data"),disabled:!p,withinPortal:!0,zIndex:310,children:n.jsx(a.Text,{size:"sm",children:t("panel.variable.labels")})})}),n.jsx(a.Tabs.Tab,{value:"Visualization",leftSection:n.jsx(C.IconChartHistogram,{size:14}),disabled:p,children:n.jsx(a.Tooltip,{label:t("data.requires_data"),disabled:!p,withinPortal:!0,zIndex:310,children:n.jsx(a.Text,{size:"sm",children:t("visualization.label")})})}),n.jsx(a.Tabs.Tab,{value:"Interactions",leftSection:n.jsx(C.IconRoute,{size:14}),children:t("interactions.label")})]}),n.jsxs(a.Tabs.Panel,{value:"Data",children:[n.jsx(a.LoadingOverlay,{visible:d,transitionProps:{exitDuration:0}}),n.jsx(NI,{})]}),n.jsx(a.Tabs.Panel,{value:"Panel",children:n.jsx(Ko,{children:n.jsx(PI,{})})}),n.jsx(a.Tabs.Panel,{value:"Variables",children:n.jsx(Ko,{children:n.jsx(tM,{})})}),n.jsx(a.Tabs.Panel,{value:"Visualization",children:n.jsx(Ie,{children:n.jsx(Ko,{children:n.jsx(UI,{})})})}),n.jsx(a.Tabs.Panel,{value:"Interactions",children:n.jsx(Ie,{children:n.jsx(Iv,{})})})]})]})}),iM=k.observer(({viewID:e,panelID:t})=>{const r=re();if(!r.views.findByID(e))return n.jsxs(a.Text,{size:"14px",children:["View by ID[",e,"] is not found"]});const i=r.panels.findByID(t);return i?n.jsx(sM,{panel:i}):n.jsxs(a.Text,{size:"14px",children:["Panel by ID[",t,"] is not found"]})}),aM=k.observer(()=>{const{t:e}=_.useTranslation(),[t,r]=f.useState([]),s=dt.useModals(),i=se(),o=x=>{i.editor.setPath(["_QUERIES_",x])},l=()=>{s.openConfirmModal({title:"Delete ununsed queries?",children:n.jsx(a.Text,{size:"sm",children:"This action cannot be undone."}),labels:{confirm:e("common.actions.confirm"),cancel:e("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>i.content.removeUnusedQueries(),confirmProps:{color:"red"},zIndex:320})},c=()=>{i.content.queries.downloadSchema(t)},u=f.useMemo(()=>i.content.queries.sortedList.map(x=>x.id),[i.content.queries.sortedList]),d=()=>{r(u)},p=()=>{r([])},h=i.content.queriesUsage;return n.jsxs(a.Stack,{sx:{height:"100%"},gap:"sm",pb:"59px",children:[n.jsx(a.Box,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:n.jsx(a.Text,{px:"md",ta:"left",sx:{userSelect:"none",cursor:"default"},children:e("query.manage")})}),n.jsxs(a.Flex,{justify:"space-between",align:"center",px:12,children:[n.jsxs(a.Group,{justify:"flex-start",children:[n.jsxs(a.Button.Group,{children:[n.jsx(a.Button,{variant:"default",size:"xs",onClick:d,children:e("common.actions.select_all")}),n.jsx(a.Button,{variant:"default",size:"xs",onClick:p,children:e("common.actions.clear_selection")})]}),n.jsx(a.Button,{size:"xs",color:"blue",leftSection:n.jsx(C.IconCode,{size:14}),disabled:t.length===0,onClick:c,children:e("common.actions.download_schema")})]}),n.jsx(a.Button,{variant:"subtle",size:"xs",color:"red",leftSection:n.jsx(C.IconTrash,{size:14}),disabled:!i.content.hasUnusedQueries,onClick:l,children:e("query.delete_unused")})]}),n.jsx(a.Box,{sx:{flexGrow:1,overflow:"auto"},children:n.jsx(a.Checkbox.Group,{size:"xs",value:t,onChange:r,children:n.jsxs(a.Table,{fz:"sm",highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[n.jsx(a.Table.Thead,{children:n.jsxs(a.Table.Tr,{children:[n.jsx(a.Table.Th,{style:{width:"40px"}}),n.jsx(a.Table.Th,{children:e("common.name")}),n.jsx(a.Table.Th,{style:{width:"200px"},children:e("data_source.label")}),n.jsx(a.Table.Th,{style:{width:"100px",textAlign:"right"},children:e("common.type")}),n.jsx(a.Table.Th,{style:{width:"100px",textAlign:"center"},children:e("query.usage.label")}),n.jsx(a.Table.Th,{style:{width:"300px",paddingLeft:"24px"},children:e("common.action")})]})}),n.jsx(a.Table.Tbody,{children:i.content.queries.sortedList.map(x=>{var m;const b=((m=h[x.id])==null?void 0:m.length)??0;return n.jsxs(a.Table.Tr,{children:[n.jsx(a.Table.Td,{children:n.jsx(a.Checkbox,{value:x.id,styles:{input:{cursor:"pointer"}}})}),n.jsx(a.Table.Td,{children:x.name}),n.jsx(a.Table.Td,{children:x.key}),n.jsx(a.Table.Td,{style:{textAlign:"right"},children:x.type}),n.jsx(a.Table.Td,{style:{color:b===0?"#ff0000":"#000",fontWeight:b===0?"bold":"normal",textAlign:"center"},children:b}),n.jsx(a.Table.Td,{children:n.jsx(a.Button,{variant:"subtle",size:"xs",onClick:()=>o(x.id),children:e("common.actions.open")})})]},x.id)})})]})})})]})}),oM=e=>{const{t}=_.useTranslation(),{queryModel:r}=e,s=se(),i=re(),l=i.findQueryUsage(r.id).length>0,c=dt.useModals(),u=()=>{c.openConfirmModal({title:`${t("query.delete")}?`,labels:{confirm:t("common.actions.confirm"),cancel:t("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>{i.queries.removeQuery(r.id),s.editor.setPath(["_QUERIES_",""])},confirmProps:{color:"red"},zIndex:320})};return l?n.jsx(a.Tooltip,{label:t("query.cant_delete"),withArrow:!0,events:{hover:!0,focus:!1,touch:!1},withinPortal:!0,zIndex:320,position:"top-end",children:n.jsx(a.Box,{sx:{alignSelf:"flex-end"},children:n.jsx(a.Button,{disabled:!0,size:"xs",leftSection:n.jsx(C.IconTrash,{size:16}),children:t("query.delete")})})}):n.jsx(a.Button,{color:"red",size:"xs",onClick:u,leftSection:n.jsx(C.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:t("query.delete")})},lM=k.observer(oM),Sg=({width:e="calc(100% - 32px)",lastWidth:t="50%",height:r,count:s,spacing:i=16,pl:o=0})=>n.jsxs(a.Stack,{gap:i,mt:6,pl:o,children:[Array.from(new Array(s-1),(l,c)=>n.jsx(a.Skeleton,{width:e,height:r,radius:"xs"},c)),n.jsx(a.Skeleton,{width:t,height:r,radius:"xs"})]}),Pr=({value:e})=>e===null||e===""?null:n.jsx(a.Tooltip,{label:e,disabled:!e,multiline:!0,zIndex:340,children:n.jsx(a.ActionIcon,{variant:"subtle",children:n.jsx(C.IconInfoCircle,{size:14})})}),cM=({column:e})=>{const{column_key:t,column_key_text:r}=e;return t?n.jsx(a.Tooltip,{label:r,disabled:!r,children:n.jsx(a.Badge,{variant:"light",children:t})}):null},uM=k.observer(({dataSource:e})=>{const{columns:t}=e.dbInfo;return t.loading?n.jsx(Sg,{height:"24px",width:"100%",lastWidth:"100%",count:20,pl:6}):t.empty?null:n.jsxs(a.Table,{highlightOnHover:!0,fz:14,sx:{width:"auto",minWidth:"1000px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[n.jsxs("colgroup",{children:[n.jsx("col",{style:{width:50}}),n.jsx("col",{style:{minWidth:300}}),n.jsx("col",{style:{width:30}}),n.jsx("col",{style:{width:70}}),n.jsx("col",{style:{minWidth:300}}),n.jsx("col",{style:{minWidth:80,width:80}}),n.jsx("col",{style:{minWidth:120,width:120}})]}),n.jsx(a.Table.Thead,{children:n.jsxs(a.Table.Tr,{children:[n.jsx(a.Table.Th,{children:"#"}),n.jsx(a.Table.Th,{children:"Column Name"}),n.jsx(a.Table.Th,{}),n.jsx(a.Table.Th,{}),n.jsx(a.Table.Th,{children:"Type"}),n.jsx(a.Table.Th,{children:"Nullable"}),n.jsx(a.Table.Th,{children:"Default Value"})]})}),n.jsx(a.Table.Tbody,{children:t.data.map(r=>n.jsxs(a.Table.Tr,{children:[n.jsx(a.Table.Td,{children:r.ordinal_position}),n.jsx(a.Table.Td,{children:r.column_name}),n.jsx(a.Table.Td,{children:n.jsx(Pr,{value:r.column_comment})}),n.jsx(a.Table.Td,{children:n.jsx(cM,{column:r})}),n.jsx(a.Table.Td,{children:r.column_type}),n.jsx(a.Table.Td,{children:r.is_nullable}),n.jsx(a.Table.Td,{children:n.jsx(Pr,{value:r.column_default})})]},r.column_name))})]})}),dM=k.observer(({dataSource:e})=>{const{indexes:t}=e.dbInfo,r=t.data;return n.jsxs(a.Table,{highlightOnHover:!0,fz:14,sx:{width:"auto",minWidth:"950px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[n.jsxs("colgroup",{children:[n.jsx("col",{style:{width:100}}),n.jsx("col",{style:{minWidth:300}}),n.jsx("col",{style:{width:150}}),n.jsx("col",{style:{width:150}}),n.jsx("col",{style:{width:250}})]}),n.jsx(a.Table.Thead,{children:n.jsxs(a.Table.Tr,{children:[n.jsx(a.Table.Th,{children:"Index Length"}),n.jsx(a.Table.Th,{children:"Index Name"}),n.jsx(a.Table.Th,{children:"Index Algorithm"}),n.jsx(a.Table.Th,{children:"Unique"}),n.jsx(a.Table.Th,{children:"Column Name"})]})}),n.jsx(a.Table.Tbody,{children:r.map(s=>n.jsxs(a.Table.Tr,{children:[n.jsx(a.Table.Td,{children:s.index_length}),n.jsx(a.Table.Td,{children:s.index_name}),n.jsx(a.Table.Td,{children:s.index_algorithm}),n.jsx(a.Table.Td,{children:s.is_unique?"YES":"NO"}),n.jsx(a.Table.Td,{children:s.column_name})]},s.index_name))})]})}),pM=k.observer(({dataSource:e})=>{const{indexes:t}=e.dbInfo,r=t.data;return n.jsxs(a.Table,{highlightOnHover:!0,fz:14,sx:{width:"auto",minWidth:"850px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[n.jsxs("colgroup",{children:[n.jsx("col",{style:{minWidth:300}}),n.jsx("col",{style:{width:150}}),n.jsx("col",{style:{width:100}}),n.jsx("col",{style:{width:100}}),n.jsx("col",{style:{width:100}}),n.jsx("col",{style:{width:100}})]}),n.jsx(a.Table.Thead,{children:n.jsxs(a.Table.Tr,{children:[n.jsx(a.Table.Th,{children:"Index Name"}),n.jsx(a.Table.Th,{children:"Index Algorithm"}),n.jsx(a.Table.Th,{children:"Unique"}),n.jsx(a.Table.Th,{children:"Definition"}),n.jsx(a.Table.Th,{children:"Condition"}),n.jsx(a.Table.Th,{children:"Comment"})]})}),n.jsx(a.Table.Tbody,{children:r.map(s=>n.jsxs(a.Table.Tr,{children:[n.jsx(a.Table.Td,{children:s.index_name}),n.jsx(a.Table.Td,{children:s.index_algorithm}),n.jsx(a.Table.Td,{children:s.is_unique?"YES":"NO"}),n.jsx(a.Table.Td,{children:n.jsx(Pr,{value:s.index_definition})}),n.jsx(a.Table.Td,{children:n.jsx(Pr,{value:s.condition})}),n.jsx(a.Table.Td,{children:n.jsx(Pr,{value:s.comment})})]},s.index_name))})]})}),hM=k.observer(({dataSource:e})=>{const{indexes:t}=e.dbInfo;return t.loading||t.empty?null:e.type===J.MySQL?n.jsx(dM,{dataSource:e}):e.type===J.Postgresql?n.jsx(pM,{dataSource:e}):null}),gM=k.observer(({dataSource:e})=>n.jsxs(a.Stack,{gap:40,pt:10,sx:{flexGrow:1,overflow:"auto",position:"relative"},children:[n.jsx(Ie,{children:n.jsx(uM,{dataSource:e})}),n.jsx(Ie,{children:n.jsx(hM,{dataSource:e})})]}));function fM({table_type:e}){return e==="VIEW"?n.jsx(C.IconEye,{size:14}):e==="BASE TABLE"?n.jsx(C.IconTable,{size:14}):null}const xM=k.observer(({dataSource:e})=>{const t=e.dbInfo,{tables:r}=t;return r.loading?n.jsx(Sg,{height:"24px",lastWidth:"50%",count:15}):n.jsx(a.Box,{h:"100%",sx:{overflow:"auto",".mantine-NavLink-label":{fontFamily:"monospace"}},children:Object.entries(r.data).map(([s,i])=>n.jsx(a.NavLink,{label:s,title:s,leftSection:n.jsx(C.IconDatabase,{size:14}),defaultOpened:t.table_schema===s,pl:0,childrenOffset:14,children:i.map(o=>n.jsx(a.NavLink,{label:o.table_name,title:o.table_name,leftSection:n.jsx(fM,{table_type:o.table_type}),onClick:()=>{t.setKeywords(s,o.table_name)},active:t.table_name===o.table_name},o.table_name))},s))})}),mM=({visible:e})=>n.jsx(a.Box,{py:10,sx:{width:"100%",height:"100%",overflow:"hidden",position:"relative"},children:n.jsx(a.LoadingOverlay,{visible:e})}),bM=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],yM={section:{"&[data-position=left]":{width:"70px",textAlign:"center"}},input:{paddingLeft:"70px"}},vM=k.observer(({dataSource:e})=>{const{t}=_.useTranslation(),{tableData:r}=e.dbInfo;return n.jsxs(a.Group,{pt:10,px:10,justify:"space-between",children:[n.jsxs(a.Group,{justify:"flex-start",children:[r.maxPage>1&&n.jsx(a.Pagination,{size:"sm",value:r.page,onChange:r.setPage,total:r.maxPage,withEdges:r.maxPage>7,styles:{control:{height:"30px"}}}),n.jsx(a.Select,{leftSection:n.jsx(a.Text,{ta:"center",c:"dimmed",size:"14px",children:t("common.pagination.page_size")}),size:"xs",styles:yM,data:bM,value:String(r.limit),onChange:s=>r.setLimit(Number(s)),comboboxProps:{zIndex:340}})]}),n.jsx(a.Group,{justify:"flex-end",children:n.jsx(a.Text,{c:"dimmed",my:0,size:"14px",children:t("common.pagination.total_rows",{total:r.total})})})]})}),_M=k.observer(({dataSource:e})=>{const t=e.dbInfo.tableData;return t.maxPage===0?n.jsx(a.Text,{mt:20,c:"red",size:"md",ta:"center",ff:"monospace",children:"This table is empty"}):t.error?n.jsx(a.Text,{mt:20,c:"red",size:"md",ta:"center",ff:"monospace",children:t.error}):t.page===1&&t.loading?n.jsx(mM,{visible:!0}):n.jsxs(Ie,{children:[n.jsx(vM,{dataSource:e}),n.jsxs(a.Box,{py:10,sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[n.jsx(a.LoadingOverlay,{visible:t.loading,overlayProps:{blur:2}}),n.jsx(wg,{data:t.data})]})]})}),jM={root:{flexGrow:1,overflow:"auto",borderLeft:"1px solid #efefef"},tabsList:{borderBottom:"1px solid #efefef"},tab:{minWidth:120}},wM=k.observer(({dataSource:e})=>{const{t}=_.useTranslation(),r=e.dbInfo;return f.useEffect(()=>{r.loadTablesIfEmpty()},[r]),r.tables.error?n.jsx(a.Text,{c:"red",size:"md",ta:"center",ff:"monospace",children:r.tables.error}):n.jsxs(a.Flex,{sx:{height:"100%"},children:[n.jsx(a.Box,{w:300,sx:{flexGrow:0,flexShrink:0,position:"relative"},children:n.jsx(Ie,{children:n.jsx(xM,{dataSource:e})})}),n.jsxs(a.Tabs,{defaultValue:"structure",styles:jM,children:[n.jsxs(a.Tabs.List,{children:[n.jsx(a.Tabs.Tab,{value:"structure",leftSection:n.jsx(C.IconColumns,{size:14}),children:t("data_source.table_structure_short")}),n.jsx(a.Tabs.Tab,{value:"data",leftSection:n.jsx(C.IconDatabase,{size:14}),children:t("data.label")})]}),n.jsx(a.Tabs.Panel,{value:"structure",children:n.jsx(gM,{dataSource:e})}),n.jsx(a.Tabs.Panel,{value:"data",sx:{width:"100%",height:"calc(100% - 36px)",overflow:"hidden"},children:n.jsx(_M,{dataSource:e})})]})]})}),CM={modal:{paddingLeft:"0px !important",paddingRight:"0px !important"},header:{marginBottom:0,padding:"20px 20px 10px",borderBottom:"1px solid #efefef",gap:"20px"},title:{flexGrow:1},body:{padding:"0 0 0 20px"}},Tg=k.observer(({dataSource:e,triggerButtonProps:t={}})=>{const{t:r}=_.useTranslation(),[s,i]=f.useState(!1),{type:o}=e;return o==="http"||o==="merico_metric_system"?null:n.jsxs(n.Fragment,{children:[n.jsx(a.Modal,{opened:s,onClose:()=>i(!1),title:n.jsxs(a.Group,{justify:"space-between",sx:{flexGrow:1},children:[n.jsx(a.Text,{size:"sm",fw:500,children:r("data_source.explorer")}),n.jsxs(a.Group,{gap:7,children:[n.jsx(a.Badge,{variant:"gradient",gradient:{from:"indigo",to:"cyan"},children:e.key}),n.jsx(a.Badge,{variant:"gradient",gradient:{from:"orange",to:"red"},children:e.type})]})]}),zIndex:320,size:"96vw",styles:CM,children:n.jsx(a.Box,{sx:{height:"calc(100vh - 220px)"},children:n.jsx(wM,{dataSource:e})})}),n.jsx(a.Button,{variant:"subtle",onClick:()=>i(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},...t,children:r("data_source.see_table_structure")})]})}),kg={http:"HTTP",mysql:"MySQL",postgresql:"PostgreSQL",merico_metric_system:"指标系统"},SM=({option:e,...t})=>{const{label:r,type:s}=e;return s===J.Transform?n.jsxs(a.Group,{className:"transform-query-option",justify:"flex-start",...t,sx:{flexGrow:1,'&[data-selected="true"]':{".mantine-Text-root":{color:"white"},svg:{stroke:"white"}}},children:[n.jsx(C.IconVectorTriangle,{size:14,color:"#228be6"}),n.jsx(a.Text,{size:"sm",c:"blue",children:r})]}):n.jsxs(a.Group,{justify:"space-between",...t,sx:{flexGrow:1},children:[n.jsx(a.Text,{size:"sm",children:r}),n.jsx(a.Text,{size:"sm",children:kg[s]})]})},Dg=k.observer(({queryModel:e,size:t="sm"})=>{const{t:r}=_.useTranslation(),s=se(),{data:i=[],loading:o}=U.useRequest(ya,{refreshDeps:[]},[]),l=f.useMemo(()=>{const p=i.map(h=>({label:h.key,value:h.key,type:h.type}));return p.push({label:r("query.transform.data_source"),value:J.Transform,type:J.Transform}),p},[i]),c=f.useMemo(()=>l.reduce((p,h)=>(p[h.value]=h.type,p),{}),[l]),u=p=>{p!==null&&(e.setKey(p),e.setType(c[p]))},d=f.useMemo(()=>s.datasources.find({type:e.type,key:e.key}),[s,e.type,e.key]);return n.jsx(a.Select,{size:t,data:l,label:n.jsxs(a.Group,{justify:"space-between",children:[n.jsx(a.Box,{children:r("data_source.label")}),d&&n.jsx(Tg,{dataSource:d,triggerButtonProps:{size:"compact-xs",px:10}})]}),renderOption:SM,rightSection:d?n.jsx(a.Text,{size:"xs",c:"dimmed",children:kg[d.type]??d.type}):void 0,rightSectionWidth:85,maxDropdownHeight:500,styles:{root:{flex:1,minWidth:"300px"},label:{display:"block"},section:{pointerEvents:"none",justifyContent:"flex-end",paddingRight:"10px",".mantine-Text-root":{userSelect:"none"}}},disabled:o,value:e.key,onChange:u})}),TM=k.observer(({queryModel:e})=>{const{t}=_.useTranslation(),[r,s]=f.useState(e.name);f.useEffect(()=>{s(e.name)},[e.name]);const i=f.useMemo(()=>e.conditionOptionsWithInvalidRunbys.optionGroups.map(l=>({group:t(l.group),items:l.items})),[e.conditionOptionsWithInvalidRunbys.optionGroups]);return n.jsx(a.Center,{ml:20,mt:20,sx:{maxWidth:"600px"},children:n.jsxs(a.Stack,{gap:10,sx:{width:"100%"},children:[n.jsx(a.Divider,{mb:-10,variant:"dashed",label:t("query.basics"),labelPosition:"center"}),n.jsx(a.TextInput,{placeholder:t("query.name_description"),label:t("query.name"),required:!0,sx:{flex:1},value:r,onChange:o=>{s(o.currentTarget.value)},rightSection:n.jsx(a.ActionIcon,{variant:"filled",color:"blue",size:"sm",onClick:()=>e.setName(r),disabled:r===e.name,children:n.jsx(C.IconDeviceFloppy,{size:16})}),onBlur:()=>{e.setName(r)}}),n.jsx(Dg,{queryModel:e}),n.jsx(a.Divider,{mt:10,mb:-10,variant:"dashed",label:t("query.conditions"),labelPosition:"center"}),n.jsx(a.MultiSelect,{label:t("query.run_by_condition.label"),description:t("query.run_by_condition.description"),placeholder:t("query.run_by_condition.unset"),data:i,value:[...e.run_by],onChange:e.setRunBy,renderOption:ud,maxDropdownHeight:500}),e.typedAsHTTP&&n.jsx(a.MultiSelect,{label:t("query.re_run_condition.label"),placeholder:t("query.re_run_condition.label"),data:i,value:[...e.config.react_to],onChange:e.config.setReactTo,renderOption:ud,maxDropdownHeight:500}),n.jsx(a.Divider,{mt:20,mb:10,variant:"dashed"}),n.jsx(lM,{queryModel:e})]})})});function kM({content:e}){return n.jsxs(a.HoverCard,{width:"60vw",shadow:"md",zIndex:340,children:[n.jsx(a.HoverCard.Target,{children:n.jsx(a.ActionIcon,{size:16,color:"blue",variant:"subtle",children:n.jsx(C.IconEye,{})})}),n.jsx(a.HoverCard.Dropdown,{children:n.jsx(zt.CodeHighlight,{language:"sql",withCopyButton:!1,code:e})})]})}const DM=k.observer(()=>{const t=[...se().globalSQLSnippets.list];return t.length===0?null:n.jsxs(a.Table,{horizontalSpacing:"xs",verticalSpacing:"xs",fz:"sm",highlightOnHover:!0,children:[n.jsx(a.Table.Thead,{children:n.jsxs(a.Table.Tr,{children:[n.jsx(a.Table.Th,{children:"Key"}),n.jsx(a.Table.Th,{children:"Value"})]})}),n.jsx(a.Table.Tbody,{children:t.map(r=>{const{id:s,content:i}=r;return n.jsxs(a.Table.Tr,{children:[n.jsx(a.Table.Td,{children:s}),n.jsx(a.Table.Td,{width:200,children:n.jsx(kM,{content:i})})]},s)})})]})}),zM=`
516
+ `,vg=()=>{const{t:e}=_.useTranslation(),[t,r]=f.useState(!1);return n.jsxs(n.Fragment,{children:[n.jsx(a.Button,{variant:"subtle",size:"compact-sm",onClick:()=>r(s=>!s),children:e(t?"common.actions.close":"filter.widget.common.see_data_structure")}),n.jsx(a.Collapse,{in:t,children:n.jsx(zt.CodeHighlight,{language:"typescript",withCopyButton:!1,code:mI})})]})},bI=k.observer(function({filter:t}){const{t:r}=_.useTranslation(),s=t.config,i=()=>{s.addStaticOption({label:"",value:""})},o=s.static_options,l=o.filter(c=>c.value!==""&&c.label!=="");return n.jsxs(n.Fragment,{children:[n.jsxs(a.Group,{justify:"space-between",children:[n.jsx(a.Checkbox,{checked:s.required,onChange:c=>s.setRequired(c.currentTarget.checked),label:r("filter.widget.select.required")}),n.jsx(Dn,{filter:t})]}),n.jsx(a.TextInput,{label:r("filter.widget.select.width"),description:r("filter.widget.multi_select.width_description"),value:s.min_width,onChange:c=>s.setMinWidth(c.currentTarget.value),placeholder:"200px"}),n.jsx(a.Divider,{label:r("filter.widget.select.configure_options"),labelPosition:"center"}),n.jsxs(a.Stack,{gap:10,sx:{position:"relative",minHeight:"50px"},children:[s.usingQuery&&n.jsxs(n.Fragment,{children:[n.jsx(a.Overlay,{backgroundOpacity:.8,color:"#000",sx:{left:"-5px",right:"-5px",top:"-5px",bottom:"-5px"}}),n.jsx(a.Center,{sx:{position:"absolute",top:0,left:0,zIndex:200,height:"100%",width:"100%"},children:n.jsx(a.Text,{c:"white",size:"16px",children:r("filter.widget.common.using_query")})})]}),l.length>0&&n.jsx(a.MultiSelect,{label:r("filter.widget.select.default_selection"),placeholder:r("filter.widget.select.no_default_selection"),data:l,value:[...s.default_value],onChange:s.setDefaultValue}),o.map((c,u)=>n.jsxs(a.Flex,{gap:10,sx:{position:"relative"},pr:"40px",children:[n.jsx(a.TextInput,{label:r("common.label"),required:!0,value:s.static_options[u].label,onChange:d=>{s.static_options[u].setLabel(d.currentTarget.value)},sx:{flexGrow:1}}),n.jsx(a.TextInput,{label:r("common.value"),required:!0,value:s.static_options[u].value,onChange:d=>{s.static_options[u].setValue(d.currentTarget.value)},sx:{flexGrow:1}}),n.jsx(a.ActionIcon,{color:"red",variant:"subtle",onClick:()=>s.removeStaticOption(u),sx:{position:"absolute",top:28,right:5},children:n.jsx(C.IconTrash,{size:16})})]},u)),n.jsx(a.Button,{mt:10,size:"xs",color:"blue",leftSection:n.jsx(C.IconPlaylistAdd,{size:20}),onClick:i,sx:{width:"50%"},mx:"auto",children:r("common.actions.add_an_option")})]}),n.jsx(a.Divider,{label:r("filter.widget.common.or_fetch_options_from_datasource"),labelPosition:"center"}),n.jsx(a.NumberInput,{value:s.default_selection_count,onChange:s.setDefaultSelectionCount,label:r("filter.widget.common.default_selection_count")}),n.jsx(Es,{value:s.options_query_id,onChange:s.setOptionsQueryID}),n.jsx(vg,{})]})}),_g={date_unit:{zh:[{label:"天",value:"day"},{label:"周",value:"week"},{label:"双周",value:"bi-week"},{label:"月",value:"month"},{label:"季度",value:"quarter"},{label:"年",value:"year"}],en:[{label:"Day",value:"day"},{label:"Week",value:"week"},{label:"Bi-Week",value:"bi-week"},{label:"Month",value:"month"},{label:"Quarter",value:"quarter"},{label:"Year",value:"year"}]}},jg=k.observer(({config:e})=>{const{t,i18n:r}=_.useTranslation(),s=()=>{e.addStaticOption({label:"",value:""})},i=f.useMemo(()=>[{label:t("filter.widget.select.preset_options.date_unit"),value:"date_unit"}],[r.language]),o=l=>{if(!l||!(l in _g))return;const c=_g[l][r.language];e.replaceStaticOptions(c),c.length>0&&e.setDefaultValue(c[0].value)};return n.jsxs(a.Group,{justify:"space-between",children:[n.jsx(a.Button,{size:"xs",color:"blue",leftSection:n.jsx(C.IconPlaylistAdd,{size:20}),onClick:s,children:t("common.actions.add_an_option")}),n.jsx(a.Select,{placeholder:t("filter.widget.select.preset_options.apply"),value:null,onChange:o,data:i,size:"xs"})]})}),yI=k.observer(({config:e})=>{const{t,i18n:r}=_.useTranslation(),s=[...e.static_options],i=f.useMemo(()=>[{label:t("filter.widget.select.no_default_selection"),value:""},...s.filter(o=>o.value!=="")],[r.language,s]);return s.length===0?n.jsx(jg,{config:e}):n.jsxs(n.Fragment,{children:[n.jsx(a.Select,{label:t("filter.widget.select.default_selection"),data:i,value:e.default_value,onChange:e.setDefaultValue}),s.map((o,l)=>n.jsxs(a.Flex,{gap:10,sx:{position:"relative"},pr:"40px",children:[n.jsx(a.TextInput,{label:t("common.label"),required:!0,value:e.static_options[l].label,onChange:c=>{e.static_options[l].setLabel(c.currentTarget.value)},sx:{flexGrow:1}}),n.jsx(a.TextInput,{label:t("common.value"),required:!0,value:e.static_options[l].value,onChange:c=>{e.static_options[l].setValue(c.currentTarget.value)},sx:{flexGrow:1}}),n.jsx(a.ActionIcon,{color:"red",variant:"subtle",onClick:()=>e.removeStaticOption(l),sx:{position:"absolute",top:28,right:5},children:n.jsx(C.IconTrash,{size:16})})]},l)),n.jsx(jg,{config:e})]})}),vI=k.observer(({filter:e})=>{const{t}=_.useTranslation(),r=e.config;return n.jsxs(n.Fragment,{children:[n.jsxs(a.Group,{justify:"space-between",children:[n.jsx(a.Checkbox,{checked:r.required,onChange:s=>r.setRequired(s.currentTarget.checked),label:t("filter.widget.select.required")}),n.jsx(a.Checkbox,{checked:r.clearable,onChange:s=>r.setClearable(s.currentTarget.checked),label:t("filter.widget.select.clearable")}),n.jsx(Dn,{filter:e})]}),n.jsx(a.TextInput,{label:t("filter.widget.select.width"),value:r.width,onChange:s=>r.setWidth(s.currentTarget.value),placeholder:"200px"}),n.jsx(a.Divider,{label:t("filter.widget.select.configure_options"),labelPosition:"center"}),n.jsxs(a.Stack,{gap:10,sx:{position:"relative",minHeight:"50px"},children:[r.usingQuery&&n.jsxs(n.Fragment,{children:[n.jsx(a.Overlay,{backgroundOpacity:.8,color:"#000",sx:{left:"-5px",right:"-5px",top:"-5px",bottom:"-5px"}}),n.jsx(a.Center,{sx:{position:"absolute",top:0,left:0,zIndex:200,height:"100%",width:"100%"},children:n.jsx(a.Text,{c:"white",size:"16px",children:t("filter.widget.common.using_query")})})]}),n.jsx(yI,{config:r})]}),n.jsx(a.Divider,{label:t("filter.widget.common.or_fetch_options_from_datasource"),labelPosition:"center"}),n.jsx(a.Checkbox,{checked:r.default_selection_count===1,onChange:s=>r.setDefaultSelectionCount(s.currentTarget.checked?1:0),label:t("filter.widget.select.select_first_option_by_default")}),n.jsx(Es,{value:r.options_query_id,onChange:r.setOptionsQueryID}),n.jsx(vg,{})]})}),_I=k.observer(function({filter:t}){const{t:r}=_.useTranslation(),s=t.config;return n.jsxs(n.Fragment,{children:[n.jsxs(a.Group,{children:[n.jsx(a.TextInput,{label:r("filter.widget.text_input.default_value"),value:s.default_value,onChange:i=>{s.setDefaultValue(i.currentTarget.value)},sx:{flexGrow:1}}),n.jsx(a.Box,{mt:22,children:n.jsx(Dn,{filter:t})})]}),n.jsx(a.Checkbox,{checked:s.required,onChange:i=>s.setRequired(i.currentTarget.checked),label:r("filter.widget.text_input.required")})]})}),jI=k.observer(function({filter:t}){const{t:r}=_.useTranslation();return n.jsxs(a.Box,{sx:{maxWidth:"480px"},children:[n.jsx(a.Text,{pt:"0",pb:"md",c:"gray",size:"sm",children:r("common.titles.config")}),n.jsx(zt.CodeHighlight,{mt:22,language:"json",withCopyButton:!1,code:JSON.stringify(t,null,4)})]})}),wI={[Q.Select]:vI,[Q.MultiSelect]:bI,[Q.TreeSelect]:v3,[Q.TreeSingleSelect]:T3,[Q.TextInput]:_I,[Q.Checkbox]:gI,[Q.DateRange]:xI},rn={[Q.Select]:"filter.widget.names.select",[Q.MultiSelect]:"filter.widget.names.multi_select",[Q.TreeSelect]:"filter.widget.names.tree_select",[Q.TreeSingleSelect]:"filter.widget.names.tree_single_select",[Q.TextInput]:"filter.widget.names.text_input",[Q.Checkbox]:"filter.widget.names.checkbox",[Q.DateRange]:"filter.widget.names.date_range"},CI=k.observer(function({filter:t}){const{t:r,i18n:s}=_.useTranslation(),i=re(),o=f.useMemo(()=>wI[t.type],[t.type]),l=f.useMemo(()=>[{label:r(rn[Q.Select]),value:"select"},{label:r(rn[Q.MultiSelect]),value:"multi-select"},{label:r(rn[Q.TreeSelect]),value:"tree-select"},{label:r(rn[Q.TreeSingleSelect]),value:"tree-single-select"},{label:r(rn[Q.TextInput]),value:"text-input"},{label:r(rn[Q.Checkbox]),value:"checkbox"},{label:r(rn[Q.DateRange]),value:"date-range"}],[s.language]);return n.jsxs(a.Group,{grow:!0,gap:20,align:"top",children:[n.jsxs(a.Box,{sx:{maxWidth:"600px"},children:[n.jsx(a.Text,{pb:"md",c:"gray",size:"sm",children:r("common.titles.edit")}),n.jsxs(a.Stack,{children:[n.jsxs(a.Group,{wrap:"nowrap",children:[n.jsx(a.NumberInput,{label:r("filter.field.order"),required:!0,value:t.order,onChange:t.setOrder,hideControls:!0,sx:{flexGrow:"1 !important"}}),t.auto_submit_supported&&n.jsx(a.Checkbox,{label:r("filter.field.auto_submit"),checked:t.auto_submit,onChange:c=>t.setAutoSubmit(c.currentTarget.checked),mt:22})]}),n.jsx(a.MultiSelect,{label:r("filter.field.visible_in"),data:i.views.options,value:[...t.visibleInViewsIDs],onChange:t.setVisibleInViewsIDs}),n.jsx(a.TextInput,{label:r("common.key"),placeholder:r("filter.field.key_placeholder"),required:!0,value:t.key,onChange:c=>{t.setKey(c.currentTarget.value)}}),n.jsx(a.TextInput,{label:r("common.label"),placeholder:r("filter.field.label_placeholder"),required:!0,value:t.label,onChange:c=>{t.setLabel(c.currentTarget.value)}}),n.jsx(a.Select,{label:r("filter.field.widget"),data:l,required:!0,value:t.type,onChange:t.setType,maxDropdownHeight:500}),n.jsx(a.Divider,{mb:0,mt:10,variant:"dashed",labelPosition:"center"}),n.jsx(o,{filter:t})]})]}),n.jsx(jI,{filter:t})]})}),SI=k.observer(({id:e})=>{const{t}=_.useTranslation(),r=dt.useModals(),s=se(),i=re();if(e==="")return null;const o=i.filters.findByID(e);if(!o)return n.jsxs(a.Text,{size:"14px",children:["Filter by ID[",e,"] is not found"]});const l=()=>{s.editor.setPath(["_FILTERS_",""])},c=()=>{r.openConfirmModal({title:`${t("filter.delete")}?`,labels:{confirm:t("common.actions.confirm"),cancel:t("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>{i.filters.removeByID(e),l()},confirmProps:{color:"red"},zIndex:320})};return n.jsxs(a.Stack,{sx:{maxWidth:"1100px",height:"100vh"},gap:"sm",pb:30,children:[n.jsx(a.Group,{justify:"flex-end",pt:10,children:n.jsx(a.Button,{size:"xs",color:"red",leftSection:n.jsx(C.IconTrash,{size:16}),onClick:c,children:t("filter.delete")})}),n.jsx(a.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:n.jsx(CI,{filter:o})})]})}),TI=k.observer(()=>{const{t:e}=_.useTranslation(),[t,r]=f.useState([]),s=se(),i=d=>{s.editor.setPath(["_FILTERS_",d])},o=()=>{s.content.filters.downloadSchema(t)},l=f.useMemo(()=>s.content.filters.sortedList.map(d=>d.id),[s.content.filters.sortedList]),c=()=>{r(l)},u=()=>{r([])};return n.jsxs(a.Stack,{sx:{height:"100%"},gap:"sm",pb:"59px",children:[n.jsx(a.Box,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:n.jsx(a.Text,{size:"sm",px:"md",ta:"left",sx:{userSelect:"none",cursor:"default"},children:e("filter.manage")})}),n.jsx(a.Flex,{justify:"space-between",align:"center",px:12,children:n.jsxs(a.Group,{justify:"flex-start",children:[n.jsxs(a.Button.Group,{children:[n.jsx(a.Button,{variant:"default",size:"xs",onClick:c,children:e("common.actions.select_all")}),n.jsx(a.Button,{variant:"default",size:"xs",onClick:u,children:e("common.actions.clear_selection")})]}),n.jsx(a.Button,{size:"xs",color:"blue",leftSection:n.jsx(C.IconCode,{size:14}),disabled:t.length===0,onClick:o,children:e("common.actions.download_schema")})]})}),n.jsx(a.Box,{sx:{flexGrow:1,overflow:"auto"},children:n.jsx(a.Checkbox.Group,{size:"xs",value:t,onChange:r,children:n.jsxs(a.Table,{fz:"sm",highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[n.jsx(a.Table.Thead,{children:n.jsxs(a.Table.Tr,{children:[n.jsx(a.Table.Th,{style:{width:"40px"}}),n.jsx(a.Table.Th,{style:{width:"300px"},children:e("common.label")}),n.jsx(a.Table.Th,{children:e("common.key")}),n.jsx(a.Table.Th,{style:{width:"100px"},children:e("filter.field.widget")}),n.jsx(a.Table.Th,{style:{width:"300px",paddingLeft:"24px"},children:e("common.action")})]})}),n.jsx(a.Table.Tbody,{children:s.content.filters.sortedList.map(d=>n.jsxs(a.Table.Tr,{children:[n.jsx(a.Table.Td,{children:n.jsx(a.Checkbox,{value:d.id,styles:{input:{cursor:"pointer"}}})}),n.jsx(a.Table.Td,{children:d.label}),n.jsx(a.Table.Td,{children:d.key}),n.jsx(a.Table.Td,{children:e(rn[d.type])}),n.jsx(a.Table.Td,{children:n.jsx(a.Button,{variant:"subtle",size:"xs",onClick:()=>i(d.id),children:e("common.actions.open")})})]},d.id))})]})})})]})}),kI=k.observer(()=>{const{t:e}=_.useTranslation(),t=re(),[r,s]=f.useState(()=>JSON.stringify(t.mock_context.current,null,4)),i=()=>{try{t.mock_context.replace(JSON.parse(r))}catch(l){$t.showNotification({title:"Failed",message:l.message,color:"red"})}},o=f.useMemo(()=>{try{return JSON.stringify(JSON.parse(r))!==JSON.stringify(t.mock_context.current)}catch{return!1}},[r,t.mock_context.current]);return n.jsxs(a.Stack,{sx:{border:"1px solid #eee",borderLeft:"none",borderRight:"none",flexGrow:1,maxWidth:"unset"},children:[n.jsx(a.Group,{justify:"flex-start",pl:"md",py:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",flexGrow:0},children:n.jsx(a.Text,{size:"sm",fw:500,children:e("mock_context.label")})}),n.jsx(a.Group,{grow:!0,px:"md",pb:"md",pt:0,sx:{flexGrow:1,position:"relative",alignItems:"flex-start"},children:n.jsxs(a.Stack,{gap:10,sx:{maxWidth:"unset !important"},children:[n.jsxs(a.Group,{justify:"flex-start",children:[n.jsx(a.Text,{size:"sm",children:e("mock_context.hint")}),n.jsx(a.Button,{color:"green",size:"compact-sm",leftSection:n.jsx(C.IconDeviceFloppy,{size:16}),onClick:i,disabled:!o,children:e("common.actions.save")})]}),n.jsx(a.JsonInput,{validationError:"Invalid json",formatOnBlur:!0,autosize:!0,minRows:30,value:r,onChange:s,sx:{flexGrow:1}})]})})]})}),DI=k.observer(()=>{const{t:e}=_.useTranslation(),{panel:t}=Pe();return n.jsx(bn,{label:e("panel.panel_description"),value:t.description,onChange:t.setDescription,styles:{root:{flexGrow:1}}},t.id)}),zI=k.observer(()=>{const{t:e}=_.useTranslation(),{panel:t}=Pe(),r=Te().layouts.findItemByPanelID(t.id),{style:s}=t;return n.jsx(n.Fragment,{children:n.jsxs(a.Stack,{gap:20,children:[n.jsxs(a.Group,{grow:!0,align:"top",children:[n.jsx(a.NumberInput,{label:e("panel.style.width"),min:1,max:36,step:1,decimalScale:0,rightSection:n.jsx(a.Text,{size:"12px",children:e("panel.style.width_postfix")}),styles:{section:{width:"auto",maxWidth:"100px",paddingRight:"14px",justifyContent:"flex-end"}},value:r.w,onChange:i=>{typeof i!="string"&&r.setWidth(i)}}),n.jsx(a.NumberInput,{label:e("panel.style.height"),rightSection:n.jsx(a.Text,{size:"12px",children:e("panel.style.height_postfix")}),styles:{section:{width:"40px"}},value:r.h,onChange:i=>{typeof i!="string"&&r.setHeight(i)}})]}),n.jsx(a.Checkbox,{ml:6,label:e("panel.style.border"),checked:s.border.enabled,onChange:i=>s.border.setEnabled(i.currentTarget.checked)})]})})}),II=()=>n.jsxs("span",{className:"mantine-103svbs mantine-InputWrapper-required mantine-Select-required","aria-hidden":"true",children:[" ","*"]}),MI=k.observer(()=>{const{t:e}=_.useTranslation(),{panel:t}=Pe(),{name:r}=t,[s,i]=ze.useInputState(r),o=r!==s,l=f.useCallback(()=>{o&&t.setName(s)},[o,s]);f.useEffect(()=>{i(r)},[r]);const c=!s.trim();return n.jsxs(a.Stack,{gap:4,children:[n.jsxs(a.Group,{align:"center",children:[n.jsxs(a.Text,{size:"14px",fw:500,children:[e("panel.panel_name"),n.jsx(II,{})]}),n.jsx(a.ActionIcon,{variant:"subtle",color:"blue",disabled:!o||c,onClick:l,children:n.jsx(C.IconDeviceFloppy,{size:18})})]}),n.jsx(a.TextInput,{value:s,onChange:i,required:!0})]})}),EI=k.observer(()=>{const{t:e}=_.useTranslation(),{panel:t}=Pe();return n.jsx(a.Stack,{gap:6,mb:10,children:n.jsxs(a.Group,{pl:6,justify:"flex-start",gap:20,children:[n.jsx(a.Checkbox,{size:"sm",checked:t.title.show,onChange:r=>t.title.setShow(r.currentTarget.checked),label:e("panel.show_title"),sx:{userSelect:"none"}}),n.jsx(a.Checkbox,{size:"sm",checked:!0,disabled:!0,label:e("panel.use_name_as_title")})]})})});function PI(){const{t:e}=_.useTranslation();return n.jsxs(a.Stack,{sx:{height:"100%"},children:[n.jsx(zI,{}),n.jsx(a.Divider,{label:e("common.info"),labelPosition:"center",variant:"dashed"}),n.jsx(MI,{}),n.jsx(EI,{}),n.jsx(DI,{})]})}const AI={width:"fit-content",minWidth:"100%",tableLayout:"fixed",tr:{width:"fit-content"},th:{position:"relative"},"th, td":{wordBreak:"break-word"},".resizer":{position:"absolute",right:0,top:"50%",transform:"translateY(-50%)",cursor:"col-resize",userSelect:"none",touchAction:"none"},".resizer.isResizing":{color:"#228be6",opacity:"1",backgroundColor:"rgb(248, 249, 250)"},"@media (hover: hover)":{".resizer":{opacity:"0"},"*:hover > .resizer":{color:"#228be6",opacity:"1"}}};function wg({data:e}){const t=f.useMemo(()=>{if(!Array.isArray(e)||e.length===0)return[];const s=We.createColumnHelper();return Object.keys(e[0]).map(i=>s.accessor(i,{cell:o=>o.getValue()}))},[e]),r=We.useReactTable({data:e,columns:t,columnResizeMode:"onChange",getCoreRowModel:We.getCoreRowModel()});return e.length===0?n.jsx(a.Box,{sx:{height:"5em"}}):n.jsx(Ie,{children:n.jsxs(a.Table,{sx:AI,children:[n.jsx(a.Table.Thead,{children:r.getHeaderGroups().map(s=>n.jsx(a.Table.Tr,{children:s.headers.map(i=>n.jsxs(a.Table.Th,{style:{width:i.getSize()},children:[i.isPlaceholder?null:We.flexRender(i.column.columnDef.header,i.getContext()),n.jsx(a.ActionIcon,{variant:"subtle",onMouseDown:i.getResizeHandler(),onTouchStart:i.getResizeHandler(),className:`resizer ${i.column.getIsResizing()?"isResizing":""}`,children:n.jsx(C.IconArrowBarToRight,{})})]},i.id))},s.id))}),n.jsx(a.Table.Tbody,{children:r.getRowModel().rows.map(s=>n.jsx(a.Table.Tr,{children:s.getVisibleCells().map(i=>n.jsx(a.Table.Td,{children:n.jsx(Ie,{children:typeof i.getValue()=="object"?n.jsx("pre",{children:JSON.stringify(i.getValue(),null,2)}):We.flexRender(i.column.columnDef.cell,i.getContext())})},i.id))},s.id))})]})})}const LI=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],OI={section:{"&[data-position=left]":{width:"70px",textAlign:"center"}},input:{paddingLeft:"70px"}},VI=({data:e,page:t,setPage:r,limit:s,setLimit:i})=>{const{t:o}=_.useTranslation(),l=e.length,c=Math.ceil(l/s),u=p=>{p&&(r(1),i(Number(p)))};if(l===0)return null;const d=c===1&&l<=10;return n.jsxs(a.Group,{pt:10,px:10,justify:"space-between",children:[n.jsxs(a.Group,{justify:"flex-start",children:[c>1&&n.jsx(a.Pagination,{size:"sm",value:t,onChange:r,total:c,withEdges:c>7,styles:{control:{height:"30px"}}}),!d&&n.jsx(a.Select,{leftSection:n.jsx(a.Text,{ta:"center",c:"dimmed",size:"14px",children:o("common.pagination.page_size")}),size:"xs",styles:OI,data:LI,value:String(s),onChange:u})]}),n.jsx(a.Group,{justify:"flex-end",children:n.jsx(a.Text,{c:"dimmed",my:0,size:"14px",children:o("common.pagination.total_rows",{total:l})})})]})},BI=md(({data:e,loading:t})=>{const[r,s]=f.useState(1),[i,o]=f.useState(20),l=f.useMemo(()=>{const c=(r-1)*i,u=c+i;return e.slice(c,u)},[e,r,i]);return n.jsxs(Ie,{children:[n.jsx(VI,{data:e,page:r,setPage:s,limit:i,setLimit:o}),n.jsxs(a.Box,{py:10,sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[n.jsx(a.LoadingOverlay,{visible:t,overlayProps:{blur:2}}),n.jsx(wg,{data:l})]})]})}),qI=k.observer(({queryID:e})=>{const{t}=_.useTranslation(),r=Te(),s=f.useMemo(()=>r.queries.findByID(e),[r,e]);if(!s||s.state==="loading")return null;const{error:i,metricQueryPayloadErrorString:o,stateMessage:l}=s;return i||o?n.jsx(a.Text,{mt:10,c:"red",size:"md",ta:"center",ff:"monospace",children:i??o}):l?n.jsx(a.Text,{size:"sm",mt:10,c:"gray",ta:"center",children:t(l)}):null}),Uo=k.observer(({id:e,moreActions:t,refreshOnMount:r})=>{const{t:s}=_.useTranslation(),i=Te(),{data:o,state:l}=i.getDataStuffByID(e),c=l==="loading",u=f.useCallback(()=>{i.queries.refetchDataByQueryID(e)},[e,i]),d=()=>{i.queries.downloadDataByQueryID(e)};f.useEffect(()=>{r&&u()},[u,r]);const p=!Array.isArray(o)||o.length===0;return n.jsxs(a.Stack,{gap:0,sx:{height:"100%",border:"1px solid #eee"},children:[n.jsxs(a.Group,{justify:"space-between",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[n.jsx(a.Group,{justify:"flex-start",children:n.jsx(a.Text,{size:"sm",fw:500,children:s("data.preview_data")})}),n.jsxs(a.Group,{pr:15,children:[t,n.jsx(a.ActionIcon,{variant:"subtle",color:"blue",disabled:c,onClick:u,children:n.jsx(C.IconRefresh,{size:16})}),n.jsx(a.ActionIcon,{variant:"subtle",color:"blue",disabled:c||p,onClick:d,children:n.jsx(C.IconDownload,{size:16})})]})]}),n.jsxs(a.Box,{pb:20,sx:{position:"relative",flexGrow:1,overflow:"auto"},children:[n.jsx(qI,{queryID:e}),n.jsx(BI,{data:o,loading:c})]})]})}),NI=k.observer(function(){const{t}=_.useTranslation(),r=se(),s=re(),{panel:i}=Pe(),[o,l]=f.useState(!1),c=d=>{r.editor.setPath(["_QUERIES_",d])},u=i.queryIDs.length;return n.jsxs(n.Fragment,{children:[n.jsx(a.Drawer,{opened:o,onClose:()=>l(!1),title:t("panel.settings.choose_queries"),padding:"xl",size:500,zIndex:320,children:n.jsx(a.Checkbox.Group,{value:[...i.queryIDs],onChange:i.setQueryIDs,children:n.jsx(a.Stack,{gap:"lg",children:s.queries.options.map(d=>n.jsx(a.Checkbox,{label:d.label,value:d.value},d.value))})})}),n.jsxs(a.Stack,{gap:6,children:[n.jsx(a.Group,{justify:"flex-start",children:n.jsx(a.Button,{variant:"light",size:"sm",leftSection:n.jsx(C.IconLine,{size:16}),onClick:()=>l(!0),children:t(u===0?"panel.settings.need_to_choose_queries":"panel.settings.choose_queries")})}),u===1&&n.jsx(Uo,{id:i.queryIDs[0],moreActions:n.jsx(a.Tooltip,{label:t("query.open"),children:n.jsx(a.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>c(i.queryIDs[0]),children:n.jsx(C.IconArrowCurveRight,{size:16})})})}),u>1&&n.jsxs(a.Tabs,{defaultValue:i.queryIDs[0],children:[n.jsx(a.Tabs.List,{children:i.queries.map(d=>n.jsx(a.Tabs.Tab,{value:d.id,children:d.name},d.id))}),i.queries.map(d=>n.jsx(a.Tabs.Panel,{value:d.id,children:n.jsx(Uo,{id:d.id,moreActions:n.jsx(a.Tooltip,{label:t("query.open"),children:n.jsx(a.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>c(d.id),children:n.jsx(C.IconArrowCurveRight,{size:16})})})})},d.id))]})]})]})}),$I=k.observer(()=>{const{panel:e}=He();return e.title.show?n.jsx(a.Group,{grow:!0,justify:"center",className:"panel-title-wrapper",sx:{flexGrow:1},children:n.jsx(a.Text,{size:"sm",ta:"center",lineClamp:1,className:"panel-title-text",children:e.title.show?e.name:""})}):null}),GI=k.observer(()=>{const{panel:e}=He();return n.jsx(Ie,{children:n.jsxs(a.Box,{className:`panel-root ${e.title.show?"panel-root--show-title":""}`,p:0,sx:{border:"1px solid",borderColor:e.style.border.enabled?"#e9ecef":"transparent",flexGrow:0,flexShrink:0,width:"600px !important",height:"450px !important"},children:[n.jsx(a.Box,{className:"panel-description-popover-wrapper",children:n.jsx(Vo,{})}),n.jsx($I,{}),n.jsx(Bo,{panel:e})]})})});function FI(){const{t:e}=_.useTranslation(),{vizManager:t}=f.useContext(tn);return f.useMemo(()=>v.orderBy(Object.entries(v.groupBy(t.availableVizList,"displayGroup")),[i=>i[0]],["asc"]).map(([i,o])=>{const l=o.map(c=>({value:c.name,label:e(c.displayName??it.name)}));return{group:e(i??"ungrouped"),items:v.orderBy(l,[c=>c.label],["asc"])}}),[t])}const QI=k.observer(({value:e,submit:t})=>{const{t:r}=_.useTranslation(),[s,i]=ze.useInputState(e);f.useEffect(()=>{i(e)},[e]);const o=FI(),l=e!==s;return n.jsx(a.Select,{label:r("visualization.component"),value:s,searchable:!0,onChange:i,data:o,rightSection:n.jsx(a.ActionIcon,{variant:"filled",color:"green",disabled:!l,onClick:()=>t(s),styles:{root:{pointerEvents:"all"}},children:n.jsx(C.IconDeviceFloppy,{size:20})}),maxDropdownHeight:600})}),Cg=[];function WI(e,t){try{return e.resolveComponent(t).createConfig()}catch{return null}}function RI(){const{data:e,panel:{variables:t,viz:r,title:s,name:i,queryIDs:o,description:l,id:c}}=Pe(),{vizManager:u}=f.useContext(tn),d={name:i,title:s,description:l,viz:r,queryIDs:o,id:c},p=Ah(d);try{return u.resolveComponent(d.viz.type),n.jsx(Ms,{configure:p,children:n.jsx(c5,{variables:t,setVizConf:r.setConf,panel:d,vizManager:u,data:e})})}catch(h){return console.info(v.get(h,"message")),null}}const UI=k.observer(()=>{const{data:e,panel:{viz:t}}=Pe(),{vizManager:r}=f.useContext(tn),s=f.useCallback(d=>{if(d===t.type)return;const p=WI(r,d);t.setType(d),t.setConf(p||{})},[t.type]),i=d=>{try{t.setConf(JSON.parse(d))}catch(p){console.error(p)}},o=f.useMemo(()=>{var d;return(d=Cg.find(p=>p.value===t.type))==null?void 0:d.Panel},[t.type,Cg]),l=RI(),c=o?f.createElement(o,{data:e,conf:t.conf,setConf:t.setConf}):null,u=l||c;return n.jsxs(a.Stack,{align:"stretch",sx:{height:"100%",overflow:"hidden"},children:[n.jsx(QI,{submit:s,value:t.type}),n.jsxs(Ie,{children:[n.jsx(a.Stack,{pb:10,sx:{flexGrow:1,maxHeight:"100%",overflow:"auto"},children:u}),!u&&n.jsx(a.JsonInput,{minRows:20,label:"Config",value:JSON.stringify(t.conf,null,2),onChange:i})]})]})}),YI=k.observer(({panel:e,sourceViewID:t})=>{const{t:r}=_.useTranslation(),s=re(),[i,o]=f.useState(t);f.useEffect(()=>{o(t)},[t]);const[l,{open:c,close:u}]=ze.useDisclosure(!1),d=()=>{e.moveToView(t,i),u()};return n.jsxs(n.Fragment,{children:[n.jsx(a.Button,{size:"xs",variant:"subtle",color:"blue",onClick:c,leftSection:n.jsx(C.IconBoxMultiple,{size:14}),children:r("panel.settings.change_view")}),n.jsx(a.Modal,{opened:l,onClose:u,title:r("panel.settings.change_view_title"),zIndex:320,children:n.jsxs(a.Stack,{sx:{maxHeight:"calc(100vh - 185px)",overflow:"hidden"},children:[n.jsx(a.Radio.Group,{value:i,onChange:o,pb:10,sx:{flexGrow:1,maxHeight:"calc(100vh - 185px - 30px)",overflow:"auto"},children:n.jsx(a.Stack,{gap:"xs",children:s.views.options.map(p=>n.jsx(a.Radio,{value:p.value,label:p.label},p.value))})}),n.jsxs(a.Group,{wrap:"nowrap",justify:"space-between",sx:{flexGrow:0,flexShrink:0},children:[n.jsx(a.Button,{size:"xs",color:"red",leftSection:n.jsx(C.IconX,{size:14}),onClick:u,children:r("common.actions.cancel")}),n.jsx(a.Button,{size:"xs",color:"blue",leftSection:n.jsx(C.IconDeviceFloppy,{size:14}),onClick:d,disabled:i===t,children:r("common.actions.confirm")})]})]})})]})}),KI=k.observer(({sx:e={}})=>{const{t}=_.useTranslation(),r=Te(),{panel:s}=He(),i=r.dashboardState,o=(()=>{const l={...i,...s.variableStrings};return JSON.stringify(l,null,2)})();return n.jsx(a.Stack,{sx:{overflow:"hidden",...e},children:n.jsxs(a.Tabs,{defaultValue:"vars",keepMounted:!1,children:[n.jsxs(a.Tabs.List,{children:[n.jsx(a.Tabs.Tab,{value:"guide",leftSection:n.jsx(C.IconAlertCircle,{size:14}),children:t("panel.variable.guide.tabs.guide")}),n.jsx(a.Tabs.Tab,{value:"vars",leftSection:n.jsx(C.IconVariable,{size:14}),children:t("panel.variable.guide.tabs.vars")})]}),n.jsx(a.Tabs.Panel,{value:"guide",pt:"xs",children:n.jsx(zt.CodeHighlight,{language:"sql",sx:{width:"100%"},withCopyButton:!1,code:t("panel.variable.guide.text")})}),n.jsx(a.Tabs.Panel,{value:"vars",pt:"xs",children:n.jsx(zt.CodeHighlight,{language:"json",sx:{width:"100%"},withCopyButton:!1,code:o})})]})})}),Yo={name:"new_var",size:"1rem",weight:"initial",color:{type:"static",staticColor:"Red"},data_field:"",aggregation:{type:"sum",config:{},fallback:"0"},formatter:{output:"number",mantissa:0,trimMantissa:!1,average:!1}};class XI{constructor(t){N(this,"panel");N(this,"selected");this.panel=t,t.variables.length>0&&(this.selected=t.variables[0]),te.makeAutoObservable(this,{},{deep:!1,autoBind:!0})}get variables(){return this.panel.variables}get variableOptions(){return this.panel.variables.map(t=>({label:t.name,value:t.name,description:t.aggregation.type}))}addNew(){const t=this.panel.variables.filter(r=>r.name.startsWith(Yo.name)).length;this.panel.addVariable(v.cloneDeep({...Yo,name:`${Yo.name}${t||""}`})),this.selected=v.last(this.panel.variables)}select(t){this.selected=t}selectByName(t){if(!t){console.warn("Unexpected null name when calling selectByName");return}const r=this.variables.find(s=>s.name===t);if(!r){console.error(`Variable by name[${t}] not found`);return}this.selected=r}remove(t){this.selected===t&&(this.selected=void 0);const r=this.panel.variables.indexOf(t);if(this.panel.removeVariable(t),!this.selected&&!v.isEmpty(this.panel.variables)){const s=Math.min(this.panel.variables.length-1,r);this.selected=this.panel.variables[s]}}}function HI(){const{panel:e}=Pe();return U.useCreation(()=>new XI(e),[e])}const ZI=f.forwardRef(function({value:t,onChange:r,remove:s},i){const{t:o}=_.useTranslation(),l=(c,u)=>{const d=v.cloneDeep(t);v.set(d,c,u),r(d)};return n.jsxs(a.Stack,{ref:i,children:[n.jsxs(a.Stack,{gap:"xs",px:"sm",py:"md",sx:{border:"1px solid #e9ecef"},children:[n.jsxs(a.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(a.TextInput,{label:o("common.name"),required:!0,value:t.name,onChange:c=>l("name",c.currentTarget.value)}),n.jsx(R,{label:o("common.data_field"),required:!0,value:t.data_field,onChange:c=>l("data_field",c)})]}),n.jsx(Va,{label:o("panel.variable.aggregation.label"),pt:0,value:t.aggregation,onChange:c=>l("aggregation",c),withFallback:!0}),t.aggregation.type!=="custom"&&n.jsxs(n.Fragment,{children:[n.jsx(a.Divider,{mt:"xl",mb:0,label:o("numbro.format.label"),labelPosition:"center",variant:"dashed"}),n.jsx(Tt,{value:t.formatter,onChange:c=>l("formatter",c)})]})]}),n.jsx(a.Button,{mt:20,leftSection:n.jsx(C.IconTrash,{size:16}),color:"red",variant:"light",onClick:s,children:o("panel.variable.delete")})]})}),JI=k.observer(e=>{const{t}=_.useTranslation(),r=U.useCreation(()=>Dh(e.variable),[e.variable]),s=()=>e.uiModel.remove(e.variable);return n.jsxs(a.Stack,{"data-testid":"variable-editor",align:"stretch",children:[n.jsxs(a.Group,{justify:"space-between",children:[n.jsx(a.Button,{variant:"subtle",size:"xs",disabled:!r.changed,color:"red",onClick:r.reset,leftSection:n.jsx(C.IconRecycle,{size:18}),children:t("common.actions.revert_changes")}),n.jsx(a.Button,{variant:"filled",size:"xs",disabled:!r.changed,color:"green",onClick:r.commit,leftSection:n.jsx(C.IconDeviceFloppy,{size:18}),children:t("common.actions.save_changes")})]}),n.jsx(ZI,{value:g.getSnapshot(r.copy),onChange:r.update,remove:s})]})});k.observer(e=>{const{uiModel:t}=e;return n.jsx(a.Stack,{className:"var-list",children:t.variables.map(r=>n.jsx(a.Button,{variant:t.selected===r?"filled":"subtle",color:"gray",onClick:()=>t.select(r),children:r.name},r.name))})});const eM=k.observer(({model:e})=>{const{t}=_.useTranslation();return n.jsx(a.Overlay,{color:"#fff",backgroundOpacity:1,sx:{position:"absolute"},children:n.jsx(a.Button,{variant:"light",size:"xs",leftSection:n.jsx(C.IconPlus,{size:16}),onClick:e.addNew,sx:{flexGrow:0,flexShrink:0,alignSelf:"flex-end",height:"38px"},children:t("panel.variable.add")})})}),tM=k.observer(()=>{var r;const{t:e}=_.useTranslation(),t=HI();return t.variableOptions.length===0?n.jsx(eM,{model:t}):n.jsxs(a.Stack,{pb:20,children:[n.jsxs(a.Group,{justify:"flex-start",children:[n.jsx(a.Select,{label:e("panel.variable.labels"),data:t.variableOptions,value:(r=t.selected)==null?void 0:r.name,onChange:t.selectByName,maxDropdownHeight:600,sx:{flexGrow:1}}),n.jsx(a.Button,{variant:"light",size:"xs",leftSection:n.jsx(C.IconPlus,{size:16}),onClick:t.addNew,sx:{flexGrow:0,flexShrink:0,alignSelf:"flex-end",height:"38px"},children:e("panel.variable.add")})]}),n.jsx(a.Divider,{variant:"dashed"}),t.selected?n.jsx(JI,{uiModel:t,variable:t.selected}):n.jsx("span",{children:"Select or create a new variable on right side"})]})}),nM={root:{flexGrow:1,width:"100%",minWidth:"1200px",overflow:"hidden"},panel:{width:"100%",minWidth:"1200px",height:"calc(100% - 44px)",padding:10,overflow:"auto"}},Ko=({children:e})=>n.jsxs(a.Group,{wrap:"nowrap",grow:!0,justify:"flex-start",gap:20,sx:{width:"100%",height:"100%",position:"relative"},children:[n.jsx(a.Box,{sx:{maxWidth:"calc(100% - 610px - 10px)",height:"100%",overflow:"auto"},children:e}),n.jsxs(a.Stack,{justify:"flex-start",sx:{alignSelf:"flex-start",width:"600px",flexGrow:0,flexShrink:0},children:[n.jsx(GI,{}),n.jsx(a.Box,{sx:{flexGrow:1},children:n.jsx(KI,{})})]})]});function rM(e){return!["richText","button"].includes(e)}const sM=k.observer(({panel:e})=>{const{t}=_.useTranslation(),r=dt.useModals(),s=se(),i=re(),[o,l]=f.useState(s.editor.panelTab),c=e.queries,d=rM(e.viz.type)&&e.dataLoading,p=d||e.queryErrors.length>0||e.queryStateMessages!==""||c.length===0,h=s.editor.path[1];f.useEffect(()=>{l(j=>p&&j==="Visualization"?"Data":j)},[e.id,p]);const x=f.useCallback(j=>{l(j),s.editor.setPanelTab(o)},[]),b=()=>{s.editor.setPath(["_VIEWS_",h])},m=()=>r.openConfirmModal({title:`${t("panel.delete")}?`,labels:{confirm:t("common.actions.confirm"),cancel:t("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>{i.removePanelByID(e.id,h),b()},confirmProps:{color:"red"},zIndex:320});return n.jsxs(ii,{value:{panel:e,data:e.data,loading:d,errors:e.queryErrors,downloadPanelScreenshot:()=>{}},children:[n.jsxs(a.Group,{px:16,justify:"space-between",sx:{borderBottom:"1px solid #eee"},children:[n.jsx(a.Text,{size:"sm",pt:9,pb:8,children:e.name}),n.jsxs(a.Group,{justify:"flex-end",wrap:"nowrap",children:[n.jsx(YI,{panel:e,sourceViewID:h}),n.jsx(a.Button,{size:"xs",variant:"subtle",color:"red",onClick:m,leftSection:n.jsx(C.IconTrash,{size:14}),children:t("panel.delete")})]})]}),n.jsxs(a.Tabs,{value:o,onChange:x,keepMounted:!1,styles:nM,children:[n.jsxs(a.Tabs.List,{children:[n.jsx(a.Tabs.Tab,{value:"Data",leftSection:n.jsx(C.IconDatabase,{size:14}),disabled:d,children:t("data.label")}),n.jsx(a.Tabs.Tab,{value:"Panel",leftSection:n.jsx(C.IconAppWindow,{size:14}),children:t("panel.label")}),n.jsx(a.Tabs.Tab,{value:"Variables",leftSection:n.jsx(C.IconVariable,{size:14}),disabled:p,children:n.jsx(a.Tooltip,{label:t("data.requires_data"),disabled:!p,withinPortal:!0,zIndex:310,children:n.jsx(a.Text,{size:"sm",children:t("panel.variable.labels")})})}),n.jsx(a.Tabs.Tab,{value:"Visualization",leftSection:n.jsx(C.IconChartHistogram,{size:14}),disabled:p,children:n.jsx(a.Tooltip,{label:t("data.requires_data"),disabled:!p,withinPortal:!0,zIndex:310,children:n.jsx(a.Text,{size:"sm",children:t("visualization.label")})})}),n.jsx(a.Tabs.Tab,{value:"Interactions",leftSection:n.jsx(C.IconRoute,{size:14}),children:t("interactions.label")})]}),n.jsxs(a.Tabs.Panel,{value:"Data",children:[n.jsx(a.LoadingOverlay,{visible:d,transitionProps:{exitDuration:0}}),n.jsx(NI,{})]}),n.jsx(a.Tabs.Panel,{value:"Panel",children:n.jsx(Ko,{children:n.jsx(PI,{})})}),n.jsx(a.Tabs.Panel,{value:"Variables",children:n.jsx(Ko,{children:n.jsx(tM,{})})}),n.jsx(a.Tabs.Panel,{value:"Visualization",children:n.jsx(Ie,{children:n.jsx(Ko,{children:n.jsx(UI,{})})})}),n.jsx(a.Tabs.Panel,{value:"Interactions",children:n.jsx(Ie,{children:n.jsx(Iv,{})})})]})]})}),iM=k.observer(({viewID:e,panelID:t})=>{const r=re();if(!r.views.findByID(e))return n.jsxs(a.Text,{size:"14px",children:["View by ID[",e,"] is not found"]});const i=r.panels.findByID(t);return i?n.jsx(sM,{panel:i}):n.jsxs(a.Text,{size:"14px",children:["Panel by ID[",t,"] is not found"]})}),aM=k.observer(()=>{const{t:e}=_.useTranslation(),[t,r]=f.useState([]),s=dt.useModals(),i=se(),o=x=>{i.editor.setPath(["_QUERIES_",x])},l=()=>{s.openConfirmModal({title:"Delete ununsed queries?",children:n.jsx(a.Text,{size:"sm",children:"This action cannot be undone."}),labels:{confirm:e("common.actions.confirm"),cancel:e("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>i.content.removeUnusedQueries(),confirmProps:{color:"red"},zIndex:320})},c=()=>{i.content.queries.downloadSchema(t)},u=f.useMemo(()=>i.content.queries.sortedList.map(x=>x.id),[i.content.queries.sortedList]),d=()=>{r(u)},p=()=>{r([])},h=i.content.queriesUsage;return n.jsxs(a.Stack,{sx:{height:"100%"},gap:"sm",pb:"59px",children:[n.jsx(a.Box,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:n.jsx(a.Text,{px:"md",ta:"left",sx:{userSelect:"none",cursor:"default"},children:e("query.manage")})}),n.jsxs(a.Flex,{justify:"space-between",align:"center",px:12,children:[n.jsxs(a.Group,{justify:"flex-start",children:[n.jsxs(a.Button.Group,{children:[n.jsx(a.Button,{variant:"default",size:"xs",onClick:d,children:e("common.actions.select_all")}),n.jsx(a.Button,{variant:"default",size:"xs",onClick:p,children:e("common.actions.clear_selection")})]}),n.jsx(a.Button,{size:"xs",color:"blue",leftSection:n.jsx(C.IconCode,{size:14}),disabled:t.length===0,onClick:c,children:e("common.actions.download_schema")})]}),n.jsx(a.Button,{variant:"subtle",size:"xs",color:"red",leftSection:n.jsx(C.IconTrash,{size:14}),disabled:!i.content.hasUnusedQueries,onClick:l,children:e("query.delete_unused")})]}),n.jsx(a.Box,{sx:{flexGrow:1,overflow:"auto"},children:n.jsx(a.Checkbox.Group,{size:"xs",value:t,onChange:r,children:n.jsxs(a.Table,{fz:"sm",highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[n.jsx(a.Table.Thead,{children:n.jsxs(a.Table.Tr,{children:[n.jsx(a.Table.Th,{style:{width:"40px"}}),n.jsx(a.Table.Th,{children:e("common.name")}),n.jsx(a.Table.Th,{style:{width:"200px"},children:e("data_source.label")}),n.jsx(a.Table.Th,{style:{width:"100px",textAlign:"right"},children:e("common.type")}),n.jsx(a.Table.Th,{style:{width:"100px",textAlign:"center"},children:e("query.usage.label")}),n.jsx(a.Table.Th,{style:{width:"300px",paddingLeft:"24px"},children:e("common.action")})]})}),n.jsx(a.Table.Tbody,{children:i.content.queries.sortedList.map(x=>{var m;const b=((m=h[x.id])==null?void 0:m.length)??0;return n.jsxs(a.Table.Tr,{children:[n.jsx(a.Table.Td,{children:n.jsx(a.Checkbox,{value:x.id,styles:{input:{cursor:"pointer"}}})}),n.jsx(a.Table.Td,{children:x.name}),n.jsx(a.Table.Td,{children:x.key}),n.jsx(a.Table.Td,{style:{textAlign:"right"},children:x.type}),n.jsx(a.Table.Td,{style:{color:b===0?"#ff0000":"#000",fontWeight:b===0?"bold":"normal",textAlign:"center"},children:b}),n.jsx(a.Table.Td,{children:n.jsx(a.Button,{variant:"subtle",size:"xs",onClick:()=>o(x.id),children:e("common.actions.open")})})]},x.id)})})]})})})]})}),oM=e=>{const{t}=_.useTranslation(),{queryModel:r}=e,s=se(),i=re(),l=i.findQueryUsage(r.id).length>0,c=dt.useModals(),u=()=>{c.openConfirmModal({title:`${t("query.delete")}?`,labels:{confirm:t("common.actions.confirm"),cancel:t("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>{i.queries.removeQuery(r.id),s.editor.setPath(["_QUERIES_",""])},confirmProps:{color:"red"},zIndex:320})};return l?n.jsx(a.Tooltip,{label:t("query.cant_delete"),withArrow:!0,events:{hover:!0,focus:!1,touch:!1},withinPortal:!0,zIndex:320,position:"top-end",children:n.jsx(a.Box,{sx:{alignSelf:"flex-end"},children:n.jsx(a.Button,{disabled:!0,size:"xs",leftSection:n.jsx(C.IconTrash,{size:16}),children:t("query.delete")})})}):n.jsx(a.Button,{color:"red",size:"xs",onClick:u,leftSection:n.jsx(C.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:t("query.delete")})},lM=k.observer(oM),Sg=({width:e="calc(100% - 32px)",lastWidth:t="50%",height:r,count:s,spacing:i=16,pl:o=0})=>n.jsxs(a.Stack,{gap:i,mt:6,pl:o,children:[Array.from(new Array(s-1),(l,c)=>n.jsx(a.Skeleton,{width:e,height:r,radius:"xs"},c)),n.jsx(a.Skeleton,{width:t,height:r,radius:"xs"})]}),Pr=({value:e})=>e===null||e===""?null:n.jsx(a.Tooltip,{label:e,disabled:!e,multiline:!0,zIndex:340,children:n.jsx(a.ActionIcon,{variant:"subtle",children:n.jsx(C.IconInfoCircle,{size:14})})}),cM=({column:e})=>{const{column_key:t,column_key_text:r}=e;return t?n.jsx(a.Tooltip,{label:r,disabled:!r,children:n.jsx(a.Badge,{variant:"light",children:t})}):null},uM=k.observer(({dataSource:e})=>{const{columns:t}=e.dbInfo;return t.loading?n.jsx(Sg,{height:"24px",width:"100%",lastWidth:"100%",count:20,pl:6}):t.empty?null:n.jsxs(a.Table,{highlightOnHover:!0,fz:14,sx:{width:"auto",minWidth:"1000px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[n.jsxs("colgroup",{children:[n.jsx("col",{style:{width:50}}),n.jsx("col",{style:{minWidth:300}}),n.jsx("col",{style:{width:30}}),n.jsx("col",{style:{width:70}}),n.jsx("col",{style:{minWidth:300}}),n.jsx("col",{style:{minWidth:80,width:80}}),n.jsx("col",{style:{minWidth:120,width:120}})]}),n.jsx(a.Table.Thead,{children:n.jsxs(a.Table.Tr,{children:[n.jsx(a.Table.Th,{children:"#"}),n.jsx(a.Table.Th,{children:"Column Name"}),n.jsx(a.Table.Th,{}),n.jsx(a.Table.Th,{}),n.jsx(a.Table.Th,{children:"Type"}),n.jsx(a.Table.Th,{children:"Nullable"}),n.jsx(a.Table.Th,{children:"Default Value"})]})}),n.jsx(a.Table.Tbody,{children:t.data.map(r=>n.jsxs(a.Table.Tr,{children:[n.jsx(a.Table.Td,{children:r.ordinal_position}),n.jsx(a.Table.Td,{children:r.column_name}),n.jsx(a.Table.Td,{children:n.jsx(Pr,{value:r.column_comment})}),n.jsx(a.Table.Td,{children:n.jsx(cM,{column:r})}),n.jsx(a.Table.Td,{children:r.column_type}),n.jsx(a.Table.Td,{children:r.is_nullable}),n.jsx(a.Table.Td,{children:n.jsx(Pr,{value:r.column_default})})]},r.column_name))})]})}),dM=k.observer(({dataSource:e})=>{const{indexes:t}=e.dbInfo,r=t.data;return n.jsxs(a.Table,{highlightOnHover:!0,fz:14,sx:{width:"auto",minWidth:"950px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[n.jsxs("colgroup",{children:[n.jsx("col",{style:{width:100}}),n.jsx("col",{style:{minWidth:300}}),n.jsx("col",{style:{width:150}}),n.jsx("col",{style:{width:150}}),n.jsx("col",{style:{width:250}})]}),n.jsx(a.Table.Thead,{children:n.jsxs(a.Table.Tr,{children:[n.jsx(a.Table.Th,{children:"Index Length"}),n.jsx(a.Table.Th,{children:"Index Name"}),n.jsx(a.Table.Th,{children:"Index Algorithm"}),n.jsx(a.Table.Th,{children:"Unique"}),n.jsx(a.Table.Th,{children:"Column Name"})]})}),n.jsx(a.Table.Tbody,{children:r.map(s=>n.jsxs(a.Table.Tr,{children:[n.jsx(a.Table.Td,{children:s.index_length}),n.jsx(a.Table.Td,{children:s.index_name}),n.jsx(a.Table.Td,{children:s.index_algorithm}),n.jsx(a.Table.Td,{children:s.is_unique?"YES":"NO"}),n.jsx(a.Table.Td,{children:s.column_name})]},s.index_name))})]})}),pM=k.observer(({dataSource:e})=>{const{indexes:t}=e.dbInfo,r=t.data;return n.jsxs(a.Table,{highlightOnHover:!0,fz:14,sx:{width:"auto",minWidth:"850px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[n.jsxs("colgroup",{children:[n.jsx("col",{style:{minWidth:300}}),n.jsx("col",{style:{width:150}}),n.jsx("col",{style:{width:100}}),n.jsx("col",{style:{width:100}}),n.jsx("col",{style:{width:100}}),n.jsx("col",{style:{width:100}})]}),n.jsx(a.Table.Thead,{children:n.jsxs(a.Table.Tr,{children:[n.jsx(a.Table.Th,{children:"Index Name"}),n.jsx(a.Table.Th,{children:"Index Algorithm"}),n.jsx(a.Table.Th,{children:"Unique"}),n.jsx(a.Table.Th,{children:"Definition"}),n.jsx(a.Table.Th,{children:"Condition"}),n.jsx(a.Table.Th,{children:"Comment"})]})}),n.jsx(a.Table.Tbody,{children:r.map(s=>n.jsxs(a.Table.Tr,{children:[n.jsx(a.Table.Td,{children:s.index_name}),n.jsx(a.Table.Td,{children:s.index_algorithm}),n.jsx(a.Table.Td,{children:s.is_unique?"YES":"NO"}),n.jsx(a.Table.Td,{children:n.jsx(Pr,{value:s.index_definition})}),n.jsx(a.Table.Td,{children:n.jsx(Pr,{value:s.condition})}),n.jsx(a.Table.Td,{children:n.jsx(Pr,{value:s.comment})})]},s.index_name))})]})}),hM=k.observer(({dataSource:e})=>{const{indexes:t}=e.dbInfo;return t.loading||t.empty?null:e.type===J.MySQL?n.jsx(dM,{dataSource:e}):e.type===J.Postgresql?n.jsx(pM,{dataSource:e}):null}),gM=k.observer(({dataSource:e})=>n.jsxs(a.Stack,{gap:40,pt:10,sx:{flexGrow:1,overflow:"auto",position:"relative"},children:[n.jsx(Ie,{children:n.jsx(uM,{dataSource:e})}),n.jsx(Ie,{children:n.jsx(hM,{dataSource:e})})]}));function fM({table_type:e}){return e==="VIEW"?n.jsx(C.IconEye,{size:14}):e==="BASE TABLE"?n.jsx(C.IconTable,{size:14}):null}const xM=k.observer(({dataSource:e})=>{const t=e.dbInfo,{tables:r}=t;return r.loading?n.jsx(Sg,{height:"24px",lastWidth:"50%",count:15}):n.jsx(a.Box,{h:"100%",sx:{overflow:"auto",".mantine-NavLink-label":{fontFamily:"monospace"}},children:Object.entries(r.data).map(([s,i])=>n.jsx(a.NavLink,{label:s,title:s,leftSection:n.jsx(C.IconDatabase,{size:14}),defaultOpened:t.table_schema===s,pl:0,childrenOffset:14,children:i.map(o=>n.jsx(a.NavLink,{label:o.table_name,title:o.table_name,leftSection:n.jsx(fM,{table_type:o.table_type}),onClick:()=>{t.setKeywords(s,o.table_name)},active:t.table_name===o.table_name},o.table_name))},s))})}),mM=({visible:e})=>n.jsx(a.Box,{py:10,sx:{width:"100%",height:"100%",overflow:"hidden",position:"relative"},children:n.jsx(a.LoadingOverlay,{visible:e})}),bM=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],yM={section:{"&[data-position=left]":{width:"70px",textAlign:"center"}},input:{paddingLeft:"70px"}},vM=k.observer(({dataSource:e})=>{const{t}=_.useTranslation(),{tableData:r}=e.dbInfo;return n.jsxs(a.Group,{pt:10,px:10,justify:"space-between",children:[n.jsxs(a.Group,{justify:"flex-start",children:[r.maxPage>1&&n.jsx(a.Pagination,{size:"sm",value:r.page,onChange:r.setPage,total:r.maxPage,withEdges:r.maxPage>7,styles:{control:{height:"30px"}}}),n.jsx(a.Select,{leftSection:n.jsx(a.Text,{ta:"center",c:"dimmed",size:"14px",children:t("common.pagination.page_size")}),size:"xs",styles:yM,data:bM,value:String(r.limit),onChange:s=>r.setLimit(Number(s)),comboboxProps:{zIndex:340}})]}),n.jsx(a.Group,{justify:"flex-end",children:n.jsx(a.Text,{c:"dimmed",my:0,size:"14px",children:t("common.pagination.total_rows",{total:r.total})})})]})}),_M=k.observer(({dataSource:e})=>{const t=e.dbInfo.tableData;return t.maxPage===0?n.jsx(a.Text,{mt:20,c:"red",size:"md",ta:"center",ff:"monospace",children:"This table is empty"}):t.error?n.jsx(a.Text,{mt:20,c:"red",size:"md",ta:"center",ff:"monospace",children:t.error}):t.page===1&&t.loading?n.jsx(mM,{visible:!0}):n.jsxs(Ie,{children:[n.jsx(vM,{dataSource:e}),n.jsxs(a.Box,{py:10,sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[n.jsx(a.LoadingOverlay,{visible:t.loading,overlayProps:{blur:2}}),n.jsx(wg,{data:t.data})]})]})}),jM={root:{flexGrow:1,overflow:"auto",borderLeft:"1px solid #efefef"},tabsList:{borderBottom:"1px solid #efefef"},tab:{minWidth:120}},wM=k.observer(({dataSource:e})=>{const{t}=_.useTranslation(),r=e.dbInfo;return f.useEffect(()=>{r.loadTablesIfEmpty()},[r]),r.tables.error?n.jsx(a.Text,{c:"red",size:"md",ta:"center",ff:"monospace",children:r.tables.error}):n.jsxs(a.Flex,{sx:{height:"100%"},children:[n.jsx(a.Box,{w:300,sx:{flexGrow:0,flexShrink:0,position:"relative"},children:n.jsx(Ie,{children:n.jsx(xM,{dataSource:e})})}),n.jsxs(a.Tabs,{defaultValue:"structure",styles:jM,children:[n.jsxs(a.Tabs.List,{children:[n.jsx(a.Tabs.Tab,{value:"structure",leftSection:n.jsx(C.IconColumns,{size:14}),children:t("data_source.table_structure_short")}),n.jsx(a.Tabs.Tab,{value:"data",leftSection:n.jsx(C.IconDatabase,{size:14}),children:t("data.label")})]}),n.jsx(a.Tabs.Panel,{value:"structure",children:n.jsx(gM,{dataSource:e})}),n.jsx(a.Tabs.Panel,{value:"data",sx:{width:"100%",height:"calc(100% - 36px)",overflow:"hidden"},children:n.jsx(_M,{dataSource:e})})]})]})}),CM={modal:{paddingLeft:"0px !important",paddingRight:"0px !important"},header:{marginBottom:0,padding:"20px 20px 10px",borderBottom:"1px solid #efefef",gap:"20px"},title:{flexGrow:1},body:{padding:"0 0 0 20px"}},Tg=k.observer(({dataSource:e,triggerButtonProps:t={}})=>{const{t:r}=_.useTranslation(),[s,i]=f.useState(!1),{type:o}=e;return o==="http"||o==="merico_metric_system"?null:n.jsxs(n.Fragment,{children:[n.jsx(a.Modal,{opened:s,onClose:()=>i(!1),title:n.jsxs(a.Group,{justify:"space-between",sx:{flexGrow:1},children:[n.jsx(a.Text,{size:"sm",fw:500,children:r("data_source.explorer")}),n.jsxs(a.Group,{gap:7,children:[n.jsx(a.Badge,{variant:"gradient",gradient:{from:"indigo",to:"cyan"},children:e.key}),n.jsx(a.Badge,{variant:"gradient",gradient:{from:"orange",to:"red"},children:e.type})]})]}),zIndex:320,size:"96vw",styles:CM,children:n.jsx(a.Box,{sx:{height:"calc(100vh - 220px)"},children:n.jsx(wM,{dataSource:e})})}),n.jsx(a.Button,{variant:"subtle",onClick:()=>i(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},...t,children:r("data_source.see_table_structure")})]})}),kg={http:"HTTP",mysql:"MySQL",postgresql:"PostgreSQL",merico_metric_system:"指标系统"},SM=({option:e,...t})=>{const{label:r,type:s}=e;return s===J.Transform?n.jsxs(a.Group,{className:"transform-query-option",justify:"flex-start",...t,sx:{flexGrow:1,'&[data-selected="true"]':{".mantine-Text-root":{color:"white"},svg:{stroke:"white"}}},children:[n.jsx(C.IconVectorTriangle,{size:14,color:"#228be6"}),n.jsx(a.Text,{size:"sm",c:"blue",children:r})]}):n.jsxs(a.Group,{justify:"space-between",...t,sx:{flexGrow:1},children:[n.jsx(a.Text,{size:"sm",children:r}),n.jsx(a.Text,{size:"sm",children:kg[s]})]})},Dg=k.observer(({queryModel:e,size:t="sm"})=>{const{t:r}=_.useTranslation(),s=se(),{data:i=[],loading:o}=U.useRequest(ya,{refreshDeps:[]},[]),l=f.useMemo(()=>{const p=i.map(h=>({label:h.key,value:h.key,type:h.type}));return p.push({label:r("query.transform.data_source"),value:J.Transform,type:J.Transform}),p},[i]),c=f.useMemo(()=>l.reduce((p,h)=>(p[h.value]=h.type,p),{}),[l]),u=p=>{p!==null&&(e.setKey(p),e.setType(c[p]))},d=f.useMemo(()=>s.datasources.find({type:e.type,key:e.key}),[s,e.type,e.key]);return n.jsx(a.Select,{size:t,data:l,label:n.jsxs(a.Group,{justify:"space-between",children:[n.jsx(a.Box,{children:r("data_source.label")}),d&&n.jsx(Tg,{dataSource:d,triggerButtonProps:{size:"compact-xs",px:10}})]}),renderOption:SM,rightSection:d?n.jsx(a.Text,{size:"xs",c:"dimmed",children:kg[d.type]??d.type}):void 0,rightSectionWidth:85,maxDropdownHeight:500,styles:{root:{flex:1,minWidth:"300px"},label:{display:"block"},section:{pointerEvents:"none",justifyContent:"flex-end",paddingRight:"10px",".mantine-Text-root":{userSelect:"none"}}},disabled:o,value:e.key,onChange:u})}),TM=k.observer(({queryModel:e})=>{const{t}=_.useTranslation(),[r,s]=f.useState(e.name);f.useEffect(()=>{s(e.name)},[e.name]);const i=f.useMemo(()=>e.conditionOptionsWithInvalidRunbys.optionGroups.map(l=>({group:t(l.group),items:l.items})),[e.conditionOptionsWithInvalidRunbys.optionGroups]);return n.jsx(a.Center,{ml:20,mt:20,sx:{maxWidth:"600px"},children:n.jsxs(a.Stack,{gap:10,sx:{width:"100%"},children:[n.jsx(a.Divider,{mb:-10,variant:"dashed",label:t("query.basics"),labelPosition:"center"}),n.jsx(a.TextInput,{placeholder:t("query.name_description"),label:t("query.name"),required:!0,sx:{flex:1},value:r,onChange:o=>{s(o.currentTarget.value)},rightSection:n.jsx(a.ActionIcon,{variant:"filled",color:"blue",size:"sm",onClick:()=>e.setName(r),disabled:r===e.name,children:n.jsx(C.IconDeviceFloppy,{size:16})}),onBlur:()=>{e.setName(r)}}),n.jsx(Dg,{queryModel:e}),n.jsx(a.Divider,{mt:10,mb:-10,variant:"dashed",label:t("query.conditions"),labelPosition:"center"}),n.jsx(a.MultiSelect,{label:t("query.run_by_condition.label"),description:t("query.run_by_condition.description"),placeholder:t("query.run_by_condition.unset"),data:i,value:[...e.run_by],onChange:e.setRunBy,renderOption:ud,maxDropdownHeight:500}),e.typedAsHTTP&&n.jsx(a.MultiSelect,{label:t("query.re_run_condition.label"),placeholder:t("query.re_run_condition.label"),data:i,value:[...e.config.react_to],onChange:e.config.setReactTo,renderOption:ud,maxDropdownHeight:500}),n.jsx(a.Divider,{mt:20,mb:10,variant:"dashed"}),n.jsx(lM,{queryModel:e})]})})});function kM({content:e}){return n.jsxs(a.HoverCard,{width:"60vw",shadow:"md",zIndex:340,children:[n.jsx(a.HoverCard.Target,{children:n.jsx(a.ActionIcon,{size:16,color:"blue",variant:"subtle",children:n.jsx(C.IconEye,{})})}),n.jsx(a.HoverCard.Dropdown,{children:n.jsx(zt.CodeHighlight,{language:"sql",withCopyButton:!1,code:e})})]})}const DM=k.observer(()=>{const t=[...se().globalSQLSnippets.list];return t.length===0?null:n.jsxs(a.Table,{horizontalSpacing:"xs",verticalSpacing:"xs",fz:"sm",highlightOnHover:!0,children:[n.jsx(a.Table.Thead,{children:n.jsxs(a.Table.Tr,{children:[n.jsx(a.Table.Th,{children:"Key"}),n.jsx(a.Table.Th,{children:"Value"})]})}),n.jsx(a.Table.Tbody,{children:t.map(r=>{const{id:s,content:i}=r;return n.jsxs(a.Table.Tr,{children:[n.jsx(a.Table.Td,{children:s}),n.jsx(a.Table.Td,{width:200,children:n.jsx(kM,{content:i})})]},s)})})]})}),zM=`
517
517
  -- You may reference query variables in SQL or VizConfig.
518
518
  SELECT *
519
519
  FROM commit