var s = Object.defineProperty;
var i = (r, e, t) => e in r ? s(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
var o = (r, e, t) => (i(r, typeof e != "symbol" ? e + "" : e, t), t);
import { defineComponent as c, getCurrentInstance as a } from "vue";
import { useViewController as h } from "@ibiz-template/vue-util";
import { Neuron as l, ViewNerve as d, ViewController as u } from "@ibiz-template/controller";
class p extends l {
}
class m extends d {
  constructor() {
    super(...arguments);
    o(this, "chart");
  }
  createNeuron() {
    return new p(this.bindAbility());
  }
  inclusive(t) {
    return t === "chart" || super.inclusive(t);
  }
  connect(t, n) {
    super.connect(t, n), t === "chart" && (this.chart = n, this.chart.evt.on("destroyed", () => {
      this.chart = void 0;
    }));
  }
  destroy() {
    super.destroy(), this.chart = void 0;
  }
}
class v extends u {
  createNerve() {
    return new m(this);
  }
  async onInit() {
    await super.onInit();
    const { chart: e } = this.model;
    e && (this.providers[e.name] = await ibiz.register.control.get(e)), this.nerve.self.evt.on("mounted", () => {
      this.model.source.loadDefault && this.load();
    });
  }
  /**
   * 视图加载方法
   *
   * @return {*}  {Promise<IData[]>}
   * @memberof ChartViewController
   */
  async load() {
    const { chart: e } = this.nerve;
    return e.call.load();
  }
  /**
   * 刷新视图
   *
   * @author zhanghengfeng
   * @date 2023-04-07 17:04:41
   * @return {*}  {Promise<void>}
   */
  async refresh() {
    this.load();
  }
}
function f(r, e) {
  return h(
    r,
    (t, n) => new v(e, t, n)
  );
}
const V = c({
  props: {
    context: Object,
    params: {
      type: Object,
      default: () => ({})
    },
    modelPath: {
      type: String,
      required: !0
    },
    modal: {
      type: Object
    }
  },
  setup(r) {
    const {
      proxy: e
    } = a();
    return {
      c: f(e, r.modelPath)
    };
  },
  render(r) {
    let e = null;
    if (this.c.complete) {
      const {
        chart: t
      } = this.c.model;
      this.c.providers[t.name] && (e = r(this.c.providers[t.name].component, {
        props: {
          modelData: t,
          context: this.c.context,
          params: this.c.params
        },
        on: {
          neuronInit: this.c.nerve.onNeuronInit(t.name)
        }
      }));
    }
    return r("view-base", {
      attrs: {
        controller: this.c
      }
    }, [e]);
  }
});
export {
  V as default
};