var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/dataSourceComponents/provider/dataSource/DataSourceProvider.tsx
var DataSourceProvider_exports = {};
__export(DataSourceProvider_exports, {
  default: () => DataSourceProvider_default
});
module.exports = __toCommonJS(DataSourceProvider_exports);
var import_react = __toESM(require("react"));
var import_ahooks = require("ahooks");
var import_utils = require("@pisell/utils");
var import_DataSourceContext = __toESM(require("./DataSourceContext"));
var import_useActions = __toESM(require("../../hooks/useActions"));
var import_useVariables = __toESM(require("../../hooks/useVariables"));
var import_useSetRequest = __toESM(require("../../../../hooks/useSetRequest"));
var DataSourceProvider = (props) => {
  const {
    children,
    dataSource: propsDataSource,
    currentValue,
    actions: externalActions,
    overrideData,
    autoRun,
    __designMode
  } = props;
  (0, import_useSetRequest.default)();
  const { parseVariable } = (0, import_useVariables.default)();
  const dataSource = (0, import_utils.isString)(propsDataSource) ? parseVariable == null ? void 0 : parseVariable(propsDataSource) : propsDataSource;
  const standardActions = (0, import_useActions.default)({
    dataSource,
    currentValue,
    __designMode
  });
  const list = (externalActions == null ? void 0 : externalActions.list) || standardActions.list;
  const get = (externalActions == null ? void 0 : externalActions.get) || standardActions.get;
  const update = (externalActions == null ? void 0 : externalActions.update) || standardActions.update;
  const create = (externalActions == null ? void 0 : externalActions.create) || standardActions.create;
  const destroy = (externalActions == null ? void 0 : externalActions.destroy) || standardActions.destroy;
  const listResult = (0, import_ahooks.useRequest)(list, {
    manual: (0, import_utils.isBoolean)(autoRun == null ? void 0 : autoRun.list) ? !(autoRun == null ? void 0 : autoRun.list) : true
  });
  const getResult = (0, import_ahooks.useRequest)(get, {
    manual: (0, import_utils.isBoolean)(autoRun == null ? void 0 : autoRun.get) ? !(autoRun == null ? void 0 : autoRun.get) : true
  });
  const destroyResult = (0, import_ahooks.useRequest)(destroy, {
    manual: true
  });
  const updateResult = (0, import_ahooks.useRequest)(update, {
    manual: true
  });
  const createResult = (0, import_ahooks.useRequest)(create, {
    manual: true
  });
  const value = (0, import_react.useMemo)(() => {
    return {
      __designMode,
      dataSource,
      list: {
        ...listResult,
        data: (overrideData == null ? void 0 : overrideData.list) || listResult.data
      },
      get: {
        ...getResult,
        data: (overrideData == null ? void 0 : overrideData.get) || getResult.data
      },
      destroy: destroyResult,
      update: updateResult,
      create: createResult
    };
  }, [
    dataSource,
    listResult,
    destroyResult,
    getResult,
    updateResult,
    createResult,
    overrideData,
    __designMode
  ]);
  return /* @__PURE__ */ import_react.default.createElement(import_DataSourceContext.default.Provider, { value }, children);
};
var DataSourceProvider_default = DataSourceProvider;
