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/ticketBooking/components/ProductDisplayAdapter/ProductDisplayAdapter.tsx
var ProductDisplayAdapter_exports = {};
__export(ProductDisplayAdapter_exports, {
  default: () => ProductDisplayAdapter_default
});
module.exports = __toCommonJS(ProductDisplayAdapter_exports);
var import_react = __toESM(require("react"));
var import_ahooks = require("ahooks");
var import_productSelect = __toESM(require("../../../../plus/productSelect"));
var import_List = __toESM(require("../../../list/List"));
var import_SkuCard = __toESM(require("../../../../plus/productSelect/ProductCard/SkuCard"));
var import_utils = require("./utils");
var import_index = require("./index.less");
var ProductDisplayAdapter = (props) => {
  const {
    config,
    dataSource,
    loading = false,
    currentProductId,
    onSelectProduct,
    emptyDescription,
    style,
    className
  } = props;
  const { displayMode = "product-select" } = config;
  const listRef = (0, import_react.useRef)(null);
  const size = (0, import_ahooks.useSize)(listRef);
  const renderProductSelect = (0, import_react.useMemo)(() => {
    const {
      showSearch = true,
      showTab = true,
      layout = { grid: true, config: "12:12" },
      productListSetting = {
        isProductCover: 1,
        isTitle: 1,
        isSubtitle: 1,
        isPrice: 1,
        isOriginPrice: 0,
        isStock: 0
      }
    } = config.productSelectConfig || {};
    return /* @__PURE__ */ import_react.default.createElement(
      import_productSelect.default,
      {
        dataSource,
        layout,
        onChange: onSelectProduct,
        value: currentProductId,
        loading,
        productListSetting,
        showSearch,
        showTab,
        emptyDescription,
        style
      }
    );
  }, [
    config.productSelectConfig,
    dataSource,
    currentProductId,
    onSelectProduct,
    loading,
    emptyDescription,
    style
  ]);
  const renderSkuList = (0, import_react.useMemo)(() => {
    const { listConfig = {}, skuCardAllConfig = {} } = config.skuListConfig || {};
    const displayStyle = listConfig.layout || "grid";
    const columns = listConfig.columns || 2;
    const paginationType = listConfig.showPagination ? "pager" : "all";
    const enableTab = listConfig.showTab || false;
    const tabStyle = listConfig.tabStyle || "switch";
    const stickyTop = listConfig.stickyTop !== void 0 ? listConfig.stickyTop : true;
    const tabData = enableTab ? (0, import_utils.generateProductTabs)(dataSource, tabStyle) : void 0;
    const filteredData = dataSource.map((item) => {
      var _a, _b;
      return {
        ...item,
        category: ((_b = (_a = item.category) == null ? void 0 : _a.map) == null ? void 0 : _b.call(_a, (category) => `${category.id}`)) || []
      };
    });
    return /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: `sku-list-container ${className || ""}`,
        style,
        ref: listRef
      },
      /* @__PURE__ */ import_react.default.createElement(
        import_List.default,
        {
          className: "sku-list",
          style: { maxHeight: size == null ? void 0 : size.height, overflow: "auto" },
          data: filteredData,
          loading,
          displayStyle,
          columns,
          paginationType,
          layoutDirection: "vertical",
          tabStyle: enableTab ? tabStyle : "none",
          tabData,
          tabGroup: "category",
          stickyTop,
          emptyConfig: {
            show: !loading && filteredData.length === 0,
            text: emptyDescription
          },
          renderItem: (item, index) => /* @__PURE__ */ import_react.default.createElement(
            import_SkuCard.default,
            {
              key: item.id,
              ...skuCardAllConfig,
              dataSource: (0, import_utils.formatSkuDataSource)(item),
              onCardClick: () => onSelectProduct(item),
              isSelected: item.id === currentProductId
            }
          )
        }
      )
    );
  }, [
    config.skuListConfig,
    dataSource,
    loading,
    currentProductId,
    onSelectProduct,
    emptyDescription,
    style,
    className,
    size == null ? void 0 : size.height
  ]);
  if (displayMode === "sku-list") {
    return renderSkuList;
  }
  return renderProductSelect;
};
var ProductDisplayAdapter_default = ProductDisplayAdapter;
