function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import React, { useMemo, useState } from 'react';
import { useSalesSdk } from "../../hooks/useSalesSdk";
import { useSalesSdkCart } from "../../hooks/useSalesSdkCart";
import { useSalesSdkCustomer } from "../../hooks/useSalesSdkCustomer";
import { useSalesSdkSummary } from "../../hooks/useSalesSdkSummary";
import { useSalesSdkProducts } from "../../hooks/useSalesSdkProducts";
import { deriveSummary } from "../../selectors";
import { FIXTURE_EDIT, mergeMutableFixture } from "../fixtures";
import { RawSnapshotPanel } from "./RawSnapshotPanel";
import { DemoAdvancedConfig } from "./DemoAdvancedConfig";
import { DemoStepRunner } from "./DemoStepRunner";
import { buildEditSteps } from "./buildSteps";
/**
 * 编辑 Tab：一键跑「loadDetail → loadCustomers → selectCustomer → loadProducts → addProduct
 *          → recalcSummary → submit」全流程。
 *
 * 与新建 Tab 的差异：首步是 sales.loadDetail(orderId) 拉一份既有订单，后续在该 tempOrder
 * 之上追加客户 / 商品 / submit。
 */
export var DemoTabEdit = function DemoTabEdit(_ref) {
  var initialOrderId = _ref.initialOrderId;
  var sales = useSalesSdk();
  var customer = useSalesSdkCustomer();
  var products = useSalesSdkProducts();
  var cart = useSalesSdkCart();
  var summaryState = useSalesSdkSummary();
  var initialFixture = useMemo(function () {
    return _objectSpread(_objectSpread({}, FIXTURE_EDIT), initialOrderId ? {
      orderId: initialOrderId
    } : {});
  }, [initialOrderId]);
  var _useState = useState({}),
    _useState2 = _slicedToArray(_useState, 2),
    override = _useState2[0],
    setOverride = _useState2[1];
  var fixture = useMemo(function () {
    var merged = mergeMutableFixture(initialFixture, override);
    // orderId 不属于 mutable 字段，单独 merge
    return _objectSpread(_objectSpread({}, merged), {}, {
      orderId: override.orderId != null ? Number(override.orderId) : initialFixture.orderId
    });
  }, [initialFixture, override]);
  var steps = useMemo(function () {
    return buildEditSteps({
      sales: sales,
      customer: customer,
      products: products,
      cart: cart
    }, fixture);
  }, [sales, customer, products, cart, fixture]);
  var summary = deriveSummary(summaryState.summary);
  return /*#__PURE__*/React.createElement("section", {
    className: "sales-sdk-demo__tab"
  }, /*#__PURE__*/React.createElement("header", {
    className: "sales-sdk-demo__panel sales-sdk-demo__panel--warn"
  }, /*#__PURE__*/React.createElement("div", {
    className: "sales-sdk-demo__section-title"
  }, /*#__PURE__*/React.createElement("h3", null, "\u7F16\u8F91\u8BA2\u5355\u4E00\u952E\u6D41\u7A0B\uFF08orderId = ", fixture.orderId, "\uFF09"), /*#__PURE__*/React.createElement("span", null, "status: ", sales.status, " / ready: ", sales.isReady ? 'yes' : 'no')), /*#__PURE__*/React.createElement("p", {
    className: "sales-sdk-demo__hint"
  }, "\u6CE8\u610F\uFF1A\u6B64 Tab \u4F1A\u5148 loadDetail \u52A0\u8F7D\u65E2\u6709\u8BA2\u5355\uFF0C\u518D\u8FFD\u52A0\u5BA2\u6237 / \u5546\u54C1 / submit\uFF0C\u5747\u4E3A\u771F\u5B9E OS \u63A5\u53E3\u3002")), /*#__PURE__*/React.createElement(DemoAdvancedConfig, {
    variant: "edit",
    value: override,
    onChange: setOverride
  }), /*#__PURE__*/React.createElement(DemoStepRunner, {
    title: "\u6B65\u9AA4\u5E8F\u5217\uFF08\u70B9\u4E00\u952E\u4E32\u884C\u6267\u884C / \u4E5F\u53EF\u5355\u6B65\uFF09",
    steps: steps
  }), sales.error ? /*#__PURE__*/React.createElement("section", {
    className: "sales-sdk-demo__panel sales-sdk-demo__panel--error"
  }, /*#__PURE__*/React.createElement("h3", null, "SDK Error"), /*#__PURE__*/React.createElement("pre", null, sales.error.message)) : null, /*#__PURE__*/React.createElement(RawSnapshotPanel, {
    sales: sales,
    cart: cart,
    customer: customer,
    summary: summaryState.summary,
    products: products.products
  }));
};