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/components/eventBooking/components/Provider/Cart/Item/index.tsx
var Item_exports = {};
__export(Item_exports, {
  default: () => Item_default
});
module.exports = __toCommonJS(Item_exports);
var import_react = __toESM(require("react"));
var import_utils = require("@pisell/utils");
var import_shoppingCart = __toESM(require("../../../../../shoppingCart"));
var import_Sales = require("../../../../../Sales");
var import_SelectHolderModal = __toESM(require("../../SelectHolderModal"));
var import_ContinueButton = __toESM(require("../ContinueButton"));
var import__ = require("../../../../../index");
var import_useEngineContext = __toESM(require("../../../../../../hooks/useEngineContext"));
var import_Deposit = __toESM(require("../Deposit"));
var import_Voucher = __toESM(require("../../../Voucher"));
var import_index = require("./index.less");
var CartItem = () => {
  var _a, _b;
  const { open, holderData, selectedHolderIds } = (0, import_Sales.useHolder)();
  const {
    deleteCartItem,
    deleteCartItemByHolder,
    cartData,
    addNoteToCartItem
  } = (0, import_Sales.useCart)();
  const {
    taxTitle,
    taxRate,
    totalTaxFee,
    isPriceIncludeTax,
    total,
    deposit,
    subtotal,
    surcharge
  } = (0, import_Sales.useSummary)();
  const { isLastStep } = (0, import_Sales.useStep)();
  const context = (0, import_useEngineContext.default)();
  const { translation } = ((_a = context == null ? void 0 : context.appHelper) == null ? void 0 : _a.utils) || {};
  const handleClickCard = (e, type, key) => {
    if (type === "note") {
      return addNoteToCartItem(e);
    }
    if (type === "delete") {
      return deleteCartItem(e);
    }
    if (type === "delete_holders") {
      return deleteCartItemByHolder(key);
    }
  };
  const showDeposit = (0, import_react.useMemo)(() => {
    var _a2;
    return ((_a2 = cartData == null ? void 0 : cartData.cartItems) == null ? void 0 : _a2.length) > 0 && (deposit == null ? void 0 : deposit.hasDeposit);
  }, [(_b = cartData == null ? void 0 : cartData.cartItems) == null ? void 0 : _b.length, deposit == null ? void 0 : deposit.hasDeposit]);
  const subTotalList = (0, import_react.useMemo)(() => {
    const surchargeList = ((surcharge == null ? void 0 : surcharge.surchargeList) || []).map(
      (d, index) => {
        return {
          key: `custom_surcharge_${index}`,
          label: translation(d == null ? void 0 : d.name),
          value: d.amount
        };
      }
    );
    return [
      {
        key: "deposit",
        value: deposit == null ? void 0 : deposit.total,
        label: import_utils.locales.getText("pisell2.appointment.deposit"),
        hidden: !showDeposit
      },
      {
        key: "sub_total",
        value: subtotal
      },
      ...surchargeList,
      {
        key: "tax",
        value: totalTaxFee,
        hidden: Number(totalTaxFee) <= 0,
        tax: {
          rate: taxRate,
          is_price_include_tax: isPriceIncludeTax,
          title: taxTitle
        }
      },
      {
        key: "custom_total",
        value: total,
        label: import_utils.locales.getText("pisell2.event.total"),
        bold: !showDeposit
      }
    ];
  }, [
    total,
    subtotal,
    surcharge == null ? void 0 : surcharge.surchargeList,
    deposit == null ? void 0 : deposit.total,
    taxRate,
    isPriceIncludeTax,
    totalTaxFee,
    taxTitle,
    showDeposit
  ]);
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: `cart-item-wrap ${(0, import_utils.isMobile)() ? "cart-mobile-item-wrap" : ""}`
    },
    /* @__PURE__ */ import_react.default.createElement("div", { className: "content" }, /* @__PURE__ */ import_react.default.createElement(
      import_shoppingCart.default,
      {
        productParams: {
          products: (cartData == null ? void 0 : cartData.cartItems) || [],
          hideAddBtn: false,
          holders: (holderData == null ? void 0 : holderData.selectedHolderItems) || [],
          disabledEdit: isLastStep
        },
        collapseParams: {
          activeKey: selectedHolderIds,
          ghost: true
        },
        platform: "h5",
        emptyText: import_utils.locales.getText("pisell2.event.empty.service"),
        isOpenGroup: !!(selectedHolderIds == null ? void 0 : selectedHolderIds.length),
        onChange: (e, type, key) => handleClickCard(e, type, key)
      }
    )),
    /* @__PURE__ */ import_react.default.createElement("div", { className: "event-footer" }, /* @__PURE__ */ import_react.default.createElement(import_Voucher.default, null), /* @__PURE__ */ import_react.default.createElement(
      import__.SubTotal,
      {
        list: subTotalList,
        style: { padding: 0 },
        children: showDeposit ? /* @__PURE__ */ import_react.default.createElement(import_Deposit.default, { showTitle: false }) : null
      }
    ), /* @__PURE__ */ import_react.default.createElement(import_ContinueButton.default, null))
  ), /* @__PURE__ */ import_react.default.createElement(import_SelectHolderModal.default, { open }));
};
var Item_default = CartItem;
