define(["@grafana/data","react","@grafana/ui"],((e,t,a)=>(()=>{"use strict";var n={305:t=>{t.exports=e},388:e=>{e.exports=a},650:e=>{e.exports=t}},s={};function r(e){var t=s[e];if(void 0!==t)return t.exports;var a=s[e]={exports:{}};return n[e](a,a.exports,r),a.exports}r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var a in t)r.o(t,a)&&!r.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:t[a]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};return(()=>{r.r(o),r.d(o,{plugin:()=>p});var e=r(305),t=r(650),a=r.n(t),n=r(388);function s(t){return t&&t.length?(0,e.toCSV)(t.map((t=>(0,e.toDataFrame)(t)))):""}class i extends t.PureComponent{constructor(){super(...arguments),this.state={text:""},this.onSeriesParsed=(t,a)=>{const{options:n,onOptionsChange:s}=this.props;t||(t=[new e.MutableDataFrame]);const r=Object.assign(Object.assign({},n.jsonData),{data:t});s(Object.assign(Object.assign({},n),{jsonData:r})),this.setState({text:a})}}componentDidMount(){const{options:e}=this.props;if(e.jsonData.data){const t=s(e.jsonData.data);this.setState({text:t})}}render(){const{text:e}=this.state;return a().createElement("div",null,a().createElement("div",{className:"gf-form-group"},a().createElement("h4",null,"Shared Data:"),a().createElement("span",null,"Enter CSV"),a().createElement(n.TableInputCSV,{text:e,onSeriesParsed:this.onSeriesParsed,width:"100%",height:200})),a().createElement("div",{className:"grafana-info-box"},"This data is stored in the datasource json and is returned to every user in the initial request for any datasource. This is an appropriate place to enter a few values. Large datasets will perform better in other datasources.",a().createElement("br",null),a().createElement("br",null),a().createElement("b",null,"NOTE:")," Changes to this data will only be reflected after a browser refresh."))}}class l extends e.DataSourceApi{constructor(t){super(t),this.data=[],t.jsonData.data&&(this.data=t.jsonData.data.map((t=>(0,e.toDataFrame)(t))))}getQueryDisplayText(e){return e.data?"Panel Data: "+u(e.data):`Shared Data From: ${this.name} (${u(this.data)})`}metricFindQuery(e,t){return new Promise(((e,t)=>{const a=[];for(const e of this.data)for(const t of e.fields)a.push({text:t.name});e(a)}))}query(t){const a=[];for(const n of t.targets){if(n.hide)continue;let t=this.data;n.data&&(t=n.data.map((t=>(0,e.toDataFrame)(t))));for(let e=0;e<t.length;e++)a.push(Object.assign(Object.assign({},t[e]),{refId:n.refId}))}return Promise.resolve({data:a})}testDatasource(){return new Promise(((e,t)=>{let a=0,n=`${this.data.length} Series:`;for(const e of this.data){const t=e.length;n+=` [${e.fields.length} Fields, ${t} Rows]`,a+=t}a>0&&e({status:"success",message:n}),t({status:"error",message:"No Data Entered"})}))}}function d(e){return e&&e.fields&&e.fields.length?e.hasOwnProperty("length")?e.length:e.fields[0].values.length:0}function u(e){if(!e||!e.length)return"";if(e.length>1){const t=e.reduce(((e,t)=>e+d(t)),0);return`${e.length} Series, ${t} Rows`}const t=e[0];if(!t.fields)return"Missing Fields";const a=d(t);return`${t.fields.length} Fields, ${a} Rows`}const c=[{value:"panel",label:"Panel",description:"Save data in the panel configuration."},{value:"shared",label:"Shared",description:"Save data in the shared datasource object."}];class h extends t.PureComponent{constructor(){super(...arguments),this.state={text:""},this.onSourceChange=t=>{const{datasource:a,query:n,onChange:s,onRunQuery:r}=this.props;let o;if("panel"===t.value){if(n.data)return;o=[...a.data],o||(o=[new e.MutableDataFrame]),this.setState({text:(0,e.toCSV)(o)})}s(Object.assign(Object.assign({},n),{data:o})),r()},this.onSeriesParsed=(t,a)=>{const{query:n,onChange:s,onRunQuery:r}=this.props;this.setState({text:a}),t||(t=[new e.MutableDataFrame]),s(Object.assign(Object.assign({},n),{data:t})),r()}}onComponentDidMount(){const{query:e}=this.props,t=s(e.data);this.setState({text:t})}render(){const{datasource:e,query:t}=this.props,{uid:s,name:r}=e,{text:o}=this.state,i=t.data?c[0]:c[1];return a().createElement("div",null,a().createElement(n.InlineField,{label:"Data",labelWidth:8},a().createElement(a().Fragment,null,a().createElement(n.Select,{width:20,options:c,value:i,onChange:this.onSourceChange}),t.data?a().createElement("div",{style:{alignSelf:"center"}},u(t.data)):a().createElement(n.LinkButton,{fill:"text",href:`datasources/edit/${s}/`},r,": ",u(e.data),"   ",a().createElement(n.Icon,{name:"pen"})))),t.data&&a().createElement(n.TableInputCSV,{text:o,onSeriesParsed:this.onSeriesParsed,width:"100%",height:200}))}}const p=new e.DataSourcePlugin(l).setConfigEditor(i).setQueryEditor(h)})(),o})()));
//# sourceMappingURL=module.js.map