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/plus/salesSdk/context/SalesSdkBookingContext.tsx
var SalesSdkBookingContext_exports = {};
__export(SalesSdkBookingContext_exports, {
  SalesSdkBookingContext: () => SalesSdkBookingContext,
  SalesSdkBookingContextProvider: () => SalesSdkBookingContextProvider,
  useSalesSdkBookingContext: () => useSalesSdkBookingContext
});
module.exports = __toCommonJS(SalesSdkBookingContext_exports);
var import_react = __toESM(require("react"));
var import_ahooks = require("ahooks");
var import_SalesSdkContext = require("./SalesSdkContext");
var import_bookingDate = require("../utils/bookingDate");
var SalesSdkBookingContext = (0, import_react.createContext)(null);
SalesSdkBookingContext.displayName = "SalesSdkBookingContext";
function ensureMethod(bookingTicket, method) {
  const fn = bookingTicket == null ? void 0 : bookingTicket[method];
  if (typeof fn !== "function" || !bookingTicket) {
    throw new Error(`[SalesSdk] BookingContext: bookingTicket.${String(method)} 不可用，请升级 pisellos`);
  }
  return fn.bind(bookingTicket);
}
var SalesSdkBookingContextProvider = ({ children }) => {
  const sales = (0, import_react.useContext)(import_SalesSdkContext.SalesSdkContext);
  const bookingTicket = (sales == null ? void 0 : sales.bookingTicket) ?? null;
  const setBookingConfig = (0, import_ahooks.useMemoizedFn)((config) => {
    ensureMethod(bookingTicket, "setBookingConfig")(config);
  });
  const getBookingConfig = (0, import_ahooks.useMemoizedFn)(() => {
    var _a;
    return ((_a = bookingTicket == null ? void 0 : bookingTicket.getBookingConfig) == null ? void 0 : _a.call(bookingTicket)) || null;
  });
  const setResources = (0, import_ahooks.useMemoizedFn)((resources) => {
    ensureMethod(bookingTicket, "setResources")(resources);
  });
  const getResourcesOrigin = (0, import_ahooks.useMemoizedFn)(() => {
    var _a;
    return ((_a = bookingTicket == null ? void 0 : bookingTicket.getResourcesOrigin) == null ? void 0 : _a.call(bookingTicket)) || [];
  });
  const getResourcesOriginMap = (0, import_ahooks.useMemoizedFn)(() => {
    var _a;
    return ((_a = bookingTicket == null ? void 0 : bookingTicket.getResourcesOriginMap) == null ? void 0 : _a.call(bookingTicket)) || {};
  });
  const setDate = (0, import_ahooks.useMemoizedFn)((date) => {
    if (!(bookingTicket == null ? void 0 : bookingTicket.setBookingDate)) {
      console.warn("[SalesSdk] setDate: bookingTicket 未就绪，跳过写入");
      return;
    }
    const normalized = (0, import_bookingDate.formatBookingDateTime)(date);
    bookingTicket.setBookingDate(normalized ?? date);
  });
  const getDate = (0, import_ahooks.useMemoizedFn)(() => {
    var _a;
    return ((_a = bookingTicket == null ? void 0 : bookingTicket.getBookingDate) == null ? void 0 : _a.call(bookingTicket)) || null;
  });
  const getResourcesForProduct = (0, import_ahooks.useMemoizedFn)(
    (product, options) => ensureMethod(bookingTicket, "getResourcesForProduct")(product, options)
  );
  const getProductExtend = (0, import_ahooks.useMemoizedFn)(
    (cacheItem, extra) => ensureMethod(bookingTicket, "getProductExtend")(cacheItem, extra)
  );
  const getResourceErrors = (0, import_ahooks.useMemoizedFn)(
    (resource, cacheItem) => ensureMethod(bookingTicket, "getResourceErrors")(resource, cacheItem)
  );
  const value = (0, import_react.useMemo)(
    () => ({
      setBookingConfig,
      getBookingConfig,
      setResources,
      getResourcesOrigin,
      getResourcesOriginMap,
      setDate,
      getDate,
      getResourcesForProduct,
      getProductExtend,
      getResourceErrors
    }),
    [
      setBookingConfig,
      getBookingConfig,
      setResources,
      getResourcesOrigin,
      getResourcesOriginMap,
      setDate,
      getDate,
      getResourcesForProduct,
      getProductExtend,
      getResourceErrors
    ]
  );
  return /* @__PURE__ */ import_react.default.createElement(SalesSdkBookingContext.Provider, { value }, children);
};
function useSalesSdkBookingContext() {
  const ctx = (0, import_react.useContext)(SalesSdkBookingContext);
  if (!ctx) {
    throw new Error("[SalesSdk] useSalesSdkBookingContext 必须在 <SalesSdkBookingContextProvider> 内调用");
  }
  return ctx;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  SalesSdkBookingContext,
  SalesSdkBookingContextProvider,
  useSalesSdkBookingContext
});
