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/ticketBooking/components/ProductDisplayAdapter/utils.ts
var utils_exports = {};
__export(utils_exports, {
  formatSkuDataSource: () => formatSkuDataSource,
  generateProductTabs: () => generateProductTabs
});
module.exports = __toCommonJS(utils_exports);
var import_utils = require("@pisell/utils");
var formatSkuDataSource = (dataSource) => {
  return {
    id: dataSource.id,
    title: dataSource.title,
    subtitle: dataSource.subtitle,
    cover: dataSource.cover,
    price: dataSource.price,
    original_price: dataSource.original_price,
    stock: dataSource.stock_quantity,
    sortKeys: ["title", "subtitle", "price"]
  };
};
var generateProductTabs = (products, tabStyle = "switch") => {
  if (!products || products.length === 0) {
    return [{ key: "all", label: import_utils.locales.getText("pisell2.ticket-booking.all") }];
  }
  if (tabStyle === "switch") {
    const categoryMap = /* @__PURE__ */ new Map();
    products.forEach((product) => {
      if (product.category && Array.isArray(product.category)) {
        product.category.forEach((cat) => {
          if (!categoryMap.has(cat.id)) {
            categoryMap.set(cat.id, cat);
          }
        });
      }
    });
    const sortedCategories = Array.from(categoryMap.values()).sort(
      (a, b) => (b.sort || 0) - (a.sort || 0)
    );
    const tabs = [
      { key: "all", label: import_utils.locales.getText("pisell2.ticket-booking.all") }
    ];
    sortedCategories.forEach((category) => {
      tabs.push({
        key: String(category.id),
        label: category.name,
        group: String(category.id)
      });
    });
    return tabs;
  } else {
    const categoryCount = products.reduce((acc, product) => {
      if (product.category && Array.isArray(product.category)) {
        product.category.forEach((cat) => {
          const key = String(cat.id);
          if (!acc[key]) {
            acc[key] = { count: 0, category: cat };
          }
          acc[key].count += 1;
        });
      }
      return acc;
    }, {});
    const tabs = [
      { key: "all", label: `${import_utils.locales.getText("pisell2.ticket-booking.all")} (${products.length})` }
    ];
    const sortedEntries = Object.entries(categoryCount).sort(
      ([, a], [, b]) => (b.category.sort || 0) - (a.category.sort || 0)
    );
    sortedEntries.forEach(([key, { count, category }]) => {
      tabs.push({
        key,
        label: `${category.name} (${count})`,
        group: key
      });
    });
    return tabs;
  }
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  formatSkuDataSource,
  generateProductTabs
});
