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/DemoAdvancedConfig.tsx
var DemoAdvancedConfig_exports = {};
__export(DemoAdvancedConfig_exports, {
  DemoAdvancedConfig: () => DemoAdvancedConfig
});
module.exports = __toCommonJS(DemoAdvancedConfig_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
function parseNumberOrUndefined(raw) {
  const t = raw.trim();
  if (!t) return void 0;
  const n = Number(t);
  return Number.isFinite(n) ? n : void 0;
}
function parseMenuListIds(raw) {
  const t = raw.trim();
  if (!t) return void 0;
  return t.split(/[,\s]+/).map((s) => Number(s)).filter((n) => Number.isFinite(n));
}
function FieldText({
  label,
  value,
  placeholder,
  onChange
}) {
  return /* @__PURE__ */ import_react.default.createElement("label", { className: "sales-sdk-demo__field" }, /* @__PURE__ */ import_react.default.createElement("span", null, label), /* @__PURE__ */ import_react.default.createElement(
    "input",
    {
      value,
      placeholder,
      onChange: (e) => onChange(e.target.value)
    }
  ));
}
function DetailForm({
  value,
  onChange
}) {
  return /* @__PURE__ */ import_react.default.createElement("div", { className: "sales-sdk-demo__advanced-form" }, /* @__PURE__ */ import_react.default.createElement(
    FieldText,
    {
      label: "orderId",
      value: value.orderId != null ? String(value.orderId) : "",
      placeholder: "使用 fixture 默认值",
      onChange: (next) => onChange({ ...value, orderId: parseNumberOrUndefined(next) })
    }
  ));
}
function MutableForm({
  value,
  onChange
}) {
  const params = value.loadProductsParams || {};
  const picker = value.productPicker || {};
  const setParams = (patch) => {
    onChange({ ...value, loadProductsParams: { ...params, ...patch } });
  };
  const setPicker = (patch) => {
    onChange({ ...value, productPicker: { ...picker, ...patch } });
  };
  return /* @__PURE__ */ import_react.default.createElement("div", { className: "sales-sdk-demo__advanced-form" }, /* @__PURE__ */ import_react.default.createElement(
    FieldText,
    {
      label: "loadProductsParams.schedule_date",
      value: params.schedule_date ?? "",
      placeholder: "YYYY-MM-DD",
      onChange: (next) => setParams({ schedule_date: next || void 0 })
    }
  ), /* @__PURE__ */ import_react.default.createElement(
    FieldText,
    {
      label: "loadProductsParams.schedule_datetime",
      value: params.schedule_datetime ?? "",
      placeholder: "YYYY-MM-DD HH:mm:ss",
      onChange: (next) => setParams({ schedule_datetime: next || void 0 })
    }
  ), /* @__PURE__ */ import_react.default.createElement(
    FieldText,
    {
      label: "loadProductsParams.menu_list_ids",
      value: Array.isArray(params.menu_list_ids) ? params.menu_list_ids.join(",") : "",
      placeholder: "逗号分隔，如 44858,44859",
      onChange: (next) => setParams({ menu_list_ids: parseMenuListIds(next) })
    }
  ), /* @__PURE__ */ import_react.default.createElement(
    FieldText,
    {
      label: "customerId",
      value: value.customerId != null ? String(value.customerId) : "",
      placeholder: "缺省 = customer.list[0]",
      onChange: (next) => {
        const parsed = parseNumberOrUndefined(next);
        onChange({ ...value, customerId: parsed });
      }
    }
  ), /* @__PURE__ */ import_react.default.createElement(
    FieldText,
    {
      label: "productPicker.productId",
      value: picker.productId != null ? String(picker.productId) : "",
      placeholder: "缺省 = products[0].id",
      onChange: (next) => setPicker({ productId: parseNumberOrUndefined(next) })
    }
  ), /* @__PURE__ */ import_react.default.createElement(
    FieldText,
    {
      label: "productPicker.variantIndex",
      value: picker.variantIndex != null ? String(picker.variantIndex) : "",
      placeholder: "缺省 0",
      onChange: (next) => setPicker({ variantIndex: parseNumberOrUndefined(next) })
    }
  ), /* @__PURE__ */ import_react.default.createElement(
    FieldText,
    {
      label: "productPicker.num",
      value: picker.num != null ? String(picker.num) : "",
      placeholder: "缺省 1",
      onChange: (next) => setPicker({ num: parseNumberOrUndefined(next) })
    }
  ));
}
function OrderMetaForm({
  value,
  onChange
}) {
  const contactsJson = value.contactsInfo === void 0 ? "" : value.contactsInfo === null ? "null" : JSON.stringify(value.contactsInfo);
  return /* @__PURE__ */ import_react.default.createElement("div", { className: "sales-sdk-demo__advanced-form sales-sdk-demo__advanced-form--meta" }, /* @__PURE__ */ import_react.default.createElement(
    FieldText,
    {
      label: "orderNote（sales.setOrderNote）",
      value: value.orderNote ?? "",
      placeholder: "留空 = 使用 fixture 默认；填 __skip__ 跳过步骤",
      onChange: (next) => {
        const t = next.trim();
        if (t === "__skip__") {
          const { orderNote: _omit, ...rest } = value;
          onChange(rest);
          return;
        }
        if (!t) {
          const { orderNote: _omit, ...rest } = value;
          onChange(rest);
          return;
        }
        onChange({ ...value, orderNote: t });
      }
    }
  ), /* @__PURE__ */ import_react.default.createElement(
    FieldText,
    {
      label: "shopDiscount（sales.setShopDiscount）",
      value: value.shopDiscount != null ? String(value.shopDiscount) : "",
      placeholder: "如 5 或 5.00；填 __skip__ 跳过步骤",
      onChange: (next) => {
        const t = next.trim();
        if (t === "__skip__" || !t) {
          const { shopDiscount: _omit, ...rest } = value;
          onChange(rest);
          return;
        }
        const n = Number(t);
        onChange({
          ...value,
          shopDiscount: Number.isFinite(n) ? n : t
        });
      }
    }
  ), /* @__PURE__ */ import_react.default.createElement("label", { className: "sales-sdk-demo__field" }, /* @__PURE__ */ import_react.default.createElement("span", null, "contactsInfo（sales.setContactsInfo，JSON）"), /* @__PURE__ */ import_react.default.createElement(
    "textarea",
    {
      className: "sales-sdk-demo__textarea",
      value: contactsJson,
      placeholder: '如 {"name":"Demo"}；填 __skip__ 跳过；填 null 清空',
      rows: 3,
      onChange: (e) => {
        const t = e.target.value.trim();
        if (t === "__skip__" || t === "") {
          const { contactsInfo: _omit, ...rest } = value;
          onChange(rest);
          return;
        }
        if (t === "null") {
          onChange({ ...value, contactsInfo: null });
          return;
        }
        try {
          const parsed = JSON.parse(t);
          if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
            throw new Error("contactsInfo 须为 JSON 对象或 null");
          }
          onChange({ ...value, contactsInfo: parsed });
        } catch {
        }
      }
    }
  )));
}
function EditForm({
  value,
  onChange
}) {
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(
    FieldText,
    {
      label: "orderId",
      value: value.orderId != null ? String(value.orderId) : "",
      placeholder: "使用 fixture 默认值",
      onChange: (next) => onChange({ ...value, orderId: parseNumberOrUndefined(next) })
    }
  ), /* @__PURE__ */ import_react.default.createElement(OrderMetaForm, { value, onChange }), /* @__PURE__ */ import_react.default.createElement(MutableForm, { value, onChange }));
}
var DemoAdvancedConfig = (props) => {
  const renderBody = () => {
    if (props.variant === "detail") {
      return /* @__PURE__ */ import_react.default.createElement(DetailForm, { value: props.value, onChange: props.onChange });
    }
    if (props.variant === "create") {
      return /* @__PURE__ */ import_react.default.createElement(MutableForm, { value: props.value, onChange: props.onChange });
    }
    return /* @__PURE__ */ import_react.default.createElement(EditForm, { value: props.value, onChange: props.onChange });
  };
  return /* @__PURE__ */ import_react.default.createElement("div", { className: "sales-sdk-demo__advanced" }, /* @__PURE__ */ import_react.default.createElement(
    import_antd.Collapse,
    {
      ghost: true,
      items: [
        {
          key: "adv",
          label: "高级配置（覆盖 fixture）",
          children: renderBody()
        }
      ]
    }
  ));
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  DemoAdvancedConfig
});
