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/ticketBooking/components/ticketBooking/index.tsx
var ticketBooking_exports = {};
__export(ticketBooking_exports, {
  _formatBookingDetail: () => _formatBookingDetail,
  default: () => ticketBooking_default
});
module.exports = __toCommonJS(ticketBooking_exports);
var import_react = __toESM(require("react"));
var import_utils = require("@pisell/utils");
var import_antd = require("antd");
var import_serve = require("../../serve");
var apis = __toESM(require("../../serve"));
var import_dayjs = __toESM(require("dayjs"));
var import_useEngineContext = __toESM(require("../../../../hooks/useEngineContext"));
var import_miniRedux = require("../../miniRedux");
var import_info = __toESM(require("../../../../components/booking/info"));
var import_utils2 = require("../../utils");
var import_addServiceVariant = __toESM(require("../addServiceVariant"));
var import_timeBar = __toESM(require("../timeBar"));
var import_index = require("./index.less");
var import_utils3 = require("../../../booking/info/service2/utils");
var import_amount = require("../../../booking/components/footer/amount");
var import_formatProductMessage = __toESM(require("../../utils/formatProductMessage"));
var _formatBookingDetail = (data, modalState) => {
  var _a, _b, _c, _d;
  let {
    customer_id,
    holder,
    customer_name,
    email,
    phone,
    country_calling_code,
    bookings,
    customer,
    note,
    payment_status,
    is_other_entrance_edited,
    shop_discount
  } = data;
  const clientValue = {
    name: ((customer == null ? void 0 : customer.display_name) || "").trim() || ((customer == null ? void 0 : customer.nickname) || "").trim() || "",
    id: customer_id || (customer == null ? void 0 : customer.id) || (customer == null ? void 0 : customer.customer_id) || 1,
    email: customer == null ? void 0 : customer.email,
    phone: (customer == null ? void 0 : customer.phone) || "",
    country_calling_code: (customer == null ? void 0 : customer.country_calling_code) || "",
    cover: (customer == null ? void 0 : customer.cover) || ""
  };
  const start_date = (_b = (_a = bookings == null ? void 0 : bookings.list) == null ? void 0 : _a[0]) == null ? void 0 : _b.start_date;
  const dateValue = (0, import_dayjs.default)(
    start_date ? start_date + " " + ((_d = (_c = bookings == null ? void 0 : bookings.list) == null ? void 0 : _c[0]) == null ? void 0 : _d.start_time) : /* @__PURE__ */ new Date()
  );
  const petsValue = holder;
  const getCapacity = (resetD) => {
    var _a2;
    return (_a2 = resetD.metadata) == null ? void 0 : _a2.capacity;
  };
  const getResource = (resetD) => {
    var _a2;
    if (!bookings.relation_type) {
      try {
        if ((resetD == null ? void 0 : resetD.event_resources) && ((_a2 = resetD == null ? void 0 : resetD.event_resources) == null ? void 0 : _a2.length)) {
          return resetD.event_resources.reduce((pre, cur) => {
            if (pre[cur.form_id]) {
              pre[cur.form_id].push(cur);
            } else {
              pre[cur.form_id] = [cur];
            }
            return pre;
          }, {});
        }
      } catch (err) {
        console.error(err);
      }
    }
    return resetD.relation_id;
  };
  const serviceValue = bookings.list.map((d) => {
    let { detail, product, ...resetD } = d;
    let _detail = detail || mockProduct;
    let start_date2 = (0, import_dayjs.default)(resetD.start_date + " " + resetD.start_time);
    let end_date = (0, import_dayjs.default)(resetD.end_date + " " + resetD.end_time);
    return {
      _id: (Math.random() + "").replace(/\D/g, "").substring(0, 11),
      ..._detail,
      booking_id: resetD.id,
      id: _detail.product_id,
      title: _detail.product_title,
      quantity: Number(_detail.product_quantity),
      cover: _detail.product_cover,
      // 商品本身的价格
      price: Number(_detail.source_product_price),
      relation_form_name: resetD.relation_form_name,
      product_resource: product == null ? void 0 : product.product_resource,
      capacity: product == null ? void 0 : product.capacity,
      _extend: {
        ...resetD,
        quantity: Number(_detail.product_quantity),
        startDate: start_date2,
        start_date: start_date2,
        endDate: end_date,
        end_date,
        // 商品本身的价格
        price: Number(_detail.source_product_price),
        product_name: _detail.product_title,
        discount_reason: _detail.product_discount_reason,
        // resource: resetD.relation_id,
        order_detail_id: _detail.order_detail_id,
        // 总价: 商品本身价格 + 套餐价格 + 单规格价格   包含折扣
        total: Number(_detail.selling_price),
        // 原总价: 商品本身价格 + 套餐价格 + 单规格价格 不包含折扣
        origin_total: Number(_detail.original_price),
        payment_price: Number(_detail.payment_price),
        other: (0, import_utils2.restoreProductOtherData)(d),
        // 是否编辑了套餐 默认为0  如果编辑之后为1
        bundle_edit: 0,
        discount_per: _detail.discount_per,
        discount_type: _detail.discount_type,
        discountway: _detail.discountway,
        capacity: getCapacity(resetD),
        resource: getResource(resetD)
      }
    };
  });
  let disabledEdit = (0, import_utils2.getDisabledEdit)(data);
  let channelDisabledEdit = !!is_other_entrance_edited;
  return {
    ...modalState,
    client: {
      ...modalState.client,
      value: clientValue,
      edit: false,
      showModal: false
    },
    date: {
      ...modalState.date,
      value: dateValue,
      edit: false,
      showModal: false
    },
    pet: {
      ...modalState.pet,
      showModal: false,
      edit: false
    },
    service: {
      ...modalState.service,
      value: serviceValue,
      addModal: false,
      editModal: false,
      edit: false
    },
    notes: {
      ...modalState.notes,
      orderNote: note,
      edit: false
    },
    disabledEdit,
    channelDisabledEdit,
    appointment_status: bookings == null ? void 0 : bookings.appointment_status
  };
};
var TicketBooking = () => {
  var _a, _b, _c;
  const [state, setState] = (0, import_miniRedux.useStore)();
  const engineContext = (0, import_useEngineContext.default)();
  const { props: engineProps } = engineContext.engine;
  const {
    action,
    isTerminal,
    lowcodeRef,
    interaction,
    store,
    storage,
    Toast,
    getSymbolic,
    translation
  } = (_a = engineContext.appHelper) == null ? void 0 : _a.utils;
  const _persistentRef = (0, import_react.useRef)(false);
  const _initStateRef = (0, import_react.useRef)({});
  const _listTimerRef = (0, import_react.useRef)();
  const _timerRef = (0, import_react.useRef)();
  const _callbackFnRef = (0, import_react.useRef)();
  (0, import_react.useEffect)(() => {
    var _a2, _b2, _c2, _d, _e, _f;
    _persistentRef.current = storage.get(`drawer-booking`) === "true" ? true : isTerminal();
    if (lowcodeRef) {
      lowcodeRef.onReady(void 0);
    }
    if (action) {
      action({
        type: "pisell1.registerPlugin",
        data: {
          pluginList: ["ProductDetailPlugin"]
        }
      });
    }
    (_a2 = interaction == null ? void 0 : interaction.utils) == null ? void 0 : _a2.mountFunction(
      "booking",
      "scanBookingDetailResult",
      _scanBookingDetailResult
    );
    const off = _addVisibilityListener(() => {
      setState({
        verticalAddServiceKey: state.verticalAddServiceKey + 1
      });
    });
    setState(
      {
        amountSymbol: ((_d = (_c2 = (_b2 = store == null ? void 0 : store.getState) == null ? void 0 : _b2.call(store)) == null ? void 0 : _c2.global) == null ? void 0 : _d.symbol) || "$"
      },
      () => {
        _initStateRef.current = JSON.parse(JSON.stringify(state));
        _getBoardConfig();
      }
    );
    _setShopOpeningHours();
    _setIntervalTime(true);
    (_e = interaction == null ? void 0 : interaction.utils) == null ? void 0 : _e.mountFunction(
      "booking",
      "refreshBookingDetail",
      (type, orderId) => {
        _initFn(() => {
        });
      }
    );
    (_f = interaction == null ? void 0 : interaction.utils) == null ? void 0 : _f.mountFunction(
      "booking",
      "voidBooking",
      (orderId) => {
        (0, import_serve.voidAppointment)(orderId);
      }
    );
    return () => {
      off == null ? void 0 : off();
      if (_listTimerRef.current) clearInterval(_listTimerRef.current);
    };
  }, []);
  const _onDateChange = (date, dateString) => {
    _setIntervalTime(false);
    setState({
      isDateChange: true
    });
    _setDataChange(date, dateString);
  };
  const _setIntervalTime = (isInterval) => {
    clearInterval(_timerRef.current);
    if (isInterval) {
      setState({
        isTimeChange: false,
        isDateChange: false
      });
      if (state.bookingId) {
        _openModal({});
      }
      _setDataChange((0, import_dayjs.default)());
      _timerRef.current = setInterval(() => {
        _setDataChange((0, import_dayjs.default)());
      }, 1e3 * 60);
    }
    setState({
      intervalSetTime: isInterval
    });
  };
  (0, import_react.useEffect)(() => {
    var _a2, _b2, _c2, _d, _e, _f, _g, _h, _i, _j;
    const cartItems = (_b2 = (_a2 = state == null ? void 0 : state.modalState) == null ? void 0 : _a2.service) == null ? void 0 : _b2.value;
    if (!Array.isArray(cartItems) || cartItems.length === 0) {
      (_d = (_c2 = interaction == null ? void 0 : interaction.utils) == null ? void 0 : _c2.postMessageToApp) == null ? void 0 : _d.call(_c2, {
        module: "cds",
        key: "cartUpdate",
        data: {
          currency_symbol: getSymbolic(),
          total: "0",
          // 小计
          products: [],
          fees: []
        }
      });
    }
    const total = (0, import_amount.getSumTotal)(state.modalState, true);
    let formatedProducts = [];
    try {
      formatedProducts = (0, import_utils3.formatProducts)(
        cartItems,
        state.modalState,
        false,
        true,
        true
      );
    } catch (error) {
      console.error(error);
    }
    console.log("formatedProducts", total, formatedProducts);
    let fees = [];
    let products = [];
    for (const item of formatedProducts) {
      const { id, name, image, origin_total, total: total2, num, note, _origin } = item;
      (_e = _origin == null ? void 0 : _origin.discount_list) == null ? void 0 : _e.forEach((dl) => {
        fees.push({
          isReduce: dl.type === "good_pass",
          title: translation(dl == null ? void 0 : dl.discount.title),
          price: dl.amount,
          type: dl.type
        });
      });
      let msg = "";
      try {
        msg = (0, import_formatProductMessage.default)(
          {
            ...item,
            currency_symbol: getSymbolic()
          },
          (_f = engineContext.appHelper) == null ? void 0 : _f.utils
        );
      } catch (error) {
        console.error(error);
      }
      let _item = {
        productID: id,
        title: name,
        cover: image,
        //  封面图
        price: total2,
        // 售价
        buyCount: num,
        // 购买数量
        productFormatMessage: msg,
        note
      };
      if (origin_total !== total2) _item.modifyPrice = origin_total;
      products.push(_item);
    }
    console.log(
      "formatedProducts",
      (_g = import_utils.locales.getText("pisell2.product.card.cart-items")) == null ? void 0 : _g(products.length)
    );
    if (products.length > 0) {
      fees.unshift({
        title: import_utils.locales.getText("pisell2.product.card.subtotal"),
        price: total.productAmount,
        type: "subtotal",
        message: (_h = import_utils.locales.getText("pisell2.product.card.cart-items")) == null ? void 0 : _h(
          products.length
        )
      });
    }
    console.log("start post message, config:", {
      module: "cds",
      key: "cartUpdate",
      data: {
        currency_symbol: getSymbolic(),
        total: total.productAmount,
        // 小计
        products,
        fees
      }
    });
    (_j = (_i = interaction == null ? void 0 : interaction.utils) == null ? void 0 : _i.postMessageToApp) == null ? void 0 : _j.call(_i, {
      module: "cds",
      key: "cartUpdate",
      data: {
        currency_symbol: getSymbolic(),
        total: total.expectAmount,
        // 小计
        products,
        fees
      }
    });
  }, [(_c = (_b = state == null ? void 0 : state.modalState) == null ? void 0 : _b.service) == null ? void 0 : _c.value]);
  const _setModalState = (props) => {
    var _a2, _b2;
    console.log("同步state到外层", props);
    let newVal = { ...props };
    if (newVal.service) {
      newVal.service.value = ((_a2 = newVal == null ? void 0 : newVal.service) == null ? void 0 : _a2.value) || [];
    }
    console.log((_b2 = newVal == null ? void 0 : newVal.service) == null ? void 0 : _b2.value, "newVal.service.value");
    setState({
      modalState: {
        ...state.modalState,
        ...newVal
      }
    });
  };
  const _setDataChange = (date, dateString, isTimeChange) => {
    if (state.modalState.disabledEdit) return;
    _setListState({
      params: {
        ...state.list.params,
        booking_time_start_between: (0, import_utils2.formatDateToStr)([
          date.startOf(isTimeChange ? "minute" : "day"),
          date.endOf(isTimeChange ? "minute" : "day")
        ])
      }
    });
    _setModalState({
      date: {
        ...state.modalState.date,
        value: date,
        edit: true
      }
    });
    setTimeout(() => {
      var _a2, _b2, _c2, _d, _e;
      if ((_b2 = (_a2 = state.modalState.service) == null ? void 0 : _a2.value) == null ? void 0 : _b2.length) {
        let _list = (_e = (_c2 = state.bookingFunctions) == null ? void 0 : _c2.updateServiceDate) == null ? void 0 : _e.call(
          _c2,
          (_d = state.modalState.service) == null ? void 0 : _d.value,
          date,
          false
        );
        _setModalState({
          service: {
            ...state.modalState.service,
            value: _list,
            edit: true
          }
        });
      }
    }, 100);
  };
  const _setShopOpeningHours = () => {
    var _a2, _b2, _c2, _d, _e;
    let time = (_e = (_d = (_c2 = (_b2 = (_a2 = store == null ? void 0 : store.getState) == null ? void 0 : _a2.call(store)) == null ? void 0 : _b2.global) == null ? void 0 : _c2.shopDetail) == null ? void 0 : _d.operating_day_boundary) == null ? void 0 : _e.time;
    if (time) {
      localStorage.setItem("shopOpeningHours", time);
    }
  };
  const _getAddTimeProducts = async () => {
    const data = await (0, import_serve.getServices)({
      skip: 1,
      num: 500,
      extension_type: ["product_add_time"]
    });
    console.log("wwww", data);
    setState({
      addTimeProducts: (data == null ? void 0 : data.list) || []
    });
  };
  const _getBoardConfig = async () => {
    var _a2, _b2, _c2;
    const { bookingConfigParams } = state;
    const data = await (0, import_serve.getBookingConfig)({
      ...bookingConfigParams
    });
    if ((_c2 = (_b2 = (_a2 = data == null ? void 0 : data.config) == null ? void 0 : _a2.information_tab) == null ? void 0 : _b2.appointment_card) == null ? void 0 : _c2.quick_time) {
      _getAddTimeProducts();
    }
    setState({
      bookingConfig: data
    });
  };
  const _addVisibilityListener = (callback) => {
    const handleVisibilityChange = () => {
      if (!document.hidden) {
        callback();
      }
    };
    document.addEventListener("visibilitychange", handleVisibilityChange);
    return () => {
      document.removeEventListener("visibilitychange", handleVisibilityChange);
    };
  };
  const _setListState = (data, cb) => {
    setState(
      {
        list: {
          ...state.list,
          ...data
        }
      },
      () => {
        cb == null ? void 0 : cb();
      }
    );
  };
  const _getInitState = (resetProps = {}) => {
    var _a2;
    const { modalState } = state;
    let initState = JSON.parse(JSON.stringify(_initStateRef.current || {}));
    let _state = {
      ...initState,
      ...resetProps
    };
    let _modalState = { ...modalState };
    for (let key in _modalState) {
      if (key === "notes") {
        _modalState[key].orderNote = initState.modalState[key].orderNote;
        _modalState[key].internalNotes = initState.modalState[key].internalNotes;
      } else {
        if (typeof _modalState[key] === "object") {
          if (key !== "date") {
            _modalState[key].value = (_a2 = initState.modalState[key]) == null ? void 0 : _a2.value;
          }
        }
      }
      if (typeof _modalState[key] === "object") {
        if (_modalState[key].showModal) {
          _modalState[key].showModal = initState.modalState[key].showModal;
        }
        if (_modalState[key].addModal) {
          _modalState[key].addModal = initState.modalState[key].addModal;
        }
        if (_modalState[key].editModal) {
          _modalState[key].editModal = initState.modalState[key].editModal;
        }
        if (_modalState[key].edit) {
          _modalState[key].edit = false;
        }
        if (_modalState[key].load) {
          _modalState[key].load = initState.modalState[key].load;
        }
      }
    }
    _modalState.service.value = [];
    _modalState.service.cacheItem = null;
    _modalState.service.addTimeModal = false;
    _modalState.service.changeService = false;
    _modalState.disabledEdit = initState.modalState.disabledEdit;
    _modalState.channelDisabledEdit = initState.modalState.channelDisabledEdit;
    _modalState.appointment_status = initState.modalState.appointment_status;
    _state.modalState = _modalState;
    return _state;
  };
  const _getBookingType = (record) => {
    const { type } = state;
    if (record.parent_id > 0 && record.item_type !== "recurring_booking" && !type) {
      return "pisell2";
    }
    return "pisell1";
  };
  const _scrollToBooking = (bookingId) => {
    var _a2;
    if (bookingId || state.bookingId) {
      const dom = document.getElementById(bookingId || state.bookingId);
      (_a2 = dom == null ? void 0 : dom.scrollIntoView) == null ? void 0 : _a2.call(dom, { block: "center", behavior: "smooth" });
    }
  };
  const _initBookingData = (type, data) => {
    var _a2, _b2, _c2, _d, _e, _f, _g;
    let initState = _getInitState({
      bookingDetail: null,
      bookingConfig: state.bookingConfig,
      renderType: state.renderType,
      isShowDeposit: state.isShowDeposit,
      openRebook: state.openRebook,
      disableEventBookingEdit: state.disableEventBookingEdit,
      isShowInfo: state.isShowInfo,
      persistent: state.persistent,
      list: state.list,
      intervalSetTime: state.intervalSetTime,
      createCount: state.createCount,
      bookingFunctions: state.bookingFunctions
    });
    if (type === "edit") {
      initState.bookingDetail = data;
      initState.modalState = _formatBookingDetail(data, state.modalState);
    }
    if (type === "create") {
      if ((_a2 = data == null ? void 0 : data.serviceParams) == null ? void 0 : _a2.start_date) {
        initState.modalState.date.value = (0, import_dayjs.default)(
          (_b2 = data == null ? void 0 : data.serviceParams) == null ? void 0 : _b2.start_date
        );
        sessionStorage.setItem(
          "pisell2.booking.serviceParams",
          JSON.stringify(data)
        );
      } else {
        let timezone = (_f = (_e = (_d = (_c2 = store == null ? void 0 : store.getState) == null ? void 0 : _c2.call(store)) == null ? void 0 : _d.global) == null ? void 0 : _e.globalConfig) == null ? void 0 : _f.timezone;
        initState.modalState.date.value = import_dayjs.default.tz(/* @__PURE__ */ new Date(), timezone);
        sessionStorage.removeItem("pisell2.booking.serviceParams");
      }
      if ((_g = data == null ? void 0 : data.params) == null ? void 0 : _g.customer) {
        initState.modalState.client.value = data == null ? void 0 : data.params.customer;
      }
      if (data == null ? void 0 : data.eventBookingServiceParams) {
      }
    }
    console.log(initState, "initState");
    setState({
      ...initState,
      [state.renderType === "eventBooking" ? "eventOpen" : "open"]: true,
      bookingId: state.bookingId
    });
  };
  const _rebook = () => {
    var _a2, _b2, _c2;
    let date = (0, import_utils2.getNextTimeSlice)(
      ((_c2 = (_b2 = (_a2 = state.bookingConfig) == null ? void 0 : _a2.config) == null ? void 0 : _b2.basic) == null ? void 0 : _c2.service_time.value) || 10
    );
    setState({
      rebookState: {
        ...state.rebookState,
        open: true,
        date
      }
    });
  };
  const _getBookingDetail = async (bookingId) => {
    const { renderType, openRebook } = state;
    setState({ loading: true });
    const getDetail = renderType === "eventBooking" ? import_serve.getEventBookingDetail : import_serve.getBookingDetail;
    let data = await getDetail(bookingId || state.bookingId, {});
    if (renderType === "eventBooking") {
      data = {
        ...data,
        bookings: {
          ...data.bookings,
          list: [data.bookings]
        }
      };
    }
    console.log("getBookingDetail", data);
    _initBookingData("edit", data);
    if (openRebook) {
      setTimeout(() => {
        _rebook();
      });
    }
  };
  const _openModal = (props) => {
    const {
      bookingId,
      serviceParams,
      params,
      eventBookingServiceParams,
      renderType = "booking",
      openRebook
    } = props || {};
    setState({
      isShowInfo: false
    });
    const _isTerminal = isTerminal();
    const defaultInit = () => {
      if (renderType === "eventBooking") {
        _getBoardConfig();
      }
      if (bookingId) {
        _getBookingDetail(bookingId);
      } else {
        _initBookingData("create", {
          serviceParams,
          params,
          eventBookingServiceParams
        });
      }
    };
    const isOpen = state.open;
    setState(
      {
        [renderType === "eventBooking" ? "eventOpen" : "open"]: true,
        bookingId: bookingId || 0,
        renderType,
        openRebook,
        disableEventBookingEdit: eventBookingServiceParams == null ? void 0 : eventBookingServiceParams.disableEventBookingEdit,
        modalState: {
          ...state.modalState,
          eventOtherParams: eventBookingServiceParams
        },
        isShowInfo: !_isTerminal,
        persistent: storage.get(`drawer-booking`) === "true" ? true : _isTerminal
      },
      () => {
        console.log(isOpen, "isOpen");
        if (isOpen) {
          setTimeout(() => {
            setState({
              isShowInfo: true
            });
          });
        }
        defaultInit();
      }
    );
  };
  const _scanBookingDetailResult = async (detail) => {
    var _a2, _b2, _c2;
    (_a2 = Toast == null ? void 0 : Toast.loading) == null ? void 0 : _a2.call(Toast, import_utils.locales.getText("pisell2.ticket-booking.loading"), 6e4);
    let result = {};
    try {
      result = JSON.parse(detail) || {};
    } catch (err) {
    }
    if (!(result == null ? void 0 : result.value)) {
      (_b2 = import_antd.message) == null ? void 0 : _b2.error(
        import_utils.locales.getText("pisell2.ticket-booking.appointment-not-found")
      );
      Toast == null ? void 0 : Toast.hide();
      return;
    }
    const objDetail = await (0, import_serve.getOrderInfoByCode)({ code: result.value });
    Toast == null ? void 0 : Toast.hide();
    if (!(objDetail == null ? void 0 : objDetail.order_id) || (objDetail == null ? void 0 : objDetail.event_id) === 0) {
      (_c2 = import_antd.message) == null ? void 0 : _c2.error(
        import_utils.locales.getText("pisell2.ticket-booking.appointment-not-found")
      );
      return;
    }
    if (_getBookingType(objDetail) === "pisell1") {
      setState({
        confirmOpen: true
      });
      return;
    }
    _scrollToBooking(objDetail.order_id);
    _openModal({
      bookingId: objDetail.order_id,
      id: objDetail.event_id
    });
  };
  const _onAction = (props) => {
    if (props === "init") {
      _getBookingDetail(state.bookingId);
      return;
    }
    action == null ? void 0 : action(props);
  };
  const _setActiveTab = (key) => {
  };
  const _initFn = (callback, open) => {
    setState(
      {
        ..._getInitState({
          bookingDetail: null,
          bookingConfig: state.bookingConfig,
          renderType: state.renderType,
          isShowDeposit: state.isShowDeposit,
          disableEventBookingEdit: state.disableEventBookingEdit,
          list: state.list,
          intervalSetTime: state.intervalSetTime,
          createCount: state.createCount,
          bookingFunctions: state.bookingFunctions
        }),
        loading: false,
        open: open ?? false,
        eventOpen: false,
        isShowInfo: false,
        bookingId: 0
      },
      () => {
        callback == null ? void 0 : callback();
      }
    );
  };
  const _callback = (data, type) => {
    if (isTerminal() && type === "checkout") {
      return;
    }
    setState({
      createCount: state.createCount + 1
    });
    if (data == null ? void 0 : data.afterCloseUpdate) {
      return _callbackFnRef.current = () => {
        lowcodeRef == null ? void 0 : lowcodeRef.onChange({ type: "refresh", ...data });
      };
    }
    const { bookingId, renderType } = state;
    let cb;
    if (bookingId && renderType !== "eventBooking") {
      cb = () => {
        _openModal({
          bookingId
        });
      };
    }
    if (!bookingId) {
      _setIntervalTime(true);
    }
    _initFn(cb);
  };
  const _refreshData = () => {
    if (lowcodeRef) {
      lowcodeRef.onChange({ type: "refresh" });
    }
  };
  const _clearAllValue = () => {
    setState({
      modalState: _getInitState().modalState
    });
  };
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      style: {
        flex: 1,
        overflow: "hidden",
        display: "flex",
        flexDirection: "column"
      }
    },
    /* @__PURE__ */ import_react.default.createElement("div", { style: { flex: 1, overflow: "hidden" } }, /* @__PURE__ */ import_react.default.createElement(
      import_addServiceVariant.default,
      {
        globalState: {
          ...state.modalState,
          amountSymbol: state.amountSymbol,
          bookingConfig: state.bookingConfig,
          bookingDetail: state.bookingDetail,
          bookingId: state.bookingId,
          bookingStatus: state.bookingStatus,
          apis,
          action: _onAction,
          callback: _callback,
          locale: engineProps.locale,
          modalOpen: state.open,
          onRebook: _rebook,
          refreshData: _refreshData,
          setActiveTab: _setActiveTab,
          addTimeProducts: state.addTimeProducts,
          isBookingCreatePage: true,
          closeAutoOpenService: true,
          productExtensionType: state.productExtensionType,
          isBookingTicket2: true
        },
        setGlobalState: _setModalState
      }
    )),
    /* @__PURE__ */ import_react.default.createElement(
      import_timeBar.default,
      {
        setGlobalState: setState,
        globalState: state,
        onDateChange: (...args) => {
          _onDateChange(...args);
        },
        onDateTimeChange: (...args) => {
          _setDataChange(...args, true);
        },
        setIntervalTime: _setIntervalTime,
        locale: engineProps.locale
      }
    )
  ), /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      style: {
        flexShrink: 0,
        width: 355
      }
    },
    /* @__PURE__ */ import_react.default.createElement(
      import_info.default,
      {
        key: state.createCount,
        globalState: {
          ...state.modalState,
          hideCreateText: true,
          amountSymbol: state.amountSymbol,
          bookingConfig: state.bookingConfig,
          bookingDetail: state.bookingDetail,
          bookingId: state.bookingId,
          bookingStatus: state.bookingStatus,
          apis,
          modalOpen: state.open,
          onRebook: _rebook,
          addTimeProducts: state.addTimeProducts,
          isBookingCreatePage: true,
          closeAutoOpenService: true,
          renderType: "booking",
          action: _onAction,
          callback: _callback,
          locale: engineProps.locale,
          refreshData: _refreshData,
          setActiveTab: _setActiveTab,
          clearAllValue: _clearAllValue,
          drawerMask: true,
          isBookingTicket2: true
        },
        setGlobalState: _setModalState,
        setState,
        modules: {
          client: 1,
          date: 0,
          service: 1,
          holder: 1,
          note: 1
        }
      }
    )
  ));
};
var ticketBooking_default = TicketBooking;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  _formatBookingDetail
});
