import { r as registerInstance, h, H as Host } from './index-6334d911.js';
import './index-70f14ac5.js';
import { c as coreState } from './core-aa3ec348.js';
import './_commonjsHelpers-66ac50f5.js';
import { s as src } from './index-25ead363.js';

const DataFetcher = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.data = null;
  }
  async componentWillLoad() {
    if (this.query) {
      this.fetchData();
    }
  }
  async fetchData() {
    this.data = await coreState.client.query({ query: 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 h(Host, null, this.renderData());
  }
  static get watchers() { return {
    "query": ["fetchData"]
  }; }
};

export { DataFetcher as corejam_data_fetcher };
