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; }
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_CREATE, mergeMutableFixture } from "../fixtures";
import { RawSnapshotPanel } from "./RawSnapshotPanel";
import { DemoAdvancedConfig } from "./DemoAdvancedConfig";
import { DemoStepRunner } from "./DemoStepRunner";
import { buildCreateSteps } from "./buildSteps";

/**
 * 新建 Tab：一键跑「createNew → loadCustomers → selectCustomer → loadProducts → addProduct
 *          → recalcSummary → submit」全流程。
 *
 * 每步可单独执行，便于排查具体哪一步抛错；步骤间通过闭包传递上一步挑出的客户 / 商品引用。
 * 真实接口（submit / addProduct）的副作用提示由顶部 banner 给出。
 */
export var DemoTabCreate = function DemoTabCreate() {
  var sales = useSalesSdk();
  var customer = useSalesSdkCustomer();
  var products = useSalesSdkProducts();
  var cart = useSalesSdkCart();
  var summaryState = useSalesSdkSummary();
  var _useState = useState({}),
    _useState2 = _slicedToArray(_useState, 2),
    override = _useState2[0],
    setOverride = _useState2[1];
  var fixture = useMemo(function () {
    return mergeMutableFixture(FIXTURE_CREATE, override);
  }, [override]);
  var steps = useMemo(function () {
    return buildCreateSteps({
      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, "\u65B0\u5EFA\u8BA2\u5355\u4E00\u952E\u6D41\u7A0B"), /*#__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\u8C03\u7528\u771F\u5B9E OS \u63A5\u53E3\uFF08createNew / addProduct / submit\uFF09\u3002submit \u4F1A\u5F39\u4E8C\u6B21\u786E\u8BA4\uFF0C\u5176\u5B83\u6B65\u9AA4\u76F4\u63A5\u6267\u884C\u3002")), /*#__PURE__*/React.createElement(DemoAdvancedConfig, {
    variant: "create",
    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
  }));
};