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_dayjs = __toESM(require("dayjs"));
var import_utils = require("@pisell/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 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 getOrderStatusColor(status) {
  const key = status == null ? void 0 : status.toLowerCase();
  return key && ORDER_STATUS_COLOR_MAP[key] || ORDER_STATUS_COLOR_MAP.open;
}
function formatDateTime(value) {
  if (!value) return "-";
  const date = (0, import_dayjs.default)(value);
  return date.isValid() ? date.format("DD/MM/YYYY HH:mm") : value;
}
function SaleOverview({
  context,
  className
}) {
  const saleInfo = (0, import_react.useMemo)(() => {
    const { tempOrder } = context.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
    };
  }, [context]);
  const paymentStatusColor = (0, import_react.useMemo)(
    () => getPaymentStatusColor(saleInfo.paymentStatus),
    [saleInfo.paymentStatus]
  );
  const orderStatusColor = (0, import_react.useMemo)(
    () => getOrderStatusColor(saleInfo.status),
    [saleInfo.status]
  );
  const paymentStatusMap = (0, import_react.useMemo)(
    () => ({
      authorized: import_utils.locales.getText(
        "pisell2.sale-detail.paymentStatus.authorized"
      ),
      paid: import_utils.locales.getText("pisell2.sale-detail.paymentStatus.paid"),
      partially_paid: import_utils.locales.getText(
        "pisell2.sale-detail.paymentStatus.partially_paid"
      ),
      partially_refunded: import_utils.locales.getText(
        "pisell2.sale-detail.paymentStatus.partially_refunded"
      ),
      payment_pending: import_utils.locales.getText(
        "pisell2.sale-detail.paymentStatus.payment_pending"
      ),
      refunded: import_utils.locales.getText("pisell2.sale-detail.paymentStatus.refunded"),
      unpaid: import_utils.locales.getText("pisell2.sale-detail.paymentStatus.unpaid"),
      voided: import_utils.locales.getText("pisell2.sale-detail.paymentStatus.voided"),
      payment_processing: import_utils.locales.getText(
        "pisell2.sale-detail.paymentStatus.payment_processing"
      )
    }),
    []
  );
  const orderStatusMap = (0, import_react.useMemo)(
    () => ({
      open: import_utils.locales.getText("pisell2.sale-detail.orderStatus.open"),
      completed: import_utils.locales.getText("pisell2.sale-detail.orderStatus.completed"),
      cancelled: import_utils.locales.getText("pisell2.sale-detail.orderStatus.cancelled")
    }),
    []
  );
  if (!saleInfo.orderNumber) {
    return null;
  }
  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" }, saleInfo.orderNumber), /* @__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"), " ·", " ", formatDateTime(saleInfo.createdAt)))),
    /* @__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
        }
      },
      paymentStatusMap[saleInfo.paymentStatus] || saleInfo.paymentStatus
    ))
  );
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  SaleOverview
});
