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 } from "./../../orderList/serve";
import { getOrderStatusMap, getPaymentStatusMap } from "./order";
import ResourceSelector from "../components/ResourceSelector";
export var getBookingStatusMap = function getBookingStatusMap() {
  return {
    new: locales.getText('pisell2.salesManagement.booking.status.new'),
    confirmed: locales.getText('pisell2.salesManagement.booking.status.confirmed'),
    arrived: locales.getText('pisell2.salesManagement.booking.status.arrived'),
    started: locales.getText('pisell2.salesManagement.booking.status.started'),
    cancelled: locales.getText('pisell2.salesManagement.booking.status.cancelled'),
    no_show: locales.getText('pisell2.salesManagement.booking.status.no_show'),
    completed: locales.getText('pisell2.salesManagement.booking.status.completed')
  };
};
export var BOOKING_STATUS_COLOR_MAP = {
  new: '#91caff',
  confirmed: '#b7eb8f',
  arrived: '#d3adf7',
  started: '#fffb8f',
  cancelled: '#bfbfbf',
  no_show: '#ffa39e',
  completed: '#ffd591'
};

/**
 * 预约 Monitor 列设置（显隐 + 顺序）localStorage 后缀。
 * bump 版本号以应用新默认列序，避免沿用旧 `column_order`。
 */
export var BOOKING_MONITOR_COLUMN_STORAGE_KEY_SUFFIX = '.booking-monitor-columns.v2';

/** 由低代码 `__id` 派生预约 Monitor 专用列持久化 key（与订单视角 `__id` 分流） */
export function resolveBookingMonitorColumnStorageKey(baseComponentId) {
  if (!baseComponentId) return undefined;
  return "".concat(baseComponentId).concat(BOOKING_MONITOR_COLUMN_STORAGE_KEY_SUFFIX);
}
export var getBookingPlatformMap = function getBookingPlatformMap() {
  return {
    online_store: locales.getText('pisell2.salesManagement.booking.platform.online_store'),
    wholesalebusiness: locales.getText('pisell2.salesManagement.booking.platform.wholesalebusiness'),
    'table-order': locales.getText('pisell2.salesManagement.booking.platform.table-order'),
    mobile_order: locales.getText('pisell2.salesManagement.booking.platform.mobile_order'),
    kiosk: locales.getText('pisell2.salesManagement.booking.platform.kiosk'),
    pos: locales.getText('pisell2.salesManagement.booking.platform.pos')
  };
};
export var getBookingHeaderLabels = function getBookingHeaderLabels() {
  return {
    bookingBrief: locales.getText('pisell2.salesManagement.booking.column.bookingBrief'),
    serviceTime: locales.getText('pisell2.salesManagement.booking.column.serviceTime'),
    customer: locales.getText('pisell2.salesManagement.booking.column.customer'),
    contact: locales.getText('pisell2.salesManagement.booking.column.contact'),
    holder: locales.getText('pisell2.salesManagement.booking.column.holder'),
    services: locales.getText('pisell2.salesManagement.booking.column.services'),
    pax: locales.getText('pisell2.salesManagement.booking.column.pax'),
    resource: locales.getText('pisell2.salesManagement.booking.column.resource'),
    forms: locales.getText('pisell2.salesManagement.booking.column.forms'),
    orderInfo: locales.getText('pisell2.salesManagement.booking.column.orderInfo'),
    paymentMethod: locales.getText('pisell2.salesManagement.booking.column.paymentMethod'),
    bookingId: locales.getText('pisell2.salesManagement.booking.column.bookingId'),
    orderOrigin: locales.getText('pisell2.salesManagement.booking.column.orderOrigin'),
    updated: locales.getText('pisell2.salesManagement.booking.column.updated'),
    orderNote: locales.getText('pisell2.salesManagement.booking.common.orderNote'),
    internalNote: locales.getText('pisell2.salesManagement.booking.common.internalNote'),
    more: locales.getText('pisell2.salesManagement.booking.common.more'),
    createdBy: locales.getText('pisell2.salesManagement.booking.common.createdBy'),
    guest: locales.getText('pisell2.salesManagement.order.common.guest'),
    walkIn: locales.getText('pisell2.salesManagement.order.common.walkIn')
  };
};

