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 { locales } from '@pisell/utils';
import { getCustomerSelectOptions, getChannelSelectOptions, getPaymentSelectOptions, getLogisticsSelectOptions, getLocationSelectOptions, getTagSelectOptions } from "./../../orderList/serve";

/**
 * 获取支付状态映射
 */
export var getPaymentStatusMap = function getPaymentStatusMap() {
  return {
    authorized: locales.getText('pisell2.salesManagement.order.paymentStatus.authorized'),
    paid: locales.getText('pisell2.salesManagement.order.paymentStatus.paid'),
    partially_paid: locales.getText('pisell2.salesManagement.order.paymentStatus.partially_paid'),
    partially_refunded: locales.getText('pisell2.salesManagement.order.paymentStatus.partially_refunded'),
    refunded: locales.getText('pisell2.salesManagement.order.paymentStatus.refunded'),
    unpaid: locales.getText('pisell2.salesManagement.order.paymentStatus.unpaid'),
    voided: locales.getText('pisell2.salesManagement.order.paymentStatus.voided'),
    payment_processing: locales.getText('pisell2.salesManagement.order.paymentStatus.payment_processing')
  };
};
export var PAYMENT_STATUS_COLOR_MAP = {
  unpaid: '#B2DDFF',
  payment_processing: '#FEDF89',
  partially_paid: '#FDB022',
  authorized: '#ABEFC6',
  paid: '#ABEFC6',
  refunded: '#FECDCA',
  partially_refunded: '#FCCEEE',
  voided: '#D0D5DD'
};

// 获取下单渠道映射
export var getPlatformMap = function getPlatformMap() {
  return {
    online_store: locales.getText('pisell2.salesManagement.order.platform.online_store'),
    wholesalebusiness: locales.getText('pisell2.salesManagement.order.platform.wholesalebusiness'),
    'table-order': locales.getText('pisell2.salesManagement.order.platform.table-order'),
    mobile_order: locales.getText('pisell2.salesManagement.order.platform.mobile_order'),
    kiosk: locales.getText('pisell2.salesManagement.order.platform.kiosk'),
    pos: locales.getText('pisell2.salesManagement.order.platform.pos')
  };
};

/**
 * 获取订单状态映射
 * @param locales - 多语言对象
 */
export var getOrderStatusMap = function getOrderStatusMap() {
  return {
    open: locales.getText('pisell2.salesManagement.order.orderStatus.open'),
    completed: locales.getText('pisell2.salesManagement.order.orderStatus.completed'),
    cancelled: locales.getText('pisell2.salesManagement.order.orderStatus.cancelled')
  };
};
export var ORDER_STATUS_COLOR_MAP = {
  open: {
    borderColor: '#1570EF',
    textColor: '#175CD3'
  },
  completed: {
    borderColor: '#079455',
    textColor: '#067647'
  },
  cancelled: {
    borderColor: '#D92D20',
    textColor: '#B42318'
  }
};

/**
 * 获取处理状态映射
 */
export var getShippingStatusMap = function getShippingStatusMap() {
  return {
    fulfilled: locales.getText('pisell2.salesManagement.order.fulfillmentStatus.fulfilled'),
    unfulfilled: locales.getText('pisell2.salesManagement.order.fulfillmentStatus.unfulfilled'),
    fulfilling: locales.getText('pisell2.salesManagement.order.fulfillmentStatus.fulfilling'),
    partial_fulfilled: locales.getText('pisell2.salesManagement.order.fulfillmentStatus.partial_fulfilled')
  };
};
export var FULFILLMENT_STATUS_COLOR_MAP = {
  fulfilling: {
    borderColor: '#DC6803',
    textColor: '#B54708'
  },
  unfulfilled: {
    borderColor: '#DC6803',
    textColor: '#B54708'
  },
  partial_fulfilled: {
    borderColor: '#088AB2',
    textColor: '#0E7090'
  },
  fulfilled: {
    borderColor: '#475467',
    textColor: '#344054'
  }
};

/**
 * 获取配送方式映射
 */
