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/demo/components/DemoTabDetail.tsx
var DemoTabDetail_exports = {};
__export(DemoTabDetail_exports, {
  DemoTabDetail: () => DemoTabDetail
});
module.exports = __toCommonJS(DemoTabDetail_exports);
var import_react = __toESM(require("react"));
var import_useSalesSdk = require("../../hooks/useSalesSdk");
var import_useSalesSdkCart = require("../../hooks/useSalesSdkCart");
var import_useSalesSdkCustomer = require("../../hooks/useSalesSdkCustomer");
var import_useSalesSdkSummary = require("../../hooks/useSalesSdkSummary");
var import_useSalesSdkProducts = require("../../hooks/useSalesSdkProducts");
var import_selectors = require("../../selectors");
var import_fixtures = require("../fixtures");
var import_RawSnapshotPanel = require("./RawSnapshotPanel");
var import_ActionLog = require("./ActionLog");
var import_DemoAdvancedConfig = require("./DemoAdvancedConfig");
var DemoTabDetail = ({ initialOrderId }) => {
  const sales = (0, import_useSalesSdk.useSalesSdk)();
  const customer = (0, import_useSalesSdkCustomer.useSalesSdkCustomer)();
  const cart = (0, import_useSalesSdkCart.useSalesSdkCart)();
  const summaryState = (0, import_useSalesSdkSummary.useSalesSdkSummary)();
  const products = (0, import_useSalesSdkProducts.useSalesSdkProducts)();
  const initialFixture = (0, import_react.useMemo)(() => {
    return { ...import_fixtures.FIXTURE_DETAIL, ...initialOrderId ? { orderId: initialOrderId } : {} };
  }, [initialOrderId]);
  const [override, setOverride] = (0, import_react.useState)({});
  const fixture = (0, import_react.useMemo)(
    () => (0, import_fixtures.mergeDetailFixture)(initialFixture, override),
    [initialFixture, override]
  );
  const [entries, setEntries] = (0, import_react.useState)([]);
  const [loading, setLoading] = (0, import_react.useState)(false);
  const [bookingStatus, setBookingStatusInput] = (0, import_react.useState)("confirmed");
  const [statusLoading, setStatusLoading] = (0, import_react.useState)(false);
  const summary = (0, import_selectors.deriveSummary)(summaryState.summary);
  const append = (entry) => {
    setEntries((prev) => [...prev, entry]);
  };
  const runLoadDetail = async () => {
    if (!Number.isFinite(fixture.orderId) || fixture.orderId <= 0) {
      append({ status: "error", message: "orderId 必须为正整数" });
      return;
    }
    setLoading(true);
    append({ status: "running", message: `loadDetail(${fixture.orderId}) running...` });
    try {
      const result = await sales.loadDetail(fixture.orderId);
      append({
        status: "success",
        message: `loadDetail(${fixture.orderId}) success
${safeJson(result)}`
      });
    } catch (e) {
      append({
        status: "error",
        message: `loadDetail(${fixture.orderId}) failed
${String((e == null ? void 0 : e.message) ?? e)}`
      });
    } finally {
      setLoading(false);
    }
  };
  const runSetBookingStatus = async () => {
    const next = bookingStatus.trim();
    if (!next) {
      append({ status: "error", message: "appointment_status 不能为空" });
      return;
    }
    setStatusLoading(true);
    append({ status: "running", message: `setBookingStatus(${next}) running...` });
    try {
      const result = await sales.setBookingStatus(next);
      append({
        status: "success",
        message: `setBookingStatus(${next}) success
${safeJson(result)}`
      });
    } catch (e) {
      append({
        status: "error",
        message: `setBookingStatus(${next}) failed
${String((e == null ? void 0 : e.message) ?? e)}`
      });
    } finally {
      setStatusLoading(false);
    }
  };
  const handleCheckout = async () => {
    append({ status: "running", message: "openCheckout running..." });
    try {
      const result = await sales.openCheckout();
      append({
        status: "success",
        message: `openCheckout success
${safeJson(result)}`
      });
    } catch (e) {
      append({
        status: "error",
        message: `openCheckout failed
${String((e == null ? void 0 : e.message) ?? e)}`
      });
    }
  };
  return /* @__PURE__ */ import_react.default.createElement("section", { className: "sales-sdk-demo__tab" }, /* @__PURE__ */ import_react.default.createElement("header", { className: "sales-sdk-demo__panel" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "sales-sdk-demo__section-title" }, /* @__PURE__ */ import_react.default.createElement("h3", null, "详情展示"), /* @__PURE__ */ import_react.default.createElement("span", null, "status: ", sales.status, " / ready: ", sales.isReady ? "yes" : "no")), /* @__PURE__ */ import_react.default.createElement("p", { className: "sales-sdk-demo__hint" }, "只读场景：调用 ", /* @__PURE__ */ import_react.default.createElement("code", null, "sales.loadDetail(orderId)"), " 拉取服务端订单详情后展示客户 / 购物车 / 汇总。"), /* @__PURE__ */ import_react.default.createElement("div", { className: "sales-sdk-demo__toolbar" }, /* @__PURE__ */ import_react.default.createElement(
    "button",
    {
      type: "button",
      className: "sales-sdk-demo__primary",
      disabled: loading,
      onClick: runLoadDetail
    },
    "一键查看详情（orderId = ",
    fixture.orderId,
    "）"
  ), /* @__PURE__ */ import_react.default.createElement(
    "button",
    {
      type: "button",
      className: "sales-sdk-demo__primary",
      disabled: loading,
      onClick: handleCheckout
    },
    "结账（orderId = ",
    fixture.orderId,
    "）"
  )), /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: "sales-sdk-demo__toolbar",
      style: { marginTop: 8, gap: 8, alignItems: "center" }
    },
    /* @__PURE__ */ import_react.default.createElement("span", { style: { fontSize: 12, color: "#666" } }, "变更预约状态："),
    /* @__PURE__ */ import_react.default.createElement(
      "select",
      {
        value: bookingStatus,
        onChange: (e) => setBookingStatusInput(e.target.value),
        disabled: statusLoading || !sales.isReady
      },
      /* @__PURE__ */ import_react.default.createElement("option", { value: "confirmed" }, "confirmed"),
      /* @__PURE__ */ import_react.default.createElement("option", { value: "pending" }, "pending"),
      /* @__PURE__ */ import_react.default.createElement("option", { value: "checked_in" }, "checked_in"),
      /* @__PURE__ */ import_react.default.createElement("option", { value: "completed" }, "completed"),
      /* @__PURE__ */ import_react.default.createElement("option", { value: "cancelled" }, "cancelled"),
      /* @__PURE__ */ import_react.default.createElement("option", { value: "no_show" }, "no_show")
    ),
    /* @__PURE__ */ import_react.default.createElement(
      "button",
      {
        type: "button",
        className: "sales-sdk-demo__primary",
        disabled: statusLoading || !sales.isReady,
        onClick: runSetBookingStatus,
        title: !sales.isReady ? "请先点「一键查看详情」加载订单" : void 0
      },
      statusLoading ? "提交中..." : `setBookingStatus(${bookingStatus})`
    )
  )), /* @__PURE__ */ import_react.default.createElement(import_DemoAdvancedConfig.DemoAdvancedConfig, { variant: "detail", value: override, onChange: setOverride }), sales.error ? /* @__PURE__ */ import_react.default.createElement("section", { className: "sales-sdk-demo__panel sales-sdk-demo__panel--error" }, /* @__PURE__ */ import_react.default.createElement("h3", null, "SDK Error"), /* @__PURE__ */ import_react.default.createElement("pre", null, sales.error.message)) : null, /* @__PURE__ */ import_react.default.createElement(
    import_RawSnapshotPanel.RawSnapshotPanel,
    {
      sales,
      cart,
      customer,
      summary: summaryState.summary,
      products: products.products
    }
  ), /* @__PURE__ */ import_react.default.createElement(import_ActionLog.ActionLog, { entries }));
};
function safeJson(value) {
  try {
    return JSON.stringify(value, null, 2);
  } catch {
    return String(value);
  }
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  DemoTabDetail
});
