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 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); }
export var DEFAULT_ACTION_CONFIG = {
  note: {
    row: 1,
    order: 10,
    buttonProps: {
      size: 'large'
    }
  },
  save: {
    row: 1,
    order: 20,
    buttonProps: {
      size: 'large'
    }
  },
  checkout: {
    row: 1,
    order: 30,
    buttonProps: {
      size: 'large'
    }
  },
  'checkout-cart': {
    row: 1,
    order: 30,
    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-receipts': {
    row: 3,
    order: 30,
    buttonProps: {
      size: 'large'
    }
  },
  'print-wristband': {
    row: 3,
    order: 20,
    buttonProps: {
      size: 'large'
    }
  },
  cancel: {
    row: 3,
    order: 30,
    buttonProps: {
      size: 'large'
    }
  },
  more: {
    row: 2,
    order: 10,
    buttonProps: {
      size: 'large'
    }
  }
};
export 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;
  });
}
export function getActionKey(action) {
  return typeof action === 'string' ? action : action.name;
}
export function getActionConfig(action) {
  return typeof action === 'string' ? {} : action;
}
export function mergeActionItem(item, config) {
  return _objectSpread(_objectSpread(_objectSpread({}, item), config), {}, {
    buttonProps: _objectSpread(_objectSpread({}, item.buttonProps), config.buttonProps)
  });
}
export 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
  };
}
export 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);
  });
}
export function resolveSaleDetailOrderId(context) {
  var _context$sales$tempOr, _context$sales$tempOr2, _context$sales$salesD;
  var id = (_context$sales$tempOr = (_context$sales$tempOr2 = context.sales.tempOrder) === null || _context$sales$tempOr2 === void 0 ? void 0 : _context$sales$tempOr2.order_id) !== null && _context$sales$tempOr !== void 0 ? _context$sales$tempOr : (_context$sales$salesD = context.sales.salesDetail) === null || _context$sales$salesD === void 0 || (_context$sales$salesD = _context$sales$salesD.header) === null || _context$sales$salesD === void 0 ? void 0 : _context$sales$salesD.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;
}
export 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');
}
export function updateLocalOrder(action, orderId) {
  if (orderId == null || typeof action !== 'function') return;
  action({
    type: 'webpos.updateLocalOrderApi',
    data: {
      order_id: orderId
    }
  });
}