import { createVNode as _createVNode } from "vue";
import { funcType, objectType, useState } from "@antdv/pro-utils";
import { Spin } from "ant-design-vue";
import { defineComponent, ref, watch } from "vue";
import { ProHelpContext } from "./HelpProvide.mjs";
import { RenderContentPanel } from "./RenderContentPanel.mjs";
const asyncContentPanelProps = {
  item: objectType().isRequired,
  onInit: funcType()
};
const AsyncContentPanel = defineComponent({
  name: "AsyncContentPanel",
  props: asyncContentPanelProps,
  inheritAttrs: false,
  setup(props) {
    const {
      onLoadContext
    } = ProHelpContext.useContext();
    const [loading, setLoading] = useState(false);
    const content = ref(void 0);
    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 _createVNode("div", {
          "key": item.key,
          "style": {
            display: "flex",
            justifyContent: "center",
            width: "100%",
            boxSizing: "border-box",
            padding: `24px`
          }
        }, [_createVNode(Spin, null, null)]);
      }
      return _createVNode(RenderContentPanel, {
        "onInit": (_ref) => {
          onInit == null ? void 0 : onInit(_ref);
        },
        "dataSourceChildren": content.value
      }, null);
    };
  }
});
export {
  AsyncContentPanel,
  asyncContentPanelProps
};
