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 _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
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 _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
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 { createElement, useCallback, useMemo, useState } from 'react';
import { CloseCircleOutlined, EditOutlined, PrinterOutlined, RollbackOutlined, UndoOutlined } from '@ant-design/icons';
import { message, Modal } from 'antd';
import { locales } from '@pisell/utils';
import { PisellText } from '@pisell/materials';
import { getWristbandList } from "../serve";
import useEngineContext from "../../../hooks/useEngineContext";
import { deriveDisabledEdit } from "../../salesSdk/selectors";
var PisellAmount = PisellText.Amount;
// 手环 标签类型
var WRISTBAND_TAGS = ["ticket", "product_package_ticket", "appointment_ticket", "session_ticket"];
var DEFAULT_SALE_DETAIL_ACTIONS = ['checkout'];
var DEFAULT_ACTION_CONFIG = {
  checkout: {
    row: 2,
    order: 20,
    buttonProps: {
      size: 'large'
    }
  },
  refund: {
    row: 1,
    order: 10,
    buttonProps: {
      size: 'large'
    }
  },
  return: {
    row: 1,
    order: 20,
    buttonProps: {
      size: 'large'
    }
  },
  edit: {
    row: 1,
    order: 30,
    buttonProps: {
      size: 'large'
    }
  },
  print: {
    row: 1,
    order: 20,
    buttonProps: {
      size: 'large'
    }
  },
  'print-product-voucher': {
    row: 3,
    order: 10,
    buttonProps: {
      size: 'large'
    }
  },
  'print-receipts': {
    row: 3,
    order: 30,
    buttonProps: {
      size: 'large'
    }
  },
  'print-wristband': {
    row: 3,
    order: 20,
    buttonProps: {
      size: 'large'
    }
  },
  'print-all': {
    row: 3,
    order: 40,
    buttonProps: {
      size: 'large'
    }
  },
  cancel: {
    row: 3,
    order: 30,
    buttonProps: {
      size: 'large'
    }
  },
  more: {
    row: 2,
    order: 10,
    buttonProps: {
      size: 'large'
    }
  }
};
var EBizPrintType = /*#__PURE__*/function (EBizPrintType) {
  EBizPrintType["INVOICE"] = "INVOICE";
  EBizPrintType["WALLET"] = "WALLET";
  EBizPrintType["WRISTBAND"] = "WRISTBAND";
  EBizPrintType["PRINT_ALL"] = "PRINT_ALL";
  return EBizPrintType;
}(EBizPrintType || {});
var WRISTBAND_PRINT_TAGS = ['ticket', 'product_package_ticket', 'appointment_ticket', 'session_ticket'];
function hasWristbandVoucher(dataSource) {
  var _dataSource$sales$tem;
  var vouchers = (_dataSource$sales$tem = dataSource.sales.tempOrder) === null || _dataSource$sales$tem === void 0 ? void 0 : _dataSource$sales$tem.vouchers;
  return Array.isArray(vouchers) ? vouchers.some(function (voucher) {
    return WRISTBAND_PRINT_TAGS.includes(String((voucher === null || voucher === void 0 ? void 0 : voucher.tag) || ''));
  }) : false;
}
function toButtonGroupList(items) {
  var actionRows = items.filter(function (item) {
    return !item.hidden;
  }).sort(function (prev, next) {
    var _prev$order, _next$order;
    return ((_prev$order = prev.order) !== null && _prev$order !== void 0 ? _prev$order : 0) - ((_next$order = next.order) !== null && _next$order !== void 0 ? _next$order : 0);
  }).reduce(function (rows, item) {
    var _item$row;
    var row = (_item$row = item.row) !== null && _item$row !== void 0 ? _item$row : 1;
    rows[row] = rows[row] || [];
    rows[row].push(item);
    return rows;
  }, {});
  return Object.keys(actionRows).map(Number).sort(function (prev, next) {
    return prev - next;
  }).map(function (row) {
    return actionRows[row];
  }).filter(function (rowItems) {
    return rowItems.length > 0;
  });
}
function getActionKey(action) {
  return typeof action === 'string' ? action : action.name;
}
function getActionConfig(action) {
  return typeof action === 'string' ? {} : action;
}
function mergeActionItem(item, config) {
  return _objectSpread(_objectSpread(_objectSpread({}, item), config), {}, {
    buttonProps: _objectSpread(_objectSpread({}, item.buttonProps), config.buttonProps)
  });
}
function toDropdownMenuItem(item) {
  var buttonProps = item.buttonProps;
  return {
    key: item.id,
    label: buttonProps === null || buttonProps === void 0 ? void 0 : buttonProps.children,
    icon: buttonProps === null || buttonProps === void 0 ? void 0 : buttonProps.icon,
    danger: buttonProps === null || buttonProps === void 0 ? void 0 : buttonProps.danger,
    disabled: Boolean((buttonProps === null || buttonProps === void 0 ? void 0 : buttonProps.disabled) || (buttonProps === null || buttonProps === void 0 ? void 0 : buttonProps.loading)),
    onClick: buttonProps === null || buttonProps === void 0 ? void 0 : buttonProps.onClick,
    children: item.isMore ? item.menuData : undefined
  };
}
function getSortedVisibleActionItems(items) {
  return items.filter(function (item) {
    return !item.hidden;
  }).sort(function (prev, next) {
    var _prev$order2, _next$order2;
    return ((_prev$order2 = prev.order) !== null && _prev$order2 !== void 0 ? _prev$order2 : 0) - ((_next$order2 = next.order) !== null && _next$order2 !== void 0 ? _next$order2 : 0);
  });
}
function resolveSaleDetailOrderId(dataSource) {
  var _dataSource$sales$tem2, _dataSource$sales$tem3, _dataSource$sales$sal;
  var id = (_dataSource$sales$tem2 = (_dataSource$sales$tem3 = dataSource.sales.tempOrder) === null || _dataSource$sales$tem3 === void 0 ? void 0 : _dataSource$sales$tem3.order_id) !== null && _dataSource$sales$tem2 !== void 0 ? _dataSource$sales$tem2 : (_dataSource$sales$sal = dataSource.sales.salesDetail) === null || _dataSource$sales$sal === void 0 || (_dataSource$sales$sal = _dataSource$sales$sal.header) === null || _dataSource$sales$sal === void 0 ? void 0 : _dataSource$sales$sal.order_id;
  if (id == null || id === '') return undefined;
  if (typeof id === 'number' && Number.isFinite(id)) return id;
  var value = String(id).trim();
  if (!value) return undefined;
  var numericId = Number(value);
  return Number.isFinite(numericId) && String(numericId) === value ? numericId : value;
}
function getSalesHostModule(pisellos) {
  var _getModule, _ref;
  return pisellos === null || pisellos === void 0 || (_getModule = (_ref = pisellos).getModule) === null || _getModule === void 0 ? void 0 : _getModule.call(_ref, 'sales');
}
function updateLocalOrder(action, orderId) {
  if (orderId == null || typeof action !== 'function') return;
  action({
    type: 'webpos.updateLocalOrderApi',
    data: {
      order_id: orderId
    }
  });
}
function resolveLoadDetailOrderId(orderId) {
  if (orderId == null) return undefined;
  var numericOrderId = Number(orderId);
  return Number.isFinite(numericOrderId) ? numericOrderId : undefined;
}
function hasOwnValue(record, key) {
  return record[key] !== undefined && record[key] !== null;
}
function getSaleDetailPrintSource(dataSource) {
  var _ref2, _dataSource$sales$sal2, _dataSource$sales$sal3;
  return (_ref2 = (_dataSource$sales$sal2 = (_dataSource$sales$sal3 = dataSource.sales.salesDetail) === null || _dataSource$sales$sal3 === void 0 ? void 0 : _dataSource$sales$sal3.raw) !== null && _dataSource$sales$sal2 !== void 0 ? _dataSource$sales$sal2 : dataSource.sales.tempOrder) !== null && _ref2 !== void 0 ? _ref2 : {};
}
function getArrayValue(record, key) {
  var value = record[key];
  return Array.isArray(value) ? value : undefined;
}
function buildSaleDetailPrintData(dataSource, orderId) {
  var source = getSaleDetailPrintSource(dataSource);
  var paymentInfo = source.payment_info;
  var printData = {
    order_id: orderId
  };
  if (hasOwnValue(source, 'machine_code_print_info')) {
    printData.machine_code_print_info = source.machine_code_print_info;
  }
  if (hasOwnValue(source, 'machine_code_print_info_v2')) {
    printData.machine_code_print_info_v2 = source.machine_code_print_info_v2;
  }
  if (hasOwnValue(source, 'small_ticket_data')) {
    printData.small_ticket_data = source.small_ticket_data;
  } else if (paymentInfo && hasOwnValue(paymentInfo, 'small_ticket_data')) {
    printData.small_ticket_data = paymentInfo.small_ticket_data;
  }
  if (hasOwnValue(source, 'voucher_ids')) {
    printData.voucher_ids = source.voucher_ids;
  }
  return printData;
}
function buildSaleDetailWristbandPrintData(dataSource, orderId) {
  var source = getSaleDetailPrintSource(dataSource);
  var machineCodePrintInfoV2 = getArrayValue(source, 'machine_code_print_info_v2');
  var voucherIds = getArrayValue(source, 'voucher_ids');
  var printData = {
    order_id: orderId
  };
  if (voucherIds !== null && voucherIds !== void 0 && voucherIds.length) {
    printData.voucher_ids = voucherIds;
    return printData;
  }
  var wristbandPrintInfo = machineCodePrintInfoV2 === null || machineCodePrintInfoV2 === void 0 ? void 0 : machineCodePrintInfoV2.filter(function (item) {
    return WRISTBAND_PRINT_TAGS.includes(String((item === null || item === void 0 ? void 0 : item.tag) || ''));
  });
  if (wristbandPrintInfo !== null && wristbandPrintInfo !== void 0 && wristbandPrintInfo.length) {
    printData.machine_code_print_info_v2 = wristbandPrintInfo;
  }
  return printData;
}
function isPrintSuccessful(result) {
  return (result === null || result === void 0 ? void 0 : result.status) === 'success' || (result === null || result === void 0 ? void 0 : result.result) === true;
}
function useEditBookingAction(_ref3) {
  var _context$appHelper, _dataSource$sales$tem4, _dataSource$sales$sal4, _dataSource$sales$sal5, _dataSource$sales$sal6;
  var dataSource = _ref3.dataSource,
    getRemotePrintActionsData = _ref3.getRemotePrintActionsData;
  var context = useEngineContext();
  var action = context === null || context === void 0 || (_context$appHelper = context.appHelper) === null || _context$appHelper === void 0 || (_context$appHelper = _context$appHelper.utils) === null || _context$appHelper === void 0 ? void 0 : _context$appHelper.action;
  var orderId = resolveSaleDetailOrderId(dataSource);
  var businessCode = ((_dataSource$sales$tem4 = dataSource.sales.tempOrder) === null || _dataSource$sales$tem4 === void 0 ? void 0 : _dataSource$sales$tem4.business_code) || ((_dataSource$sales$sal4 = dataSource.sales.salesDetail) === null || _dataSource$sales$sal4 === void 0 || (_dataSource$sales$sal4 = _dataSource$sales$sal4.raw) === null || _dataSource$sales$sal4 === void 0 ? void 0 : _dataSource$sales$sal4.business_code);
  var _deriveDisabledEdit = deriveDisabledEdit((_dataSource$sales$sal5 = dataSource.sales.salesDetail) === null || _dataSource$sales$sal5 === void 0 ? void 0 : _dataSource$sales$sal5.rootBooking, (_dataSource$sales$sal6 = dataSource.sales.salesDetail) === null || _dataSource$sales$sal6 === void 0 ? void 0 : _dataSource$sales$sal6.header),
    disabledEdit = _deriveDisabledEdit.disabledEdit;
  var refreshSaleDetail = useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
    return _regeneratorRuntime().wrap(function _callee$(_context) {
      while (1) switch (_context.prev = _context.next) {
        case 0:
          _context.next = 2;
          return dataSource.sales.refreshSalesDetail();
        case 2:
        case "end":
          return _context.stop();
      }
    }, _callee);
  })), [dataSource.sales, orderId]);
  var handleEdit = useCallback(function () {
    if (typeof action !== 'function' || orderId == null) {
      message.error(locales.getText('pisell2.sale-detail.action-unavailable'));
      return;
    }
    action({
      type: 'pisell1.handleOpenCachedBigSale',
      data: {
        order_id: orderId,
        business_code: businessCode
      },
      callback: function callback() {
        void refreshSaleDetail();
        // 更新远端打印动作列表
        void (getRemotePrintActionsData === null || getRemotePrintActionsData === void 0 ? void 0 : getRemotePrintActionsData());
      }
    });
  }, [action, getRemotePrintActionsData, orderId, refreshSaleDetail]);
  return {
    disabled: disabledEdit || orderId == null,
    handleEdit: handleEdit
  };
}
export function useEditActionItem(_ref5) {
  var dataSource = _ref5.dataSource,
    getRemotePrintActionsData = _ref5.getRemotePrintActionsData;
  var _useEditBookingAction = useEditBookingAction({
      dataSource: dataSource,
      getRemotePrintActionsData: getRemotePrintActionsData
    }),
    disabled = _useEditBookingAction.disabled,
    handleEdit = _useEditBookingAction.handleEdit;
  return useMemo(function () {
    return {
      id: 'edit',
      buttonProps: {
        block: true,
        children: locales.getText('pisell2.sale-detail.action.edit'),
        className: 'pisell-sale-detail-button-actions__button pisell-sale-detail-button-actions__button--edit',
        disabled: disabled,
        icon: /*#__PURE__*/createElement(EditOutlined),
        onClick: handleEdit
      }
    };
  }, [disabled, handleEdit]);
}
export function useReturnActionItem(_ref6) {
  var dataSource = _ref6.dataSource,
    getRemotePrintActionsData = _ref6.getRemotePrintActionsData;
  var _useEditBookingAction2 = useEditBookingAction({
      dataSource: dataSource,
      getRemotePrintActionsData: getRemotePrintActionsData
    }),
    disabled = _useEditBookingAction2.disabled,
    handleEdit = _useEditBookingAction2.handleEdit;
  return useMemo(function () {
    return {
      id: 'return',
      buttonProps: {
        block: true,
        children: /*#__PURE__*/createElement('span', {
          className: 'pisell-sale-detail-button-actions__return-label'
        }, locales.getText('pisell2.sale-detail.action.return-item')),
        className: 'pisell-sale-detail-button-actions__button pisell-sale-detail-button-actions__button--return',
        disabled: disabled,
        icon: /*#__PURE__*/createElement(RollbackOutlined),
        onClick: handleEdit
      }
    };
  }, [disabled, handleEdit]);
}
export function useRefundActionItem(_ref7) {
  var _context$appHelper2;
  var dataSource = _ref7.dataSource;
  var context = useEngineContext();
  var NativePage = context === null || context === void 0 || (_context$appHelper2 = context.appHelper) === null || _context$appHelper2 === void 0 || (_context$appHelper2 = _context$appHelper2.utils) === null || _context$appHelper2 === void 0 ? void 0 : _context$appHelper2.NativePage;
  var orderId = resolveSaleDetailOrderId(dataSource);
  var handleRefund = useCallback(function () {
    if (orderId == null) {
      message.error(locales.getText('pisell2.sale-detail.missing-order-id'));
      return;
    }
    var nativePage = typeof NativePage === 'function' ? NativePage() : undefined;
    if (typeof (nativePage === null || nativePage === void 0 ? void 0 : nativePage.open) !== 'function') {
      message.error(locales.getText('pisell2.sale-detail.action-unavailable'));
      return;
    }
    nativePage.open({
      page: '/native/order/refund',
      params: {
        order_id: orderId
      }
    });
  }, [NativePage, orderId]);
  return useMemo(function () {
    return {
      id: 'refund',
      buttonProps: {
        block: true,
        children: locales.getText('pisell2.sale-detail.action.refund'),
        className: 'pisell-sale-detail-button-actions__button',
        disabled: orderId == null || typeof NativePage !== 'function',
        icon: /*#__PURE__*/createElement(UndoOutlined),
        onClick: handleRefund
      }
    };
  }, [NativePage, handleRefund, orderId]);
}
function useSaleDetailPrintAction(dataSource, printType) {
  var _context$appHelper3;
  var buildPrintData = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : buildSaleDetailPrintData;
  var _useState = useState(false),
    _useState2 = _slicedToArray(_useState, 2),
    loading = _useState2[0],
    setLoading = _useState2[1];
  var context = useEngineContext();
  var action = context === null || context === void 0 || (_context$appHelper3 = context.appHelper) === null || _context$appHelper3 === void 0 || (_context$appHelper3 = _context$appHelper3.utils) === null || _context$appHelper3 === void 0 ? void 0 : _context$appHelper3.action;
  var orderId = resolveSaleDetailOrderId(dataSource);
  var handlePrint = useCallback(function () {
    if (loading) return;
    if (orderId == null) {
      message.error(locales.getText('pisell2.sale-detail.missing-order-id'));
      return;
    }
    if (typeof action !== 'function') {
      message.error(locales.getText('pisell2.sale-detail.action-unavailable'));
      return;
    }
    setLoading(true);
    try {
      action({
        type: 'webpos.handlePrint',
        data: {
          type: printType,
          data: buildPrintData(dataSource, orderId)
        },
        callback: function callback(result) {
          setLoading(false);
          if (isPrintSuccessful(result)) return;
        }
      });
    } catch (_unused) {
      setLoading(false);
    }
  }, [action, buildPrintData, dataSource, loading, orderId, printType]);
  return {
    disabled: orderId == null || typeof action !== 'function' || loading,
    handlePrint: handlePrint,
    loading: loading
  };
}
export function usePrintReceiptsActionItem(_ref8) {
  var dataSource = _ref8.dataSource;
  var _useSaleDetailPrintAc = useSaleDetailPrintAction(dataSource, EBizPrintType.INVOICE),
    disabled = _useSaleDetailPrintAc.disabled,
    handlePrint = _useSaleDetailPrintAc.handlePrint,
    loading = _useSaleDetailPrintAc.loading;
  return useMemo(function () {
    return {
      id: 'print-receipts',
      buttonProps: {
        block: true,
        children: locales.getText('pisell2.sale-detail.action.print-receipts'),
        className: 'pisell-sale-detail-button-actions__button',
        disabled: disabled,
        icon: /*#__PURE__*/createElement(PrinterOutlined),
        loading: loading,
        onClick: handlePrint
      }
    };
  }, [disabled, handlePrint, loading]);
}
export function usePrintActionItem() {
  return useMemo(function () {
    return {
      id: 'print',
      isMore: true,
      buttonProps: {
        block: true,
        children: locales.getText('pisell2.sale-detail.action.print'),
        className: 'pisell-sale-detail-button-actions__button',
        icon: /*#__PURE__*/createElement(PrinterOutlined)
      }
    };
  }, []);
}
export function usePrintProductVoucherActionItem(_ref9) {
  var dataSource = _ref9.dataSource;
  var _useSaleDetailPrintAc2 = useSaleDetailPrintAction(dataSource, EBizPrintType.WALLET),
    disabled = _useSaleDetailPrintAc2.disabled,
    handlePrint = _useSaleDetailPrintAc2.handlePrint,
    loading = _useSaleDetailPrintAc2.loading;
  return useMemo(function () {
    return {
      id: 'print-product-voucher',
      buttonProps: {
        block: true,
        children: locales.getText('pisell2.sale-detail.action.print-product-voucher'),
        className: 'pisell-sale-detail-button-actions__button',
        disabled: disabled,
        icon: /*#__PURE__*/createElement(PrinterOutlined),
        loading: loading,
        onClick: handlePrint
      }
    };
  }, [disabled, handlePrint, loading]);
}
export function useMachineCodePrintActionItems(_ref10) {
  var _context$appHelper4, _context$appHelper5;
  var dataSource = _ref10.dataSource,
    _ref10$machineCodePri = _ref10.machineCodePrintActions,
    machineCodePrintActions = _ref10$machineCodePri === void 0 ? [] : _ref10$machineCodePri;
  var _useState3 = useState(),
    _useState4 = _slicedToArray(_useState3, 2),
    loadingTag = _useState4[0],
    setLoadingTag = _useState4[1];
  var context = useEngineContext();
  var action = context === null || context === void 0 || (_context$appHelper4 = context.appHelper) === null || _context$appHelper4 === void 0 || (_context$appHelper4 = _context$appHelper4.utils) === null || _context$appHelper4 === void 0 ? void 0 : _context$appHelper4.action;
  var getData = context === null || context === void 0 || (_context$appHelper5 = context.appHelper) === null || _context$appHelper5 === void 0 || (_context$appHelper5 = _context$appHelper5.utils) === null || _context$appHelper5 === void 0 ? void 0 : _context$appHelper5.getData;
  var orderId = resolveSaleDetailOrderId(dataSource);
  var handlePrintMachineCode = useCallback( /*#__PURE__*/function () {
    var _ref11 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(printAction) {
      var tag, _error$message;
      return _regeneratorRuntime().wrap(function _callee2$(_context2) {
        while (1) switch (_context2.prev = _context2.next) {
          case 0:
            tag = String(printAction.tag || '').trim();
            console.log(printAction, 'printAction xxxxx');
            if (!(!tag || loadingTag)) {
              _context2.next = 4;
              break;
            }
            return _context2.abrupt("return");
          case 4:
            if (!(orderId == null)) {
              _context2.next = 6;
              break;
            }
            return _context2.abrupt("return");
          case 6:
            if (!(typeof action !== 'function' || typeof getData !== 'function')) {
              _context2.next = 8;
              break;
            }
            return _context2.abrupt("return");
          case 8:
            setLoadingTag(tag);
            try {
              action({
                type: 'webpos.handlePrint',
                data: {
                  type: EBizPrintType.WALLET,
                  data: {
                    order_id: orderId,
                    machine_code_print_info_v2: [printAction]
                  }
                },
                callback: function callback() {
                  setLoadingTag(undefined);
                }
              });
            } catch (error) {
              setLoadingTag(undefined);
              message.error(String((_error$message = error === null || error === void 0 ? void 0 : error.message) !== null && _error$message !== void 0 ? _error$message : error));
            }
          case 10:
          case "end":
            return _context2.stop();
        }
      }, _callee2);
    }));
    return function (_x) {
      return _ref11.apply(this, arguments);
    };
  }(), [action, getData, loadingTag, orderId]);
  return useMemo(function () {
    return machineCodePrintActions.map(function (printAction, index) {
      var tag = String((printAction === null || printAction === void 0 ? void 0 : printAction.tag) || '').trim();
      if (!tag || WRISTBAND_TAGS.includes(tag)) return undefined;
      return {
        id: "print-machine-code-".concat(tag, "-").concat(index),
        order: 10 + index,
        buttonProps: {
          block: true,
          children: printAction.name || locales.getText('pisell2.sale-detail.action.print-product-voucher'),
          className: 'pisell-sale-detail-button-actions__button',
          disabled: orderId == null || typeof action !== 'function' || typeof getData !== 'function' || Boolean(loadingTag && loadingTag !== tag),
          icon: /*#__PURE__*/createElement(PrinterOutlined),
          loading: loadingTag === tag,
          onClick: function onClick() {
            void handlePrintMachineCode(printAction);
          }
        }
      };
    }).filter(Boolean);
  }, [action, getData, handlePrintMachineCode, loadingTag, machineCodePrintActions, orderId]);
}
export function usePrintWristbandActionItem(_ref12) {
  var _context$appHelper6;
  var dataSource = _ref12.dataSource;
  var context = useEngineContext();
  var action = context === null || context === void 0 || (_context$appHelper6 = context.appHelper) === null || _context$appHelper6 === void 0 || (_context$appHelper6 = _context$appHelper6.utils) === null || _context$appHelper6 === void 0 ? void 0 : _context$appHelper6.action;
  var getData = context.appHelper.utils.getData;
  var _useSaleDetailPrintAc3 = useSaleDetailPrintAction(dataSource, EBizPrintType.WRISTBAND, buildSaleDetailWristbandPrintData),
    disabled = _useSaleDetailPrintAc3.disabled,
    loading = _useSaleDetailPrintAc3.loading;
  var orderId = resolveSaleDetailOrderId(dataSource);
  var shouldShowWristbandPrint = hasWristbandVoucher(dataSource);
  var handlePrintWristband = useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
    var res, voucherIds;
    return _regeneratorRuntime().wrap(function _callee3$(_context3) {
      while (1) switch (_context3.prev = _context3.next) {
        case 0:
          _context3.next = 2;
          return getWristbandList({
            order_id: orderId
          }, {
            headers: {
              'Shop-Id': getData('shop_id')
            }
          });
        case 2:
          res = _context3.sent;
          voucherIds = Array.isArray(res.list) ? res.list.map(function (item) {
            return item.id;
          }) : [];
          action({
            type: 'webpos.handlePrint',
            data: {
              type: EBizPrintType.WRISTBAND,
              data: {
                order_id: orderId,
                voucher_ids: voucherIds
              }
            }
          });
        case 5:
        case "end":
          return _context3.stop();
      }
    }, _callee3);
  })), [action, getData, orderId]);
  return useMemo(function () {
    return {
      id: 'print-wristband',
      hidden: !shouldShowWristbandPrint,
      buttonProps: {
        block: true,
        children: locales.getText('pisell2.sale-detail.action.print-wristband'),
        className: 'pisell-sale-detail-button-actions__button',
        disabled: disabled,
        icon: /*#__PURE__*/createElement(PrinterOutlined),
        loading: loading,
        onClick: handlePrintWristband
      }
    };
  }, [disabled, handlePrintWristband, loading, shouldShowWristbandPrint]);
}
export function usePrintAllActionItem(_ref14) {
  var dataSource = _ref14.dataSource;
  var _useSaleDetailPrintAc4 = useSaleDetailPrintAction(dataSource, EBizPrintType.PRINT_ALL),
    disabled = _useSaleDetailPrintAc4.disabled,
    handlePrint = _useSaleDetailPrintAc4.handlePrint,
    loading = _useSaleDetailPrintAc4.loading;
  return useMemo(function () {
    return {
      id: 'print-all',
      buttonProps: {
        block: true,
        children: locales.getText('pisell2.sale-detail.action.print-all'),
        className: 'pisell-sale-detail-button-actions__button',
        disabled: disabled,
        icon: /*#__PURE__*/createElement(PrinterOutlined),
        loading: loading,
        onClick: handlePrint
      }
    };
  }, [disabled, handlePrint, loading]);
}
export function useMoreActionItem(_ref15) {
  var printReceiptsAction = _ref15.printReceiptsAction,
    printWristbandAction = _ref15.printWristbandAction,
    cancelAction = _ref15.cancelAction;
  return useMemo(function () {
    return {
      id: 'more',
      isMore: true,
      buttonProps: {
        block: true,
        className: 'pisell-sale-detail-button-actions__button'
      },
      menuData: [toDropdownMenuItem(printReceiptsAction), toDropdownMenuItem(printWristbandAction), toDropdownMenuItem(cancelAction)]
    };
  }, [cancelAction, printReceiptsAction, printWristbandAction]);
}
export function useCancelActionItem(_ref16) {
  var _context$appHelper7, _context$appHelper8;
  var dataSource = _ref16.dataSource;
  var _useState5 = useState(false),
    _useState6 = _slicedToArray(_useState5, 2),
    loading = _useState6[0],
    setLoading = _useState6[1];
  var context = useEngineContext();
  var action = context === null || context === void 0 || (_context$appHelper7 = context.appHelper) === null || _context$appHelper7 === void 0 || (_context$appHelper7 = _context$appHelper7.utils) === null || _context$appHelper7 === void 0 ? void 0 : _context$appHelper7.action;
  var pisellos = context === null || context === void 0 || (_context$appHelper8 = context.appHelper) === null || _context$appHelper8 === void 0 || (_context$appHelper8 = _context$appHelper8.utils) === null || _context$appHelper8 === void 0 ? void 0 : _context$appHelper8.pisellos;
  var orderId = resolveSaleDetailOrderId(dataSource);
  var refreshSaleDetail = useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
    return _regeneratorRuntime().wrap(function _callee4$(_context4) {
      while (1) switch (_context4.prev = _context4.next) {
        case 0:
          _context4.next = 2;
          return dataSource.sales.refreshSalesDetail();
        case 2:
        case "end":
          return _context4.stop();
      }
    }, _callee4);
  })), [dataSource.sales, orderId]);
  var handleCancel = useCallback(function () {
    if (loading) return;
    Modal.confirm({
      title: locales.getText('pisell2.sale-detail.action.cancel-confirm-title'),
      okText: locales.getText('pisell2.sale-detail.action.cancel-confirm-ok'),
      cancelText: locales.getText('pisell2.sale-detail.action.cancel-confirm-cancel'),
      centered: true,
      okButtonProps: {
        danger: true
      },
      onOk: function () {
        var _onOk = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
          var salesModule, cancelOrder, _error$message2;
          return _regeneratorRuntime().wrap(function _callee5$(_context5) {
            while (1) switch (_context5.prev = _context5.next) {
              case 0:
                if (!(orderId == null)) {
                  _context5.next = 3;
                  break;
                }
                message.error(locales.getText('pisell2.sale-detail.missing-order-id'));
                return _context5.abrupt("return");
              case 3:
                salesModule = getSalesHostModule(pisellos);
                cancelOrder = salesModule === null || salesModule === void 0 ? void 0 : salesModule.cancelOrder;
                if (!(typeof cancelOrder !== 'function')) {
                  _context5.next = 8;
                  break;
                }
                message.error(locales.getText('pisell2.sale-detail.cancel-order-unavailable'));
                return _context5.abrupt("return");
              case 8:
                _context5.prev = 8;
                setLoading(true);
                _context5.next = 12;
                return cancelOrder.call(salesModule, [orderId]);
              case 12:
                updateLocalOrder(action, orderId);
                _context5.next = 15;
                return refreshSaleDetail();
              case 15:
                message.success(locales.getText('pisell2.sale-detail.cancel-order-success'));
                _context5.next = 21;
                break;
              case 18:
                _context5.prev = 18;
                _context5.t0 = _context5["catch"](8);
                message.error(String((_error$message2 = _context5.t0 === null || _context5.t0 === void 0 ? void 0 : _context5.t0.message) !== null && _error$message2 !== void 0 ? _error$message2 : _context5.t0));
              case 21:
                _context5.prev = 21;
                setLoading(false);
                return _context5.finish(21);
              case 24:
              case "end":
                return _context5.stop();
            }
          }, _callee5, null, [[8, 18, 21, 24]]);
        }));
        function onOk() {
          return _onOk.apply(this, arguments);
        }
        return onOk;
      }()
    });
  }, [action, loading, orderId, pisellos, refreshSaleDetail]);
  return useMemo(function () {
    return {
      id: 'cancel',
      buttonProps: {
        block: true,
        children: locales.getText('pisell2.sale-detail.action.cancel'),
        className: 'pisell-sale-detail-button-actions__button',
        danger: true,
        disabled: orderId == null,
        icon: /*#__PURE__*/createElement(CloseCircleOutlined),
        loading: loading,
        onClick: handleCancel
      }
    };
  }, [handleCancel, loading, orderId]);
}
export function useCheckoutActionItem(_ref18) {
  var _dataSource$summary, _summary$amount_gap, _summary$expect_amoun, _summary$order_paid_a;
  var dataSource = _ref18.dataSource;
  var _useState7 = useState(false),
    _useState8 = _slicedToArray(_useState7, 2),
    loading = _useState8[0],
    setLoading = _useState8[1];
  var tempOrder = dataSource.sales.tempOrder;
  var orderId = resolveSaleDetailOrderId(dataSource);
  var summary = (_dataSource$summary = dataSource.summary) === null || _dataSource$summary === void 0 ? void 0 : _dataSource$summary.summary;
  var amountGap = (_summary$amount_gap = summary === null || summary === void 0 ? void 0 : summary.amount_gap) !== null && _summary$amount_gap !== void 0 ? _summary$amount_gap : 0;
  var expectAmount = (_summary$expect_amoun = summary === null || summary === void 0 ? void 0 : summary.expect_amount) !== null && _summary$expect_amoun !== void 0 ? _summary$expect_amoun : 0;
  var orderPaidAmount = Number((_summary$order_paid_a = summary === null || summary === void 0 ? void 0 : summary.order_paid_amount) !== null && _summary$order_paid_a !== void 0 ? _summary$order_paid_a : 0);
  var amountDue = orderPaidAmount > 0 ? amountGap : expectAmount;
  var shouldShowCheckout = Number(amountDue) > 0;
  var isPaid = (tempOrder === null || tempOrder === void 0 ? void 0 : tempOrder.payment_status) === 'paid';
  var orderStatus = tempOrder === null || tempOrder === void 0 ? void 0 : tempOrder.status;
  var checkoutDisabledByAmount = summary ? Number(summary.total_refund_amount) > 0 || Number(summary.total_amount) <= 0 || Number(summary.expect_amount) <= 0 : false;
  var refreshSaleDetail = useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
    return _regeneratorRuntime().wrap(function _callee6$(_context6) {
      while (1) switch (_context6.prev = _context6.next) {
        case 0:
          _context6.next = 2;
          return dataSource.sales.refreshSalesDetail();
        case 2:
        case "end":
          return _context6.stop();
      }
    }, _callee6);
  })), [dataSource.sales, orderId]);
  var handleCheckout = useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
    return _regeneratorRuntime().wrap(function _callee7$(_context7) {
      while (1) switch (_context7.prev = _context7.next) {
        case 0:
          setLoading(true);
          _context7.prev = 1;
          _context7.next = 4;
          return dataSource.sales.openCheckout();
        case 4:
          _context7.next = 6;
          return refreshSaleDetail();
        case 6:
          _context7.prev = 6;
          setLoading(false);
          return _context7.finish(6);
        case 9:
        case "end":
          return _context7.stop();
      }
    }, _callee7, null, [[1,, 6, 9]]);
  })), [dataSource.sales, refreshSaleDetail]);
  return useMemo(function () {
    return {
      id: 'checkout',
      hidden: !shouldShowCheckout,
      buttonProps: {
        block: true,
        children: /*#__PURE__*/createElement('span', {
          className: 'pisell-sale-detail-button-actions__checkout-content'
        }, /*#__PURE__*/createElement('span', {
          className: 'pisell-sale-detail-button-actions__checkout-title'
        }, locales.getText('pisell2.sale-detail.action.collect-money')), /*#__PURE__*/createElement('span', {
          className: 'pisell-sale-detail-button-actions__checkout-amount'
        }, locales.getText('pisell2.sale-detail.action.amount-due'), ' ', /*#__PURE__*/createElement(PisellAmount, {
          value: amountDue
        }))),
        className: 'pisell-sale-detail-button-actions__button pisell-sale-detail-button-actions__button--primary',
        type: 'primary',
        loading: loading,
        disabled: orderId == null || loading || checkoutDisabledByAmount || isPaid || orderStatus === 'cancelled',
        // icon: createElement(Iconfont, { type: 'pisell2-coins-hand' }),
        onClick: handleCheckout
      }
    };
  }, [amountDue, checkoutDisabledByAmount, handleCheckout, isPaid, loading, orderId, orderStatus, shouldShowCheckout]);
}
export function useSaleDetailActions(_ref21) {
  var _dataSource$sales$tem5;
  var dataSource = _ref21.dataSource,
    _ref21$actions = _ref21.actions,
    actions = _ref21$actions === void 0 ? DEFAULT_SALE_DETAIL_ACTIONS : _ref21$actions,
    _ref21$machineCodePri = _ref21.machineCodePrintActions,
    machineCodePrintActions = _ref21$machineCodePri === void 0 ? [] : _ref21$machineCodePri,
    getRemotePrintActionsData = _ref21.getRemotePrintActionsData;
  var editAction = useEditActionItem({
    dataSource: dataSource,
    getRemotePrintActionsData: getRemotePrintActionsData
  });
  var refundAction = useRefundActionItem({
    dataSource: dataSource
  });
  var returnAction = useReturnActionItem({
    dataSource: dataSource,
    getRemotePrintActionsData: getRemotePrintActionsData
  });
  var printAction = usePrintActionItem();
  var printProductVoucherAction = usePrintProductVoucherActionItem({
    dataSource: dataSource
  });
  var machineCodePrintActionItems = useMachineCodePrintActionItems({
    dataSource: dataSource,
    machineCodePrintActions: machineCodePrintActions
  });
  var printReceiptsAction = usePrintReceiptsActionItem({
    dataSource: dataSource
  });
  var printWristbandAction = usePrintWristbandActionItem({
    dataSource: dataSource
  });
  var printAllAction = usePrintAllActionItem({
    dataSource: dataSource
  });
  var cancelAction = useCancelActionItem({
    dataSource: dataSource
  });
  var checkoutAction = useCheckoutActionItem({
    dataSource: dataSource
  });
  var moreAction = useMoreActionItem({
    printReceiptsAction: printReceiptsAction,
    printWristbandAction: printWristbandAction,
    cancelAction: cancelAction
  });
  var isCancelled = ((_dataSource$sales$tem5 = dataSource.sales.tempOrder) === null || _dataSource$sales$tem5 === void 0 ? void 0 : _dataSource$sales$tem5.status) === 'cancelled';
  return useMemo(function () {
    if (isCancelled) return [];
    var actionItemMap = {
      edit: editAction,
      refund: refundAction,
      return: returnAction,
      print: printAction,
      'print-product-voucher': printProductVoucherAction,
      'print-receipts': printReceiptsAction,
      'print-wristband': printWristbandAction,
      'print-all': printAllAction,
      cancel: cancelAction,
      checkout: checkoutAction,
      more: moreAction
    };
    var resolveActionItem = function resolveActionItem(action) {
      var _config$items;
      var actionKey = getActionKey(action);
      var actionConfig = getActionConfig(action);
      var config = _objectSpread(_objectSpread(_objectSpread({}, DEFAULT_ACTION_CONFIG[actionKey]), actionConfig), {}, {
        buttonProps: _objectSpread(_objectSpread({}, DEFAULT_ACTION_CONFIG[actionKey].buttonProps), actionConfig.buttonProps)
      });
      var actionItem = mergeActionItem(actionItemMap[actionKey], config);
      if (!((_config$items = config.items) !== null && _config$items !== void 0 && _config$items.length)) return actionItem;
      var nestedActionItems = getSortedVisibleActionItems([].concat(_toConsumableArray(actionKey === 'print' ? machineCodePrintActionItems : []), _toConsumableArray(config.items.map(resolveActionItem))));
      if (nestedActionItems.length === 1) {
        return _objectSpread(_objectSpread({}, nestedActionItems[0]), {}, {
          row: actionItem.row,
          order: actionItem.order
        });
      }
      var menuData = nestedActionItems.map(toDropdownMenuItem);
      return _objectSpread(_objectSpread({}, actionItem), {}, {
        isMore: true,
        menuData: menuData
      });
    };
    var saleDetailActions = actions.map(resolveActionItem);
    return toButtonGroupList(saleDetailActions);
  }, [actions, cancelAction, checkoutAction, editAction, isCancelled, machineCodePrintActionItems, machineCodePrintActions, moreAction, printAction, printAllAction, printProductVoucherAction, printReceiptsAction, printWristbandAction, refundAction, returnAction]);
}