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/bigSale/templates/Standard/index.tsx
var Standard_exports = {};
__export(Standard_exports, {
  StandardBigSaleTemplate: () => StandardBigSaleTemplate,
  default: () => Standard_default
});
module.exports = __toCommonJS(Standard_exports);
var import_react = __toESM(require("react"));
var import_classnames = __toESM(require("classnames"));
var import_ahooks = require("ahooks");
var import_Base = __toESM(require("../../../../plus/saleDetail/Base"));
var import_DetailActions = require("../../../../plus/saleDetail/components/DetailActions");
var import_BookingFloatingPanel = __toESM(require("../../components/BookingFloatingPanel"));
var import_FloatingActions = __toESM(require("../../components/FloatingActions"));
var import_OrderHeaderBar = __toESM(require("../../components/OrderHeaderBar"));
var import_ProductList = require("../../components/ProductList");
var import_TimeBar = __toESM(require("../../components/TimeBar"));
var import_hooks = require("../../hooks");
var import_useSelectFloorMapResourceForBigSale = require("../../hooks/useSelectFloorMapResourceForBigSale");
function isRealBigSaleOrderId(orderId) {
  if (orderId == null || orderId === "") return false;
  return !String(orderId).startsWith("local_order");
}
function resolveBigSaleOrderHeaderTitle(context) {
  var _a;
  const tempOrder = context.sales.tempOrder;
  const detailHeader = (_a = context.sales.salesDetail) == null ? void 0 : _a.header;
  const detailRoot = context.sales.salesDetail;
  const orderId = (tempOrder == null ? void 0 : tempOrder.order_id) ?? (detailHeader == null ? void 0 : detailHeader.order_id) ?? (detailRoot == null ? void 0 : detailRoot.order_id);
  if (!isRealBigSaleOrderId(orderId)) return null;
  const label = (tempOrder == null ? void 0 : tempOrder.shop_full_order_number) || (tempOrder == null ? void 0 : tempOrder.shop_order_number) || (tempOrder == null ? void 0 : tempOrder.order_number) || (detailHeader == null ? void 0 : detailHeader.shop_full_order_number) || (detailHeader == null ? void 0 : detailHeader.shop_order_number) || (detailHeader == null ? void 0 : detailHeader.order_number) || orderId;
  return label != null && String(label).trim() !== "" ? String(label) : `#${String(orderId)}`;
}
function withBigSaleHolderValidation(actions) {
  return actions.map((action) => {
    if (action.key !== "save" && action.key !== "checkout-cart") {
      return action;
    }
    return {
      ...action,
      validateHolder: true
    };
  });
}
function StandardBigSaleTemplate({
  isActive = true,
  context,
  mode,
  variant,
  productLoadParams,
  businessCode,
  bookingConfigParams,
  hideSelectFloorMapResourceAction,
  productDisplayConfig,
  productCatalogSessionKey,
  saleDetailTemplate,
  saleDetailModuleConfig,
  orderId,
  locale,
  saleDetailHeaderSlot,
  onOrderComplete
}) {
  const floatingPanelRef = (0, import_react.useRef)(null);
  const timeBarRef = (0, import_react.useRef)(null);
  const saleDetailContext = (0, import_hooks.usePickSaleDetailContext)(context, onOrderComplete);
  const {
    hasReservationRuleProduct,
    openSelectFloorMapResource
  } = (0, import_useSelectFloorMapResourceForBigSale.useSelectFloorMapResourceForBigSale)({
    context,
    mode,
    businessCode,
    bookingConfigParams,
    productLoadParams
  });
  (0, import_hooks.useSyncBigSaleCartToCds)(context, { enabled: orderId == null });
  const shouldInjectFloorResourceAction = hasReservationRuleProduct && !hideSelectFloorMapResourceAction;
  const dineInOrderActions = (0, import_react.useMemo)(() => {
    if (!shouldInjectFloorResourceAction) return void 0;
    return [
      {
        key: "select-floor-resource",
        row: 1,
        order: 10,
        slot: "footer-muted",
        buttonProps: {
          size: "large",
          onClick: openSelectFloorMapResource
        }
      },
      {
        key: "note",
        row: 1,
        order: 11,
        slot: "footer-muted",
        buttonProps: {
          size: "large"
        }
      },
      {
        key: "save",
        row: 1,
        order: 20,
        slot: "footer-secondary",
        // BigSale 保存需要沿用预约提交前的 holder 必填确认。
        validateHolder: true,
        buttonProps: {
          icon: null
        }
      },
      {
        key: "checkout-cart",
        row: 1,
        order: 30,
        slot: "footer-primary",
        // BigSale 收款前需要沿用预约提交前的 holder 必填确认。
        validateHolder: true
      }
    ];
  }, [openSelectFloorMapResource, shouldInjectFloorResourceAction]);
  const effectiveSaleDetailModuleConfig = (0, import_react.useMemo)(() => {
    const orderActions = withBigSaleHolderValidation(
      dineInOrderActions || (saleDetailModuleConfig == null ? void 0 : saleDetailModuleConfig.orderActions) || import_DetailActions.TEMPLATE_A_ACTIONS
    );
    return {
      ...saleDetailModuleConfig,
      orderActions
    };
  }, [dineInOrderActions, saleDetailModuleConfig]);
  const internalOrderHeaderTitle = resolveBigSaleOrderHeaderTitle(context);
  const handleClearCurrentOrderWorkspace = (0, import_ahooks.useMemoizedFn)(async () => {
    await context.sales.clearCartAndReset();
    await context.cart.recalcSummary();
  });
  const effectiveSaleDetailHeaderSlot = (0, import_react.useMemo)(() => {
    if (saleDetailHeaderSlot) return saleDetailHeaderSlot;
    if (!internalOrderHeaderTitle) return null;
    return /* @__PURE__ */ import_react.default.createElement(
      import_OrderHeaderBar.default,
      {
        title: internalOrderHeaderTitle,
        variant,
        onClear: handleClearCurrentOrderWorkspace
      }
    );
  }, [
    saleDetailHeaderSlot,
    internalOrderHeaderTitle,
    variant,
    handleClearCurrentOrderWorkspace
  ]);
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement("section", { className: "pisell-big-sale__product-panel" }, /* @__PURE__ */ import_react.default.createElement(
    import_ProductList.BigSaleProductList,
    {
      isActive,
      mode,
      context,
      productLoadParams,
      productDisplayConfig,
      productCatalogSessionKey,
      variant
    }
  ), /* @__PURE__ */ import_react.default.createElement(
    import_FloatingActions.default,
    {
      variant,
      floatingPanelRef,
      timeBarRef
    }
  )), /* @__PURE__ */ import_react.default.createElement(
    "section",
    {
      className: (0, import_classnames.default)("pisell-big-sale__sale-detail", {
        "pisell-big-sale__sale-detail--has-header": Boolean(
          effectiveSaleDetailHeaderSlot
        )
      })
    },
    effectiveSaleDetailHeaderSlot,
    /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-big-sale__sale-detail-body" }, /* @__PURE__ */ import_react.default.createElement(
      import_Base.default,
      {
        context: saleDetailContext,
        renderType: "current",
        template: saleDetailTemplate,
        variant,
        mobilePresentation: "bottomSheet",
        moduleConfig: effectiveSaleDetailModuleConfig
      }
    ))
  ), /* @__PURE__ */ import_react.default.createElement(
    import_TimeBar.default,
    {
      context,
      productLoadParams,
      orderId,
      locale,
      variant,
      ref: timeBarRef
    }
  ), /* @__PURE__ */ import_react.default.createElement(
    import_BookingFloatingPanel.default,
    {
      context,
      ref: floatingPanelRef,
      variant
    }
  ));
}
var Standard_default = StandardBigSaleTemplate;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  StandardBigSaleTemplate
});