export var getDeliveryTypeMap = function getDeliveryTypeMap() {
  return {
    nil: locales.getText('pisell2.salesManagement.order.deliveryType.nil'),
    shipping: locales.getText('pisell2.salesManagement.order.deliveryType.shipping'),
    local_delivery: locales.getText('pisell2.salesManagement.order.deliveryType.local_delivery'),
    pickup: locales.getText('pisell2.salesManagement.order.deliveryType.pickup'),
    shop_service: locales.getText('pisell2.salesManagement.order.deliveryType.shop_service')
  };
};

/**
 * 获取到店服务类型映射
 * @param locales - 多语言对象
 */
export var getShopServiceTypeMap = function getShopServiceTypeMap() {
  return {
    'dine-in': locales.getText('pisell2.salesManagement.order.shopServiceType.dine-in'),
    takeaway: locales.getText('pisell2.salesManagement.order.shopServiceType.takeaway')
  };
};
export var DELIVERY_TYPE_COLOR_MAP = {
  shipping: '',
  local_delivery: 'orange',
  pickup: 'blue'
};
export var SHOP_SERVICE_TYPE_COLOR_MAP = {
  'dine-in': 'green',
  takeaway: 'red'
};
export var getOrderHeaderLabels = function getOrderHeaderLabels() {
  return {
    saleBrief: locales.getText('pisell2.salesManagement.order.column.saleBrief'),
    customer: locales.getText('pisell2.salesManagement.order.column.customer'),
    contact: locales.getText('pisell2.salesManagement.order.column.contact'),
    paymentInfo: locales.getText('pisell2.salesManagement.order.column.paymentInfo'),
    paymentMethod: locales.getText('pisell2.salesManagement.order.column.paymentMethod'),
    items: locales.getText('pisell2.salesManagement.order.column.items'),
    paymentStatus: locales.getText('pisell2.salesManagement.order.column.paymentStatus'),
    orderOrigin: locales.getText('pisell2.salesManagement.order.column.orderOrigin'),
    shippingMethod: locales.getText('pisell2.salesManagement.order.column.shippingMethod'),
    fulfillmentMethod: locales.getText('pisell2.salesManagement.order.column.fulfillmentMethod'),
    orderStatus: locales.getText('pisell2.salesManagement.order.column.orderStatus'),
    fulfillmentStatus: locales.getText('pisell2.salesManagement.order.column.fulfillmentStatus'),
    updated: locales.getText('pisell2.salesManagement.order.column.updated'),
    orderId: locales.getText('pisell2.salesManagement.order.column.orderId'),
    orderNote: locales.getText('pisell2.salesManagement.order.common.orderNote'),
    internalNote: locales.getText('pisell2.salesManagement.order.common.internalNote'),
    createdBy: locales.getText('pisell2.salesManagement.order.common.createdBy'),
    guest: locales.getText('pisell2.salesManagement.order.common.guest'),
    walkIn: locales.getText('pisell2.salesManagement.order.common.walkIn')
  };
};
export var defaultPaymentStatusKeys = ['payment_processing', 'paid', 'partially_refunded', 'refunded'];
export var getFilterButtonList = function getFilterButtonList() {
  var ORDER_STATUS_MAP = getOrderStatusMap();
  var PAYMENT_STATUS_MAP = getPaymentStatusMap();
  var SHIPPING_STATUS_MAP = getShippingStatusMap();
  var DELIVERY_TYPE_MAP = getDeliveryTypeMap();
  return [{
    name: 'status',
    type: 'single',
    key: 'status',
    label: locales.getText('pisell2.salesManagement.order.filter.orderStatus.label'),
    other: {
      allowClear: true,
      mode: 'multiple',
      maxTagCount: 'responsive',
      placeholder: locales.getText('pisell2.salesManagement.order.filter.orderStatus.placeholder'),
      options: Object.entries(ORDER_STATUS_MAP).map(function (_ref) {
        var _ref2 = _slicedToArray(_ref, 2),
          key = _ref2[0],
          value = _ref2[1];
        return {
          label: value,
          value: key
        };
      })
    }
  }, {
    name: 'payment_status',
    type: 'single',
    key: 'payment_status',
    label: locales.getText('pisell2.salesManagement.order.filter.paymentStatus.label'),
    other: {
      allowClear: true,
      mode: 'multiple',
      maxTagCount: 'responsive',
      placeholder: locales.getText('pisell2.salesManagement.order.filter.paymentStatus.placeholder'),
      options: Object.entries(PAYMENT_STATUS_MAP).map(function (_ref3) {
        var _ref4 = _slicedToArray(_ref3, 2),
          key = _ref4[0],
          value = _ref4[1];
        return {
          label: value,
          value: key
        };
      })
    }
  }, {
    name: 'shipping_status',
    type: 'single',
    key: 'shipping_status',
    label: locales.getText('pisell2.salesManagement.order.filter.fulfillmentStatus.label'),
    other: {
      allowClear: true,
      mode: 'multiple',
      maxTagCount: 'responsive',
      placeholder: locales.getText('pisell2.salesManagement.order.filter.fulfillmentStatus.placeholder'),
      options: Object.entries(SHIPPING_STATUS_MAP).map(function (_ref5) {
        var _ref6 = _slicedToArray(_ref5, 2),
          key = _ref6[0],
          value = _ref6[1];
        return {
          label: value,
          value: key
        };
      })
    }
  }, {
    name: 'customer_id',
    type: 'single',
    key: 'customer_id',
    label: locales.getText('pisell2.salesManagement.order.filter.customer.label'),
    other: {
      allowClear: true,
      isSearchServer: true,
      showSearch: true,
      placeholder: locales.getText('pisell2.salesManagement.order.filter.customer.placeholder'),
      options: function options(params) {
        return getCustomerSelectOptions(params).then(function (res) {
          return res.map(function (item) {
            return {
              label: item.display_name,
              value: item.id
            };
          });
        });
      }
    }
  }, {
    name: 'order_sales_channel',
    type: 'single',
    key: 'order_sales_channel',
    label: locales.getText('pisell2.salesManagement.order.filter.salesChannel.label'),
    other: {
      allowClear: true,
      mode: 'multiple',
      maxTagCount: 'responsive',
      placeholder: locales.getText('pisell2.salesManagement.order.filter.salesChannel.placeholder'),
      options: function options() {
        return getChannelSelectOptions().then(function (res) {
          return res.map(function (item) {
            return {
              label: item.name,
              value: item.code
            };
          });
        });
      }
    }
  }, {
    name: 'payment_methods',
    type: 'single',
    key: 'payment_methods',
    label: locales.getText('pisell2.salesManagement.order.filter.paymentMethod.label'),
    other: {
      allowClear: true,
      mode: 'multiple',
      maxTagCount: 'responsive',
      virtual: false,
      placeholder: locales.getText('pisell2.salesManagement.order.filter.paymentMethod.placeholder'),
      options: function options() {
        return getPaymentSelectOptions().then(function (res) {
          var map = new Map(res.map(function (item) {
            return [item.code, {
              label: item.name,
              value: item.code
            }];
          }));
          return Array.from(map.values());
        });
      }
    }
  }, {
    name: 'total_amount',
    //max_total_amount 分两个字段
    type: 'numberRange',
    key: 'total_amount',
    label: locales.getText('pisell2.salesManagement.order.filter.totalAmount.label'),
    other: {
      placeholder: locales.getText('pisell2.salesManagement.order.filter.totalAmount.placeholder'),
      minInputNumberProps: {
        min: 0
      },
      maxInputNumberProps: {
        min: 0
      }
    }
  }, {
    name: 'tag_ids',
    type: 'single',
    key: 'tag_ids',
    label: locales.getText('pisell2.salesManagement.order.filter.tags.label'),
    other: {
      allowClear: true,
      mode: 'multiple',
      maxTagCount: 'responsive',
      isSearchServer: true,
      showSearch: true,
      placeholder: locales.getText('pisell2.salesManagement.order.filter.tags.placeholder'),
      options: function options(params) {
        return getTagSelectOptions(params).then(function (res) {
          return res.map(function (item) {
            return {
              label: item.name,
              value: item.id
            };
          });
        });
      }
    }
  }, {
    name: 'delivery_type',
    type: 'single',
    key: 'delivery_type',
    label: locales.getText('pisell2.salesManagement.order.filter.fulfillmentMethod.label'),
    other: {
      allowClear: true,
      mode: 'multiple',
      maxTagCount: 'responsive',
      placeholder: locales.getText('pisell2.salesManagement.order.filter.fulfillmentMethod.placeholder'),
      options: Object.entries(DELIVERY_TYPE_MAP).filter(function (_ref7) {
        var _ref8 = _slicedToArray(_ref7, 1),
          key = _ref8[0];
        return !['nil', 'shop_service'].includes(key);
      }).map(function (_ref9) {
        var _ref10 = _slicedToArray(_ref9, 2),
          key = _ref10[0],
          value = _ref10[1];
        return {
          label: value,
          value: key
        };
      })
    }
  }, {
    name: 'delivery_zone_name',
    type: 'text',
    key: 'delivery_zone_name',
    label: locales.getText('pisell2.salesManagement.order.filter.deliveryZone.label'),
    other: {
      placeholder: locales.getText('pisell2.salesManagement.order.filter.deliveryZone.placeholder')
    }
  }, {
    name: 'location_id',
    type: 'single',
    key: 'location_id',
    label: locales.getText('pisell2.salesManagement.order.filter.pickupLocation.label'),
    other: {
      allowClear: true,
      placeholder: locales.getText('pisell2.salesManagement.order.filter.pickupLocation.placeholder'),
      options: function options() {
        return getLocationSelectOptions().then(function (res) {
          return res.map(function (item) {
            return {
              label: item.name,
              value: item.id
            };
          });
        });
      }
    }
  }, {
    name: 'shipping_order_number',
    type: 'text',
    key: 'shipping_order_number',
    label: locales.getText('pisell2.salesManagement.order.filter.trackingNumber.label'),
    other: {
      placeholder: locales.getText('pisell2.salesManagement.order.filter.trackingNumber.placeholder')
    }
  }, {
    name: 'logistics_company_id',
    type: 'single',
    key: 'logistics_company_id',
    label: locales.getText('pisell2.salesManagement.order.filter.logistics.label'),
    other: {
      allowClear: true,
      mode: 'multiple',
      maxTagCount: 'responsive',
      placeholder: locales.getText('pisell2.salesManagement.order.filter.logistics.placeholder'),
      options: function options() {
        return getLogisticsSelectOptions().then(function (res) {
          return res.map(function (item) {
            return {
              label: item.name,
              value: item.id
            };
          });
        });
      }
    }
  }, {
    name: 'zip',
    type: 'text',
    key: 'zip',
    label: locales.getText('pisell2.salesManagement.order.filter.zipCode.label'),
    other: {
      placeholder: locales.getText('pisell2.salesManagement.order.filter.zipCode.placeholder')
    }
  }];
};
export var getSortList = function getSortList() {
  return [{
    type: 'time',
    isCustom: true,
    name: 'created_at',
    label: locales.getText('pisell2.salesManagement.order.sort.createdAt'),
    getSortItems: function getSortItems() {
      return [{
        key: 'created_at:asc',
        label: locales.getText('pisell2.salesManagement.sort.oldestFirst')
      }, {
        key: 'created_at:desc',
        label: locales.getText('pisell2.salesManagement.sort.newestFirst')
      }];
    }
  }, {
    type: 'time',
    isCustom: true,
    name: 'updated_at',
    label: locales.getText('pisell2.salesManagement.order.sort.updatedAt'),
    getSortItems: function getSortItems() {
      return [{
        key: 'updated_at:asc',
        label: locales.getText('pisell2.salesManagement.sort.oldestFirst')
      }, {
        key: 'updated_at:desc',
        label: locales.getText('pisell2.salesManagement.sort.newestFirst')
      }];
    }
  }, {
    type: 'number',
    isCustom: false,
    name: 'total_amount',
    label: locales.getText('pisell2.salesManagement.order.sort.totalAmount')
  }, {
    type: 'number',
    isCustom: false,
    name: 'amount_gap',
    label: locales.getText('pisell2.salesManagement.sort.balanceDue')
  }, {
    type: 'string',
    isCustom: false,
    name: 'customer_name',
    label: locales.getText('pisell2.salesManagement.order.sort.customerName')
  }];
};