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 _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 _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 _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 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 { useMemo } from 'react';
import { useCancelActionItem, useCheckoutActionItem, useCheckoutCartActionItem, useEditActionItem, useNoteActionItem, useRefundActionItem, useReturnActionItem, useSaveActionItem } from "./orderActions";
import { usePrintActionItem, usePrintReceiptsActionItem, usePrintWristbandActionItem, useRemotePrintActions } from "./printActions";
import { DEFAULT_ACTION_CONFIG, getActionConfig, getActionKey, getSortedVisibleActionItems, mergeActionItem, toButtonGroupList, toDropdownMenuItem } from "./utils";
var DEFAULT_SALE_DETAIL_ACTIONS = ['checkout'];
export function useMoreActionItem(_ref) {
  var printReceiptsAction = _ref.printReceiptsAction,
    printWristbandAction = _ref.printWristbandAction,
    cancelAction = _ref.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 useSaleDetailActions(_ref2) {
  var _context$sales$tempOr;
  var context = _ref2.context,
    _ref2$actions = _ref2.actions,
    actions = _ref2$actions === void 0 ? DEFAULT_SALE_DETAIL_ACTIONS : _ref2$actions;
  var _useRemotePrintAction = useRemotePrintActions({
      context: context
    }),
    machineCodePrintActionItems = _useRemotePrintAction.machineCodePrintActionItems,
    refreshRemotePrintActions = _useRemotePrintAction.refreshRemotePrintActions;
  var editAction = useEditActionItem({
    context: context,
    onAfterEdit: refreshRemotePrintActions
  });
  var refundAction = useRefundActionItem({
    context: context
  });
  var returnAction = useReturnActionItem({
    context: context,
    onAfterEdit: refreshRemotePrintActions
  });
  var printAction = usePrintActionItem();
  var printReceiptsAction = usePrintReceiptsActionItem({
    context: context
  });
  var printWristbandAction = usePrintWristbandActionItem({
    context: context
  });
  var cancelAction = useCancelActionItem({
    context: context
  });
  var noteAction = useNoteActionItem({
    context: context
  });
  var saveAction = useSaveActionItem({
    context: context
  });
  var checkoutAction = useCheckoutActionItem({
    context: context
  });
  var checkoutCartAction = useCheckoutCartActionItem({
    context: context
  });
  var moreAction = useMoreActionItem({
    printReceiptsAction: printReceiptsAction,
    printWristbandAction: printWristbandAction,
    cancelAction: cancelAction
  });
  var isCancelled = ((_context$sales$tempOr = context.sales.tempOrder) === null || _context$sales$tempOr === void 0 ? void 0 : _context$sales$tempOr.status) === 'cancelled';
  return useMemo(function () {
    if (isCancelled) return [];
    var actionItemMap = {
      edit: editAction,
      refund: refundAction,
      return: returnAction,
      print: printAction,
      'print-receipts': printReceiptsAction,
      'print-wristband': printWristbandAction,
      cancel: cancelAction,
      note: noteAction,
      save: saveAction,
      checkout: checkoutAction,
      'checkout-cart': checkoutCartAction,
      more: moreAction
    };
    var resolveActionItem = function resolveActionItem(action) {
      var _config$items;
      var actionKey = getActionKey(action);
      var actionConfig = getActionConfig(action);
      var defaultConfig = DEFAULT_ACTION_CONFIG[actionKey];
      var config = _objectSpread(_objectSpread(_objectSpread({}, defaultConfig), actionConfig), {}, {
        buttonProps: _objectSpread(_objectSpread({}, defaultConfig === null || defaultConfig === void 0 ? void 0 : defaultConfig.buttonProps), actionConfig.buttonProps)
      });
      var baseActionItem = actionItemMap[actionKey];
      if (!baseActionItem) {
        return {
          id: actionKey,
          hidden: true
        };
      }
      var actionItem = mergeActionItem(baseActionItem, 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, checkoutCartAction, editAction, isCancelled, machineCodePrintActionItems, moreAction, noteAction, printAction, printReceiptsAction, printWristbandAction, refundAction, returnAction, saveAction]);
}
export { useCancelActionItem, useCheckoutActionItem, useCheckoutCartActionItem, useEditActionItem, useNoteActionItem, useRefundActionItem, useReturnActionItem, useSaveActionItem } from "./orderActions";
export { usePrintActionItem, usePrintReceiptsActionItem, usePrintWristbandActionItem, useRemotePrintActions } from "./printActions";
export { EBizPrintType } from "./types";