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/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_ahooks = require("ahooks");
var import_antd = require("antd");
var import_react = __toESM(require("react"));
var import_collapsibleList = __toESM(require("../../../components/collapsibleList"));
var import_utils2 = require("../../../components/collapsibleList/utils");
var import_drawer = __toESM(require("../../../components/drawer"));
var import_duration = __toESM(require("../../../materiels/duration"));
var import_holder = __toESM(require("../../../materiels/holder"));
var import_model = require("../../model");
var import_BookingList = __toESM(require("./BookingList"));
var import_index = require("./index.less");
var import_materials = require("@pisell/materials");
var import_dayjs = __toESM(require("dayjs"));
var import_mock = require("../../../mock");
var import_utils3 = require("../../../utils");
var import_utils4 = require("../../service2/Group/utils");
var import_useSelectPet = __toESM(require("../../service2/hooks/useSelectPet"));
var import_utils5 = require("../../service2/utils");
var import_utils6 = require("../addService/utils");
var import_like = __toESM(require("../like"));
var import_utils7 = require("../../utils");
var import_serviceManager = require("../serviceManager");
var import_EditTabs = __toESM(require("./EditTabs"));
var import_constants = require("./constants");
var import_useEngineContext = __toESM(require("../../../../../hooks/useEngineContext"));
var submitLock = false;
var Info = (_, 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;
  const [form] = import_antd.Form.useForm();
  const context = (0, import_useEngineContext.default)();
  const useTotal = import_antd.Form.useWatch("total", form);
  const useLikeStatus = import_antd.Form.useWatch("like_status", 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 useStartDate = import_antd.Form.useWatch("start_date", form);
  const useEndDate = import_antd.Form.useWatch("end_date", form);
  const [resourceLoading, setResourceLoading] = (0, import_react.useState)(false);
  const { state, dispatch } = (0, import_react.useContext)(import_model.Context);
  const [selectOpen, setSelectOpen] = (0, import_react.useState)();
  const { holderLists } = (0, import_useSelectPet.default)(state);
  const isChangeTotal = (0, import_react.useRef)(false);
  const { editBookingData, editBooking } = (0, import_serviceManager.useService)({ state, dispatch });
  const [currentTab, setCurrentTab] = (0, import_react.useState)("batch_edit");
  const isDayBookingMode = (0, import_react.useMemo)(() => {
    return (0, import_utils5.isDayBooking)(state);
  }, [state == null ? void 0 : state.renderType]);
  const isDaysBookingMode = (0, import_react.useMemo)(() => {
    return (0, import_utils5.isDaysBooking)(state);
  }, [state == null ? void 0 : state.renderType]);
  const isEventBookingMode = (0, import_react.useMemo)(() => {
    return (0, import_utils5.isEventBooking)(state);
  }, [state == null ? void 0 : state.renderType]);
  const getCurrentCacheItem = (_cacheItem) => {
    var _a2;
    let values = form.getFieldsValue();
    let _item = _cacheItem || ((_a2 = state == null ? void 0 : state.service) == null ? void 0 : _a2.cacheItem);
    return {
      ..._item,
      _extend: {
        ..._item == null ? void 0 : _item._extend,
        ...values
      }
    };
  };
  const currentResource = (0, import_react.useMemo)(() => {
    const list = state.service.resources;
    let item = list.find((d) => d.form_record_id == useResource) || {};
    return item;
  }, [useResource, state.service.resources]);
  const durationProps = (0, import_react.useMemo)(() => {
    var _a2, _b2, _c2;
    let _cacheItem = getCurrentCacheItem();
    return (0, import_utils6.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
    });
  }, [
    currentResource,
    state.service.cacheItem,
    useStartTime,
    useResource,
    (_c = (_b = (_a = state.bookingConfig) == null ? void 0 : _a.config) == null ? void 0 : _b.basic) == null ? void 0 : _c.service_time
  ]);
  const flexibleOption = (0, import_react.useMemo)(() => {
    return (0, import_utils6.getFlexibleOption)({
      durationProps
    });
  }, [durationProps, import_utils.locales.locale]);
  const timeObj = (0, import_react.useMemo)(() => {
    return (0, import_utils6.getTimeObj)({
      durationProps,
      useStartTime,
      currentResource,
      state,
      useDuration
    });
  }, [state, import_utils.locales.locale, useDuration, useStartTime, flexibleOption]);
  (0, import_react.useEffect)(() => {
    try {
      if (useDuration.indexOf("flexible_") == 0) {
        if (flexibleOption) {
          form.setFieldsValue({
            duration: flexibleOption.value
          });
        }
      }
    } catch (err) {
    }
  }, [useDuration, flexibleOption]);
  const getResources = async (cacheItem, open) => {
    console.log("getResources2");
    try {
      let _list = state.service.resourcesOrigin || [];
      const _cacheItem = cacheItem || getCurrentCacheItem();
      let autoClose = _cacheItem == null ? void 0 : _cacheItem.autoClose;
      if (!_cacheItem._extend) {
        return;
      }
      dispatch({
        type: "setService",
        payload: {
          resources: (0, import_utils6.formatResources)({
            cacheItem: _cacheItem,
            resourcesOrigin: _list,
            isDay: isDayBookingMode
          })
        }
      });
      if (_cacheItem.new) {
        if (autoClose) {
          setTimeout(() => {
            form.submit();
          }, 200);
        } else {
          setTimeout(() => {
            if (selectOpen === void 0 || open) {
              setSelectOpen(true);
            }
          }, 500);
        }
      }
    } catch (err) {
    }
  };
  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;
    if ((0, import_utils4.isGroupBooking)(_id)) {
      _list = (0, import_utils4.filterItemByGroupId)(_id, _list);
    } else {
      _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
      }
    });
  });
  const renderOptions = (0, import_react.useCallback)(
    (array, value = "value", label = "label", type) => {
      return array.map((d) => {
        let props = {};
        if (type === "resource") {
          props.labelText = d.labelText;
        }
        return /* @__PURE__ */ import_react.default.createElement(import_antd.Select.Option, { value: d[value], key: d[value], ...props }, d[label]);
      });
    },
    []
  );
  const handleLikeResource = (0, import_ahooks.useMemoizedFn)((status) => {
    form.setFieldsValue({
      like_status: status
    });
  });
  const getErrorMsg = () => {
    var _a2, _b2;
    const list = state.service.resources;
    let item = list.find((d) => d.form_record_id == useResource);
    if (item) {
      const isMaxLimitRange = (_b2 = (_a2 = item._extend.usableTime) == null ? void 0 : _a2._extend) == null ? void 0 : _b2.isMaxLimitRange;
      if (isMaxLimitRange === "unknown") {
      }
    }
  };
  const getDiscount = () => {
    var _a2;
    console.log("折扣内", state.service.cacheItem);
    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 = (0, import_ahooks.useMemoizedFn)(async (values) => {
    if (submitLock) {
      return;
    }
    submitLock = true;
    setTimeout(() => {
      submitLock = false;
    }, 1500);
    const data = await editBookingData({
      changeValues: {
        ...values,
        errorList
      }
    });
    if (isChangeTotal.current) {
      delete data.discount_list;
    }
    await editBooking({ booking: data });
  });
  const setEditData = (0, import_ahooks.useMemoizedFn)(
    (_cacheItem, open, openProductDetail) => {
      setCurrentTab("batch_edit");
      isChangeTotal.current = false;
      let cacheItem = _cacheItem || state.service.cacheItem;
      let values = cacheItem._extend;
      values = {
        ...values,
        discount_reason: (values == null ? void 0 : values.discount_reason) || ""
      };
      form.setFieldsValue(values);
      if (openProductDetail) {
        setTimeout(() => {
          handleEdit({});
        }, 100);
      }
      if (!isEventBookingMode) {
        getResources(cacheItem, open);
      }
    }
  );
  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, (_e = (_d = state.service.cacheItem) == null ? void 0 : _d._extend) == null ? void 0 : _e.origin_total]);
  const errorList = (0, import_react.useMemo)(() => {
    return (0, import_utils3.getErrorList)(
      currentResource,
      getCurrentCacheItem(),
      isDayBookingMode
    );
  }, [currentResource, useDuration, useStartTime]);
  (0, import_ahooks.useUpdateEffect)(() => {
    var _a2;
    if (state.service.cacheItem && !((_a2 = state.service.cacheItem) == null ? void 0 : _a2.autoClose)) {
      if (useStartTime && useDuration && !isEventBookingMode) {
        getResources();
      }
    }
  }, [
    useStartTime,
    useDuration,
    state.renderType,
    state.service.resourcesOrigin,
    (_f = state.service.cacheItem) == null ? void 0 : _f.autoClose
  ]);
  const isTerminalBooking = (0, import_react.useMemo)(() => {
    return state.isBookingCreatePage || state.isTerminalDayBookingPage;
  }, [state.isBookingCreatePage, state.isTerminalDayBookingPage]);
  (0, import_react.useEffect)(() => {
    if (isTerminalBooking && state.service.editModal) {
      setEditData(null, true);
    }
  }, [state.service.editModal, isTerminalBooking]);
  (0, import_react.useEffect)(() => {
    getErrorMsg();
  }, [useResource, useStartTime, useDuration, useStartDate, useEndDate]);
  (0, import_react.useEffect)(() => {
    getDiscount();
  }, [useTotal, (_h = (_g = state.service.cacheItem) == null ? void 0 : _g._extend) == null ? void 0 : _h.origin_total]);
  const isDiscount = (0, import_react.useMemo)(() => {
    var _a2, _b2, _c2;
    if (!((_a2 = state.service) == null ? void 0 : _a2.cacheItem)) {
      return false;
    }
    return useTotal != ((_c2 = (_b2 = state.service) == null ? void 0 : _b2.cacheItem) == null ? void 0 : _c2._extend.origin_total);
  }, [useTotal, (_j = (_i = state.service) == null ? void 0 : _i.cacheItem) == null ? void 0 : _j._extend.origin_total]);
  (0, import_react.useEffect)(() => {
    if (useResource === 0) {
      handleLikeResource("common");
    }
  }, [useResource]);
  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) || [];
  }, [(_n = (_m = (_l = (_k = state.service) == null ? void 0 : _k.cacheItem) == null ? void 0 : _l._extend) == null ? void 0 : _m.other) == null ? void 0 : _n.bundle]);
  const multiDayPrices = (0, import_react.useMemo)(() => {
    var _a2, _b2, _c2;
    return Object.entries(
      (0, import_utils7.getMultiDayPrices)(((_c2 = (_b2 = (_a2 = state.service) == null ? void 0 : _a2.cacheItem) == null ? void 0 : _b2._extend) == null ? void 0 : _c2.multi_day) || [])
    ).map(([key, value]) => {
      return {
        key,
        value
      };
    });
  }, [(_q = (_p = (_o = state.service) == null ? void 0 : _o.cacheItem) == null ? void 0 : _p._extend) == null ? void 0 : _q.multi_day]);
  const getResourcesData = async () => {
    var _a2, _b2, _c2, _d2, _e2;
    setResourceLoading(true);
    try {
      let params = {};
      if (isDayBookingMode) {
        const format = "YYYY-MM-DD HH:mm";
        const startDate = useStartDate || state.date.value;
        const endDate = useEndDate || state.date.end_date;
        const { startDateTime, endDateTime } = (0, import_utils5.formatDayTime)({
          startDate,
          endDate
        });
        if ((0, import_dayjs.default)(startDateTime).isAfter((0, import_dayjs.default)(endDateTime))) return;
        params.check_time = {
          start_time: (0, import_dayjs.default)(startDateTime).format(format),
          end_time: (0, import_dayjs.default)(endDateTime).format(format)
        };
      } else {
        params.with_date_times = state.date.value.format("YYYY-MM-DD");
      }
      const isPartyRoomResourceShop = (0, import_constants.getIsPartyRoomResourceShop)(
        (_e2 = (_d2 = (_c2 = (_b2 = (_a2 = context.appHelper.utils.store) == null ? void 0 : _a2.getState) == null ? void 0 : _b2.call(_a2)) == null ? void 0 : _c2.global) == null ? void 0 : _d2.globalConfig) == null ? void 0 : _e2.id
      );
      const codes = isPartyRoomResourceShop ? ["resources", "therapist", "table", "party_room"] : ["resources", "therapist", "table"];
      let data = await state.apis.getResources({
        skip: 1,
        num: 1e3,
        codes,
        _config: { abort: true },
        ...params
      });
      let _list = [(0, import_mock.getNoResource)()].concat((data == null ? void 0 : data.list) || []);
      dispatch({
        type: "setService",
        payload: {
          resourcesOrigin: _list
        }
      });
    } catch (err) {
      console.log(err, "err");
    }
    setResourceLoading(false);
  };
  (0, import_react.useEffect)(() => {
    if (isEventBookingMode) {
      return;
    }
    setTimeout(() => {
      getResourcesData();
    }, 20);
  }, [
    (_t = (_s = (_r = state.date) == null ? void 0 : _r.value) == null ? void 0 : _s.format) == null ? void 0 : _t.call(_s, "YYYY-MM-DD"),
    (_u = state.date) == null ? void 0 : _u.end_date,
    useStartDate,
    useEndDate,
    isEventBookingMode
  ]);
  const handleEdit = (0, import_ahooks.useMemoizedFn)((e) => {
    var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i2, _j2, _k2;
    const item = state.service.cacheItem;
    let values = form.getFieldsValue();
    let dayValue = {};
    if (isDayBookingMode) {
      const option = (_c2 = (_b2 = (_a2 = item._extend) == null ? void 0 : _a2.other) == null ? void 0 : _b2.option) == null ? void 0 : _c2.map((o) => {
        return {
          ...o,
          option_group_item_id: o.product_option_item_id
        };
      });
      dayValue.product_variant = ((_e2 = (_d2 = item._extend) == null ? void 0 : _d2.other) == null ? void 0 : _e2.product_variant_id) || 0;
      dayValue.product_option = option || [];
    }
    const isSession = (0, import_utils3.isSessionProduct)(item);
    const sessionValue = {};
    if (isSession) {
      sessionValue.startEndTime = {
        startDate: (_f2 = item == null ? void 0 : item._extend) == null ? void 0 : _f2.start_date,
        endDate: (_g2 = item == null ? void 0 : item._extend) == null ? void 0 : _g2.end_date,
        duration: (_h2 = item == null ? void 0 : item._extend) == null ? void 0 : _h2.duration
      };
    }
    state.action({
      type: "pisell1.handleOpenProductModal",
      data: {
        id: item.id,
        date: state.date.value.format("YYYY-MM-DD"),
        showConfig: {
          option: isDayBookingMode ? true : false,
          session: isSession,
          variant: isDayBookingMode ? true : false,
          package: true
        },
        value: {
          ...((_i2 = item._extend) == null ? void 0 : _i2.other) || {},
          ...dayValue,
          ...sessionValue
        },
        isOS: isSession,
        customer_id: (_k2 = (_j2 = state.client) == null ? void 0 : _j2.value) == null ? void 0 : _k2.id
      },
      callback: async (e2, extension_type, detail) => {
        var _a3, _b3, _c3, _d3;
        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,
            // 覆盖选择的规格和套餐
            other
          },
          new: 0
        };
        let _total = (0, import_utils3.getProductTotalPrice)(cacheItem);
        if ((_b3 = (_a3 = cacheItem == null ? void 0 : cacheItem._extend) == null ? void 0 : _a3.other) == null ? void 0 : _b3.product_variant_id) {
          cacheItem._extend.price = Number((_d3 = (_c3 = cacheItem._extend) == null ? void 0 : _c3.other) == null ? void 0 : _d3.price);
        }
        const sessionDetail = (0, import_utils7.editSessionProduct)(cacheItem, e2.session);
        cacheItem._extend.total = _total;
        cacheItem._extend.origin_total = _total;
        dispatch({
          type: "setService",
          payload: {
            cacheItem
          }
        });
        if (isDaysBookingMode) {
          setTimeout(() => {
            updateMultiDay({
              start_date: values.start_date,
              end_date: values.end_date
            });
          }, 100);
        } else {
          form.setFieldsValue({
            total: _total,
            ...(0, import_utils3.isSessionProduct)(cacheItem) && sessionDetail ? {
              start_time: sessionDetail.start_time,
              duration: sessionDetail.duration
            } : {}
          });
        }
      }
    });
  });
  const handleChange = (0, import_ahooks.useMemoizedFn)((e) => {
    if (state.channelDisabledEdit) {
      return;
    }
    dispatch({
      type: "setService",
      payload: {
        addModal: true,
        editModal: true,
        //用于控制 添加商品 和 编辑服务弹窗的上下层级
        changeService: true
      }
    });
  });
  (0, import_react.useImperativeHandle)(ref, () => {
    return {
      init: setEditData
    };
  });
  const SelectTime = (_v = window.BaseMaterials) == null ? void 0 : _v.SelectTime;
  const DateCom = (position) => {
    return /* @__PURE__ */ import_react.default.createElement(
      import_antd.DatePicker,
      {
        className: "pisell-lowcode__booking-service-select-date",
        disabledDate: (current) => (0, import_utils5.disabledDate)(current, position, useStartDate),
        size: "large",
        style: { width: "100%" },
        format: state.locale === "en" ? "DD/MM/YYYY" : "YYYY-MM-DD"
      }
    );
  };
  const updateMultiDay = async ({ start_date, end_date, duration }) => {
    const cacheItem = await (0, import_utils6.getMultiDay)({
      start_date,
      end_date,
      state,
      cacheItem: getCurrentCacheItem()
    });
    if (duration !== void 0) {
      cacheItem._extend.duration = duration;
    }
    cacheItem._extend.items = (0, import_utils4.createBookingItemsByGroup)(cacheItem);
    cacheItem._extend = {
      ...cacheItem._extend,
      ...(0, import_utils4.getGroupTotalPrice)(cacheItem._extend.items)
    };
    dispatch({
      type: "setService",
      payload: {
        cacheItem
      }
    });
    let fieldsValues = {
      total: cacheItem._extend.total
    };
    form.setFieldsValue(fieldsValues);
  };
  const onValuesChange = (changedValues) => {
    if (isDayBookingMode) {
      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 duration = (0, import_utils3.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 });
        return form.setFieldsValue({
          duration
        });
      }
    }
  };
  const showResource = (0, import_react.useMemo)(() => {
    if (isEventBookingMode) {
      return false;
    }
    if (isDayBookingMode) {
      return (0, import_utils5.isDayBookingProduct)(state.service.cacheItem, state);
    }
    return true;
  }, [state.service.cacheItem, state.renderType]);
  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,
    useLikeStatus,
    currentResource,
    useTotal
  ]);
  const isEditGroup = (0, import_react.useMemo)(() => {
    return items.length;
  }, [items]);
  const handleTotalChange = (number) => {
    isChangeTotal.current = true;
  };
  return (0, import_react.useMemo)(() => {
    var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i2, _j2, _k2, _l2, _m2, _n2, _o2, _p2;
    return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(
      import_drawer.default,
      {
        titleNoWrap: true,
        zIndex: state.service.changeService ? 999 : 1e3,
        forceRender: true,
        open: state.service.editModal && !((_a2 = state.service.cacheItem) == null ? void 0 : _a2.autoClose),
        title: isDayBookingMode ? import_utils.locales.getText("pisell2.text.edit-select-service") : import_utils.locales.getText("pisell2.text.edit-service"),
        onClose: () => {
          var _a3;
          (_a3 = window.closeBookingEditModal) == null ? void 0 : _a3.call(window);
          dispatch({
            type: "setService",
            payload: {
              editModal: false,
              cacheItem: null,
              changeService: false
            }
          });
        }
      },
      /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode__booking-service-body-edit" }, isEditGroup ? /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__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 })
      )) : null, /* @__PURE__ */ import_react.default.createElement(
        "div",
        {
          className: "",
          style: {
            display: currentTab === "batch_edit" ? "block" : "none"
          }
        },
        /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(import_materials.Page, null, /* @__PURE__ */ import_react.default.createElement(
          import_antd.Form,
          {
            layout: "vertical",
            form,
            onFinish,
            onValuesChange
          },
          /* @__PURE__ */ import_react.default.createElement(import_antd.Row, { style: { width: "100%" }, gutter: [16, 0] }, /* @__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" }, ((_d2 = (_c2 = (_b2 = state.service) == null ? void 0 : _b2.cacheItem) == null ? void 0 : _c2._extend) == null ? void 0 : _d2.product_name) || "-"), /* @__PURE__ */ import_react.default.createElement(import_antd.Button, { onClick: handleEdit }, import_utils.locales.getText("pisell2.text.edit")), !isTerminalBooking && /* @__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)
            }
          )))), /* @__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 !== ((_f2 = (_e2 = state.service.cacheItem) == null ? void 0 : _e2._extend) == null ? void 0 : _f2.origin_total) && import_utils.locales.getText("page.booking.text.price-extra")(
                (0, import_utils.formatAmount)(
                  (_h2 = (_g2 = state.service.cacheItem) == null ? void 0 : _g2._extend) == null ? void 0 : _h2.origin_total,
                  2,
                  state.amountSymbol
                ),
                (0, import_utils.formatAmount)(useTotal, 2, state.amountSymbol)
              )
            },
            /* @__PURE__ */ import_react.default.createElement(
              import_materials.PisellAdjustPriceInputNumber,
              {
                style: { width: "100%" },
                min: 0,
                precision: 2,
                onChange: handleTotalChange,
                prefix: state.amountSymbol,
                disabled: state.channelDisabledEdit,
                originValue: ((_j2 = (_i2 = state.service.cacheItem) == null ? void 0 : _i2._extend) == null ? void 0 : _j2.origin_total) || 0,
                placeholder: ((_l2 = (_k2 = state.service.cacheItem) == null ? void 0 : _k2._extend) == null ? void 0 : _l2.origin_total) || "0"
              }
            )
          )), 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, showResource && /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(import_antd.Col, { span: 12 }, /* @__PURE__ */ import_react.default.createElement(
            import_antd.Form.Item,
            {
              label: import_utils.locales.getText(
                isDayBookingMode ? "pisell2.text.start_date" : "pisell2.text.start_time"
              ),
              name: isDayBookingMode ? "start_date" : "start_time",
              rules: [{ required: true }]
            },
            isDayBookingMode ? DateCom("start") : SelectTime ? /* @__PURE__ */ import_react.default.createElement(
              SelectTime,
              {
                slice: (_p2 = (_o2 = (_n2 = (_m2 = state.bookingConfig) == null ? void 0 : _m2.config) == null ? void 0 : _n2.basic) == null ? void 0 : _o2.service_time) == null ? void 0 : _p2.value,
                timePickerProps: {
                  style: { width: "100%" }
                },
                timeProps: {
                  style: { zoom: 0.8 }
                }
              }
            ) : null
          )), isDayBookingMode ? /* @__PURE__ */ import_react.default.createElement(import_antd.Col, { span: 12 }, /* @__PURE__ */ import_react.default.createElement(
            import_antd.Form.Item,
            {
              label: import_utils.locales.getText(
                isDayBookingMode ? "pisell2.text.end_date" : "pisell2.text.end_time"
              ),
              name: "end_date",
              rules: [{ required: true }]
            },
            DateCom("end")
          )) : null, /* @__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.duration"),
              name: "duration",
              rules: [{ required: true }]
            },
            /* @__PURE__ */ import_react.default.createElement(import_duration.default, { ...durationProps, timeObj })
          )), isDayBookingMode && (holderLists == null ? void 0 : holderLists.length) > 0 ? /* @__PURE__ */ import_react.default.createElement(import_antd.Col, { span: isDayBookingMode ? 12 : 24 }, /* @__PURE__ */ import_react.default.createElement(
            import_antd.Form.Item,
            {
              label: import_utils.locales.getText("pisell2.text.holder"),
              name: "holder_id",
              rules: [{ required: isDayBookingMode }]
            },
            /* @__PURE__ */ import_react.default.createElement(import_holder.default, { size: "large" })
          )) : null, /* @__PURE__ */ import_react.default.createElement(import_antd.Col, { span: 24 }, /* @__PURE__ */ import_react.default.createElement(
            import_antd.Form.Item,
            {
              required: true,
              label: import_utils.locales.getText("pisell2.text.resource")
            },
            /* @__PURE__ */ import_react.default.createElement("div", { className: "resource-col" }, /* @__PURE__ */ import_react.default.createElement(
              import_antd.Button,
              {
                className: "resource-col-like-wrap",
                disabled: !useResource,
                onClick: () => {
                  handleLikeResource(
                    useLikeStatus === "like" ? "common" : "like"
                  );
                }
              },
              /* @__PURE__ */ import_react.default.createElement(
                import_like.default,
                {
                  status: useLikeStatus
                }
              )
            ), /* @__PURE__ */ import_react.default.createElement(
              import_antd.Form.Item,
              {
                name: "resource",
                noStyle: true,
                rules: [{ required: true }]
              },
              /* @__PURE__ */ import_react.default.createElement(
                import_antd.Select,
                {
                  loading: resourceLoading,
                  size: "large",
                  allowClear: true,
                  showSearch: true,
                  open: selectOpen,
                  onDropdownVisibleChange: setSelectOpen,
                  filterOption: (str, option) => {
                    return (option.labelText || "").toLowerCase().includes((str || "").toLowerCase());
                  }
                },
                renderOptions(
                  state.service.resources || [],
                  "form_record_id",
                  "label",
                  "resource"
                )
              )
            ))
          )), /* @__PURE__ */ import_react.default.createElement(import_antd.Form.Item, { hidden: true, name: "quantity" }, /* @__PURE__ */ import_react.default.createElement(import_antd.InputNumber, null)), /* @__PURE__ */ import_react.default.createElement(import_antd.Form.Item, { hidden: true, name: "like_status" }, /* @__PURE__ */ import_react.default.createElement(import_antd.Input, null))), !isEventBookingMode && isDayBookingMode && !(0, import_utils5.isDayBookingProduct)(state.service.cacheItem, state) ? /* @__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;
                }
              }
            )
          )) : null)
        )), showResource && errorList.map((d, i) => {
          return /* @__PURE__ */ import_react.default.createElement(
            import_antd.Alert,
            {
              key: d.type,
              message: d.label,
              type: "warning",
              showIcon: true,
              style: { marginBottom: 12 }
            }
          );
        }))
      ), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode__booking-service-body-edit-footer" }, /* @__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" })
      ), /* @__PURE__ */ import_react.default.createElement(
        import_antd.Button,
        {
          type: "primary",
          className: "pisell-lowcode__booking-service-body-edit-footer-apple",
          disabled: resourceLoading,
          onClick: () => {
            form.submit();
          }
        },
        import_utils.locales.getText("pisell2.text.apply")
      )))
    ));
  }, [
    state.service.changeService,
    state.service.editModal,
    (_w = state.service.cacheItem) == null ? void 0 : _w.autoClose,
    import_utils.locales,
    (_z = (_y = (_x = state.service) == null ? void 0 : _x.cacheItem) == null ? void 0 : _y._extend) == null ? void 0 : _z.product_name,
    bundles,
    state.amountSymbol,
    state.channelDisabledEdit,
    (_B = (_A = state.service.cacheItem) == null ? void 0 : _A._extend) == null ? void 0 : _B.origin_total,
    isDiscount,
    isReason,
    state.renderType,
    (_F = (_E = (_D = (_C = state.bookingConfig) == null ? void 0 : _C.config) == null ? void 0 : _D.basic) == null ? void 0 : _E.service_time) == null ? void 0 : _F.value,
    SelectTime,
    durationProps,
    timeObj,
    useResource,
    useLikeStatus,
    resourceLoading,
    selectOpen,
    state.service.resources,
    errorList,
    useTotal,
    useStartDate,
    useEndDate,
    showResource,
    holderLists,
    multiDayPrices,
    currentTab,
    items,
    isEventBookingMode
  ]);
};
var editService_default = (0, import_react.forwardRef)(Info);
