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); }
import React, { useCallback, useMemo } from 'react';
import { PisellTags, PisellDateTimeDisplay } from '@pisell/materials';
import { locales } from '@pisell/utils';
import useEngineContext from "../../../hooks/useEngineContext";
import ClientName from "../../clientName";
import { FULFILLMENT_STATUS_COLOR_MAP, DELIVERY_TYPE_COLOR_MAP, getOrderHeaderLabels, getShippingStatusMap, ORDER_STATUS_COLOR_MAP, SHOP_SERVICE_TYPE_COLOR_MAP, getOrderStatusMap, PAYMENT_STATUS_COLOR_MAP, getPaymentStatusMap, getPlatformMap, getDeliveryTypeMap, getShopServiceTypeMap, getFilterButtonList, getSortList } from "../config/order";
import { getBusinessLabelMap, BUSINESS_COLOR_MAP } from "../config";
import { Tag, formatAmount, getDisplayLines, textStyles, formatPhone } from "./perspectiveUtils";
import BookingNotesPreview from "../components/BookingNotesPreview";
import { createNoteApis } from "../serve";
export var useOrderPerspective = function useOrderPerspective() {
  var _context$appHelper, _context$appHelper$ge, _context$appHelper2, _context$engine;
  var context = useEngineContext();
  var app = context === null || context === void 0 || (_context$appHelper = context.appHelper) === null || _context$appHelper === void 0 || (_context$appHelper = _context$appHelper.utils) === null || _context$appHelper === void 0 || (_context$appHelper$ge = _context$appHelper.getApp) === null || _context$appHelper$ge === void 0 ? void 0 : _context$appHelper$ge.call(_context$appHelper);
  var NativePage = context === null || context === void 0 || (_context$appHelper2 = context.appHelper) === null || _context$appHelper2 === void 0 || (_context$appHelper2 = _context$appHelper2.utils) === null || _context$appHelper2 === void 0 ? void 0 : _context$appHelper2.NativePage;
  /** 监听 locale，切换语言时重新计算 label/filter/sort 等文案 */
  var locale = context === null || context === void 0 || (_context$engine = context.engine) === null || _context$engine === void 0 || (_context$engine = _context$engine.props) === null || _context$engine === void 0 ? void 0 : _context$engine.locale;

  /**
   * 静态部分：label maps 等只需计算一次的数据。
   */
  var staticData = useMemo(function () {
    var PAYMENT_STATUS_LABEL_MAP = getPaymentStatusMap();
    var PLATFORM_LABEL_MAP = getPlatformMap();
    var ORDER_STATUS_LABEL_MAP = getOrderStatusMap();
    var SHIPPING_STATUS_LABEL_MAP = getShippingStatusMap();
    var DELIVERY_TYPE_LABEL_MAP = getDeliveryTypeMap();
    var SHOP_SERVICE_TYPE_LABEL_MAP = getShopServiceTypeMap();
    var BUSINESS_LABEL_MAP = getBusinessLabelMap();
    var orderLabels = getOrderHeaderLabels();
    var amountLabels = {
      total: locales.getText('pisell2.orderList.common.totalAmount'),
      paid: locales.getText('pisell2.orderList.common.paidAmount'),
      due: locales.getText('pisell2.orderList.common.dueAmount'),
      refunded: locales.getText('pisell2.orderList.common.refundedAmount'),
      items: locales.getText('pisell2.orderList.common.itemsCount')
    };
    return {
      PAYMENT_STATUS_LABEL_MAP: PAYMENT_STATUS_LABEL_MAP,
      PLATFORM_LABEL_MAP: PLATFORM_LABEL_MAP,
      ORDER_STATUS_LABEL_MAP: ORDER_STATUS_LABEL_MAP,
      SHIPPING_STATUS_LABEL_MAP: SHIPPING_STATUS_LABEL_MAP,
      DELIVERY_TYPE_LABEL_MAP: DELIVERY_TYPE_LABEL_MAP,
      SHOP_SERVICE_TYPE_LABEL_MAP: SHOP_SERVICE_TYPE_LABEL_MAP,
      BUSINESS_LABEL_MAP: BUSINESS_LABEL_MAP,
      orderLabels: orderLabels,
      amountLabels: amountLabels
    };
  }, [locale]);

  /**
   * 构建 columns 的工厂：接收 runtimeContext，使列渲染可访问 refresh 等运行时能力。
   */
  var buildColumns = useCallback(function (ctx) {
    var PAYMENT_STATUS_LABEL_MAP = staticData.PAYMENT_STATUS_LABEL_MAP,
      PLATFORM_LABEL_MAP = staticData.PLATFORM_LABEL_MAP,
      ORDER_STATUS_LABEL_MAP = staticData.ORDER_STATUS_LABEL_MAP,
      SHIPPING_STATUS_LABEL_MAP = staticData.SHIPPING_STATUS_LABEL_MAP,
      DELIVERY_TYPE_LABEL_MAP = staticData.DELIVERY_TYPE_LABEL_MAP,
      SHOP_SERVICE_TYPE_LABEL_MAP = staticData.SHOP_SERVICE_TYPE_LABEL_MAP,
      BUSINESS_LABEL_MAP = staticData.BUSINESS_LABEL_MAP,
      orderLabels = staticData.orderLabels,
      amountLabels = staticData.amountLabels;
    return [{
      title: orderLabels.saleBrief,
      key: 'sale_brief',
      width: 225,
      // fixed: 'left',
      render: function render(_, record) {
        var orderCode = record === null || record === void 0 ? void 0 : record.shop_full_order_number;
        var currencySymbol = record === null || record === void 0 ? void 0 : record.currency_symbol;
        var totalAmount = record === null || record === void 0 ? void 0 : record.total_amount;
        var paymentStatus = record === null || record === void 0 ? void 0 : record.payment_status;
        var orderNote = record === null || record === void 0 ? void 0 : record.note;
        var internalNotes = record === null || record === void 0 ? void 0 : record.internal_note;
        var noteApis = createNoteApis((record === null || record === void 0 ? void 0 : record.id) || (record === null || record === void 0 ? void 0 : record.order_id) || (record === null || record === void 0 ? void 0 : record.orderId));
        var tags = (record === null || record === void 0 ? void 0 : record.tag) || (record === null || record === void 0 ? void 0 : record.tags) || [];
        var paymentLabel = PAYMENT_STATUS_LABEL_MAP[paymentStatus] || paymentStatus || '-';
        var paymentColor = PAYMENT_STATUS_COLOR_MAP[paymentStatus] || '';
        return /*#__PURE__*/React.createElement("div", {
          style: {
            display: 'flex',
            flexDirection: 'column'
          }
        }, /*#__PURE__*/React.createElement("div", {
          style: {
            fontWeight: 'bold',
            textDecoration: 'underline',
            color: 'var(--theme-color, #7f56d9)'
          }
        }, orderCode), Array.isArray(tags) && tags.length > 0 ? /*#__PURE__*/React.createElement("div", {
          style: {
            display: 'flex',
            gap: 4,
            flexWrap: 'wrap'
          }
        }, tags.map(function (item) {
          return /*#__PURE__*/React.createElement(Tag, {
            key: "".concat(item === null || item === void 0 ? void 0 : item.id),
            style: {
              margin: 0,
              maxWidth: 160,
              whiteSpace: 'nowrap',
              overflow: 'hidden',
              textOverflow: 'ellipsis',
              fontWeight: 500
            }
          }, item === null || item === void 0 ? void 0 : item.name);
        })) : null, /*#__PURE__*/React.createElement("div", {
          style: {
            fontWeight: 'bold'
          }
        }, /*#__PURE__*/React.createElement("span", {
          style: {
            marginRight: 6
          }
        }, amountLabels.total, ":"), /*#__PURE__*/React.createElement("span", null, formatAmount(totalAmount, currencySymbol))), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Tag, {
          style: {
            backgroundColor: paymentColor,
            whiteSpace: 'nowrap',
            border: 'none',
            fontWeight: 500
          }
        }, paymentLabel)), /*#__PURE__*/React.createElement(BookingNotesPreview, {
          dataSource: {
            note: orderNote,
            internalNotes: internalNotes,
            apis: noteApis,
            onChange: function onChange(value, type, noteType) {
              ctx.refresh();
            }
          },
          labels: {
            orderNote: orderLabels.orderNote,
            internalNote: orderLabels.internalNote
          },
          style: {
            maxWidth: 160
          }
        }));
      }
    }, {
      title: orderLabels.customer,
      key: 'customer',
      align: 'center',
      width: 150,
      uniformCompare: function uniformCompare(value, record) {
        var customer = record === null || record === void 0 ? void 0 : record.customer;
        if (!customer) return '-';
        var guestCode = customer === null || customer === void 0 ? void 0 : customer.guest_code;
        if (guestCode) return "".concat(guestCode);
        if (customer.user_id === 1) return 'walk-in'; // 返回任意固定值即可
        return customer;
      },
      render: function render(_, record) {
        var customer = record === null || record === void 0 ? void 0 : record.customer;
        if (!customer) return '-';
        var guestCode = customer === null || customer === void 0 ? void 0 : customer.guest_code;
        if (guestCode) {
          return /*#__PURE__*/React.createElement("div", {
            style: {
              display: 'flex',
              flexDirection: 'column',
              alignItems: 'center',
              textAlign: 'center'
            }
          }, /*#__PURE__*/React.createElement("div", {
            style: {
              fontWeight: 'bold'
            }
          }, orderLabels.guest));
        }
        var phone = formatPhone((customer === null || customer === void 0 ? void 0 : customer.phone) || (record === null || record === void 0 ? void 0 : record.phone), (customer === null || customer === void 0 ? void 0 : customer.country_calling_code) || (record === null || record === void 0 ? void 0 : record.country_calling_code));
        var lines = getDisplayLines([phone, customer === null || customer === void 0 ? void 0 : customer.email]);
        return /*#__PURE__*/React.createElement("div", {
          style: {
            display: 'flex',
            flexDirection: 'column',
            alignItems: 'center',
            textAlign: 'center'
          }
        }, /*#__PURE__*/React.createElement(ClientName, {
          dataSource: customer,
          style: {
            fontSize: 14
          }
        }), lines.map(function (line, index) {
          return /*#__PURE__*/React.createElement("div", {
            key: "".concat(line, "-").concat(index),
            style: textStyles.text
          }, line);
        }));
      }
    }, {
      title: orderLabels.contact,
      dataIndex: 'contacts_info',
      key: 'contacts_info',
      align: 'center',
      width: 150,
      uniformCompare: function uniformCompare(value, record) {
        if (!value) return '-';
        return value;
      },
      render: function render(value) {
        if (!value) return '-';
        var info = (value === null || value === void 0 ? void 0 : value.value) || {};
        var phone = formatPhone(info === null || info === void 0 ? void 0 : info.phone);
        var lines = getDisplayLines([phone, info === null || info === void 0 ? void 0 : info.email]);
        return /*#__PURE__*/React.createElement("div", {
          style: {
            display: 'flex',
            flexDirection: 'column',
            alignItems: 'center',
            textAlign: 'center'
          }
        }, /*#__PURE__*/React.createElement(ClientName, {
          dataSource: info,
          style: {
            fontSize: 14
          }
        }), lines.map(function (line, index) {
          return /*#__PURE__*/React.createElement("div", {
            key: "".concat(line, "-").concat(index),
            style: textStyles.text
          }, line);
        }));
      }
    }, {
      title: orderLabels.paymentInfo,
      key: 'payment_info',
      width: 124,
      align: 'center',
      render: function render(_, record) {
        var value = record === null || record === void 0 ? void 0 : record.payment_status;
        var currencySymbol = record === null || record === void 0 ? void 0 : record.currency_symbol;
        var totalAmount = Number((record === null || record === void 0 ? void 0 : record.total_amount) || 0);
        var paidAmount = Number((record === null || record === void 0 ? void 0 : record.paid_amount) || 0);
        var refundedAmount = Number((record === null || record === void 0 ? void 0 : record.total_refund_amount) || 0);
        var dueAmount = totalAmount - paidAmount;
        var amountStyles = {
          due: {
            fontWeight: 'bold',
            color: '#D92D20'
          },
          refunded: {
            color: '#CA8504',
            fontWeight: 'bold'
          }
        };
        var lines = [];
        if (['payment_processing', 'unpaid', 'partially_paid'].includes(value)) {
          lines.push({
            label: amountLabels.due,
            value: formatAmount(dueAmount, currencySymbol),
            bold: true,
            kind: 'due'
          });
          lines.push({
            label: amountLabels.total,
            value: formatAmount(totalAmount, currencySymbol),
            kind: 'total'
          });
        } else if (value === 'paid') {
          lines.push({
            label: amountLabels.paid,
            value: formatAmount(paidAmount, currencySymbol),
            bold: true,
            kind: 'paid'
          });
          lines.push({
            label: amountLabels.total,
            value: formatAmount(totalAmount, currencySymbol),
            kind: 'total'
          });
        } else if (['partially_refunded', 'refunded'].includes(value)) {
          lines.push({
            label: amountLabels.refunded,
            value: formatAmount(refundedAmount, currencySymbol),
            bold: true,
            kind: 'refunded'
          });
          lines.push({
            label: amountLabels.paid,
            value: formatAmount(paidAmount, currencySymbol),
            kind: 'paid'
          });
          lines.push({
            label: amountLabels.total,
            value: formatAmount(totalAmount, currencySymbol),
            kind: 'total'
          });
        } else if (['voided', 'authorized'].includes(value)) {
          lines.push({
            label: amountLabels.total,
            value: formatAmount(totalAmount, currencySymbol),
            bold: true,
            kind: 'total'
          });
        } else {
          lines.push({
            label: amountLabels.total,
            value: formatAmount(totalAmount, currencySymbol),
            bold: true,
            kind: 'total'
          });
        }
        return /*#__PURE__*/React.createElement("div", {
          style: {
            display: 'flex',
            flexDirection: 'column',
            gap: 4,
            alignItems: 'flex-start'
          }
        }, lines.map(function (line) {
          return /*#__PURE__*/React.createElement("div", {
            key: line.label,
            style: textStyles.text
          }, /*#__PURE__*/React.createElement("span", {
            style: _objectSpread({
              whiteSpace: 'nowrap'
            }, line.kind && amountStyles[line.kind] ? amountStyles[line.kind] : {})
          }, line.label, ": ", line.value));
        }));
      }
    }, {
      title: orderLabels.items,
      key: 'product_quantity',
      align: 'center',
      width: 120,
      render: function render(_, record) {
        var count = (record === null || record === void 0 ? void 0 : record.product_quantity) || 0;
        return /*#__PURE__*/React.createElement("span", {
          style: _objectSpread(_objectSpread({}, textStyles.text), {}, {
            textAlign: 'center'
          })
        }, count, amountLabels.items);
      }
    }, {
      title: orderLabels.orderOrigin,
      key: 'order_origin',
      width: 138,
      align: 'center',
      render: function render(_, record) {
        var channel = PLATFORM_LABEL_MAP[record === null || record === void 0 ? void 0 : record.order_sales_channel] || PLATFORM_LABEL_MAP[record === null || record === void 0 ? void 0 : record.order_platform] || (record === null || record === void 0 ? void 0 : record.order_sales_channel) || (record === null || record === void 0 ? void 0 : record.order_platform);
        var device = (record === null || record === void 0 ? void 0 : record.device_name) || (record === null || record === void 0 ? void 0 : record.device) || (record === null || record === void 0 ? void 0 : record.terminal);
        var time = (record === null || record === void 0 ? void 0 : record.created_at) || (record === null || record === void 0 ? void 0 : record.order_time);
        var lines = getDisplayLines([channel, device]);
        if (lines.length === 0) {
          return null;
        }
        var businessLabel = BUSINESS_LABEL_MAP[record.business_code];
        return /*#__PURE__*/React.createElement("div", {
          style: {
            display: 'flex',
            flexDirection: 'column',
            alignItems: 'flex-start'
          }
        }, businessLabel ? /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Tag, {
          color: BUSINESS_COLOR_MAP[record.business_code],
          style: {
            color: 'black',
            fontWeight: 500
          }
        }, businessLabel)) : null, lines.map(function (line, index) {
          return /*#__PURE__*/React.createElement("div", {
            key: "".concat(line, "-").concat(index),
            style: textStyles.text
          }, line);
        }), /*#__PURE__*/React.createElement("div", {
          style: {
            display: 'flex',
            alignItems: 'center',
            whiteSpace: 'nowrap'
          }
        }, /*#__PURE__*/React.createElement("span", null, orderLabels.createdBy, ":"), /*#__PURE__*/React.createElement(ClientName, {
          dataSource: record.create_account,
          style: {
            fontSize: 14
          }
        })), /*#__PURE__*/React.createElement(PisellDateTimeDisplay, {
          value: time,
          layout: "inline",
          textAlign: "left",
          timeFormat: {
            padHour: true
          },
          dateFormat: {
            showYear: false,
            shortMonth: true,
            showRelativeDay: true,
            useCommaBeforeYear: false
          },
          fields: {
            fieldOrder: ['time', 'weekday', 'date']
            // inlineSeparators: [' ', ', '],
          },
          style: {
            whiteSpace: 'nowrap'
          }
        }));
      }
    }, {
      title: orderLabels.paymentStatus,
      dataIndex: 'payment_status',
      key: 'payment_status',
      align: 'center',
      width: 160,
      render: function render(value) {
        var key = value === 'partially_paid' ? 'unpaid' : value;
        var label = PAYMENT_STATUS_LABEL_MAP[key] || value || '-';
        var color = PAYMENT_STATUS_COLOR_MAP[key] || '';
        return /*#__PURE__*/React.createElement("div", {
          style: {
            textAlign: 'center'
          }
        }, /*#__PURE__*/React.createElement(PisellTags, {
          style: {
            backgroundColor: color,
            whiteSpace: 'nowrap'
          }
        }, label));
      }
    }, {
      title: orderLabels.shippingMethod,
      key: 'delivery_type',
      align: 'center',
      width: 160,
      render: function render(_, record) {
        var _record$metadata;
        var deliveryType = record === null || record === void 0 ? void 0 : record.delivery_type;
        var serverType = record === null || record === void 0 || (_record$metadata = record.metadata) === null || _record$metadata === void 0 || (_record$metadata = _record$metadata.shop_service_type) === null || _record$metadata === void 0 ? void 0 : _record$metadata.server_type;
        if (!deliveryType && !serverType) return '-';
        var isShopService = deliveryType === 'shop_service';
        var label = isShopService ? SHOP_SERVICE_TYPE_LABEL_MAP[serverType] : DELIVERY_TYPE_LABEL_MAP[deliveryType];
        if (!label || !isShopService && deliveryType === 'nil') return '-';
        var color = isShopService ? SHOP_SERVICE_TYPE_COLOR_MAP[serverType] : DELIVERY_TYPE_COLOR_MAP[deliveryType];
        return /*#__PURE__*/React.createElement("div", {
          style: {
            textAlign: 'center'
          }
        }, /*#__PURE__*/React.createElement(Tag, {
          style: {
            whiteSpace: 'nowrap',
            fontWeight: 500
          },
          color: color
        }, label));
      },
      uniformCompare: function uniformCompare(_, record) {
        var _record$metadata2;
        var deliveryType = (record === null || record === void 0 ? void 0 : record.delivery_type) || '';
        var serverType = (record === null || record === void 0 || (_record$metadata2 = record.metadata) === null || _record$metadata2 === void 0 || (_record$metadata2 = _record$metadata2.shop_service_type) === null || _record$metadata2 === void 0 ? void 0 : _record$metadata2.server_type) || '';
        return "".concat(deliveryType, "|").concat(serverType);
      }
    }, {
      title: orderLabels.orderStatus,
      dataIndex: 'status',
      key: 'status',
      align: 'center',
      width: 150,
      render: function render(value) {
        var color = ORDER_STATUS_COLOR_MAP[value];
        var label = ORDER_STATUS_LABEL_MAP[value] || value || '-';
        return /*#__PURE__*/React.createElement("div", {
          style: {
            textAlign: 'center'
          }
        }, /*#__PURE__*/React.createElement(PisellTags, {
          style: {
            whiteSpace: 'nowrap',
            borderColor: color === null || color === void 0 ? void 0 : color.borderColor,
            color: color === null || color === void 0 ? void 0 : color.textColor
          }
        }, label));
      }
    }, {
      title: orderLabels.fulfillmentStatus,
      dataIndex: 'shipping_status',
      key: 'shipping_status',
      align: 'center',
      width: 160,
      render: function render(value) {
        var color = FULFILLMENT_STATUS_COLOR_MAP[value];
        var label = SHIPPING_STATUS_LABEL_MAP[value] || value || '-';
        return /*#__PURE__*/React.createElement("div", {
          style: {
            textAlign: 'center'
          }
        }, /*#__PURE__*/React.createElement(PisellTags, {
          style: {
            whiteSpace: 'nowrap',
            borderColor: color === null || color === void 0 ? void 0 : color.borderColor,
            color: color === null || color === void 0 ? void 0 : color.textColor
          }
        }, label));
      }
    }, {
      title: orderLabels.updated,
      key: 'last_edit_account',
      width: 132,
      align: 'center',
      render: function render(_, record) {
        var editor = record === null || record === void 0 ? void 0 : record.last_edit_account;
        var time = (editor === null || editor === void 0 ? void 0 : editor.created_at) || (record === null || record === void 0 ? void 0 : record.updated_at);
        var channel = PLATFORM_LABEL_MAP[record === null || record === void 0 ? void 0 : record.order_platform] || (record === null || record === void 0 ? void 0 : record.order_platform);
        var lines = getDisplayLines([channel]);
        return /*#__PURE__*/React.createElement("div", {
          style: {
            display: 'flex',
            flexDirection: 'column',
            alignItems: 'flex-start'
          }
        }, /*#__PURE__*/React.createElement(ClientName, {
          dataSource: editor || record.create_account,
          style: {
            fontSize: 14
          }
        }), /*#__PURE__*/React.createElement(PisellDateTimeDisplay, {
          value: time,
          layout: "inline",
          textAlign: "left",
          timeFormat: {
            padHour: true
          },
          dateFormat: {
            showYear: false,
            shortMonth: true,
            showRelativeDay: true,
            useCommaBeforeYear: false
          },
          fields: {
            fieldOrder: ['time', 'weekday', 'date']
            // inlineSeparators: [' ', ', '],
          },
          style: {
            whiteSpace: 'nowrap'
          }
        }), lines.map(function (line, index) {
          return /*#__PURE__*/React.createElement("div", {
            key: "".concat(line, "-").concat(index),
            style: textStyles.text
          }, line);
        }));
      }
    }, {
      title: orderLabels.orderId,
      dataIndex: 'id',
      key: 'id',
      align: 'center',
      width: 100,
      render: function render(value) {
        return /*#__PURE__*/React.createElement("span", {
          style: _objectSpread(_objectSpread({}, textStyles.text), {}, {
            textAlign: 'center'
          })
        }, value);
      }
    }];
  }, [staticData]);

  /**
   * 最终 perspective 配置：
   * 使用 getChildComponentProps 工厂函数，使 onRow、columns 等可访问运行时上下文。
   */
  var _perspective = useMemo(function () {
    return {
      key: 'handle',
      label: 'Handle',
      getChildComponentProps: function getChildComponentProps(ctx) {
        return {
          grid: {
            bordered: true,
            collapseUniformColumns: true,
            columns: buildColumns(ctx),
            defaultHiddenColumnKeys: ['order_origin', 'payment_status', 'delivery_type', 'status', 'shipping_status', 'last_edit_account', 'id'],
            scroll: {
              x: 'max-content',
              autoCalc: true,
              scrollToFirstRowOnChange: true
            },
            rowSelection: {
              fixed: true,
              columnWidth: 48
            },
            onRow: function onRow(record) {
              return {
                onClick: function onClick() {
                  var _ref, _record$order_id, _app$history, _app$history2;
                  var orderId = (_ref = (_record$order_id = record === null || record === void 0 ? void 0 : record.order_id) !== null && _record$order_id !== void 0 ? _record$order_id : record === null || record === void 0 ? void 0 : record.orderId) !== null && _ref !== void 0 ? _ref : record === null || record === void 0 ? void 0 : record.id;
                  var nativePage = NativePage === null || NativePage === void 0 ? void 0 : NativePage();
                  if (nativePage !== null && nativePage !== void 0 && nativePage.open && orderId != null) {
                    nativePage.open({
                      page: '/native/order/detail',
                      params: {
                        order_id: orderId
                      }
                    });
                    return;
                  }
                  var pathname = encodeURIComponent((app === null || app === void 0 || (_app$history = app.history) === null || _app$history === void 0 || (_app$history = _app$history.instance) === null || _app$history === void 0 || (_app$history = _app$history.location) === null || _app$history === void 0 ? void 0 : _app$history.pathname) || '');
                  app === null || app === void 0 || (_app$history2 = app.history) === null || _app$history2 === void 0 || _app$history2.push("/order-detail?id=".concat(record.id, "&goback=").concat(pathname));
                }
              };
            }
          },
          toolBar: {
            search: {
              showConfirmButton: false
            },
            sort: {
              list: getSortList()
            },
            quickFilter: {
              filterList: [{
                type: 'rangePicker',
                name: 'orderDate',
                key: 'orderDate',
                props: {
                  placeholder: locales.getText('pisell2.orderList.quickFilter.orderDate.label')
                }
              }]
            },
            filter: {
              hiddenQuickFilter: true,
              defaultFilterValue: {
                quickFilter: [],
                otherFilter: getFilterButtonList(),
                values: {}
              }
            }
          },
          batchActionBar: {
            overflowThreshold: 2,
            defaultActions: {
              showSelectAll: false,
              showClear: false,
              showInvert: false,
              showDelete: false
            }
          }
        };
      }
    };
  }, [buildColumns, app, locale, NativePage]);
  return _perspective;
};