var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/plus/saleDetail/hooks/saleDetailActions/index.ts
var saleDetailActions_exports = {};
__export(saleDetailActions_exports, {
  EBizPrintType: () => import_types.EBizPrintType,
  useCancelActionItem: () => import_orderActions2.useCancelActionItem,
  useCheckoutActionItem: () => import_orderActions2.useCheckoutActionItem,
  useCheckoutCartActionItem: () => import_orderActions2.useCheckoutCartActionItem,
  useEditActionItem: () => import_orderActions2.useEditActionItem,
  useMoreActionItem: () => useMoreActionItem,
  useNoteActionItem: () => import_orderActions2.useNoteActionItem,
  usePrintActionItem: () => import_printActions2.usePrintActionItem,
  usePrintReceiptsActionItem: () => import_printActions2.usePrintReceiptsActionItem,
  usePrintWristbandActionItem: () => import_printActions2.usePrintWristbandActionItem,
  useRefundActionItem: () => import_orderActions2.useRefundActionItem,
  useRemotePrintActions: () => import_printActions2.useRemotePrintActions,
  useReturnActionItem: () => import_orderActions2.useReturnActionItem,
  useSaleDetailActions: () => useSaleDetailActions,
  useSaveActionItem: () => import_orderActions2.useSaveActionItem
});
module.exports = __toCommonJS(saleDetailActions_exports);
var import_react = require("react");
var import_orderActions = require("./orderActions");
var import_printActions = require("./printActions");
var import_utils = require("./utils");
var import_orderActions2 = require("./orderActions");
var import_printActions2 = require("./printActions");
var import_types = require("./types");
var DEFAULT_SALE_DETAIL_ACTIONS = ["checkout"];
function useMoreActionItem({
  printReceiptsAction,
  printWristbandAction,
  cancelAction
}) {
  return (0, import_react.useMemo)(
    () => ({
      id: "more",
      isMore: true,
      buttonProps: {
        block: true,
        className: "pisell-sale-detail-button-actions__button"
      },
      menuData: [
        (0, import_utils.toDropdownMenuItem)(printReceiptsAction),
        (0, import_utils.toDropdownMenuItem)(printWristbandAction),
        (0, import_utils.toDropdownMenuItem)(cancelAction)
      ]
    }),
    [cancelAction, printReceiptsAction, printWristbandAction]
  );
}
function useSaleDetailActions({
  context,
  actions = DEFAULT_SALE_DETAIL_ACTIONS
}) {
  var _a;
  const { machineCodePrintActionItems, refreshRemotePrintActions } = (0, import_printActions.useRemotePrintActions)({ context });
  const editAction = (0, import_orderActions.useEditActionItem)({
    context,
    onAfterEdit: refreshRemotePrintActions
  });
  const refundAction = (0, import_orderActions.useRefundActionItem)({ context });
  const returnAction = (0, import_orderActions.useReturnActionItem)({
    context,
    onAfterEdit: refreshRemotePrintActions
  });
  const printAction = (0, import_printActions.usePrintActionItem)();
  const printReceiptsAction = (0, import_printActions.usePrintReceiptsActionItem)({ context });
  const printWristbandAction = (0, import_printActions.usePrintWristbandActionItem)({ context });
  const cancelAction = (0, import_orderActions.useCancelActionItem)({ context });
  const noteAction = (0, import_orderActions.useNoteActionItem)({ context });
  const saveAction = (0, import_orderActions.useSaveActionItem)({ context });
  const checkoutAction = (0, import_orderActions.useCheckoutActionItem)({ context });
  const checkoutCartAction = (0, import_orderActions.useCheckoutCartActionItem)({ context });
  const moreAction = useMoreActionItem({
    printReceiptsAction,
    printWristbandAction,
    cancelAction
  });
  const isCancelled = ((_a = context.sales.tempOrder) == null ? void 0 : _a.status) === "cancelled";
  return (0, import_react.useMemo)(() => {
    if (isCancelled) return [];
    const 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
    };
    const resolveActionItem = (action) => {
      var _a2;
      const actionKey = (0, import_utils.getActionKey)(action);
      const actionConfig = (0, import_utils.getActionConfig)(action);
      const defaultConfig = import_utils.DEFAULT_ACTION_CONFIG[actionKey];
      const config = {
        ...defaultConfig,
        ...actionConfig,
        buttonProps: {
          ...defaultConfig == null ? void 0 : defaultConfig.buttonProps,
          ...actionConfig.buttonProps
        }
      };
      const baseActionItem = actionItemMap[actionKey];
      if (!baseActionItem) {
        return {
          id: actionKey,
          hidden: true
        };
      }
      const actionItem = (0, import_utils.mergeActionItem)(baseActionItem, config);
      if (!((_a2 = config.items) == null ? void 0 : _a2.length)) return actionItem;
      const nestedActionItems = (0, import_utils.getSortedVisibleActionItems)([
        ...actionKey === "print" ? machineCodePrintActionItems : [],
        ...config.items.map(resolveActionItem)
      ]);
      if (nestedActionItems.length === 1) {
        return {
          ...nestedActionItems[0],
          row: actionItem.row,
          order: actionItem.order
        };
      }
      const menuData = nestedActionItems.map(import_utils.toDropdownMenuItem);
      return {
        ...actionItem,
        isMore: true,
        menuData
      };
    };
    const saleDetailActions = actions.map(resolveActionItem);
    return (0, import_utils.toButtonGroupList)(saleDetailActions);
  }, [
    actions,
    cancelAction,
    checkoutAction,
    checkoutCartAction,
    editAction,
    isCancelled,
    machineCodePrintActionItems,
    moreAction,
    noteAction,
    printAction,
    printReceiptsAction,
    printWristbandAction,
    refundAction,
    returnAction,
    saveAction
  ]);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  EBizPrintType,
  useCancelActionItem,
  useCheckoutActionItem,
  useCheckoutCartActionItem,
  useEditActionItem,
  useMoreActionItem,
  useNoteActionItem,
  usePrintActionItem,
  usePrintReceiptsActionItem,
  usePrintWristbandActionItem,
  useRefundActionItem,
  useRemotePrintActions,
  useReturnActionItem,
  useSaleDetailActions,
  useSaveActionItem
});
