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/info2/service/editNormalService/index.tsx
var editNormalService_exports = {};
__export(editNormalService_exports, {
  default: () => editNormalService_default
});
module.exports = __toCommonJS(editNormalService_exports);
var import_react = __toESM(require("react"));
var import_ahooks = require("ahooks");
var import_skuDetailModal = __toESM(require("../../../../../pro/skuDetailModal"));
var import_model = require("../../../info/model");
var import_utils = require("../editService/utils");
var EditNormalService = (0, import_react.forwardRef)((props, ref) => {
  const { state, dispatch } = (0, import_react.useContext)(import_model.Context);
  const modalRef = (0, import_react.useRef)(null);
  (0, import_react.useImperativeHandle)(ref, () => ({
    init: (cacheItem) => {
      modalRef.current.open(cacheItem);
    }
  }));
  const handleRemove = (0, import_ahooks.useMemoizedFn)((productData) => {
    var _a, _b;
    const newProducts = (_b = ((_a = state == null ? void 0 : state.service) == null ? void 0 : _a.value) || []) == null ? void 0 : _b.filter((item) => {
      return item._id !== productData._id;
    });
    dispatch({
      type: "setService",
      payload: {
        editModal: false,
        value: newProducts,
        edit: true,
        cacheItem: null
      }
    });
  });
  const handleConfirm = (0, import_ahooks.useMemoizedFn)((data) => {
    var _a, _b;
    const newProducts = (_b = ((_a = state == null ? void 0 : state.service) == null ? void 0 : _a.value) || []) == null ? void 0 : _b.map((item) => {
      var _a2, _b2;
      if (item._id == data._id) {
        data = (0, import_utils.setProductPrice)(data, {
          newTotal: (_a2 = data._extend) == null ? void 0 : _a2.total,
          origin_total: (_b2 = data._extend) == null ? void 0 : _b2.origin_total
        });
        return data;
      }
      return item;
    });
    dispatch({
      type: "setService",
      payload: {
        editModal: false,
        value: newProducts,
        edit: true,
        cacheItem: null
      }
    });
  });
  const handleClose = (0, import_ahooks.useMemoizedFn)(() => {
    dispatch({
      type: "setService",
      payload: {
        editModal: false,
        cacheItem: null,
        changeService: false
      }
    });
  });
  return /* @__PURE__ */ import_react.default.createElement(
    import_skuDetailModal.default,
    {
      onClose: handleClose,
      onConfirm: handleConfirm,
      onRemove: handleRemove,
      ref: modalRef
    }
  );
});
var editNormalService_default = EditNormalService;
