const require_runtime = require("../../../_virtual/_rolldown/runtime.js");
const require_toPropertyKey = require("../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/toPropertyKey.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");
const require_floorMapLayoutConstants = require("../floorMapLayoutConstants.js");
const require_floorMapToolbarPalette = require("../utils/floorMapToolbarPalette.js");
const require_index = require("../../pisellContainer/index.js");
let react = require("react");
react = require_runtime.__toESM(react);
let _pisell_utils = require("@pisell/utils");
let _ant_design_icons = require("@ant-design/icons");
let classnames = require("classnames");
classnames = require_runtime.__toESM(classnames);
//#region src/components/pisellFloorMapLayout/components/FloorMapToolbarViewAllModal.tsx
/**
* 侧栏 palette「查看全部」：任意分类下图元超过展示上限时，弹窗内按数量多选并一键落点。
*/
const I18N_TB = "pisell-floor-map-layout.toolbar";
/** 单种图元在弹窗内可添加的最大数量 */
const PALETTE_VIEW_ALL_MODAL_MAX_QTY = 99;
function FloorMapToolbarViewAllModal(props) {
	const { open, categoryLabel, entries, onClose, onConfirm, renderEntryPreview, platform = "pc" } = props;
	const [quantities, setQuantities] = (0, react.useState)({});
	(0, react.useEffect)(() => {
		if (!open) setQuantities({});
	}, [open]);
	const totalQty = (0, react.useMemo)(() => Object.values(quantities).reduce((sum, n) => sum + (Number.isFinite(n) && n > 0 ? n : 0), 0), [quantities]);
	const setQty = (0, react.useCallback)((key, next) => {
		const clamped = Math.max(0, Math.min(PALETTE_VIEW_ALL_MODAL_MAX_QTY, next));
		setQuantities((prev) => {
			if (clamped === 0) {
				const { [key]: _removed } = prev;
				return require_objectWithoutProperties._objectWithoutProperties(prev, [key].map(require_toPropertyKey.toPropertyKey));
			}
			return require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, prev), {}, { [key]: clamped });
		});
	}, []);
	const title = (0, react.useMemo)(() => _pisell_utils.locales.getText(`${I18N_TB}.view-all-modal-title`).replace(/\{category\}/g, categoryLabel), [categoryLabel]);
	return /* @__PURE__ */ react.default.createElement(require_index.default, {
		renderType: "modal",
		props: {
			platform,
			open,
			title,
			onCancel: onClose,
			destroyOnClose: true,
			width: 520,
			zIndex: 1100,
			wrapClassName: `${require_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-view-all-modal`,
			okText: _pisell_utils.locales.getText(`${I18N_TB}.view-all-modal-add`),
			cancelText: _pisell_utils.locales.getText(`${I18N_TB}.view-all-modal-cancel`),
			okButtonProps: { disabled: totalQty === 0 },
			onOk: () => {
				if (totalQty === 0) return;
				onConfirm(require_floorMapToolbarPalette.expandPaletteEntriesByQuantity(entries, quantities));
				onClose();
			}
		}
	}, /* @__PURE__ */ react.default.createElement("p", { className: `${require_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-view-all-modal-hint` }, _pisell_utils.locales.getText(`${I18N_TB}.view-all-modal-hint`)), /* @__PURE__ */ react.default.createElement("div", { className: `${require_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-view-all-modal-grid` }, entries.map((entry) => {
		var _quantities$entry$key;
		const qty = (_quantities$entry$key = quantities[entry.key]) !== null && _quantities$entry$key !== void 0 ? _quantities$entry$key : 0;
		const selected = qty > 0;
		return /* @__PURE__ */ react.default.createElement("div", {
			key: entry.key,
			className: (0, classnames.default)(`${require_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-view-all-modal-card`, { [`${require_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-view-all-modal-card--selected`]: selected })
		}, /* @__PURE__ */ react.default.createElement("div", { className: `${require_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-view-all-modal-card-preview` }, renderEntryPreview(entry)), /* @__PURE__ */ react.default.createElement("span", { className: `${require_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-view-all-modal-card-label` }, entry.label), /* @__PURE__ */ react.default.createElement("div", {
			className: `${require_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-view-all-modal-card-stepper`,
			onClick: (e) => e.stopPropagation()
		}, /* @__PURE__ */ react.default.createElement("button", {
			type: "button",
			className: `${require_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-view-all-modal-card-stepper-btn`,
			disabled: qty <= 0,
			"aria-label": _pisell_utils.locales.getText(`${I18N_TB}.view-all-modal-qty-decrease`),
			onClick: () => setQty(entry.key, qty - 1)
		}, /* @__PURE__ */ react.default.createElement(_ant_design_icons.MinusOutlined, null)), /* @__PURE__ */ react.default.createElement("span", {
			className: `${require_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-view-all-modal-card-stepper-qty`,
			"aria-live": "polite"
		}, qty), /* @__PURE__ */ react.default.createElement("button", {
			type: "button",
			className: `${require_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-view-all-modal-card-stepper-btn`,
			disabled: qty >= PALETTE_VIEW_ALL_MODAL_MAX_QTY,
			"aria-label": _pisell_utils.locales.getText(`${I18N_TB}.view-all-modal-qty-increase`),
			onClick: () => setQty(entry.key, qty + 1)
		}, /* @__PURE__ */ react.default.createElement(_ant_design_icons.PlusOutlined, null))));
	})));
}
//#endregion
exports.default = FloorMapToolbarViewAllModal;
