'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index = require('./index-1206254d.js');
require('./index-f9fece3f.js');
const core = require('./core-3efcc000.js');
require('./_commonjsHelpers-5cfcba41.js');
const index$1 = require('./index-33b35744.js');

const DataFetcher = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.data = null;
  }
  async componentWillLoad() {
    if (this.query) {
      this.fetchData();
    }
  }
  async fetchData() {
    this.data = await core.coreState.client.query({ query: index$1.src(this.query) });
  }
  renderData() {
    if (!this.query)
      return "No query.";
    if (this.renderer) {
      if (!this.data)
        this.renderer({ loading: true });
      if (this.data)
        this.renderer({ loading: false, data: this.data });
    }
    else {
      if (!this.data)
        return "Loading...";
      if (this.data)
        return JSON.stringify(this.data);
    }
  }
  render() {
    return index.h(index.Host, null, this.renderData());
  }
  static get watchers() { return {
    "query": ["fetchData"]
  }; }
};

exports.corejam_data_fetcher = DataFetcher;
