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/drawer/index.tsx
var drawer_exports = {};
__export(drawer_exports, {
  default: () => drawer_default
});
module.exports = __toCommonJS(drawer_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_ahooks = require("ahooks");
var import_classnames = __toESM(require("classnames"));
var import_utils = require("@pisell/utils");
var import_XClose = __toESM(require("@pisell/icon/es/XClose"));
var import_Pin02 = __toESM(require("@pisell/icon/es/Pin02"));
var import_index = require("./index.less");
var prefix = "pisell-lowcode-";
var Title = (props) => {
  const { placement, onClose, showPin, persistentState, setPersistentState } = props;
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: `${prefix}drawer-outside-wrap ${prefix}drawer-outside-wrap-${placement}`
    },
    /* @__PURE__ */ import_react.default.createElement("div", { className: `${prefix}drawer-outside-action-wrap`, onClick: onClose }, /* @__PURE__ */ import_react.default.createElement(import_XClose.default, null)),
    showPin && /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: (0, import_classnames.default)(`${prefix}drawer-outside-action-wrap`, {
          [`${prefix}drawer-outside-action-active`]: persistentState
        }),
        onClick: () => setPersistentState(!persistentState)
      },
      /* @__PURE__ */ import_react.default.createElement(import_Pin02.default, null)
    )
  );
};
var Drawer = (props) => {
  const { others, ...resetProps } = props;
  const {
    operateMode,
    headerStyle,
    placement,
    onClose,
    showPin,
    width,
    getContainer,
    open
  } = props;
  const [persistentState, setPersistentState] = (0, import_ahooks.useControllableValue)(
    props,
    {
      trigger: "onPersistentChange",
      valuePropName: "persistent"
    }
  );
  const currentDrawerId = props.__id;
  const storageKey = `drawer-${currentDrawerId}`;
  const innerProps = {};
  if (props.__designMode === "design") {
    innerProps.open = true;
  }
  (0, import_react.useLayoutEffect)(() => {
    if ((0, import_utils.isBoolean)(persistentState) && (0, import_utils.isUndefined)(getContainer) && showPin) {
      document.body.style.transition = "all 0.3s";
      document.body.style[`padding-${placement}`] = persistentState && open ? `${width || 378}px` : "0";
    }
    return () => {
      document.body.style[`padding-${placement}`] = "0";
      document.body.style.transition = "none";
    };
  }, [persistentState, width, showPin, placement, open]);
  (0, import_ahooks.useUpdateEffect)(() => {
    if ((0, import_utils.isBoolean)(persistentState) && showPin) {
      localStorage.setItem(storageKey, `${persistentState}`);
    }
  }, [persistentState, storageKey, showPin]);
  (0, import_react.useLayoutEffect)(() => {
    if (!(0, import_utils.isBoolean)(persistentState) && showPin) {
      setPersistentState(localStorage.getItem(storageKey) === "true");
    }
  }, [persistentState, storageKey, showPin]);
  const otherProps = (0, import_react.useMemo)(() => {
    if (operateMode === "outside") {
      return {
        headerStyle: {
          border: "none",
          height: 0,
          padding: 0
        },
        title: /* @__PURE__ */ import_react.default.createElement(
          Title,
          {
            placement,
            onClose,
            showPin,
            persistentState,
            setPersistentState
          }
        )
      };
    }
    return {
      rootClassName: `${prefix}basic-drawer-root`,
      closeIcon: /* @__PURE__ */ import_react.default.createElement(import_XClose.default, { className: `${prefix}drawer-header-close-icon` }),
      ...headerStyle
    };
  }, [operateMode, placement, onClose, persistentState, setPersistentState]);
  return /* @__PURE__ */ import_react.default.createElement(
    import_antd.Drawer,
    {
      ...resetProps,
      ...innerProps,
      ...otherProps,
      ...others
    }
  );
};
var drawer_default = Drawer;
