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/editService/index.tsx
var editService_exports = {};
__export(editService_exports, {
  default: () => editService_default
});
module.exports = __toCommonJS(editService_exports);
var import_Delete_wght300_24px = __toESM(require("@pisell/icon/es/Delete_wght300_24px"));
var import_utils = require("@pisell/utils");
var import_react = __toESM(require("react"));
var import_model = require("../../../info/model");
var import_duration = __toESM(require("../../../materiels/duration"));
var import_Capacity = __toESM(require("./Capacity"));
var import_Resources = __toESM(require("./Resources"));
var import_Holder = __toESM(require("./Holder"));
var import_antd = require("antd");
var import_index = require("./index.less");
var import_drawer = require("../../../components/drawer/index.less");
var import_collapsibleList = __toESM(require("../../../components/collapsibleList"));
var import_utils2 = require("../../../components/collapsibleList/utils");
var import_index2 = require("./index.less");
var import_ahooks = require("ahooks");
var import_materials = require("@pisell/materials");
var import_utils3 = require("../../../../ticketBooking/utils");
var import_utils4 = require("../../../info/service2/utils");
var import_utils5 = require("../../../info/utils");
var import_utils6 = require("../../../utils");
var import_utilsByBooking = require("../../utilsByBooking");
var import_utils7 = require("../addService/utils");
var import_utils8 = require("./utils");
var import_noteModal = __toESM(require("../../../../../plus/noteModal"));
var import_priceKeyboard = require("../../../../../pro/priceKeyboard");
var import_EditTabs = __toESM(require("../../../info/service/editService/EditTabs"));
var import_BookingList = __toESM(require("../../../info/service/editService/BookingList"));
var import_dayjs = __toESM(require("dayjs"));
var import_utils9 = require("../../../info/service2/Group/utils");
var import_openNormalService = require("../openNormalService");
var import_decimal = __toESM(require("decimal.js"));
var import_useEngineContext = __toESM(require("../../../../../hooks/useEngineContext"));
var import_useCartChangeEffect = __toESM(require("../../../../ticketBooking/hooks/pisellos/useCartChangeEffect"));
var import_ArrowLeft = __toESM(require("@pisell/icon/es/ArrowLeft"));
var import_classnames = __toESM(require("classnames"));
var import_compensatedPisellContainer = __toESM(require("../../../../../pro/compensatedPisellContainer"));
var import_responsive = require("../../../../../responsive");
var submitLock = false;
var Info = (props, ref) => {
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L;
  const { variant } = props;
  const [form] = import_antd.Form.useForm();
  const useTotal = import_antd.Form.useWatch("total", form);
  const useResource = import_antd.Form.useWatch("resource", form);
  const useStartTime = import_antd.Form.useWatch("start_time", form);
  const useDuration = import_antd.Form.useWatch("duration", form);
  const useHolder = import_antd.Form.useWatch("holder", form);
  const useHolderId = import_antd.Form.useWatch("holder_id", form);
  const useNote = import_antd.Form.useWatch("note", form);
  const useStartDate = import_antd.Form.useWatch("start_date", form);
  const useEndDate = import_antd.Form.useWatch("end_date", form);
  const { state, dispatch } = (0, import_react.useContext)(import_model.Context);
  const { onCartChange } = (0, import_useCartChangeEffect.default)();
  const resourcesRef = (0, import_react.useRef)(null);
  const isChangeTotal = (0, import_react.useRef)(false);
  const [noteModalOpen, setNoteModalOpen] = (0, import_react.useState)(false);
  const [open, setOpen] = (0, import_react.useState)(false);
  const [currentTab, setCurrentTab] = (0, import_react.useState)("batch_edit");
  const [maskClosable, setMaskClosable] = (0, import_react.useState)(false);
  const context = (0, import_useEngineContext.default)();
  const {
    getData
  } = (_a = context.appHelper) == null ? void 0 : _a.utils;
  const isPhoneVariant = variant === "phone";
  (0, import_react.useEffect)(() => {
    window.openBookingEditModal = () => {
      setOpen(true);
    };
    window.closeBookingEditModal = () => {
      setOpen(false);
    };
  }, []);
  const isNormalProduct = (0, import_react.useMemo)(() => {
    var _a2, _b2, _c2;
    if (!((_a2 = state == null ? void 0 : state.service) == null ? void 0 : _a2.cacheItem)) {
      return true;
    }
    return ((_b2 = state == null ? void 0 : state.service) == null ? void 0 : _b2.cacheItem) && (0, import_utils4.isNormalProductByDurationSchedule)((_c2 = state == null ? void 0 : state.service) == null ? void 0 : _c2.cacheItem);
  }, [(_b = state == null ? void 0 : state.service) == null ? void 0 : _b.cacheItem]);
  const getCurrentCacheItem = (0, import_ahooks.useMemoizedFn)((_cacheItem) => {
    let values = form.getFieldsValue();
    let _item = _cacheItem || state.service.cacheItem;
    return {
      ..._item,
      _extend: {
        ..._item == null ? void 0 : _item._extend,
        ...values
      }
    };
  });
  const currentResource = (0, import_react.useMemo)(() => {
    return null;
  }, []);
  const durationProps = (0, import_react.useMemo)(() => {
    var _a2, _b2, _c2;
    let _cacheItem = getCurrentCacheItem();
    const val2 = (0, import_utils7.getDurationProps)({
      cacheItem: _cacheItem,
      useStartTime,
      // currentResource,
      slice: (_c2 = (_b2 = (_a2 = state.bookingConfig) == null ? void 0 : _a2.config) == null ? void 0 : _b2.basic) == null ? void 0 : _c2.service_time
    });
    return val2;
  }, [
    // currentResource,
    state.service.cacheItem,
    useStartTime,
    useResource,
    (_e = (_d = (_c = state.bookingConfig) == null ? void 0 : _c.config) == null ? void 0 : _d.basic) == null ? void 0 : _e.service_time
  ]);
  const flexibleOption = (0, import_react.useMemo)(() => {
    const op = (0, import_utils7.getFlexibleOption)({
      durationProps
    });
    return op;
  }, [durationProps, import_utils.locales.locale]);
  const timeObj = (0, import_react.useMemo)(() => {
    const val2 = (0, import_utils7.getTimeObj)({
      cacheItem: getCurrentCacheItem(),
      durationProps,
      useStartTime,
      currentResource,
      state,
      useDuration
    });
    return val2;
  }, [
    durationProps,
    useStartTime,
    currentResource,
    (_h = (_g = (_f = state.bookingConfig) == null ? void 0 : _f.config) == null ? void 0 : _g.basic) == null ? void 0 : _h.service_time,
    useDuration
  ]);
  (0, import_react.useEffect)(() => {
    console.log("执行次数:于灵活时长的结束时间随");
    try {
      if (useDuration.indexOf("flexible_") == 0) {
        if (flexibleOption) {
          form.setFieldsValue({
            duration: flexibleOption.value
          });
        }
      }
    } catch (err) {
    }
  }, [useDuration, flexibleOption]);
  const handleDeleteProduct = (0, import_ahooks.useMemoizedFn)(() => {
    var _a2, _b2;
    if (state.channelDisabledEdit) {
      return;
    }
    let _list = [...state.service.value];
    let _id = (_a2 = state.service.cacheItem) == null ? void 0 : _a2._id;
    _list = _list.filter((d) => d._id !== _id);
    (_b2 = window.closeBookingEditModal) == null ? void 0 : _b2.call(window);
    dispatch({
      type: "setService",
      payload: {
        editModal: false,
        value: _list,
        edit: true,
        cacheItem: null,
        callbackPromotion: null
      }
    });
  });
  const getDiscount = () => {
    var _a2;
    let oPrice = Number(((_a2 = state.service.cacheItem) == null ? void 0 : _a2._extend.origin_total) || 0);
    let cPrice = Number(useTotal || 0);
    let discount = "";
    if (cPrice === oPrice) {
      discount = import_utils.locales.getText("pisell2.text.status.no-discount");
    } else {
      discount = `${import_utils.locales.getText("pisell2.text.status.manual")} `;
      if (cPrice < oPrice) {
        discount += (0, import_utils.formatAmount)(cPrice - oPrice, 2, state.amountSymbol) + "";
      } else {
        discount += "+" + (0, import_utils.formatAmount)(cPrice - oPrice, 2, state.amountSymbol);
      }
    }
    form.setFieldsValue({ discount });
  };
  const onFinish = (values) => {
    var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i2, _j2, _k2, _l2, _m2, _n2, _o2;
    let isSuccess = (_a2 = resourcesRef.current) == null ? void 0 : _a2.check();
    if (isShowTimeAndResource && !isSuccess) {
      return;
    }
    if (submitLock) {
      return;
    }
    submitLock = true;
    setTimeout(() => {
      submitLock = false;
    }, 1500);
    let _list = [...state.service.value];
    let _item = {
      is_price_include_tax: getData("is_price_include_tax"),
      ...state.service.cacheItem,
      autoClose: false
    };
    let _extend = {
      ..._item._extend,
      other: {
        ...((_b2 = _item._extend) == null ? void 0 : _b2.other) || {},
        quantity: values.quantity
      },
      ...values
    };
    if (isEditGroup) {
      _extend.quantity = 1;
      _extend.startDate = _extend == null ? void 0 : _extend.start_date;
      _extend.endDate = _extend == null ? void 0 : _extend.end_date;
    } else {
      const { startDate, endDate } = (0, import_utils6.getServiceTimes)({ _extend });
      _extend.startDate = startDate;
      _extend.endDate = endDate;
    }
    if (isChangeTotal.current) {
      const discountRatio = new import_decimal.default(values.total).div(_item._extend.origin_total);
      const bundles2 = ((_c2 = _extend == null ? void 0 : _extend.other) == null ? void 0 : _c2.bundle) || [];
      let childProductsTotal = new import_decimal.default(0);
      if (bundles2.length > 0) {
        bundles2.forEach((bundle) => {
          const discountedPrice = new import_decimal.default(bundle.original_price).mul(discountRatio).toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP);
          bundle.bundle_selling_price = discountedPrice.toNumber();
          childProductsTotal = childProductsTotal.add(
            discountedPrice.mul(bundle.quantity)
          );
        });
      }
      const mainProductTotal = new import_decimal.default(values.total).sub(childProductsTotal);
      const mainProductQuantity = ((_d2 = _extend.other) == null ? void 0 : _d2.quantity) || _extend.quantity || 1;
      _extend.main_product_selling_price = mainProductTotal.div(mainProductQuantity).toNumber();
    }
    if (isChangeTotal.current) {
      const discountRatio = new import_decimal.default(values.total).div(_item._extend.origin_total);
      const bundles2 = ((_e2 = _extend == null ? void 0 : _extend.other) == null ? void 0 : _e2.bundle) || [];
      let childProductsTotal = new import_decimal.default(0);
      if (bundles2.length > 0) {
        bundles2.forEach((bundle) => {
          const discountedPrice = new import_decimal.default(bundle.original_price).mul(discountRatio).toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP);
          bundle.bundle_selling_price = discountedPrice.toNumber();
          childProductsTotal = childProductsTotal.add(
            discountedPrice.mul(bundle.quantity)
          );
        });
      }
      const mainProductTotal = new import_decimal.default(values.total).sub(childProductsTotal);
      const mainProductQuantity = ((_f2 = _extend.other) == null ? void 0 : _f2.quantity) || _extend.quantity || 1;
      _extend.main_product_selling_price = mainProductTotal.div(mainProductQuantity).toNumber();
    }
    if (_extend.bundle_edit !== void 0) {
      _extend.bundle_edit = 1;
    }
    _item._extend = _extend;
    _item._time = (/* @__PURE__ */ new Date()).getTime();
    _item._serviceKey = (0, import_utils3.genServiceKey)(_item);
    _item._holderKey = (0, import_utils3.genHolderKey)(_item);
    if (((_h2 = (_g2 = _item._extend) == null ? void 0 : _g2.holder_id) == null ? void 0 : _h2.length) > 1 || ((_i2 = _item._extend) == null ? void 0 : _i2.quantity) > 1 && ((_k2 = (_j2 = _item._extend) == null ? void 0 : _j2.holder_id) == null ? void 0 : _k2.length) >= 1) {
      let holder_ids = _item._extend.holder_id;
      _item._extend.holder_id = holder_ids[0];
      holder_ids = holder_ids.slice(1);
      _item._holderKey = (0, import_utils3.genHolderKey)(_item);
      holder_ids.forEach((holder_id) => {
        const newItem = { ..._item, _id: (0, import_utils.getUniqueId)(), _extend: { ..._item._extend, holder_id: [holder_id], quantity: 1 } };
        newItem._holderKey = (0, import_utils3.genHolderKey)(newItem);
        _list.unshift(newItem);
        _item._extend.quantity -= 1;
      });
      if (_item._extend.quantity > 1) {
        const newItem = { ..._item, _id: (0, import_utils.getUniqueId)(), _extend: { ..._item._extend, holder_id: void 0, quantity: _item._extend.quantity - 1 } };
        newItem._holderKey = (0, import_utils3.genHolderKey)(newItem);
        _list.unshift(newItem);
        _item._extend.quantity = 1;
      }
    }
    let _id = _item == null ? void 0 : _item._id;
    let groupId = (_l2 = _item == null ? void 0 : _item._extend) == null ? void 0 : _l2.groupId;
    if (groupId) {
      _list = _list.filter((d) => {
        var _a3;
        return ((_a3 = d._extend) == null ? void 0 : _a3.groupId) !== groupId;
      });
      _list = _list.concat((0, import_utils9.createBookingItemsByGroup)(_item, true));
    } else {
      _item = (0, import_utils8.setProductPrice)(_item, {
        newTotal: values.total,
        origin_total: (_m2 = _item._extend) == null ? void 0 : _m2.origin_total
      });
      if (!_list.some((d) => d._id === _id)) {
        const detail = (0, import_utils3.addService)(_list, _item, state);
        _list = detail.list;
      } else {
        if (isChangeTotal.current) {
          delete _item.discount_list;
        }
        _list = _list.map((d) => d._id === _id ? { ..._item, new: 0 } : d);
      }
    }
    (0, import_utils6.deleteCacheParams)();
    console.log("_onFinish", _list);
    form.resetFields();
    if (!!((_n2 = state.service.cacheItem) == null ? void 0 : _n2.new)) {
      window.dispatchEvent(
        new CustomEvent("onAddNewService", {
          detail: {
            cacheItem: { ...state.service.cacheItem }
          }
        })
      );
    }
    (_o2 = window.closeBookingEditModal) == null ? void 0 : _o2.call(window);
    _list.sort((a, b) => {
      var _a3, _b3;
      const aHasHolderId = ((_a3 = a._extend) == null ? void 0 : _a3.holder_id) && (Array.isArray(a._extend.holder_id) ? a._extend.holder_id.length > 0 : true);
      const bHasHolderId = ((_b3 = b._extend) == null ? void 0 : _b3.holder_id) && (Array.isArray(b._extend.holder_id) ? b._extend.holder_id.length > 0 : true);
      if (!aHasHolderId && bHasHolderId) return -1;
      if (aHasHolderId && !bHasHolderId) return 1;
      return 0;
    });
    onCartChange("update", _list);
    if (state == null ? void 0 : state.callbackPromotion) {
      state.callbackPromotion(_item);
      return;
    }
    dispatch({
      type: "setService",
      payload: {
        editModal: false,
        addModal: false,
        value: _list,
        edit: true,
        cacheItem: null,
        changeService: false,
        callbackPromotion: null
      }
    });
  };
  const { run: setEditDataRun } = (0, import_ahooks.useDebounceFn)(
    (...params) => {
      setEditData(...params);
    },
    {
      wait: 50,
      leading: true,
      trailing: false
    }
  );
  const setEditData = (0, import_ahooks.useMemoizedFn)(
    (_cacheItem, open2, openProductDetail) => {
      console.timeEnd("handleChange");
      console.log("setEditDatasetEditData", _cacheItem, open2);
      setCurrentTab("batch_edit");
      isChangeTotal.current = false;
      let cacheItem = _cacheItem || state.service.cacheItem;
      let values = cacheItem._extend;
      const startTime2 = performance.now();
      console.log(startTime2, "startTime");
      form.resetFields();
      form.setFieldsValue({
        capacity: values.capacity,
        discount_reason: values.discount_reason,
        duration: values.duration,
        endDate: values.endDate,
        end_date: values.end_date,
        origin_total: values.origin_total,
        price: values.price,
        product_name: values.product_name,
        quantity: values.quantity,
        resource: values.resource,
        startDate: values.startDate,
        start_time: values.start_time,
        start_date: values.start_date,
        total: values.total,
        holder_id: values.holder_id,
        note: values.note
      });
      const endTime2 = performance.now();
      console.log(endTime2 - window.pp1, "打开商品5");
      console.log("执行时间", endTime2 - startTime2, values);
      setTimeout(() => {
      }, 20);
      if (openProductDetail) {
        setTimeout(() => {
          handleEdit({});
        }, 100);
      }
    }
  );
  const isReason = (0, import_react.useMemo)(() => {
    var _a2;
    let oPrice = Number(((_a2 = state.service.cacheItem) == null ? void 0 : _a2._extend.origin_total) || 0);
    let cPrice = Number(useTotal || 0);
    return cPrice !== oPrice;
  }, [useTotal, (_j = (_i = state.service.cacheItem) == null ? void 0 : _i._extend) == null ? void 0 : _j.origin_total]);
  const getResources = () => {
    var _a2, _b2;
    let res = (0, import_utils7.formatResources)({
      cacheItem: getCurrentCacheItem(),
      resourcesOrigin: (_b2 = (_a2 = state.service.cacheItem) == null ? void 0 : _a2._data) == null ? void 0 : _b2.resourcesOrigin
    });
    dispatch({
      type: "setService",
      payload: {
        cacheItem: {
          ...state.service.cacheItem,
          _data: {
            ...state.service.cacheItem._data,
            resources: res.list,
            resourceMaps: res.maps
          }
        }
      }
    });
    updateResourceErrors(res.maps);
  };
  const updateResourceErrors = (resourceMaps) => {
    let { resource: resource2 } = form.getFieldsValue();
    if (resource2) {
      let _resource = { ...resource2 };
      for (let form_id in _resource) {
        _resource[form_id] = _resource[form_id].map((d) => {
          var _a2, _b2;
          return {
            ...d,
            errors: (0, import_utilsByBooking.getErrorList)(
              (_b2 = (_a2 = resourceMaps == null ? void 0 : resourceMaps[form_id]) == null ? void 0 : _a2.renderListMaps) == null ? void 0 : _b2[d == null ? void 0 : d.relation_id],
              getCurrentCacheItem()
            )
          };
        });
      }
      form.setFieldsValue({
        resource: _resource
      });
      return _resource;
    }
  };
  (0, import_ahooks.useUpdateEffect)(() => {
    if (!state.service.cacheItem) {
      return;
    }
    if (useStartTime && useDuration && state.renderType !== "eventBooking") {
      getResources();
    }
  }, [
    useStartTime,
    useDuration,
    state.renderType,
    state.service.resourcesOrigin
  ]);
  (0, import_react.useEffect)(() => {
    if (state.isBookingCreatePage && state.service.editModal) {
      setEditDataRun(null);
    }
  }, [state.service.editModal, state.isBookingCreatePage]);
  (0, import_react.useEffect)(() => {
    getDiscount();
  }, [useTotal, (_l = (_k = state.service.cacheItem) == null ? void 0 : _k._extend) == null ? void 0 : _l.origin_total]);
  const bundles = (0, import_react.useMemo)(() => {
    var _a2, _b2, _c2, _d2;
    return ((_d2 = (_c2 = (_b2 = (_a2 = state.service) == null ? void 0 : _a2.cacheItem) == null ? void 0 : _b2._extend) == null ? void 0 : _c2.other) == null ? void 0 : _d2.bundle) || [];
  }, [(_p = (_o = (_n = (_m = state.service) == null ? void 0 : _m.cacheItem) == null ? void 0 : _n._extend) == null ? void 0 : _o.other) == null ? void 0 : _p.bundle]);
  const handleEdit = (0, import_ahooks.useMemoizedFn)((e) => {
    var _a2, _b2, _c2, _d2, _e2;
    const item = state.service.cacheItem;
    let values = form.getFieldsValue();
    const isSession = (0, import_utils6.isSessionProduct)(item);
    const isEject = (0, import_utils6.getIsEject)(item, "detail");
    const sessionValue = {};
    if (isSession) {
      sessionValue.startEndTime = {
        startDate: (_a2 = item == null ? void 0 : item._extend) == null ? void 0 : _a2.start_date,
        endDate: (_b2 = item == null ? void 0 : item._extend) == null ? void 0 : _b2.end_date,
        duration: (_c2 = item == null ? void 0 : item._extend) == null ? void 0 : _c2.duration
      };
    }
    const callback = (e2, extension_type, detail) => {
      var _a3, _b3;
      const _detail = detail || item;
      const other = JSON.parse(JSON.stringify(e2));
      other.session = e2.session;
      let cacheItem = {
        ...item,
        ..._detail,
        product_id: item.id,
        _id: item == null ? void 0 : item._id,
        _key: e2.key,
        _extend: {
          ...item._extend,
          // 将当前表单的值覆盖进去
          ...values,
          quantity: (e2 == null ? void 0 : e2.quantity) || (values == null ? void 0 : values.quantity) || 1,
          // 覆盖选择的规格和套餐
          other,
          priceOverride: (_a3 = _detail._extend) == null ? void 0 : _a3.priceOverride
        },
        new: 0
      };
      let _total = (0, import_utils6.getProductTotalPrice)(cacheItem);
      cacheItem._extend.total = _total;
      try {
        cacheItem._extend.capacity = (0, import_utils7.setDefaultCapacitys)({
          capacitys: cacheItem._data.capacitys,
          cacheItem
        });
      } catch (err) {
      }
      const sessionDetail = (0, import_utils5.editSessionProduct)(cacheItem, e2.session);
      if (sessionDetail) {
        setTimeout(() => {
          form.setFieldsValue({
            start_time: sessionDetail.start_time,
            duration: sessionDetail.duration
          });
        }, 200);
      }
      cacheItem._extend.origin_total = _total;
      dispatch({
        type: "setService",
        payload: {
          cacheItem
        }
      });
      form.setFieldsValue({
        total: _total,
        capacity: (_b3 = cacheItem._extend) == null ? void 0 : _b3.capacity,
        quantity: (e2 == null ? void 0 : e2.quantity) || (values == null ? void 0 : values.quantity) || 1
      });
    };
    if ((0, import_utils4.isNormalProductByDurationSchedule)(item)) {
      const openNormalService = (0, import_openNormalService.getOpenNormalServiceHandler)();
      if (openNormalService) {
        openNormalService({
          mode: "edit",
          cacheItem: item,
          callback
        });
      }
    } else {
      state.action({
        type: "pisell1.handleOpenProductModal",
        data: {
          id: item.id,
          date: state.date.value.format("YYYY-MM-DD"),
          showConfig: {
            option: true,
            session: isSession,
            variant: true,
            package: true,
            number: (0, import_utils3.getIsShowNumber)(item, state)
          },
          isOS: isSession,
          customer_id: (_e2 = (_d2 = state.client) == null ? void 0 : _d2.value) == null ? void 0 : _e2.id,
          value: {
            ...item._extend.other,
            ...sessionValue,
            quantity: values.quantity || item._extend.quantity
          }
        },
        callback
      });
    }
  });
  const handleChange = (0, import_ahooks.useMemoizedFn)((e) => {
    var _a2;
    if (state.channelDisabledEdit) {
      return;
    }
    form.resetFields();
    (_a2 = window.closeBookingEditModal) == null ? void 0 : _a2.call(window);
    dispatch({
      type: "setService",
      payload: {
        addModal: true,
        editModal: false
        //用于控制 添加商品 和 编辑服务弹窗的上下层级
        // changeService: true,
      }
    });
  });
  (0, import_react.useImperativeHandle)(ref, () => {
    return {
      init: setEditDataRun
    };
  });
  const handleTotalChange = (number) => {
    isChangeTotal.current = true;
  };
  const isShowTimeAndResource = (0, import_react.useMemo)(() => {
    if (state.renderType !== "eventBooking" && !isNormalProduct) {
      return true;
    }
    return false;
  }, [state.renderType, isNormalProduct]);
  const SelectTime = (_q = window.BaseMaterials) == null ? void 0 : _q.SelectTime;
  const isNoSpecAndPackage = (0, import_utilsByBooking.getIsNoSpecAndPackage)(state.service.cacheItem);
  const items = (0, import_react.useMemo)(() => {
    var _a2, _b2;
    return ((_b2 = (_a2 = getCurrentCacheItem()) == null ? void 0 : _a2._extend) == null ? void 0 : _b2.items) || [];
  }, [
    getCurrentCacheItem(),
    state.service.cacheItem,
    currentResource,
    useTotal
  ]);
  const isEditGroup = (0, import_react.useMemo)(() => {
    return items.length;
  }, [items]);
  const handleNoteConfirm = (noteValue) => {
    form.setFieldsValue({ note: noteValue });
    setNoteModalOpen(false);
  };
  const handleNoteDelete = () => {
    form.setFieldsValue({ note: "" });
    setNoteModalOpen(false);
  };
  const handleNoteCancel = () => {
    setNoteModalOpen(false);
  };
  console.log(isShowTimeAndResource, "isShowTimeAndResource");
  const productName = (0, import_react.useMemo)(() => {
    var _a2, _b2, _c2;
    return /* @__PURE__ */ import_react.default.createElement(import_antd.Col, { span: 24 }, /* @__PURE__ */ import_react.default.createElement(import_antd.Form.Item, { name: "product_name" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "current-service-info" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "current-service-info-name-wrap" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "current-service-info-name" }, ((_c2 = (_b2 = (_a2 = state.service) == null ? void 0 : _a2.cacheItem) == null ? void 0 : _b2._extend) == null ? void 0 : _c2.product_name) || "-"), /* @__PURE__ */ import_react.default.createElement(import_antd.Button, { onClick: handleEdit }, import_utils.locales.getText("pisell2.text.edit")), !state.isBookingCreatePage && /* @__PURE__ */ import_react.default.createElement(import_antd.Button, { onClick: handleChange }, import_utils.locales.getText("pisell2.text.change"))), /* @__PURE__ */ import_react.default.createElement(
      import_collapsibleList.default,
      {
        style: { marginTop: bundles.length ? "8px" : 0 },
        list: bundles,
        renderItem: (item) => (0, import_utils2.renderBundles)(item, state.amountSymbol)
      }
    ))));
  }, [
    (_t = (_s = (_r = state.service) == null ? void 0 : _r.cacheItem) == null ? void 0 : _s._extend) == null ? void 0 : _t.product_name,
    bundles,
    state.amountSymbol,
    state.isBookingCreatePage
  ]);
  const price = (0, import_react.useMemo)(() => {
    var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2;
    return /* @__PURE__ */ import_react.default.createElement(import_antd.Col, { span: 24 }, /* @__PURE__ */ import_react.default.createElement(
      import_antd.Form.Item,
      {
        label: import_utils.locales.getText("pisell2.text.price"),
        name: "total",
        rules: [{ required: true }],
        extra: useTotal !== ((_b2 = (_a2 = state.service.cacheItem) == null ? void 0 : _a2._extend) == null ? void 0 : _b2.origin_total) && import_utils.locales.getText("page.booking.text.price-extra")(
          (0, import_utils.formatAmount)(
            (_d2 = (_c2 = state.service.cacheItem) == null ? void 0 : _c2._extend) == null ? void 0 : _d2.origin_total,
            2,
            state.amountSymbol
          ),
          (0, import_utils.formatAmount)(useTotal, 2, state.amountSymbol)
        )
      },
      /* @__PURE__ */ import_react.default.createElement(
        import_priceKeyboard.DiscountKeyboard.InputNumber,
        {
          style: { width: "100%" },
          min: 0,
          precision: 2,
          prefix: state.amountSymbol,
          onChange: handleTotalChange,
          disabled: state.channelDisabledEdit,
          originalValue: ((_f2 = (_e2 = state.service.cacheItem) == null ? void 0 : _e2._extend) == null ? void 0 : _f2.origin_total) || 0,
          placeholder: ((_h2 = (_g2 = state.service.cacheItem) == null ? void 0 : _g2._extend) == null ? void 0 : _h2.origin_total) || "0",
          size: "large",
          keyboardProps: {
            containerProps: {
              renderType: "modal"
            },
            selectType: "dark"
          }
        }
      )
    ));
  }, [
    useTotal,
    (_v = (_u = state.service.cacheItem) == null ? void 0 : _u._extend) == null ? void 0 : _v.origin_total,
    state.amountSymbol,
    state.channelDisabledEdit
  ]);
  const reason = (0, import_react.useMemo)(() => {
    return isReason ? /* @__PURE__ */ import_react.default.createElement(import_antd.Col, { span: 24 }, /* @__PURE__ */ import_react.default.createElement(
      import_antd.Form.Item,
      {
        label: import_utils.locales.getText("pisell2.text.discount-reason"),
        name: "discount_reason"
      },
      /* @__PURE__ */ import_react.default.createElement(import_antd.Input.TextArea, { size: "large" })
    )) : null;
  }, [isReason]);
  const DateCom = (position) => {
    return /* @__PURE__ */ import_react.default.createElement(
      import_antd.DatePicker,
      {
        className: "pisell-lowcode__booking-service-select-date",
        disabledDate: (current) => (0, import_utils4.disabledDate)(current, position, state.date.value),
        size: "large",
        style: { width: "100%" },
        format: state.locale === "en" ? "DD/MM/YYYY" : "YYYY-MM-DD"
      }
    );
  };
  const startTime = (0, import_react.useMemo)(() => {
    var _a2, _b2, _c2, _d2;
    return /* @__PURE__ */ import_react.default.createElement(import_antd.Col, { span: 12 }, /* @__PURE__ */ import_react.default.createElement(
      import_antd.Form.Item,
      {
        label: import_utils.locales.getText(isEditGroup ? "pisell2.text.start_date" : "pisell2.text.start_time"),
        name: isEditGroup ? "start_date" : "start_time",
        rules: [{ required: true }]
      },
      isEditGroup ? DateCom("start") : SelectTime ? /* @__PURE__ */ import_react.default.createElement(
        SelectTime,
        {
          slice: (_d2 = (_c2 = (_b2 = (_a2 = state.bookingConfig) == null ? void 0 : _a2.config) == null ? void 0 : _b2.basic) == null ? void 0 : _c2.service_time) == null ? void 0 : _d2.value,
          timePickerProps: {
            style: { width: "100%" }
          },
          timeProps: {
            style: { zoom: 0.8 }
          }
        }
      ) : null
    ));
  }, [SelectTime, (_z = (_y = (_x = (_w = state.bookingConfig) == null ? void 0 : _w.config) == null ? void 0 : _x.basic) == null ? void 0 : _y.service_time) == null ? void 0 : _z.value, isEditGroup]);
  const endTime = (0, import_react.useMemo)(() => {
    if (!isEditGroup) {
      return null;
    }
    return /* @__PURE__ */ import_react.default.createElement(import_antd.Col, { span: 12 }, /* @__PURE__ */ import_react.default.createElement(
      import_antd.Form.Item,
      {
        label: import_utils.locales.getText("pisell2.text.end_date"),
        name: "end_date"
      },
      DateCom("end")
    ));
  }, [isEditGroup]);
  const duration = (0, import_react.useMemo)(() => {
    console.log("render form duration");
    return /* @__PURE__ */ import_react.default.createElement(import_antd.Col, { span: isEditGroup ? 24 : 12 }, /* @__PURE__ */ import_react.default.createElement(
      import_antd.Form.Item,
      {
        label: import_utils.locales.getText("pisell2.text.duration"),
        name: "duration",
        rules: [{ required: true }]
      },
      /* @__PURE__ */ import_react.default.createElement(import_duration.default, { ...durationProps, timeObj })
    ));
  }, [durationProps, timeObj, isEditGroup]);
  const resource = (0, import_react.useMemo)(() => {
    console.log("render form resource");
    return /* @__PURE__ */ import_react.default.createElement(import_antd.Form.Item, { noStyle: true, name: "resource" }, /* @__PURE__ */ import_react.default.createElement(
      import_Resources.default,
      {
        ref: resourcesRef,
        state,
        cacheItem: state.service.cacheItem,
        getCurrentCacheItem
      }
    ));
  }, [
    state.renderType,
    (_B = (_A = state.service.cacheItem) == null ? void 0 : _A._data) == null ? void 0 : _B.resources,
    (_D = (_C = state.service.cacheItem) == null ? void 0 : _C._data) == null ? void 0 : _D.resourceMaps
  ]);
  const holder = (0, import_react.useMemo)(() => {
    var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2;
    const showExtra = ((_c2 = (_b2 = (_a2 = state == null ? void 0 : state.bookingConfig) == null ? void 0 : _a2.config) == null ? void 0 : _b2.basic) == null ? void 0 : _c2.subject_require) === "require" && (!useHolderId || (useHolderId == null ? void 0 : useHolderId.length) < ((_e2 = (_d2 = state.service.cacheItem) == null ? void 0 : _d2._extend) == null ? void 0 : _e2.quantity));
    return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(
      import_antd.Form.Item,
      {
        name: "holder_id",
        style: { width: "100%" },
        rules: [
          {
            required: ((_h2 = (_g2 = (_f2 = state == null ? void 0 : state.bookingConfig) == null ? void 0 : _f2.config) == null ? void 0 : _g2.basic) == null ? void 0 : _h2.subject_require) === "require",
            validator: (rule, value, callback) => {
              if (showExtra) {
                callback(import_utils.locales.getText("page.booking.text.holder.length-error"));
              } else {
                callback();
              }
            }
          }
        ]
      },
      /* @__PURE__ */ import_react.default.createElement(
        import_Holder.default,
        {
          state,
          cacheItem: state.service.cacheItem,
          dispatch
        }
      )
    ));
  }, [state.pet, state.client, state.service.cacheItem, useHolderId]);
  const capacity = (0, import_react.useMemo)(() => {
    return /* @__PURE__ */ import_react.default.createElement(import_antd.Form.Item, { noStyle: true, name: "capacity" }, /* @__PURE__ */ import_react.default.createElement(import_Capacity.default, { state, cacheItem: state.service.cacheItem }));
  }, [
    state.locale,
    state.isTerminal,
    (_G = (_F = (_E = state.service) == null ? void 0 : _E.cacheItem) == null ? void 0 : _F._data) == null ? void 0 : _G.capacitys
  ]);
  const hiddenQuantity = (0, import_react.useMemo)(() => {
    return /* @__PURE__ */ import_react.default.createElement(import_antd.Form.Item, { hidden: true, name: "quantity" }, /* @__PURE__ */ import_react.default.createElement(import_antd.InputNumber, null));
  }, []);
  const quantity = (0, import_react.useMemo)(() => {
    return /* @__PURE__ */ import_react.default.createElement(import_antd.Col, { span: 24 }, /* @__PURE__ */ import_react.default.createElement(
      import_antd.Form.Item,
      {
        label: import_utils.locales.getText("pisell2.text.quantity"),
        name: "quantity",
        rules: [{ required: true }]
      },
      /* @__PURE__ */ import_react.default.createElement(
        import_antd.InputNumber,
        {
          size: "large",
          style: { width: "100%" },
          min: 1,
          max: 999999,
          formatter: (value) => {
            if (value !== void 0) {
              return Math.floor(value);
            }
            return value;
          }
        }
      )
    ));
  }, []);
  const footer = (0, import_react.useMemo)(() => {
    var _a2;
    return /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: "pisell-lowcode__booking-service-body-edit-footer",
        style: (state == null ? void 0 : state.isBookingTicket2) ? { justifyContent: "space-between" } : {}
      },
      /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode__booking-service-body-edit-footer-left" }, /* @__PURE__ */ import_react.default.createElement(
        "div",
        {
          className: "pisell-lowcode__booking-service-delete-wrap",
          onClick: handleDeleteProduct
        },
        /* @__PURE__ */ import_react.default.createElement(import_Delete_wght300_24px.default, { className: "pisell-lowcode__booking-service-delete-icon" })
      ), (state == null ? void 0 : state.isBookingTicket2) && /* @__PURE__ */ import_react.default.createElement(
        import_materials.ConfigProvider,
        {
          theme: {
            token: {
              colorPrimary: "#0d7fa9"
            }
          }
        },
        /* @__PURE__ */ import_react.default.createElement(
          import_antd.Button,
          {
            className: "pisell-lowcode__booking-service-buttons-item note-button",
            type: "primary",
            size: "large",
            onClick: () => setNoteModalOpen(true),
            style: { height: "48px", width: "140px" }
          },
          import_utils.locales.getText("pisell2.ticket-booking.note"),
          useNote && /* @__PURE__ */ import_react.default.createElement("span", { className: "note-indicator" }, /* @__PURE__ */ import_react.default.createElement(import_materials.Iconfont, { type: "pisell2-info-circle2" }))
        )
      )),
      /* @__PURE__ */ import_react.default.createElement(
        import_antd.Button,
        {
          type: "primary",
          className: "pisell-lowcode__booking-service-body-edit-footer-apple",
          disabled: !isNormalProduct && !((_a2 = state.service.resourcesOrigin) == null ? void 0 : _a2.length),
          onClick: () => {
            form.submit();
          }
        },
        import_utils.locales.getText("pisell2.text.apply")
      )
    );
  }, [(_H = state.service.resourcesOrigin) == null ? void 0 : _H.length, isNormalProduct]);
  console.log("render edit");
  console.log(
    state.service.editModal && !((_I = state.service.cacheItem) == null ? void 0 : _I.autoClose),
    performance.now() - window.pp1,
    "打开商品1"
  );
  const [val, setVal] = (0, import_react.useState)(false);
  (0, import_react.useEffect)(() => {
    if (isShowTimeAndResource) {
      setTimeout(() => {
        setVal(true);
      }, 200);
    } else {
      setVal(false);
    }
  }, [isShowTimeAndResource]);
  const groupDom = (0, import_react.useMemo)(() => {
    return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, !!isEditGroup && /* @__PURE__ */ import_react.default.createElement(
      import_EditTabs.default,
      {
        value: currentTab,
        onChange: (e) => {
          console.log(e);
          setCurrentTab(e);
        }
      }
    ), /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: "",
        style: {
          display: currentTab === "booking_list" ? "block" : "none"
        }
      },
      /* @__PURE__ */ import_react.default.createElement(import_BookingList.default, { items })
    ));
  }, [isEditGroup, currentTab, items]);
  const updateMultiDay = async ({ start_date, end_date, duration: duration2 }) => {
    const cacheItem = await (0, import_utils7.getMultiDay)({
      start_date,
      end_date,
      state,
      cacheItem: getCurrentCacheItem()
    });
    if (duration2 !== void 0) {
      cacheItem._extend.duration = duration2;
    }
    cacheItem._extend.items = (0, import_utils9.createBookingItemsByGroup)(cacheItem);
    cacheItem._extend = {
      ...cacheItem._extend,
      ...(0, import_utils9.getGroupTotalPrice)(cacheItem._extend.items)
    };
    dispatch({
      type: "setService",
      payload: {
        cacheItem
      }
    });
    let fieldsValues = {
      total: cacheItem._extend.total
    };
    form.setFieldsValue(fieldsValues);
  };
  const onValuesChange = (changedValues) => {
    if (isEditGroup) {
      if (changedValues == null ? void 0 : changedValues.duration) {
        const end_date = (0, import_dayjs.default)(useStartDate).add(
          changedValues == null ? void 0 : changedValues.duration,
          "day"
        );
        form.setFieldsValue({
          end_date
        });
        return updateMultiDay({
          start_date: useStartDate,
          end_date,
          duration: changedValues == null ? void 0 : changedValues.duration
        });
      }
      if (changedValues == null ? void 0 : changedValues.start_date) {
        const startDate = (0, import_dayjs.default)(changedValues == null ? void 0 : changedValues.start_date);
        const endDate = (0, import_dayjs.default)(useEndDate);
        if (startDate.isAfter(endDate)) {
          return form.setFieldsValue({
            duration: void 0,
            end_date: void 0
          });
        }
      }
      if ((changedValues == null ? void 0 : changedValues.start_date) || (changedValues == null ? void 0 : changedValues.end_date)) {
        const cacheItem = getCurrentCacheItem();
        const duration2 = (0, import_utils6.getDays)(cacheItem, "days");
        const start_date = (changedValues == null ? void 0 : changedValues.start_date) || useStartDate;
        const end_date = (changedValues == null ? void 0 : changedValues.end_date) || useEndDate;
        updateMultiDay({ start_date, end_date, duration: duration2 });
        return form.setFieldsValue({
          duration: duration2
        });
      }
    }
  };
  const drawerOpen = (0, import_react.useMemo)(() => {
    var _a2;
    return !isNoSpecAndPackage && state.service.editModal && !((_a2 = state.service.cacheItem) == null ? void 0 : _a2.autoClose);
  }, [isNoSpecAndPackage, state.service.editModal, (_J = state.service.cacheItem) == null ? void 0 : _J.autoClose]);
  (0, import_react.useEffect)(() => {
    let timer = null;
    if (drawerOpen) {
      timer = setTimeout(() => {
        setMaskClosable(true);
      }, 200);
    } else {
      setMaskClosable(false);
    }
    return () => {
      if (timer) {
        clearTimeout(timer);
      }
    };
  }, [drawerOpen]);
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(
    import_compensatedPisellContainer.default,
    {
      renderType: "drawer",
      props: {
        maskClosable,
        title: false,
        closable: false,
        //通过zIndex的方式控制  添加商品 和 编辑服务弹窗的上下层级
        zIndex: state.service.changeService ? 999 : 1e3,
        forceRender: true,
        mask: state.drawerMask,
        open: drawerOpen,
        placement: isPhoneVariant ? "bottom" : "right",
        width: isPhoneVariant ? "100%" : "600px",
        height: isPhoneVariant ? "95vh" : void 0,
        rootClassName: "booking-server-wrap",
        className: (0, import_classnames.default)(
          "pisell-lowcode__booking-drawer",
          "pisell-lowcode__booking-drawer-hide-scrollbar"
        ),
        push: false,
        bodyStyle: { padding: 0 },
        onClose: () => {
          var _a2;
          (_a2 = window.closeBookingEditModal) == null ? void 0 : _a2.call(window);
          dispatch({
            type: "setService",
            payload: {
              editModal: false,
              cacheItem: null,
              changeService: false,
              callbackPromotion: null
            }
          });
        }
      }
    },
    /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode__booking-drawer-title-wrap" }, /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: "pisell-lowcode__booking-drawer-title-line",
        onClick: () => {
          var _a2;
          (_a2 = window.closeBookingEditModal) == null ? void 0 : _a2.call(window);
          dispatch({
            type: "setService",
            payload: {
              editModal: false,
              cacheItem: null,
              changeService: false,
              callbackPromotion: null
            }
          });
        }
      },
      /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-lowcode__booking-drawer-back" }, /* @__PURE__ */ import_react.default.createElement(import_ArrowLeft.default, null)),
      /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode__booking-drawer-title pisell-lowcode__booking-drawer-title-no-wrap" }, import_utils.locales.getText("pisell2.text.edit-service"))
    )),
    /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode__booking-service-body-edit" }, groupDom, /* @__PURE__ */ import_react.default.createElement(
      import_antd.Form,
      {
        layout: "vertical",
        form,
        onFinish,
        onValuesChange,
        style: {
          display: currentTab === "batch_edit" ? "block" : "none"
        }
      },
      /* @__PURE__ */ import_react.default.createElement(import_antd.Row, { style: { width: "100%" }, gutter: [16, 0] }, productName, price, reason, val && isShowTimeAndResource && /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, startTime, endTime, duration, resource, capacity, hiddenQuantity), isNormalProduct && quantity, !(0, import_utils4.isNormalProductByDurationSchedule)(state.service.cacheItem) && !(0, import_utils6.isWalkIn)((_L = (_K = state.client) == null ? void 0 : _K.value) == null ? void 0 : _L.id) && holder),
      /* @__PURE__ */ import_react.default.createElement(import_antd.Form.Item, { noStyle: true, name: "note" }, noteModalOpen && /* @__PURE__ */ import_react.default.createElement(
        import_noteModal.default,
        {
          open: noteModalOpen,
          value: form.getFieldValue("note"),
          onConfirm: handleNoteConfirm,
          onDelete: handleNoteDelete,
          onCancel: handleNoteCancel
        }
      ))
    ), footer)
  ));
};
var ForwardedInfo = (0, import_react.forwardRef)(Info);
ForwardedInfo.displayName = "Info2EditService";
var editService_default = (0, import_responsive.withResponsive)(ForwardedInfo);
