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/CartItems/index.tsx
var CartItems_exports = {};
__export(CartItems_exports, {
  CartItems: () => CartItems
});
module.exports = __toCommonJS(CartItems_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_utils = require("@pisell/utils");
var import_materials = require("@pisell/materials");
var import_pisellNumberSelector = __toESM(require("../../../../pro/pisellNumberSelector"));
var import_index = require("./index.less");
var { LineItem } = import_materials.ProductCard;
var STATUS_OPTIONS = [
  {
    key: "new",
    labelKey: "pisell2.sale-detail.status.new",
    color: "#91caff"
  },
  {
    key: "confirmed",
    labelKey: "pisell2.sale-detail.status.confirmed",
    color: "#b7eb8f"
  },
  {
    key: "arrived",
    labelKey: "pisell2.sale-detail.status.arrived",
    color: "#d3adf7"
  },
  {
    key: "started",
    labelKey: "pisell2.sale-detail.status.started",
    color: "#fffb8f"
  },
  {
    key: "cancelled",
    labelKey: "pisell2.sale-detail.status.cancelled",
    color: "#bfbfbf",
    danger: true
  },
  {
    key: "no_show",
    labelKey: "pisell2.sale-detail.status.no_show",
    color: "#ffa39e",
    danger: true
  },
  {
    key: "completed",
    labelKey: "pisell2.sale-detail.status.completed",
    color: "#ffd591"
  }
];
var getBookingQuantity = (item) => {
  var _a, _b;
  return ((_b = (_a = item == null ? void 0 : item._extend) == null ? void 0 : _a.product) == null ? void 0 : _b.num) ?? (item == null ? void 0 : item.num) ?? (item == null ? void 0 : item.number) ?? 1;
};
function CartItems({ dataSource, sales, className }) {
  const [statusLoading, setStatusLoading] = (0, import_react.useState)(false);
  const cart = Array.isArray(dataSource) ? { bookings: [], items: dataSource } : dataSource || { bookings: [], items: [] };
  const bookings = cart.bookings || [];
  const items = cart.items || [];
  const statusOptions = (0, import_react.useMemo)(
    () => STATUS_OPTIONS.map((option) => ({
      key: option.key,
      label: import_utils.locales.getText(option.labelKey),
      color: option.color,
      danger: option.danger
    })),
    []
  );
  const handleBookingStatusChange = (0, import_react.useCallback)(
    async (status) => {
      const next = status.trim();
      if (!next) {
        import_antd.message.error(import_utils.locales.getText("pisell2.sale-detail.status-empty-error"));
        return;
      }
      if (!(sales == null ? void 0 : sales.setBookingStatus)) return;
      setStatusLoading(true);
      try {
        await sales.setBookingStatus(next);
        import_antd.message.success(import_utils.locales.getText("pisell1.text.edit-status-success"));
      } catch (e) {
        import_antd.message.error(String((e == null ? void 0 : e.message) ?? e));
      } finally {
        setStatusLoading(false);
      }
    },
    [sales]
  );
  const renderQuantityAction = (item) => [
    {
      key: "update_number",
      text: /* @__PURE__ */ import_react.default.createElement(
        import_pisellNumberSelector.default,
        {
          enablePriceAdjust: true,
          min: 1,
          className: "pisell-sale-detail-cart-items__quantity-selector",
          value: getBookingQuantity(item),
          onChange: () => {
          }
        }
      ),
      color: "#667085"
    }
  ];
  return /* @__PURE__ */ import_react.default.createElement(
    "section",
    {
      className: className ? `pisell-sale-detail-cart-items ${className}` : "pisell-sale-detail-cart-items"
    },
    bookings.map((item) => {
      var _a;
      return /* @__PURE__ */ import_react.default.createElement(
        LineItem,
        {
          key: ((_a = item.metadata) == null ? void 0 : _a.unique_identification_number) || item.booking_id,
          itemType: "booking",
          type: "a9",
          rightActions: renderQuantityAction(item),
          escapeDom: ".pisell-number-selector-popover",
          dataSource: item,
          statusOptions,
          statusLoading,
          onBookingStatusChange: void 0,
          onAction: () => {
          },
          onDelete: () => {
          },
          onNote: () => {
          },
          onCard: () => {
          },
          onPromotion: () => {
          },
          isShowNote: true,
          disabledEdit: true,
          isShowDelete: false,
          isShowAmountFooter: true,
          isShowImage: true,
          maxSpecsCount: 1,
          scenario: "booking2",
          onGift: () => {
          }
        }
      );
    }),
    items.map((item) => {
      var _a;
      return /* @__PURE__ */ import_react.default.createElement(
        LineItem,
        {
          key: ((_a = item.metadata) == null ? void 0 : _a.unique_identification_number) || item.order_detail_id || item.product_id,
          itemType: "product",
          type: "a9",
          rightActions: renderQuantityAction(item),
          escapeDom: ".pisell-number-selector-popover",
          dataSource: item,
          onAction: () => {
          },
          onDelete: () => {
          },
          onNote: () => {
          },
          onLike: () => {
          },
          onEditProduct: () => {
          },
          onCard: () => {
          },
          onChangeResource: () => {
          },
          onChangeHolder: () => {
          },
          onAddHolder: () => {
          },
          isShowNote: true,
          isShowPackageNote: true,
          disabledEdit: true,
          isShowChangeResource: false,
          isShowChangeHolder: false,
          isShowDelete: false,
          isShowHolder: false,
          isShowAddHolderButton: false,
          isShowEditProduct: false,
          isShowAmountFooter: true,
          isShowImage: true,
          maxSpecsCount: 1,
          scenario: "booking2",
          onGift: () => {
          }
        }
      );
    })
  );
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  CartItems
});
