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/booking/info/service2/Lists.tsx
var Lists_exports = {};
__export(Lists_exports, {
  default: () => Lists_default
});
module.exports = __toCommonJS(Lists_exports);
var import_react = __toESM(require("react"));
var import_shoppingCart = __toESM(require("../../../shoppingCart"));
var import_Provider = require("../../../shoppingCart/Provider");
var import_model = require("../model");
var import_useSelectPet = __toESM(require("./hooks/useSelectPet"));
var import_status = require("./status");
var import_utils = require("./utils");
var Lists = ({ onEdit, onChange }) => {
  var _a;
  const { state } = (0, import_react.useContext)(import_model.Context);
  const [params, setParams] = (0, import_react.useState)(import_status.defaultData);
  const { holderLists } = (0, import_useSelectPet.default)(state);
  (0, import_react.useEffect)(() => {
    const keys = (0, import_utils.formatActiveKey)(
      holderLists,
      params == null ? void 0 : params.platform,
      !!state.bookingId
    );
    onChange({ activeCartId: keys }, "setActiveCartId");
    setParams({
      ...params,
      activeKey: keys
    });
  }, [holderLists, params == null ? void 0 : params.platform]);
  const handleChange = (currentItem, type, other) => {
    var _a2;
    if (state.disabledEdit || state.disableEventBookingEdit) {
      return;
    }
    let products = (0, import_utils.updateServices)(state, currentItem, type, other);
    if (type === "view") {
      let product = currentItem._origin;
      (_a2 = window.openBookingEditModal) == null ? void 0 : _a2.call(window);
      onChange({ editModal: true, cacheItem: { ...product, new: 0 } });
      return onEdit == null ? void 0 : onEdit({ ...product, new: 0 });
    }
    const params2 = {
      editModal: false,
      value: products,
      edit: true,
      cacheItem: null
    };
    onChange(params2);
  };
  const handleActiveKey = (key) => {
    onChange({ activeCartId: key }, "setActiveCartId");
    setParams({
      ...params,
      activeKey: key
    });
  };
  const CollapseParams = (0, import_react.useMemo)(() => {
    const _params = {
      activeKey: params == null ? void 0 : params.activeKey,
      bordered: false
    };
    return _params;
  }, [params == null ? void 0 : params.activeKey]);
  const productParams = (0, import_react.useMemo)(() => {
    return {
      hideAddBtn: state.isTerminalDayBookingPage,
      isShowNote: (0, import_utils.isEventBooking)(state),
      isShowPackageNote: false,
      holders: holderLists,
      isEdit: !!(state == null ? void 0 : state.bookingId),
      disabledEdit: state == null ? void 0 : state.disabledEdit,
      maxLength: (0, import_utils.isEventBooking)(state) ? 1 : 999,
      productsPerRow: state.secondaryScreenCartProductsPerRow
    };
  }, [holderLists, state == null ? void 0 : state.bookingId, state == null ? void 0 : state.disabledEdit, state.secondaryScreenCartProductsPerRow]);
  return /* @__PURE__ */ import_react.default.createElement(import_Provider.CartContext.Provider, { value: { state } }, /* @__PURE__ */ import_react.default.createElement(
    import_shoppingCart.default,
    {
      onChange: handleChange,
      onAddProduct: () => onChange({ addModal: true }),
      onActiveKey: handleActiveKey,
      collapseParams: CollapseParams,
      productParams: {
        ...productParams,
        products: (0, import_utils.formatProducts)((_a = state == null ? void 0 : state.service) == null ? void 0 : _a.value, state)
      }
    }
  ));
};
var Lists_default = Lists;
