'use strict';

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

const index = require('./index-22fd9091.js');
const core = require('./core-787915c4.js');
require('./_commonjsHelpers-5cfcba41.js');
require('./index-a20d8492.js');
const index$1 = require('./index-66ca60fa.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;
