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/pisellFloorMapLayout/components/FloorMapToolbarViewAllModal.tsx
var FloorMapToolbarViewAllModal_exports = {};
__export(FloorMapToolbarViewAllModal_exports, {
  FloorMapToolbarViewAllModal: () => FloorMapToolbarViewAllModal,
  default: () => FloorMapToolbarViewAllModal_default
});
module.exports = __toCommonJS(FloorMapToolbarViewAllModal_exports);
var import_react = __toESM(require("react"));
var import_classnames = __toESM(require("classnames"));
var import_icons = require("@ant-design/icons");
var import_utils = require("@pisell/utils");
var import_pisellContainer = __toESM(require("../../pisellContainer"));
var import_floorMapLayoutConstants = require("../floorMapLayoutConstants");
var import_floorMapToolbarPalette = require("../utils/floorMapToolbarPalette");
var I18N_TB = "pisell-floor-map-layout.toolbar";
var PALETTE_VIEW_ALL_MODAL_MAX_QTY = 99;
function FloorMapToolbarViewAllModal(props) {
  const {
    open,
    categoryLabel,
    entries,
    onClose,
    onConfirm,
    renderEntryPreview,
    platform = "pc"
  } = props;
  const [quantities, setQuantities] = (0, import_react.useState)({});
  (0, import_react.useEffect)(() => {
    if (!open) {
      setQuantities({});
    }
  }, [open]);
  const totalQty = (0, import_react.useMemo)(
    () => Object.values(quantities).reduce(
      (sum, n) => sum + (Number.isFinite(n) && n > 0 ? n : 0),
      0
    ),
    [quantities]
  );
  const setQty = (0, import_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, ...rest } = prev;
        return rest;
      }
      return { ...prev, [key]: clamped };
    });
  }, []);
  const title = (0, import_react.useMemo)(
    () => import_utils.locales.getText(`${I18N_TB}.view-all-modal-title`).replace(/\{category\}/g, categoryLabel),
    [categoryLabel]
  );
  return /* @__PURE__ */ import_react.default.createElement(
    import_pisellContainer.default,
    {
      renderType: "modal",
      props: {
        platform,
        open,
        title,
        onCancel: onClose,
        destroyOnClose: true,
        width: 520,
        zIndex: 1100,
        wrapClassName: `${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-view-all-modal`,
        okText: import_utils.locales.getText(`${I18N_TB}.view-all-modal-add`),
        cancelText: import_utils.locales.getText(`${I18N_TB}.view-all-modal-cancel`),
        okButtonProps: { disabled: totalQty === 0 },
        onOk: () => {
          if (totalQty === 0) return;
          onConfirm((0, import_floorMapToolbarPalette.expandPaletteEntriesByQuantity)(entries, quantities));
          onClose();
        }
      }
    },
    /* @__PURE__ */ import_react.default.createElement("p", { className: `${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-view-all-modal-hint` }, import_utils.locales.getText(`${I18N_TB}.view-all-modal-hint`)),
    /* @__PURE__ */ import_react.default.createElement("div", { className: `${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-view-all-modal-grid` }, entries.map((entry) => {
      const qty = quantities[entry.key] ?? 0;
      const selected = qty > 0;
      return /* @__PURE__ */ import_react.default.createElement(
        "div",
        {
          key: entry.key,
          className: (0, import_classnames.default)(`${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-view-all-modal-card`, {
            [`${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-view-all-modal-card--selected`]: selected
          })
        },
        /* @__PURE__ */ import_react.default.createElement("div", { className: `${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-view-all-modal-card-preview` }, renderEntryPreview(entry)),
        /* @__PURE__ */ import_react.default.createElement("span", { className: `${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-view-all-modal-card-label` }, entry.label),
        /* @__PURE__ */ import_react.default.createElement(
          "div",
          {
            className: `${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-view-all-modal-card-stepper`,
            onClick: (e) => e.stopPropagation()
          },
          /* @__PURE__ */ import_react.default.createElement(
            "button",
            {
              type: "button",
              className: `${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-view-all-modal-card-stepper-btn`,
              disabled: qty <= 0,
              "aria-label": import_utils.locales.getText(
                `${I18N_TB}.view-all-modal-qty-decrease`
              ),
              onClick: () => setQty(entry.key, qty - 1)
            },
            /* @__PURE__ */ import_react.default.createElement(import_icons.MinusOutlined, null)
          ),
          /* @__PURE__ */ import_react.default.createElement(
            "span",
            {
              className: `${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-view-all-modal-card-stepper-qty`,
              "aria-live": "polite"
            },
            qty
          ),
          /* @__PURE__ */ import_react.default.createElement(
            "button",
            {
              type: "button",
              className: `${import_floorMapLayoutConstants.FLOOR_MAP_LAYOUT_CLASS_PREFIX}-toolbar-view-all-modal-card-stepper-btn`,
              disabled: qty >= PALETTE_VIEW_ALL_MODAL_MAX_QTY,
              "aria-label": import_utils.locales.getText(
                `${I18N_TB}.view-all-modal-qty-increase`
              ),
              onClick: () => setQty(entry.key, qty + 1)
            },
            /* @__PURE__ */ import_react.default.createElement(import_icons.PlusOutlined, null)
          )
        )
      );
    }))
  );
}
var FloorMapToolbarViewAllModal_default = FloorMapToolbarViewAllModal;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  FloorMapToolbarViewAllModal
});
