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/venueBooking/components/VenueSelection/components/PriceLegend.tsx
var PriceLegend_exports = {};
__export(PriceLegend_exports, {
  default: () => PriceLegend
});
module.exports = __toCommonJS(PriceLegend_exports);
var import_react = __toESM(require("react"));
var import_utils = require("@pisell/utils");
var import_context = require("../../../context");
var import_hooks = require("../../../hooks");
function PriceLegend() {
  var _a;
  const symbol = (0, import_hooks.useVenueBookingSymbol)();
  const { viewModel } = (0, import_context.useVenueBookingContext)();
  const venueProducts = (0, import_react.useMemo)(() => {
    var _a2;
    const products = viewModel.venueProducts || [];
    if (!products.length) return [];
    const resources = ((_a2 = viewModel.timeSlotGrid) == null ? void 0 : _a2.resources) || [];
    const resourceProductIdSet = /* @__PURE__ */ new Set();
    const resourceProductTitleSet = /* @__PURE__ */ new Set();
    resources.forEach((resource) => {
      const productId = Number(resource == null ? void 0 : resource.productId);
      if (!Number.isNaN(productId) && productId > 0) {
        resourceProductIdSet.add(productId);
      }
      const productTitle = String((resource == null ? void 0 : resource.productTitle) || "").trim();
      if (productTitle) {
        resourceProductTitleSet.add(productTitle);
      }
    });
    if (!resourceProductIdSet.size && !resourceProductTitleSet.size) return products;
    return products.filter((product) => {
      const productId = Number((product == null ? void 0 : product.id) ?? (product == null ? void 0 : product.product_id) ?? (product == null ? void 0 : product.productId));
      if (!Number.isNaN(productId) && resourceProductIdSet.has(productId)) return true;
      const productTitle = String((product == null ? void 0 : product.title) || (product == null ? void 0 : product.name) || "").trim();
      if (productTitle && resourceProductTitleSet.has(productTitle)) return true;
      return false;
    });
  }, [viewModel.venueProducts, (_a = viewModel.timeSlotGrid) == null ? void 0 : _a.resources]);
  if (!venueProducts.length) return null;
  const gridClassName = venueProducts.length === 1 ? "grid grid-cols-1 gap-2 md:gap-3" : "grid grid-cols-1 gap-2 md:grid-cols-2 md:gap-3 xl:grid-cols-4";
  return /* @__PURE__ */ import_react.default.createElement("div", { className: gridClassName }, venueProducts.map((product, index) => {
    const lines = getLegendLines(product, symbol);
    const fallbackTitlePrefix = import_utils.locales.getText("pisell2.venue.legend.product.fallback") || "商品";
    const title = String((product == null ? void 0 : product.title) || (product == null ? void 0 : product.name) || `${fallbackTitlePrefix} ${index + 1}`);
    const cardClassName = index % 2 === 0 ? "bg-[#fff4f4] ring-[#f4caca]" : "bg-[#fff7f7] ring-[#f4d7d7]";
    return /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        key: String((product == null ? void 0 : product.id) || `${title}-${index}`),
        className: `min-w-0 rounded-[16px] px-3 py-3 ring-1 md:px-4 ${cardClassName}`
      },
      /* @__PURE__ */ import_react.default.createElement("div", { className: "truncate text-[11px] font-semibold text-zinc-900 md:text-sm" }, title),
      lines.length ? lines.map((line) => /* @__PURE__ */ import_react.default.createElement(
        "div",
        {
          key: line,
          className: "mt-1 text-[10px] text-zinc-600 md:text-sm [&_p]:m-0 [&_br]:leading-tight",
          dangerouslySetInnerHTML: { __html: line }
        }
      )) : /* @__PURE__ */ import_react.default.createElement("div", { className: "mt-1 text-[10px] text-zinc-500 md:text-sm" }, "-")
    );
  }));
}
function getLegendLines(product, symbol) {
  var _a;
  const metadataLines = (_a = product == null ? void 0 : product.metadata) == null ? void 0 : _a.venue_booking_legend;
  if (Array.isArray(metadataLines) && metadataLines.length) {
    return metadataLines.map((item) => String(item || "").trim()).filter(Boolean).slice(0, 2);
  }
  const descriptionCandidates = [
    product == null ? void 0 : product.description,
    product == null ? void 0 : product.sub_title,
    product == null ? void 0 : product.subtitle,
    product == null ? void 0 : product.summary,
    product == null ? void 0 : product.intro
  ].map((item) => String(item || "").trim()).filter(Boolean);
  if (descriptionCandidates.length) return descriptionCandidates.slice(0, 2);
  const price = (product == null ? void 0 : product.price) != null ? `${symbol}${product.price}` : "";
  const originalPrice = (product == null ? void 0 : product.original_price) != null ? `${symbol}${product.original_price}` : "";
  const fallbackLine = [price, originalPrice ? `· ${originalPrice}` : ""].join("").trim();
  return fallbackLine ? [fallbackLine] : [];
}
