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/plus/pisellProResourcePickerModal/PisellFloorMapPaletteViewAllModal.tsx
var PisellFloorMapPaletteViewAllModal_exports = {};
__export(PisellFloorMapPaletteViewAllModal_exports, {
  PisellFloorMapPaletteViewAllModal: () => PisellFloorMapPaletteViewAllModal,
  default: () => PisellFloorMapPaletteViewAllModal_default
});
module.exports = __toCommonJS(PisellFloorMapPaletteViewAllModal_exports);
var import_react = __toESM(require("react"));
var import_utils = require("@pisell/utils");
var import_materials = require("@pisell/materials");
var import_useEngineContext = __toESM(require("../../hooks/useEngineContext"));
var import_PisellProResourcePickerModal = require("./PisellProResourcePickerModal");
import_utils.locales.init(import_materials.floorMapLayoutLocales, "zh-CN");
var IMAGE_KIND_VALUE = "floorMapImage";
var CATEGORY_IMAGE = "image";
var CATEGORY_ICON = "icon";
var I18N_VA = "pisell-floor-map-layout.toolbar";
function expandEntriesByQuantity(entries, quantities) {
  const out = [];
  for (const e of entries) {
    const n = Math.max(0, Math.floor(quantities[e.key] ?? 0));
    for (let i = 0; i < n; i += 1) {
      out.push({
        elementKind: e.kind.value,
        ...e.builtinShapeKey ? { builtinShapeKey: e.builtinShapeKey } : {}
      });
    }
  }
  return out;
}
function PisellFloorMapPaletteViewAllModal(props) {
  var _a;
  const {
    open,
    categoryLabel,
    entries,
    onClose,
    onConfirm,
    renderEntryPreview,
    platform
  } = props;
  const { engine } = (0, import_useEngineContext.default)();
  const engineLocale = ((_a = engine == null ? void 0 : engine.props) == null ? void 0 : _a.locale) ?? "zh-CN";
  (0, import_react.useEffect)(() => {
    if (open) {
      import_utils.locales.init(import_materials.floorMapLayoutLocales, engineLocale);
    }
  }, [open, engineLocale]);
  const records = (0, import_react.useMemo)(
    () => entries.map((e) => ({
      id: e.key,
      title: e.label,
      __category: e.kind.value === IMAGE_KIND_VALUE ? CATEGORY_IMAGE : CATEGORY_ICON,
      __entry: e
    })),
    [entries]
  );
  const tabbarDataSource = (0, import_react.useMemo)(() => {
    const hasImage = entries.some((e) => e.kind.value === IMAGE_KIND_VALUE);
    const hasIcon = entries.some((e) => e.kind.value !== IMAGE_KIND_VALUE);
    const out = [];
    if (hasImage) {
      out.push({
        id: CATEGORY_IMAGE,
        name: import_utils.locales.getText(`${I18N_VA}.view-all-modal-category-image`)
      });
    }
    if (hasIcon) {
      out.push({
        id: CATEGORY_ICON,
        name: import_utils.locales.getText(`${I18N_VA}.view-all-modal-category-icon`)
      });
    }
    return out;
  }, [entries, engineLocale]);
  const title = categoryLabel;
  return /* @__PURE__ */ import_react.default.createElement(
    import_PisellProResourcePickerModal.PisellProResourcePickerModal,
    {
      open,
      title,
      onClose,
      platform,
      onConfirm: (selected) => {
        const quantities = {};
        for (const v of selected) {
          const key = v.value.trim();
          if (!key) continue;
          quantities[key] = Math.max(0, Math.floor(v.quantity));
        }
        onConfirm(expandEntriesByQuantity(entries, quantities));
      },
      records,
      mode: "multiple",
      value: [],
      selectorValueType: "object",
      selectorShowStepper: true,
      getOptionRuleConfig: () => ({ max: 99 }),
      getSearchText: (r) => String(r.title ?? "").toLowerCase(),
      categoryConfig: { levels: [{ field: "__category" }] },
      renderFilterBar: (ctx) => /* @__PURE__ */ import_react.default.createElement(
        import_materials.PisellTabbarTemplate1,
        {
          className: "pisell-pro-resource-picker-tabbar",
          style: {
            position: "sticky",
            top: 0,
            zIndex: 10,
            padding: 6,
            background: "rgb(250, 250, 250)"
          },
          dataSource: tabbarDataSource,
          value: ctx.tabbarValue,
          onChange: ctx.onTabbarValueChange,
          onSearch: ctx.onKeywordChange,
          maxLevel: 1
        }
      ),
      getCardMeta: (r) => {
        const e = r.__entry;
        return {
          title: String(r.title ?? ""),
          subtitles: [],
          image: e ? renderEntryPreview(e) : void 0
        };
      }
    }
  );
}
var PisellFloorMapPaletteViewAllModal_default = PisellFloorMapPaletteViewAllModal;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  PisellFloorMapPaletteViewAllModal
});
