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_RESPONSIVE_LIST_CONFIG = {
  phone: {
    columns: 1,
    columnGap: 8,
    rowGap: 8
  },
  smallTablet: {
    columns: 2,
    columnGap: 10,
    rowGap: 10
  },
  tablet: {
    columns: 3,
    columnGap: 12,
    rowGap: 12
  },
  desktop: {
    columns: 5,
    columnGap: 12,
    rowGap: 12
  }
};
var BIG_SALE_ROW_CARD_RESPONSIVE_LIST_CONFIG = {
  phone: {
    columns: 1,
    columnGap: 8,
    rowGap: 8
  },
  smallTablet: {
    columns: 2,
    columnGap: 10,
    rowGap: 10
  },
  tablet: {
    columns: 2,
    columnGap: 12,
    rowGap: 12
  },
  desktop: {
    columns: 2,
    columnGap: 12,
    rowGap: 12
  }
};
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 getResponsiveListConfig(variant, skuListConfig) {
  var _a, _b;
  if (!variant) return void 0;
  const isRowCard = ((_b = (_a = skuListConfig.skuCardAllConfig) == null ? void 0 : _a.skuCardConfig) == null ? void 0 : _b.layoutDirection) === "row";
  return isRowCard ? BIG_SALE_ROW_CARD_RESPONSIVE_LIST_CONFIG[variant] : BIG_SALE_RESPONSIVE_LIST_CONFIG[variant];
}
function useBigSaleProductListConfig({
  products,
  productDisplayConfig,
  variant,
  keyword
}) {
  return (0, import_react.useMemo)(() => {
    const resolvedConfig = resolveBigSaleProductDisplayConfig(productDisplayConfig);
    const skuListConfig = resolvedConfig.skuListConfig || {};
    const responsiveListConfig = getResponsiveListConfig(variant, skuListConfig);
    const listConfig = {
      ...skuListConfig.listConfig,
      ...responsiveListConfig
    };
    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 nextKeyword = keyword.trim().toLowerCase();
    const filteredProducts = nextKeyword ? products.filter(
      (product) => getProductTitle(product).toLowerCase().includes(nextKeyword)
    ) : products;
    const tabData = enableTab ? (0, import_utils.generateProductTabs)(products, tabStyle, isTreeTab) : void 0;
    const listData = filteredProducts.map(normalizeProductForList);
    if (!isTreeTab && tabData && Array.isArray(tabData)) {
      (0, import_utils.sortProductsByTabOrder)(listData, tabData);
    }
    const listProps = {
      displayStyle,
      columns,
      columnGap,
      rowGap,
      paginationType,
      layoutDirection: "vertical",
      tabStyle: resolvedTabStyle,
      isTreeTab,
      tabData,
      tabGroup: "category",
      stickyTop,
      skeletonConfig: listConfig.skeletonConfig
    };
    return {
      data: listData,
      skuCardAllConfig: skuListConfig.skuCardAllConfig,
      listProps
    };
  }, [keyword, productDisplayConfig, products, variant]);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  useBigSaleProductListConfig
});
