import { _objectSpread2 } from "../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import { generateProductTabs, sortProductsByTabOrder } from "../../ticketBooking/components/ProductDisplayAdapter/utils.js";
import { ProductDisplayPresets } from "../../ticketBooking/components/ProductDisplayAdapter/types.js";
import { useMemo } from "react";
//#region src/components/bigSale/hooks/useBigSaleProductListConfig.ts
const DEFAULT_DISPLAY_CONFIG = "sku-list-a5";
const 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
	}
};
const 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 ProductDisplayPresets[DEFAULT_DISPLAY_CONFIG];
	if (typeof config === "string") return ProductDisplayPresets[config] || ProductDisplayPresets[DEFAULT_DISPLAY_CONFIG];
	return config;
}
function getProductTitle(product) {
	return product.title || `#${product.id}`;
}
function normalizeProductForList(product) {
	var _product$category, _product$category$map;
	return _objectSpread2(_objectSpread2({}, product), {}, { category: ((_product$category = product.category) === null || _product$category === void 0 || (_product$category$map = _product$category.map) === null || _product$category$map === void 0 ? void 0 : _product$category$map.call(_product$category, (category) => `${category.id}`)) || [] });
}
function getResponsiveListConfig(variant, skuListConfig) {
	var _skuListConfig$skuCar;
	if (!variant) return void 0;
	return ((_skuListConfig$skuCar = skuListConfig.skuCardAllConfig) === null || _skuListConfig$skuCar === void 0 || (_skuListConfig$skuCar = _skuListConfig$skuCar.skuCardConfig) === null || _skuListConfig$skuCar === void 0 ? void 0 : _skuListConfig$skuCar.layoutDirection) === "row" ? BIG_SALE_ROW_CARD_RESPONSIVE_LIST_CONFIG[variant] : BIG_SALE_RESPONSIVE_LIST_CONFIG[variant];
}
function useBigSaleProductListConfig({ products, productDisplayConfig, variant, keyword }) {
	return useMemo(() => {
		var _listConfig$columnGap, _listConfig$rowGap, _listConfig$isTreeTab;
		const skuListConfig = resolveBigSaleProductDisplayConfig(productDisplayConfig).skuListConfig || {};
		const responsiveListConfig = getResponsiveListConfig(variant, skuListConfig);
		const listConfig = _objectSpread2(_objectSpread2({}, skuListConfig.listConfig), responsiveListConfig);
		const displayStyle = listConfig.layout || "grid";
		const columns = listConfig.columns || 2;
		const columnGap = (_listConfig$columnGap = listConfig.columnGap) !== null && _listConfig$columnGap !== void 0 ? _listConfig$columnGap : 12;
		const rowGap = (_listConfig$rowGap = listConfig.rowGap) !== null && _listConfig$rowGap !== void 0 ? _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 = listConfig.isTreeTab) !== null && _listConfig$isTreeTab !== void 0 ? _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 ? generateProductTabs(products, tabStyle, isTreeTab) : void 0;
		const listData = filteredProducts.map(normalizeProductForList);
		if (!isTreeTab && tabData && Array.isArray(tabData)) 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
	]);
}
//#endregion
export { useBigSaleProductListConfig };
