var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/plus/pisellSalesManagement/hooks/useOrderPerspective.tsx
var useOrderPerspective_exports = {};
__export(useOrderPerspective_exports, {
  useOrderPerspective: () => useOrderPerspective
});
module.exports = __toCommonJS(useOrderPerspective_exports);
var import_react = __toESM(require("react"));
var import_materials = require("@pisell/materials");
var import_utils = require("@pisell/utils");
var import_useEngineContext = __toESM(require("../../../hooks/useEngineContext"));
var import_clientName = __toESM(require("../../clientName"));
var import_order = require("../config/order");
var import_config = require("../config");
var import_perspectiveUtils = require("./perspectiveUtils");
var import_BookingNotesPreview = __toESM(require("../components/BookingNotesPreview"));
var import_serve = require("../serve");
function pickContactPayload(raw) {
  const first = Array.isArray(raw) ? raw[0] : raw;
  if ((first == null ? void 0 : first.value) && typeof first.value === "object") {
    return first.value;
  }
  if (first && typeof first === "object") {
    return first;
  }
  return {};
}
function resolveOrderContactInfo(record, contactValue) {
  var _a, _b;
  const fromValue = pickContactPayload(contactValue);
  const fromSnake = pickContactPayload(record == null ? void 0 : record.contacts_info);
  const fromCamel = pickContactPayload(record == null ? void 0 : record.contactsInfo);
  const contact = Object.keys(fromValue).length ? fromValue : Object.keys(fromSnake).length ? fromSnake : fromCamel;
  const firstName = String((contact == null ? void 0 : contact.first_name) || "").trim();
  const lastName = String((contact == null ? void 0 : contact.last_name) || "").trim();
  const displayName = String(
    (contact == null ? void 0 : contact.display_name) || `${firstName} ${lastName}`
  ).trim();
  const phone = typeof (contact == null ? void 0 : contact.phone) === "string" ? contact.phone : ((_a = contact == null ? void 0 : contact.phone) == null ? void 0 : _a.phone) || ((_b = contact == null ? void 0 : contact.phone) == null ? void 0 : _b.value) || (contact == null ? void 0 : contact.mobile) || (contact == null ? void 0 : contact.phone_number) || "";
  const email = (contact == null ? void 0 : contact.email) || "";
  return {
    displayName,
    phone,
    email
  };
}
function resolveShippingMethodDisplay(record, maps) {
  var _a, _b, _c, _d, _e, _f, _g;
  const deliveryType = (record == null ? void 0 : record.delivery_type) || (record == null ? void 0 : record.shipping_type) || /**
   * 新结构兼容：部分 delivery 订单未下发 delivery_type，
   * 但会给 `type=delivery` / `business_code=delivery`。
   * 该场景按本地配送展示。
   *
   * @example
   * resolveShippingMethodDisplay({ type: 'delivery' }, maps)?.label
   */
  ((record == null ? void 0 : record.type) === "delivery" || (record == null ? void 0 : record.business_code) === "delivery" ? "local_delivery" : void 0);
  const serverType = ((_b = (_a = record == null ? void 0 : record.metadata) == null ? void 0 : _a.shop_service_type) == null ? void 0 : _b.server_type) || ((_c = record == null ? void 0 : record.shop_service_type) == null ? void 0 : _c.server_type) || (record == null ? void 0 : record.shop_service_type);
  if (deliveryType === "shop_service" || deliveryType == null && serverType) {
    const label2 = (_d = maps.shopServiceTypeLabelMap) == null ? void 0 : _d[serverType];
    if (!label2) return null;
    return {
      label: label2,
      color: (_e = import_order.SHOP_SERVICE_TYPE_COLOR_MAP) == null ? void 0 : _e[serverType]
    };
  }
  const label = (_f = maps.deliveryTypeLabelMap) == null ? void 0 : _f[deliveryType];
  if (!label || deliveryType === "nil") return null;
  return {
    label,
    color: (_g = import_order.DELIVERY_TYPE_COLOR_MAP) == null ? void 0 : _g[deliveryType]
  };
}
function resolveOrderItemsCount(record) {
  var _a;
  const topLevelCount = Number(record == null ? void 0 : record.product_quantity);
  if (Number.isFinite(topLevelCount) && topLevelCount >= 0) {
    return topLevelCount;
  }
  const summaryCount = Number((_a = record == null ? void 0 : record.summary) == null ? void 0 : _a.product_quantity);
  if (Number.isFinite(summaryCount) && summaryCount >= 0) {
    return summaryCount;
  }
  const products = Array.isArray(record == null ? void 0 : record.products) ? record.products : [];
  if (products.length === 0) return 0;
  return products.reduce((sum, item) => {
    const qty = Number((item == null ? void 0 : item.product_quantity) ?? (item == null ? void 0 : item.quantity) ?? 0);
    if (!Number.isFinite(qty) || qty <= 0) return sum;
    return sum + qty;
  }, 0);
}
function resolveOrderActorDisplay(record, preferredActor) {
  const candidate = preferredActor || (record == null ? void 0 : record.last_edit_account) || (record == null ? void 0 : record.create_account) || (record == null ? void 0 : record.customer);
  if (candidate && typeof candidate === "object") {
    const displayName = String(
      (candidate == null ? void 0 : candidate.display_name) || (candidate == null ? void 0 : candidate.customer_name) || [candidate == null ? void 0 : candidate.first_name, candidate == null ? void 0 : candidate.last_name].filter(Boolean).join(" ")
    ).trim();
    if (displayName) {
      return {
        ...candidate,
        display_name: displayName
      };
    }
  }
  if ((record == null ? void 0 : record.customer_name) || (record == null ? void 0 : record.phone) || (record == null ? void 0 : record.email)) {
    return {
      display_name: (record == null ? void 0 : record.customer_name) || "",
      phone: (record == null ? void 0 : record.phone) || "",
      country_calling_code: (record == null ? void 0 : record.country_calling_code) || "",
      email: (record == null ? void 0 : record.email) || ""
    };
  }
  return null;
}
function resolveOrderPaymentAmounts(record) {
  var _a, _b;
  const summaryTotal = Number((_a = record == null ? void 0 : record.summary) == null ? void 0 : _a.total_amount);
  const topLevelTotal = Number(record == null ? void 0 : record.total_amount);
  const totalAmount = Number.isFinite(summaryTotal) ? summaryTotal : Number.isFinite(topLevelTotal) ? topLevelTotal : 0;
  const topLevelPaid = Number(record == null ? void 0 : record.paid_amount);
  const topLevelRefunded = Number((record == null ? void 0 : record.total_refund_amount) || ((_b = record == null ? void 0 : record.summary) == null ? void 0 : _b.total_refund_amount) || 0);
  const payments = Array.isArray(record == null ? void 0 : record.payments) ? record.payments : [];
  const paidFromPayments = payments.reduce((sum, item) => {
    const status = String((item == null ? void 0 : item.status) || "").toLowerCase();
    if (!["paid", "captured", "success", "completed"].includes(status)) {
      return sum;
    }
    const amount = Number((item == null ? void 0 : item.amount) ?? (item == null ? void 0 : item.origin_amount) ?? 0);
    if (!Number.isFinite(amount) || amount <= 0) return sum;
    return sum + amount;
  }, 0);
  const refundedFromPayments = payments.reduce((sum, item) => {
    const status = String((item == null ? void 0 : item.status) || "").toLowerCase();
    if (!["refunded", "partially_refunded", "refund"].includes(status)) {
      return sum;
    }
    const amount = Number((item == null ? void 0 : item.amount) ?? (item == null ? void 0 : item.origin_amount) ?? 0);
    if (!Number.isFinite(amount) || amount <= 0) return sum;
    return sum + amount;
  }, 0);
  const paidAmount = Number.isFinite(topLevelPaid) ? topLevelPaid : paidFromPayments;
  const refundedAmount = Number.isFinite(topLevelRefunded) ? topLevelRefunded : refundedFromPayments;
  const dueAmount = Math.max(totalAmount - paidAmount, 0);
  return {
    totalAmount,
    paidAmount,
    refundedAmount,
    dueAmount
  };
}
var useOrderPerspective = () => {
  var _a, _b, _c, _d, _e, _f, _g;
  const context = (0, import_useEngineContext.default)();
  const app = (_c = (_b = (_a = context == null ? void 0 : context.appHelper) == null ? void 0 : _a.utils) == null ? void 0 : _b.getApp) == null ? void 0 : _c.call(_b);
  const NativePage = (_e = (_d = context == null ? void 0 : context.appHelper) == null ? void 0 : _d.utils) == null ? void 0 : _e.NativePage;
  const locale = (_g = (_f = context == null ? void 0 : context.engine) == null ? void 0 : _f.props) == null ? void 0 : _g.locale;
  const staticData = (0, import_react.useMemo)(() => {
    const PAYMENT_STATUS_LABEL_MAP = (0, import_order.getPaymentStatusMap)();
    const PLATFORM_LABEL_MAP = (0, import_order.getPlatformMap)();
    const ORDER_STATUS_LABEL_MAP = (0, import_order.getOrderStatusMap)();
    const SHIPPING_STATUS_LABEL_MAP = (0, import_order.getShippingStatusMap)();
    const DELIVERY_TYPE_LABEL_MAP = (0, import_order.getDeliveryTypeMap)();
    const SHOP_SERVICE_TYPE_LABEL_MAP = (0, import_order.getShopServiceTypeMap)();
    const BUSINESS_LABEL_MAP = (0, import_config.getBusinessLabelMap)();
    const orderLabels = (0, import_order.getOrderHeaderLabels)();
    const amountLabels = {
      total: import_utils.locales.getText("pisell2.orderList.common.totalAmount"),
      paid: import_utils.locales.getText("pisell2.orderList.common.paidAmount"),
      due: import_utils.locales.getText("pisell2.orderList.common.dueAmount"),
      refunded: import_utils.locales.getText("pisell2.orderList.common.refundedAmount"),
      items: import_utils.locales.getText("pisell2.orderList.common.itemsCount")
    };
    return {
      PAYMENT_STATUS_LABEL_MAP,
      PLATFORM_LABEL_MAP,
      ORDER_STATUS_LABEL_MAP,
      SHIPPING_STATUS_LABEL_MAP,
      DELIVERY_TYPE_LABEL_MAP,
      SHOP_SERVICE_TYPE_LABEL_MAP,
      BUSINESS_LABEL_MAP,
      orderLabels,
      amountLabels
    };
  }, [locale]);
  const buildColumns = (0, import_react.useCallback)(
    (ctx) => {
      const {
        PAYMENT_STATUS_LABEL_MAP,
        PLATFORM_LABEL_MAP,
        ORDER_STATUS_LABEL_MAP,
        SHIPPING_STATUS_LABEL_MAP,
        DELIVERY_TYPE_LABEL_MAP,
        SHOP_SERVICE_TYPE_LABEL_MAP,
        BUSINESS_LABEL_MAP,
        orderLabels,
        amountLabels
      } = staticData;
      return [
        {
          title: orderLabels.saleBrief,
          key: "sale_brief",
          width: 225,
          // fixed: 'left',
          render: (_, record) => {
            const orderCode = record == null ? void 0 : record.shop_full_order_number;
            const currencySymbol = record == null ? void 0 : record.currency_symbol;
            const { totalAmount } = resolveOrderPaymentAmounts(record);
            const paymentStatus = record == null ? void 0 : record.payment_status;
            const orderNote = record == null ? void 0 : record.note;
            const internalNotes = record == null ? void 0 : record.internal_note;
            const noteApis = (0, import_serve.createNoteApis)(
              (record == null ? void 0 : record.id) || (record == null ? void 0 : record.order_id) || (record == null ? void 0 : record.orderId)
            );
            const tags = (record == null ? void 0 : record.tag) || (record == null ? void 0 : record.tags) || [];
            const paymentLabel = PAYMENT_STATUS_LABEL_MAP[paymentStatus] || paymentStatus || "-";
            const paymentColor = import_order.PAYMENT_STATUS_COLOR_MAP[paymentStatus] || "";
            return /* @__PURE__ */ import_react.default.createElement(
              "div",
              {
                className: "pisell-sales-grid-sale-brief",
                style: { display: "flex", flexDirection: "column" }
              },
              /* @__PURE__ */ import_react.default.createElement(
                "div",
                {
                  style: {
                    fontWeight: "bold",
                    textDecoration: "underline",
                    color: "var(--theme-color, #7f56d9)"
                  }
                },
                orderCode
              ),
              Array.isArray(tags) && tags.length > 0 ? /* @__PURE__ */ import_react.default.createElement("div", { style: { display: "flex", gap: 4, flexWrap: "wrap" } }, tags.map((item) => /* @__PURE__ */ import_react.default.createElement(
                import_perspectiveUtils.Tag,
                {
                  key: `${item == null ? void 0 : item.id}`,
                  style: {
                    margin: 0,
                    maxWidth: 160,
                    whiteSpace: "nowrap",
                    overflow: "hidden",
                    textOverflow: "ellipsis",
                    fontWeight: 500
                  }
                },
                item == null ? void 0 : item.name
              ))) : null,
              /* @__PURE__ */ import_react.default.createElement("div", { style: { fontWeight: "bold" } }, /* @__PURE__ */ import_react.default.createElement("span", { style: { marginRight: 6 } }, amountLabels.total, ":"), /* @__PURE__ */ import_react.default.createElement("span", null, (0, import_perspectiveUtils.formatAmount)(totalAmount, currencySymbol))),
              /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement(
                import_perspectiveUtils.Tag,
                {
                  style: {
                    backgroundColor: paymentColor,
                    whiteSpace: "nowrap",
                    border: "none",
                    fontWeight: 500
                  }
                },
                paymentLabel
              )),
              /* @__PURE__ */ import_react.default.createElement(
                import_BookingNotesPreview.default,
                {
                  dataSource: {
                    note: orderNote,
                    internalNotes,
                    apis: noteApis,
                    onChange: (value, type, noteType) => {
                      ctx.refresh();
                    }
                  },
                  labels: {
                    orderNote: orderLabels.orderNote,
                    internalNote: orderLabels.internalNote
                  },
                  style: {
                    maxWidth: "100%"
                  }
                }
              )
            );
          }
        },
        {
          title: orderLabels.customer,
          key: "customer",
          align: "center",
          width: 150,
          uniformCompare: (value, record) => {
            const customer = record == null ? void 0 : record.customer;
            if (!customer) return "-";
            const guestCode = customer == null ? void 0 : customer.guest_code;
            if (guestCode) return `${guestCode}`;
            if (customer.user_id === 1) return "walk-in";
            return customer;
          },
          render: (_, record) => {
            const customer = record == null ? void 0 : record.customer;
            if (!customer) return "-";
            const guestCode = customer == null ? void 0 : customer.guest_code;
            if (guestCode) {
              return /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-sales-grid-person-cell" }, /* @__PURE__ */ import_react.default.createElement("div", { style: { fontWeight: "bold" } }, orderLabels.guest));
            }
            const phone = (0, import_perspectiveUtils.formatPhone)(
              (customer == null ? void 0 : customer.phone) || (record == null ? void 0 : record.phone),
              (customer == null ? void 0 : customer.country_calling_code) || (record == null ? void 0 : record.country_calling_code)
            );
            const lines = (0, import_perspectiveUtils.getDisplayLines)([phone, customer == null ? void 0 : customer.email]);
            return /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-sales-grid-person-cell" }, /* @__PURE__ */ import_react.default.createElement(import_clientName.default, { dataSource: customer, style: { fontSize: 14 } }), lines.map((line, index) => /* @__PURE__ */ import_react.default.createElement("div", { key: `${line}-${index}`, style: import_perspectiveUtils.textStyles.text }, line)));
          }
        },
        {
          title: orderLabels.contact,
          dataIndex: "contacts_info",
          key: "contacts_info",
          align: "center",
          width: 150,
          uniformCompare: (value, record) => {
            if (!value) return "-";
            return value;
          },
          render: (value, record) => {
            const info = resolveOrderContactInfo(record, value);
            if (!(info == null ? void 0 : info.displayName) && !(info == null ? void 0 : info.phone) && !(info == null ? void 0 : info.email)) return "-";
            const phone = (0, import_perspectiveUtils.formatPhone)(info == null ? void 0 : info.phone);
            const lines = (0, import_perspectiveUtils.getDisplayLines)([phone, info == null ? void 0 : info.email]);
            return /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-sales-grid-person-cell" }, /* @__PURE__ */ import_react.default.createElement(
              import_clientName.default,
              {
                dataSource: { display_name: info == null ? void 0 : info.displayName },
                style: { fontSize: 14 }
              }
            ), lines.map((line, index) => /* @__PURE__ */ import_react.default.createElement("div", { key: `${line}-${index}`, style: import_perspectiveUtils.textStyles.text }, line)));
          }
        },
        {
          title: orderLabels.paymentInfo,
          key: "payment_info",
          width: 124,
          align: "center",
          render: (_, record) => {
            const value = record == null ? void 0 : record.payment_status;
            const currencySymbol = record == null ? void 0 : record.currency_symbol;
            const { totalAmount, paidAmount, refundedAmount, dueAmount } = resolveOrderPaymentAmounts(record);
            const amountStyles = {
              due: {
                fontWeight: "bold",
                color: "#D92D20"
              },
              refunded: {
                color: "#CA8504",
                fontWeight: "bold"
              }
            };
            const lines = [];
            if (["payment_processing", "unpaid", "partially_paid"].includes(value)) {
              lines.push({
                label: amountLabels.due,
                value: (0, import_perspectiveUtils.formatAmount)(dueAmount, currencySymbol),
                bold: true,
                kind: "due"
              });
              lines.push({
                label: amountLabels.total,
                value: (0, import_perspectiveUtils.formatAmount)(totalAmount, currencySymbol),
                kind: "total"
              });
            } else if (value === "paid") {
              lines.push({
                label: amountLabels.paid,
                value: (0, import_perspectiveUtils.formatAmount)(paidAmount, currencySymbol),
                bold: true,
                kind: "paid"
              });
              lines.push({
                label: amountLabels.total,
                value: (0, import_perspectiveUtils.formatAmount)(totalAmount, currencySymbol),
                kind: "total"
              });
            } else if (["partially_refunded", "refunded"].includes(value)) {
              lines.push({
                label: amountLabels.refunded,
                value: (0, import_perspectiveUtils.formatAmount)(refundedAmount, currencySymbol),
                bold: true,
                kind: "refunded"
              });
              lines.push({
                label: amountLabels.paid,
                value: (0, import_perspectiveUtils.formatAmount)(paidAmount, currencySymbol),
                kind: "paid"
              });
              lines.push({
                label: amountLabels.total,
                value: (0, import_perspectiveUtils.formatAmount)(totalAmount, currencySymbol),
                kind: "total"
              });
            } else if (["voided", "authorized"].includes(value)) {
              lines.push({
                label: amountLabels.total,
                value: (0, import_perspectiveUtils.formatAmount)(totalAmount, currencySymbol),
                bold: true,
                kind: "total"
              });
            } else {
              lines.push({
                label: amountLabels.total,
                value: (0, import_perspectiveUtils.formatAmount)(totalAmount, currencySymbol),
                bold: true,
                kind: "total"
              });
            }
            return /* @__PURE__ */ import_react.default.createElement(
              "div",
              {
                style: {
                  display: "flex",
                  flexDirection: "column",
                  gap: 4,
                  alignItems: "flex-start"
                }
              },
              lines.map((line) => /* @__PURE__ */ import_react.default.createElement("div", { key: line.label, style: import_perspectiveUtils.textStyles.text }, /* @__PURE__ */ import_react.default.createElement(
                "span",
                {
                  style: {
                    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: (_, record) => {
            const count = resolveOrderItemsCount(record);
            return /* @__PURE__ */ import_react.default.createElement("span", { style: { ...import_perspectiveUtils.textStyles.text, textAlign: "center" } }, count, amountLabels.items);
          }
        },
        {
          title: orderLabels.orderOrigin,
          key: "order_origin",
          width: 138,
          align: "center",
          render: (_, record) => {
            const channel = PLATFORM_LABEL_MAP[record == null ? void 0 : record.order_sales_channel] || PLATFORM_LABEL_MAP[record == null ? void 0 : record.order_platform] || (record == null ? void 0 : record.order_sales_channel) || (record == null ? void 0 : record.order_platform);
            const device = (record == null ? void 0 : record.device_name) || (record == null ? void 0 : record.device) || (record == null ? void 0 : record.terminal);
            const time = (record == null ? void 0 : record.created_at) || (record == null ? void 0 : record.order_time);
            const actor = resolveOrderActorDisplay(record, record == null ? void 0 : record.create_account);
            const lines = (0, import_perspectiveUtils.getDisplayLines)([channel, device]);
            if (lines.length === 0) {
              return null;
            }
            const businessLabel = BUSINESS_LABEL_MAP[record.business_code];
            return /* @__PURE__ */ import_react.default.createElement(
              "div",
              {
                style: {
                  display: "flex",
                  flexDirection: "column",
                  alignItems: "flex-start"
                }
              },
              businessLabel ? /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement(
                import_perspectiveUtils.Tag,
                {
                  color: import_config.BUSINESS_COLOR_MAP[record.business_code],
                  style: {
                    color: "black",
                    fontWeight: 500
                  }
                },
                businessLabel
              )) : null,
              lines.map((line, index) => /* @__PURE__ */ import_react.default.createElement("div", { key: `${line}-${index}`, style: import_perspectiveUtils.textStyles.text }, line)),
              /* @__PURE__ */ import_react.default.createElement(
                "div",
                {
                  style: {
                    display: "flex",
                    alignItems: "center",
                    whiteSpace: "nowrap"
                  }
                },
                /* @__PURE__ */ import_react.default.createElement("span", null, orderLabels.createdBy, ":"),
                actor ? /* @__PURE__ */ import_react.default.createElement(import_clientName.default, { dataSource: actor, style: { fontSize: 14 } }) : /* @__PURE__ */ import_react.default.createElement("span", { style: { ...import_perspectiveUtils.textStyles.text, marginLeft: 4 } }, "-")
              ),
              /* @__PURE__ */ import_react.default.createElement(
                import_materials.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: (value) => {
            const key = value === "partially_paid" ? "unpaid" : value;
            const label = PAYMENT_STATUS_LABEL_MAP[key] || value || "-";
            const color = import_order.PAYMENT_STATUS_COLOR_MAP[key] || "";
            return /* @__PURE__ */ import_react.default.createElement("div", { style: { textAlign: "center" } }, /* @__PURE__ */ import_react.default.createElement(
              import_materials.PisellTags,
              {
                style: {
                  backgroundColor: color,
                  whiteSpace: "nowrap"
                }
              },
              label
            ));
          }
        },
        {
          title: orderLabels.shippingMethod,
          key: "delivery_type",
          align: "center",
          width: 160,
          render: (_, record) => {
            const method = resolveShippingMethodDisplay(record, {
              shopServiceTypeLabelMap: SHOP_SERVICE_TYPE_LABEL_MAP,
              deliveryTypeLabelMap: DELIVERY_TYPE_LABEL_MAP
            });
            if (!method) return "-";
            return /* @__PURE__ */ import_react.default.createElement("div", { style: { textAlign: "center" } }, /* @__PURE__ */ import_react.default.createElement(
              import_perspectiveUtils.Tag,
              {
                style: { whiteSpace: "nowrap", fontWeight: 500 },
                color: method.color
              },
              method.label
            ));
          },
          uniformCompare: (_, record) => {
            var _a2, _b2;
            const deliveryType = (record == null ? void 0 : record.delivery_type) || "";
            const serverType = ((_b2 = (_a2 = record == null ? void 0 : record.metadata) == null ? void 0 : _a2.shop_service_type) == null ? void 0 : _b2.server_type) || "";
            return `${deliveryType}|${serverType}`;
          }
        },
        {
          title: orderLabels.orderStatus,
          dataIndex: "status",
          key: "status",
          align: "center",
          width: 150,
          render: (value) => {
            const color = import_order.ORDER_STATUS_COLOR_MAP[value];
            const label = ORDER_STATUS_LABEL_MAP[value] || value || "-";
            return /* @__PURE__ */ import_react.default.createElement("div", { style: { textAlign: "center" } }, /* @__PURE__ */ import_react.default.createElement(
              import_materials.PisellTags,
              {
                style: {
                  whiteSpace: "nowrap",
                  borderColor: color == null ? void 0 : color.borderColor,
                  color: color == null ? void 0 : color.textColor
                }
              },
              label
            ));
          }
        },
        {
          title: orderLabels.fulfillmentStatus,
          dataIndex: "shipping_status",
          key: "shipping_status",
          align: "center",
          width: 160,
          render: (value) => {
            const color = import_order.FULFILLMENT_STATUS_COLOR_MAP[value];
            const label = SHIPPING_STATUS_LABEL_MAP[value] || value || "-";
            return /* @__PURE__ */ import_react.default.createElement("div", { style: { textAlign: "center" } }, /* @__PURE__ */ import_react.default.createElement(
              import_materials.PisellTags,
              {
                style: {
                  whiteSpace: "nowrap",
                  borderColor: color == null ? void 0 : color.borderColor,
                  color: color == null ? void 0 : color.textColor
                }
              },
              label
            ));
          }
        },
        {
          title: orderLabels.updated,
          key: "last_edit_account",
          width: 132,
          align: "center",
          render: (_, record) => {
            var _a2;
            const editor = resolveOrderActorDisplay(
              record,
              record == null ? void 0 : record.last_edit_account
            );
            const time = ((_a2 = record == null ? void 0 : record.last_edit_account) == null ? void 0 : _a2.created_at) || (editor == null ? void 0 : editor.updated_at) || (record == null ? void 0 : record.updated_at);
            const channel = PLATFORM_LABEL_MAP[record == null ? void 0 : record.order_platform] || (record == null ? void 0 : record.order_platform);
            const lines = (0, import_perspectiveUtils.getDisplayLines)([channel]);
            return /* @__PURE__ */ import_react.default.createElement(
              "div",
              {
                style: {
                  display: "flex",
                  flexDirection: "column",
                  alignItems: "flex-start"
                }
              },
              editor ? /* @__PURE__ */ import_react.default.createElement(import_clientName.default, { dataSource: editor, style: { fontSize: 14 } }) : /* @__PURE__ */ import_react.default.createElement("div", { style: { ...import_perspectiveUtils.textStyles.text } }, "-"),
              /* @__PURE__ */ import_react.default.createElement(
                import_materials.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((line, index) => /* @__PURE__ */ import_react.default.createElement("div", { key: `${line}-${index}`, style: import_perspectiveUtils.textStyles.text }, line))
            );
          }
        },
        {
          title: orderLabels.orderId,
          dataIndex: "order_id",
          key: "order_id",
          align: "center",
          width: 100,
          /**
           * Order ID 显示兼容：
           * - osServer 本地订单主键优先 `order_id`
           * - 兼容历史字段 `orderId`
           * - 最后回退 `id`
           *
           * @example
           * // record = { order_id: 1001 } => 1001
           * // record = { orderId: 1002 } => 1002
           * // record = { id: 1003 } => 1003
           */
          render: (_value, record) => {
            const orderId = record == null ? void 0 : record.shop_order_number;
            return /* @__PURE__ */ import_react.default.createElement("span", { style: { ...import_perspectiveUtils.textStyles.text, textAlign: "center" } }, orderId);
          }
        }
      ];
    },
    [staticData]
  );
  const _perspective = (0, import_react.useMemo)(
    () => ({
      key: "handle",
      label: "Handle",
      getChildComponentProps: (ctx) => ({
        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: (record) => ({
            onClick: () => {
              var _a2, _b2, _c2, _d2;
              const orderId = (record == null ? void 0 : record.order_id) ?? (record == null ? void 0 : record.orderId) ?? (record == null ? void 0 : record.id);
              const nativePage = NativePage == null ? void 0 : NativePage();
              if ((nativePage == null ? void 0 : nativePage.open) && orderId != null) {
                nativePage.open({
                  page: "/native/order/detail",
                  params: { order_id: orderId }
                });
                return;
              }
              const pathname = encodeURIComponent(
                ((_c2 = (_b2 = (_a2 = app == null ? void 0 : app.history) == null ? void 0 : _a2.instance) == null ? void 0 : _b2.location) == null ? void 0 : _c2.pathname) || ""
              );
              (_d2 = app == null ? void 0 : app.history) == null ? void 0 : _d2.push(
                `/order-detail?id=${record.id}&goback=${pathname}`
              );
            }
          })
        },
        toolBar: {
          search: { showConfirmButton: false },
          sort: { list: (0, import_order.getSortList)() },
          quickFilter: {
            filterList: [
              {
                type: "rangePicker",
                name: "orderDate",
                key: "orderDate",
                props: {
                  placeholder: import_utils.locales.getText(
                    "pisell2.orderList.quickFilter.orderDate.placeholder"
                  )
                }
              }
            ]
          },
          filter: {
            hiddenQuickFilter: true,
            defaultFilterValue: {
              quickFilter: [],
              otherFilter: (0, import_order.getFilterButtonList)(),
              values: {}
            }
          }
        },
        batchActionBar: {
          overflowThreshold: 2,
          defaultActions: {
            showSelectAll: false,
            showClear: false,
            showInvert: false,
            showDelete: false
          }
        }
      })
    }),
    [buildColumns, app, locale, NativePage]
  );
  return _perspective;
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  useOrderPerspective
});
