var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/bigSale/hooks/useBigSaleProductListConfig.ts
var useBigSaleProductListConfig_exports = {};
__export(useBigSaleProductListConfig_exports, {
  useBigSaleProductListConfig: () => useBigSaleProductListConfig
});
module.exports = __toCommonJS(useBigSaleProductListConfig_exports);
var import_react = require("react");
var import_ProductDisplayAdapter = require("../../ticketBooking/components/ProductDisplayAdapter");
var import_utils = require("../../ticketBooking/components/ProductDisplayAdapter/utils");
var DEFAULT_DISPLAY_CONFIG = "sku-list-a5";
var BIG_SALE_COLUMN_CARD_MIN_WIDTH = 220;
var BIG_SALE_ROW_CARD_MIN_WIDTH = 320;
var BIG_SALE_COLUMN_CARD_MAX_COLUMNS = 5;
var BIG_SALE_ROW_CARD_MAX_COLUMNS = 3;
function resolveBigSaleProductDisplayConfig(config) {
  if (!config) return import_ProductDisplayAdapter.ProductDisplayPresets[DEFAULT_DISPLAY_CONFIG];
  if (typeof config === "string") {
    return import_ProductDisplayAdapter.ProductDisplayPresets[config] || import_ProductDisplayAdapter.ProductDisplayPresets[DEFAULT_DISPLAY_CONFIG];
  }
  return config;
}
function getProductTitle(product) {
  return product.title || `#${product.id}`;
}
function normalizeProductForList(product) {
  var _a, _b;
  return {
    ...product,
    category: ((_b = (_a = product.category) == null ? void 0 : _a.map) == null ? void 0 : _b.call(_a, (category) => `${category.id}`)) || []
  };
}
function getListGapByWidth(listWidth) {
  if (listWidth < 480) return 8;
  if (listWidth < 768) return 10;
  return 12;
}
function getResponsiveListConfig(listWidth, skuListConfig) {
  var _a, _b, _c;
  if (!listWidth || listWidth <= 0) return void 0;
  const isRowCard = ((_b = (_a = skuListConfig.skuCardAllConfig) == null ? void 0 : _a.skuCardConfig) == null ? void 0 : _b.layoutDirection) === "row";
  const gap = getListGapByWidth(listWidth);
  const minCardWidth = isRowCard ? BIG_SALE_ROW_CARD_MIN_WIDTH : BIG_SALE_COLUMN_CARD_MIN_WIDTH;
  const maxColumns = isRowCard ? BIG_SALE_ROW_CARD_MAX_COLUMNS : Math.max(
    BIG_SALE_COLUMN_CARD_MAX_COLUMNS,
    ((_c = skuListConfig.listConfig) == null ? void 0 : _c.columns) || 0
  );
  const columns = Math.max(
    1,
    Math.min(maxColumns, Math.floor((listWidth + gap) / (minCardWidth + gap)))
  );
  return {
    columns,
    columnGap: gap,
    rowGap: gap
  };
}
function useBigSaleProductListConfig({
  products,
  productDisplayConfig,
  listWidth: propListWidth,
  keyword,
  activeTab
}) {
  const [listWidth, setListWidth] = (0, import_react.useState)(propListWidth);
  (0, import_react.useEffect)(() => {
    if (propListWidth) {
      setListWidth(propListWidth);
    }
  }, [propListWidth]);
  const resolvedConfig = (0, import_react.useMemo)(
    () => resolveBigSaleProductDisplayConfig(productDisplayConfig),
    [productDisplayConfig]
  );
  const skuListConfig = resolvedConfig.skuListConfig || {};
  const listConfig = (0, import_react.useMemo)(() => {
    const responsiveListConfig = getResponsiveListConfig(
      listWidth,
      skuListConfig
    );
    return {
      ...skuListConfig.listConfig,
      ...responsiveListConfig
    };
  }, [skuListConfig, listWidth]);
  const displayConfig = (0, import_react.useMemo)(() => {
    const displayStyle = listConfig.layout || "grid";
    const columns = listConfig.columns || 2;
    const columnGap = listConfig.columnGap ?? 12;
    const rowGap = listConfig.rowGap ?? 12;
    const paginationType = listConfig.showPagination ? "pager" : "all";
    const enableTab = listConfig.showTab || false;
    const tabStyle = listConfig.tabStyle || "switch";
    const resolvedTabStyle = enableTab ? tabStyle === "anchor" ? "anchor" : "switch" : "none";
    const isTreeTab = listConfig.isTreeTab ?? true;
    const stickyTop = listConfig.stickyTop !== void 0 ? listConfig.stickyTop : true;
    const tabData = enableTab ? (0, import_utils.generateProductTabs)(
      products,
      tabStyle,
      isTreeTab
    ) : void 0;
    const listProps = {
      displayStyle,
      columns,
      columnGap,
      rowGap,
      paginationType,
      layoutDirection: "vertical",
      tabStyle: resolvedTabStyle,
      isTreeTab,
      tabData,
      tabGroup: "category",
      stickyTop,
      skeletonConfig: listConfig.skeletonConfig
    };
    return {
      isTreeTab,
      listProps,
      skuCardAllConfig: skuListConfig.skuCardAllConfig,
      tabData
    };
  }, [listConfig, products, skuListConfig.skuCardAllConfig]);
  const listData = (0, import_react.useMemo)(() => {
    const nextKeyword = keyword.trim().toLowerCase();
    const isSearchMode = Array.isArray(activeTab) && activeTab.length === 0;
    const filteredProducts = isSearchMode && !nextKeyword ? [] : nextKeyword ? products.filter(
      (product) => getProductTitle(product).toLowerCase().includes(nextKeyword)
    ) : products;
    const normalizedProducts = filteredProducts.map(normalizeProductForList);
    if (!displayConfig.isTreeTab && displayConfig.tabData && Array.isArray(displayConfig.tabData)) {
      (0, import_utils.sortProductsByTabOrder)(
        normalizedProducts,
        displayConfig.tabData
      );
    }
    return normalizedProducts;
  }, [
    activeTab,
    displayConfig.isTreeTab,
    displayConfig.tabData,
    keyword,
    products
  ]);
  return (0, import_react.useMemo)(() => {
    return {
      data: listData,
      skuCardAllConfig: displayConfig.skuCardAllConfig,
      listProps: displayConfig.listProps
    };
  }, [displayConfig.listProps, displayConfig.skuCardAllConfig, listData]);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  useBigSaleProductListConfig
});
