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/dataSourceTable/hooks/useDrawerState.ts
var useDrawerState_exports = {};
__export(useDrawerState_exports, {
  default: () => useDrawerState_default
});
module.exports = __toCommonJS(useDrawerState_exports);
var import_antd = require("antd");
var import_react = require("react");
var import_pisellModal = __toESM(require("../../../pisellModal"));
var sizeMap = {
  small: 400,
  middle: 600,
  large: 800
};
var useDrawerState = (operationContent) => {
  const [drawerVisible, setDrawerVisible] = (0, import_react.useState)(false);
  const [item, setItem] = (0, import_react.useState)(null);
  const timerRef = (0, import_react.useRef)();
  (0, import_react.useEffect)(() => {
    return () => {
      if (timerRef.current) {
        clearTimeout(timerRef.current);
      }
    };
  }, []);
  const openDrawer = (item2) => {
    if (timerRef.current) {
      clearTimeout(timerRef.current);
    }
    setDrawerVisible(true);
    setItem(item2);
  };
  const closeDrawer = () => {
    if (timerRef.current) {
      clearTimeout(timerRef.current);
    }
    setDrawerVisible(false);
    timerRef.current = setTimeout(() => {
      var _a;
      (_a = item == null ? void 0 : item.afterClose) == null ? void 0 : _a.call(item);
      setItem(null);
      timerRef.current = void 0;
    }, 300);
  };
  const drawerContent = (0, import_react.useMemo)(() => {
    if ((item == null ? void 0 : item.key) && operationContent) {
      return operationContent[item.key];
    }
    return null;
  }, [item, operationContent]);
  const containerProps = (0, import_react.useMemo)(() => {
    if (!item) {
      return {};
    }
    const otherProps = {};
    if ((item == null ? void 0 : item.openMode) === "modal") {
      otherProps.footer = null;
    }
    return {
      width: sizeMap[item == null ? void 0 : item.openContentSize],
      title: item == null ? void 0 : item.openTitle,
      ...otherProps
    };
  }, [item]);
  const Container = (0, import_react.useMemo)(() => {
    if ((item == null ? void 0 : item.openMode) === "drawer") {
      return import_antd.Drawer;
    }
    return import_pisellModal.default;
  }, [item == null ? void 0 : item.openMode]);
  return {
    drawerVisible,
    setDrawerVisible,
    openDrawer,
    closeDrawer,
    drawerContent,
    Container,
    containerProps
  };
};
var useDrawerState_default = useDrawerState;
