var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var stdin_exports = {};
__export(stdin_exports, {
  AsyncContentPanel: () => AsyncContentPanel,
  asyncContentPanelProps: () => asyncContentPanelProps
});
module.exports = __toCommonJS(stdin_exports);
var import_vue = require("vue");
var import_pro_utils = require("@antdv/pro-utils");
var import_ant_design_vue = require("ant-design-vue");
var import_vue2 = require("vue");
var import_HelpProvide = require("./HelpProvide");
var import_RenderContentPanel = require("./RenderContentPanel");
const asyncContentPanelProps = {
  item: (0, import_pro_utils.objectType)().isRequired,
  onInit: (0, import_pro_utils.funcType)()
};
const AsyncContentPanel = (0, import_vue2.defineComponent)({
  name: "AsyncContentPanel",
  props: asyncContentPanelProps,
  inheritAttrs: false,
  setup(props) {
    const {
      onLoadContext
    } = import_HelpProvide.ProHelpContext.useContext();
    const [loading, setLoading] = (0, import_pro_utils.useState)(false);
    const content = (0, import_vue2.ref)(void 0);
    (0, import_vue2.watch)(() => props.item.key, () => {
      if (!props.item.key) return;
      setLoading(true);
      onLoadContext == null ? void 0 : onLoadContext(props.item.key, props.item).then((res) => {
        setLoading(false);
        content.value = res;
      });
    }, {
      immediate: true
    });
    return () => {
      const {
        item,
        onInit
      } = props;
      if (!item.key) return null;
      if (loading && item.key) {
        return (0, import_vue.createVNode)("div", {
          "key": item.key,
          "style": {
            display: "flex",
            justifyContent: "center",
            width: "100%",
            boxSizing: "border-box",
            padding: `24px`
          }
        }, [(0, import_vue.createVNode)(import_ant_design_vue.Spin, null, null)]);
      }
      return (0, import_vue.createVNode)(import_RenderContentPanel.RenderContentPanel, {
        "onInit": (_ref) => {
          onInit == null ? void 0 : onInit(_ref);
        },
        "dataSourceChildren": content.value
      }, null);
    };
  }
});