/** 预约看板 / Sales Monitor 等默认拉取的订单支付态（与 filter order_payment_status 对齐） */
export var defaultPaymentStatusKeys = ['payment_processing', 'partially_paid', 'paid', 'partially_refunded', 'refunded'];
export var getFilterButtonList = function getFilterButtonList() {
  var BOOKING_STATUS_MAP = getBookingStatusMap();
  var ORDER_STATUS_MAP = getOrderStatusMap();
  var PAYMENT_STATUS_MAP = getPaymentStatusMap();
  return [{
    name: 'appointment_status',
    type: 'single',
    key: 'appointmentStatus',
    label: locales.getText('pisell2.salesManagement.booking.filter.bookingStatus.label'),
    other: {
      allowClear: true,
      mode: 'multiple',
      maxTagCount: 'responsive',
      placeholder: locales.getText('pisell2.salesManagement.booking.filter.bookingStatus.placeholder'),
      options: Object.entries(BOOKING_STATUS_MAP).map(function (_ref) {
        var _ref2 = _slicedToArray(_ref, 2),
          key = _ref2[0],
          value = _ref2[1];
        return {
          label: value,
          value: key
        };
      })
    }
  },
  // {
  //   name: 'holder',
  //   type: 'input',
  //   key: 'holder',
  //   label: locales.getText(
  //     'pisell2.salesManagement.booking.filter.holder.label',
  //   ),
  //   other: {
  //     placeholder: locales.getText(
  //       'pisell2.salesManagement.booking.filter.holder.placeholder',
  //     ),
  //   },
  // },
  {
    name: 'number_between',
    type: 'numberRange',
    key: 'number_between',
    label: locales.getText('pisell2.salesManagement.booking.filter.paxRange.label'),
    other: {
      placeholder: locales.getText('pisell2.salesManagement.booking.filter.paxRange.placeholder'),
      minInputNumberProps: {
        min: 0,
        precision: 0
      },
      maxInputNumberProps: {
        min: 0,
        precision: 0
      }
    }
  }, {
    name: 'form_record_ids',
    type: 'custom',
    key: 'formRecordIds',
    label: locales.getText('pisell2.salesManagement.booking.filter.resource.label'),
    sort: true,
    localFilter: false,
    other: {
      allowClear: true,
      mode: 'multiple',
      maxTagCount: 'responsive',
      component: ResourceSelector
    }
  }, {
    name: 'order_sales_channel',
    type: 'single',
    key: 'orderSalesChannel',
    label: locales.getText('pisell2.salesManagement.booking.filter.salesChannel.label'),
    other: {
      allowClear: true,
      mode: 'multiple',
      maxTagCount: 'responsive',
      placeholder: locales.getText('pisell2.salesManagement.booking.filter.salesChannel.placeholder'),
      options: function options() {
        return getChannelSelectOptions().then(function (res) {
          return res.map(function (item) {
            return {
              label: item.name,
              value: item.code
            };
          });
        });
      }
    }
  }, {
    name: 'total_amount_between',
    type: 'numberRange',
    key: 'total_amount_between',
    label: locales.getText('pisell2.salesManagement.booking.filter.orderAmount.label'),
    other: {
      placeholder: locales.getText('pisell2.salesManagement.booking.filter.orderAmount.placeholder')
    }
  }, {
    name: 'order_status',
    type: 'single',
    key: 'order_status',
    label: locales.getText('pisell2.salesManagement.booking.filter.orderStatus.label'),
    other: {
      allowClear: true,
      mode: 'multiple',
      maxTagCount: 'responsive',
      placeholder: locales.getText('pisell2.salesManagement.booking.filter.orderStatus.placeholder'),
      options: Object.entries(ORDER_STATUS_MAP).map(function (_ref3) {
        var _ref4 = _slicedToArray(_ref3, 2),
          key = _ref4[0],
          value = _ref4[1];
        return {
          label: value,
          value: key
        };
      })
    }
  }, {
    name: 'order_payment_status',
    type: 'single',
    key: 'orderPaymentStatus',
    label: locales.getText('pisell2.salesManagement.booking.filter.paymentStatus.label'),
    other: {
      allowClear: true,
      mode: 'multiple',
      placeholder: locales.getText('pisell2.salesManagement.booking.filter.paymentStatus.placeholder'),
      options: Object.entries(PAYMENT_STATUS_MAP).map(function (_ref5) {
        var _ref6 = _slicedToArray(_ref5, 2),
          key = _ref6[0],
          value = _ref6[1];
        return {
          label: value,
          value: key
        };
      }),
      maxTagCount: 'responsive'
    }
  }, {
    name: 'customer_id',
    type: 'single',
    key: 'customer_id',
    label: locales.getText('pisell2.salesManagement.booking.filter.customer.label'),
    other: {
      allowClear: true,
      isSearchServer: true,
      showSearch: true,
      placeholder: locales.getText('pisell2.salesManagement.booking.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
            };
          });
        });
      }
    }
  },
  // todo:
  // {
  //   name: 'products',
  //   type: 'input',
  //   key: 'products',
  //   label: locales.getText(
  //     'pisell2.salesManagement.booking.filter.includeItems.label',
  //   ),
  //   other: {
  //     placeholder: locales.getText(
  //       'pisell2.salesManagement.booking.filter.includeItems.placeholder',
  //     ),
  //   },
  // },
  {
    name: 'payment_method',
    type: 'single',
    key: 'payment_method',
    label: locales.getText('pisell2.salesManagement.booking.filter.paymentMethod.label'),
    other: {
      allowClear: true,
      mode: 'multiple',
      maxTagCount: 'responsive',
      placeholder: locales.getText('pisell2.salesManagement.booking.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: 'created_at_between',
    type: 'rangePicker',
    key: 'createdAtBetween',
    label: locales.getText('pisell2.salesManagement.booking.filter.orderDate.label'),
    other: {
      placeholder: locales.getText('pisell2.salesManagement.booking.filter.orderDate.placeholder'),
      showTime: true
    }
  }, {
    name: 'updated_at_between',
    type: 'rangePicker',
    key: 'updatedAtBetween',
    label: locales.getText('pisell2.salesManagement.booking.filter.updatedDate.label'),
    other: {
      placeholder: locales.getText('pisell2.salesManagement.booking.filter.updatedDate.placeholder'),
      showTime: true
    }
  }];
};
export var getSortList = function getSortList() {
  return [{
    type: 'time',
    isCustom: true,
    name: 'after_execution_time',
    label: locales.getText('pisell2.salesManagement.booking.sort.afterExecutionTime'),
    getSortItems: function getSortItems() {
      return [{
        key: 'after_execution_time:asc',
        label: locales.getText('pisell2.salesManagement.sort.oldestFirst')
      }];
    }
  }, {
    type: 'time',
    isCustom: true,
    name: 'start_at',
    label: locales.getText('pisell2.salesManagement.booking.sort.startAt'),
    getSortItems: function getSortItems() {
      return [{
        key: 'start_at:asc',
        label: locales.getText('pisell2.salesManagement.sort.oldestFirst')
      }, {
        key: 'start_at:desc',
        label: locales.getText('pisell2.salesManagement.sort.latestFirst')
      }];
    }
  }, {
    type: 'time',
    isCustom: true,
    name: 'end_at',
    label: locales.getText('pisell2.salesManagement.booking.sort.endAt'),
    getSortItems: function getSortItems() {
      return [{
        key: 'end_at:asc',
        label: locales.getText('pisell2.salesManagement.sort.oldestFirst')
      }, {
        key: 'end_at:desc',
        label: locales.getText('pisell2.salesManagement.sort.latestFirst')
      }];
    }
  }, {
    type: 'time',
    isCustom: true,
    name: 'created_at',
    label: locales.getText('pisell2.salesManagement.booking.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.booking.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')
      }];
    },
    other: {
      style: {
        width: '100%'
      }
    }
  }
  // {
  //   type: 'number',
  //   isCustom: false,
  //   name: 'total_amount',
  //   label: locales.getText('pisell2.salesManagement.booking.sort.totalAmount'),
  // },
  // {
  //   type: 'number',
  //   isCustom: false,
  //   name: 'amount_gap',
  //   label: locales.getText('pisell2.salesManagement.sort.balanceDue'),
  // },
  // {
  //   type: 'number',
  //   isCustom: false,
  //   name: 'total_refund_amount',
  //   label: locales.getText(
  //     'pisell2.salesManagement.booking.sort.refundedAmount',
  //   ),
  // },
  // {
  //   type: 'string',
  //   isCustom: false,
  //   name: 'customer_name',
  //   label: locales.getText('pisell2.salesManagement.booking.sort.customerName'),
  // },
  ];
};