const require_runtime = require("../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_objectWithoutProperties = require("../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectWithoutProperties.js");
let react = require("react");
react = require_runtime.__toESM(react);
let _pisell_utils = require("@pisell/utils");
let antd = require("antd");
let classnames = require("classnames");
classnames = require_runtime.__toESM(classnames);
let _pisell_icon_es_XClose = require("@pisell/icon/es/XClose");
_pisell_icon_es_XClose = require_runtime.__toESM(_pisell_icon_es_XClose);
let ahooks = require("ahooks");
let _pisell_icon_es_Pin02 = require("@pisell/icon/es/Pin02");
_pisell_icon_es_Pin02 = require_runtime.__toESM(_pisell_icon_es_Pin02);
require("./index.less");
//#region src/components/drawer/index.tsx
const _excluded = ["others"];
const prefix = "pisell-lowcode-";
const Title = (props) => {
	const { placement, onClose, showPin, persistentState, setPersistentState } = props;
	return /* @__PURE__ */ react.default.createElement("div", { className: `${prefix}drawer-outside-wrap ${prefix}drawer-outside-wrap-${placement}` }, /* @__PURE__ */ react.default.createElement("div", {
		className: `${prefix}drawer-outside-action-wrap`,
		onClick: onClose
	}, /* @__PURE__ */ react.default.createElement(_pisell_icon_es_XClose.default, null)), showPin && /* @__PURE__ */ react.default.createElement("div", {
		className: (0, classnames.default)(`${prefix}drawer-outside-action-wrap`, { [`${prefix}drawer-outside-action-active`]: persistentState }),
		onClick: () => setPersistentState(!persistentState)
	}, /* @__PURE__ */ react.default.createElement(_pisell_icon_es_Pin02.default, null)));
};
const Drawer = (props) => {
	const { others } = props, resetProps = require_objectWithoutProperties._objectWithoutProperties(props, _excluded);
	const { operateMode, headerStyle, placement, onClose, showPin, width, getContainer, open } = props;
	const [persistentState, setPersistentState] = (0, ahooks.useControllableValue)(props, {
		trigger: "onPersistentChange",
		valuePropName: "persistent"
	});
	const storageKey = `drawer-${props.__id}`;
	const innerProps = {};
	if (props.__designMode === "design") innerProps.open = true;
	(0, react.useLayoutEffect)(() => {
		if ((0, _pisell_utils.isBoolean)(persistentState) && (0, _pisell_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, ahooks.useUpdateEffect)(() => {
		if ((0, _pisell_utils.isBoolean)(persistentState) && showPin) localStorage.setItem(storageKey, `${persistentState}`);
	}, [
		persistentState,
		storageKey,
		showPin
	]);
	(0, react.useLayoutEffect)(() => {
		if (!(0, _pisell_utils.isBoolean)(persistentState) && showPin) setPersistentState(localStorage.getItem(storageKey) === "true");
	}, [
		persistentState,
		storageKey,
		showPin
	]);
	const otherProps = (0, react.useMemo)(() => {
		if (operateMode === "outside") return {
			headerStyle: {
				border: "none",
				height: 0,
				padding: 0
			},
			title: /* @__PURE__ */ react.default.createElement(Title, {
				placement,
				onClose,
				showPin,
				persistentState,
				setPersistentState
			})
		};
		return require_objectSpread2._objectSpread2({
			rootClassName: `${prefix}basic-drawer-root`,
			closeIcon: /* @__PURE__ */ react.default.createElement(_pisell_icon_es_XClose.default, { className: `${prefix}drawer-header-close-icon` })
		}, headerStyle);
	}, [
		operateMode,
		placement,
		onClose,
		persistentState,
		setPersistentState
	]);
	return /* @__PURE__ */ react.default.createElement(antd.Drawer, require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, resetProps), innerProps), otherProps), others));
};
//#endregion
exports.default = Drawer;
