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/saleDetail/components/SaleOverview/index.tsx
var SaleOverview_exports = {};
__export(SaleOverview_exports, {
  SaleOverview: () => SaleOverview
});
module.exports = __toCommonJS(SaleOverview_exports);
var import_react = __toESM(require("react"));
var import_classnames = __toESM(require("classnames"));
var import_utils = require("@pisell/utils");
var import_utils2 = require("../../utils");
var import_index = require("./index.less");
var PAYMENT_STATUS_COLOR_MAP = {
  unpaid: "#B2DDFF",
  payment_processing: "#FEDF89",
  payment_pending: "#FEDF89",
  authorized: "#ABEFC6",
  paid: "#ABEFC6",
  refunded: "#FECDCA",
  partially_refunded: "#FCCEEE",
  voided: "#D0D5DD"
};
var PAYMENT_STATUS_TEXT_KEY_MAP = {
  authorized: "pisell2.sale-detail.paymentStatus.authorized",
  paid: "pisell2.sale-detail.paymentStatus.paid",
  partially_paid: "pisell2.sale-detail.paymentStatus.partially_paid",
  partially_refunded: "pisell2.sale-detail.paymentStatus.partially_refunded",
  payment_pending: "pisell2.sale-detail.paymentStatus.payment_pending",
  refunded: "pisell2.sale-detail.paymentStatus.refunded",
  unpaid: "pisell2.sale-detail.paymentStatus.unpaid",
  voided: "pisell2.sale-detail.paymentStatus.voided",
  payment_processing: "pisell2.sale-detail.paymentStatus.payment_processing"
};
var ORDER_STATUS_COLOR_MAP = {
  open: {
    borderColor: "#1570EF",
    textColor: "#1570EF"
  },
  completed: {
    borderColor: "#079455",
    textColor: "#079455"
  },
  cancelled: {
    borderColor: "#D92D20",
    textColor: "#D92D20"
  }
};
function getPaymentStatusColor(status) {
  const key = status == null ? void 0 : status.toLowerCase();
  return key && PAYMENT_STATUS_COLOR_MAP[key] || "#D0D5DD";
}
function getPaymentStatusText(status) {
  const key = status == null ? void 0 : status.toLowerCase();
  const textKey = key && PAYMENT_STATUS_TEXT_KEY_MAP[key];
  return textKey ? import_utils.locales.getText(textKey) : status || "";
}
function getOrderStatusColor(status) {
  const key = status == null ? void 0 : status.toLowerCase();
  return key && ORDER_STATUS_COLOR_MAP[key] || ORDER_STATUS_COLOR_MAP.open;
}
function SaleOverview({
  context,
  className
}) {
  var _a;
  const { sales } = context;
  const saleInfo = (0, import_react.useMemo)(() => {
    const { tempOrder } = sales;
    return {
      orderNumber: tempOrder == null ? void 0 : tempOrder.shop_full_order_number,
      paymentStatus: (tempOrder == null ? void 0 : tempOrder.payment_status) || "",
      status: (tempOrder == null ? void 0 : tempOrder.status) || "",
      createdAt: tempOrder == null ? void 0 : tempOrder.created_at,
      updatedAt: tempOrder == null ? void 0 : tempOrder.updated_at
    };
  }, [sales]);
  const paymentStatusColor = (0, import_react.useMemo)(
    () => getPaymentStatusColor(saleInfo.paymentStatus),
    [saleInfo.paymentStatus]
  );
  const orderStatusColor = (0, import_react.useMemo)(
    () => getOrderStatusColor(saleInfo.status),
    [saleInfo.status]
  );
  if (!saleInfo.orderNumber) {
    return /* @__PURE__ */ import_react.default.createElement(
      "header",
      {
        className: (0, import_classnames.default)(
          "pisell-sale-detail-sale-overview",
          "pisell-sale-detail-sale-overview--skeleton",
          className
        )
      },
      /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-sale-detail-sale-overview__main" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-sale-detail-sale-overview__skeleton pisell-sale-detail-sale-overview__skeleton--title" }), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-sale-detail-sale-overview__meta" }, /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-sale-detail-sale-overview__skeleton pisell-sale-detail-sale-overview__skeleton--meta" }), /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-sale-detail-sale-overview__skeleton pisell-sale-detail-sale-overview__skeleton--meta pisell-sale-detail-sale-overview__skeleton--meta-secondary" }))),
      /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-sale-detail-sale-overview__status" }, /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-sale-detail-sale-overview__skeleton pisell-sale-detail-sale-overview__skeleton--badge" }))
    );
  }
  return /* @__PURE__ */ import_react.default.createElement(
    "header",
    {
      className: (0, import_classnames.default)("pisell-sale-detail-sale-overview", className)
    },
    /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-sale-detail-sale-overview__main" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-sale-detail-sale-overview__order-number" }, /* @__PURE__ */ import_react.default.createElement("span", null, sales.shop_full_order_number), ((_a = sales.tempOrder) == null ? void 0 : _a.shop_order_number) ? /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-sale-detail-sale-overview__order-number-separator" }, "/"), /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-sale-detail-sale-overview__shop-order-number" }, sales.tempOrder.shop_order_number)) : null), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-sale-detail-sale-overview__meta" }, /* @__PURE__ */ import_react.default.createElement("span", null, import_utils.locales.getText("pisell2.sale-detail.placed-at"), " ·", " ", (0, import_utils2.formatLocalizedDateTime)(saleInfo.createdAt)), saleInfo.updatedAt && saleInfo.updatedAt !== saleInfo.createdAt ? /* @__PURE__ */ import_react.default.createElement("span", null, import_utils.locales.getText("pisell2.sale-detail.updated-at"), " ·", " ", (0, import_utils2.formatLocalizedDateTime)(saleInfo.updatedAt)) : null)),
    /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-sale-detail-sale-overview__status" }, /* @__PURE__ */ import_react.default.createElement(
      "span",
      {
        className: "pisell-sale-detail-sale-overview__status-badge pisell-sale-detail-sale-overview__status-badge--payment",
        style: {
          "--pisell-sale-detail-overview-payment-color": paymentStatusColor
        }
      },
      getPaymentStatusText(saleInfo.paymentStatus)
    ))
  );
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  SaleOverview
});
