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/components/footer/index.tsx
var footer_exports = {};
__export(footer_exports, {
  default: () => footer_default
});
module.exports = __toCommonJS(footer_exports);
var import_icons = require("@ant-design/icons");
var import_ChevronDown = __toESM(require("@pisell/icon/es/ChevronDown"));
var import_utils = require("@pisell/utils");
var import_antd = require("antd");
var import_classnames = __toESM(require("classnames"));
var import_react = __toESM(require("react"));
var import_useEngineContext = __toESM(require("../../../../hooks/useEngineContext"));
var import_addons = require("../../addons");
var import_utils2 = require("../../info/service2/utils");
var import_serve = require("../../info2/serve");
var import_AppointmentProductModal = __toESM(require("./AppointmentProductModal"));
var import_FooterMenus = __toESM(require("./FooterMenus"));
var import_amount = require("./amount");
var import_index = require("./index.less");
var import_serve2 = require("./serve");
var import_utils3 = require("./utils");
var import_voucher = __toESM(require("../voucher"));
var import__ = require("../../../../index");
var import_useIsBooking4Shop = require("../../hooks/useIsBooking4Shop");
var import_utils4 = require("@pisell/utils");
var import_dayjs = __toESM(require("dayjs"));
var Footer = (props) => {
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
  const { state, buttons, dispatch, source } = props;
  const [showDetail, setShowDetail] = (0, import_react.useState)(false);
  const [loading, setLoading] = (0, import_react.useState)(false);
  const [checkoutLoading, setCheckoutLoading] = (0, import_react.useState)(false);
  const [isShowPaymentLink, setIsShowPaymentLink] = (0, import_react.useState)(false);
  const isBooking4Shop = (0, import_useIsBooking4Shop.useIsBooking4Shop)(state);
  const appointmentProductRef = (0, import_react.useRef)(null);
  const context = (0, import_useEngineContext.default)();
  const { isTerminal, interaction, store, storage, businessUtils } = (_a = context.appHelper) == null ? void 0 : _a.utils;
  (0, import_react.useEffect)(() => {
    store == null ? void 0 : store.dispatch({
      type: "global/_getMetadataMap",
      callback: (data) => {
        console.log(data, "data");
        setIsShowPaymentLink(!!data["payment_collection_link_config_switch"]);
      }
    });
  }, []);
  const [modal, contextHolder] = import_antd.Modal.useModal();
  const { setActiveTab } = state;
  const isTeam = (0, import_react.useMemo)(() => {
    return storage.get("channel") === "android_team_portal" || storage.get("channel") === "ios_team_portal";
  }, []);
  const actionMap = {
    sale: {
      label: import_utils.locales.getText("pisell2.text.addons"),
      key: "sale"
    },
    paymentLink: {
      label: import_utils.locales.getText("pisell2.text.payment-link"),
      key: "payment",
      children: [
        {
          label: import_utils.locales.getText("pisell2.text.send-mail"),
          key: "sendMail"
        },
        {
          label: import_utils.locales.getText("pisell2.text.copy-to-clipboard"),
          key: "copy"
        }
      ]
    },
    print: {
      label: "Print",
      key: "print"
    },
    orderDetail: {
      label: import_utils.locales.getText("pisell2.text.deposit-order-detail"),
      key: "orderDetail"
    },
    refund: {
      label: import_utils.locales.getText("pisell2.text.refund"),
      key: "refund"
    },
    rebook: {
      label: import_utils.locales.getText("pisell2.text.rebook"),
      key: "rebook"
    },
    cancelOrder: {
      label: "Cancel order",
      key: "cancelOrder"
    }
  };
  (0, import_react.useEffect)(() => {
    if (state.bookingDetail) {
      state.action({
        type: "pisell1.registerPlugin",
        data: {
          pluginList: ["RefundPlugin"]
        }
      });
    }
  }, [state.bookingDetail]);
  const params = (0, import_react.useMemo)(() => {
    var _a2, _b2, _c2;
    return ((_c2 = (_b2 = (_a2 = state == null ? void 0 : state.bookingConfig) == null ? void 0 : _a2.config) == null ? void 0 : _b2.basic) == null ? void 0 : _c2.appointment_subject) || {};
  }, [(_d = (_c = (_b = state == null ? void 0 : state.bookingConfig) == null ? void 0 : _b.config) == null ? void 0 : _c.basic) == null ? void 0 : _d.appointment_subject]);
  const transaction_habit_selection = (0, import_react.useMemo)(() => {
    var _a2, _b2, _c2;
    return ((_c2 = (_b2 = (_a2 = state == null ? void 0 : state.bookingConfig) == null ? void 0 : _a2.config) == null ? void 0 : _b2.information_tab) == null ? void 0 : _c2.transaction_habit_selection) || {
      type: "service_now_pay_later",
      button_rows: 1
    };
  }, [(_f = (_e = state == null ? void 0 : state.bookingConfig) == null ? void 0 : _e.config) == null ? void 0 : _f.information_tab]);
  const addonsEdit = (0, import_react.useMemo)(() => {
    var _a2;
    if ((_a2 = state.addons) == null ? void 0 : _a2.edit) {
      return true;
    }
    return false;
  }, [(_g = state.addons) == null ? void 0 : _g.edit]);
  const infoEdit = (0, import_react.useMemo)(() => {
    var _a2, _b2, _c2, _d2, _e2, _f2, _g2;
    if (!state.bookingId) {
      return true;
    }
    if ((_a2 = state.client) == null ? void 0 : _a2.edit) {
      return true;
    }
    if ((_b2 = state.date) == null ? void 0 : _b2.edit) {
      return true;
    }
    if ((_c2 = state.pet) == null ? void 0 : _c2.edit) {
      return true;
    }
    if ((_d2 = state.service) == null ? void 0 : _d2.edit) {
      return true;
    }
    if ((_e2 = state.notes) == null ? void 0 : _e2.edit) {
      return true;
    }
    if ((_f2 = state.contacts) == null ? void 0 : _f2.edit) {
      return true;
    }
    if ((_g2 = state.contacts_info) == null ? void 0 : _g2.edit) {
      return true;
    }
    return false;
  }, [state]);
  const isEdit = (0, import_react.useMemo)(() => {
    return infoEdit || addonsEdit;
  }, [infoEdit, addonsEdit]);
  const total = (0, import_react.useMemo)(() => {
    return (0, import_amount.getSumTotal)(state, isEdit);
  }, [state, isEdit]);
  const isDisabled = (0, import_react.useMemo)(() => {
    var _a2;
    const isClient = state.client.value;
    if (!isClient) {
      return true;
    }
    const isService = (_a2 = state.service.value) == null ? void 0 : _a2.length;
    if (!isService) {
      return true;
    }
    const isDate = state.date.value;
    if (!isDate) {
      return true;
    }
    return false;
  }, [state, params]);
  const hasGoodPassApp = !!((_h = businessUtils == null ? void 0 : businessUtils.getAppByModal) == null ? void 0 : _h.call(businessUtils, "goodpass"));
  const hasDiscountCardApp = !!((_i = businessUtils == null ? void 0 : businessUtils.getAppByModal) == null ? void 0 : _i.call(businessUtils, "discountcard"));
  console.log("has goodpass app:", hasGoodPassApp);
  const goCheckout = async (order_id) => {
    var _a2, _b2;
    if (!order_id) return;
    if (isTerminal == null ? void 0 : isTerminal()) {
      return (_b2 = (_a2 = interaction == null ? void 0 : interaction.utils) == null ? void 0 : _a2.postMessageToApp) == null ? void 0 : _b2.call(_a2, {
        module: "booking",
        key: "booking_checkout",
        data: {
          order_id,
          callbackType: "pisell2"
        }
      });
    }
    state.action({
      type: "pisell1.handlePayment",
      data: {
        orderId: order_id
      },
      callback: () => {
        state == null ? void 0 : state.callback();
      }
    });
  };
  const handleCheckout = async () => {
    if (isEdit) {
      if ((0, import_utils2.isDayBooking)(state)) {
        const isHasDayProducts = handleDaySubmit();
        if (isHasDayProducts) return;
      }
      const res = await handleSave({
        type: "checkout",
        messageShow: !(isTerminal == null ? void 0 : isTerminal())
      });
      goCheckout((res == null ? void 0 : res.order_id) || state.bookingId);
      return;
    }
    return goCheckout(state.bookingId);
  };
  const handleSaveAddons = async () => {
    try {
      let _list = [...state.addons.value];
      await state.apis.saveAddonsByOrderId({
        products: (0, import_addons.formatProducts)(_list),
        shop_discount: state.bookingDetail.shop_discount,
        shop_discount_reason: state.bookingDetail.shop_discount_reason
      });
      import_antd.message.success(
        import_utils.locales.getText("pisell2.text.addons") + import_utils.locales.getText("pisell2.text.updated")
      );
    } catch (err) {
      console.log("state.bookingId && state.addons.edit", err);
    }
  };
  const getApis = () => {
    if (isBooking4Shop || state.renderType === "dayBooking") {
      return {
        editBooking: import_serve.editBookings,
        createBooking: import_serve.createBookings
      };
    }
    return {
      editBooking: state.apis.editBooking,
      createBooking: state.apis.createBooking
    };
  };
  const handleDaySubmit = () => {
    var _a2;
    const _isHasDayProducts = (0, import_utils2.isHasDayAppointmentProduct)(state);
    if (_isHasDayProducts) {
      (_a2 = appointmentProductRef == null ? void 0 : appointmentProductRef.current) == null ? void 0 : _a2.open();
    }
    return _isHasDayProducts;
  };
  const handleSave = async ({
    type,
    messageShow = true
  }) => {
    var _a2, _b2, _c2, _d2, _e2;
    if ((0, import_utils2.isDayBooking)(state)) {
      const isHasDayProducts = handleDaySubmit();
      if (isHasDayProducts) return;
    }
    if (isBooking4Shop && (0, import_utils2.getIsSubjectRequire)(state) && (0, import_utils3.checkHolderIsError)(state)) {
      return;
    }
    let _setLoading = type === "checkout" ? setCheckoutLoading : setLoading;
    _setLoading(true);
    const loadingTimer = setTimeout(() => {
      _setLoading(false);
    }, 2e4);
    const { createBooking, editBooking } = getApis();
    const editApi = state.renderType === "eventBooking" ? import_serve2.editEventBooking : editBooking;
    const createApi = state.renderType === "eventBooking" ? import_serve2.createEventBooking : createBooking;
    let saveOtherValue = {};
    if (type === "save") {
      saveOtherValue = await ((_a2 = state == null ? void 0 : state.onSave) == null ? void 0 : _a2.call(state, state.client)) || {};
    }
    try {
      let callbackData = null;
      let values = (0, import_utils3.formatValues)({ ...state, ...saveOtherValue });
      const api = state.bookingId ? editApi : createApi;
      (0, import_utils4.sendWarningLog)({
        title: "saveBooking",
        content: [
          { key: "下单前数据", value: JSON.stringify(values) },
          { key: "日期", value: (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm") },
          {
            key: "店铺id",
            value: (_e2 = (_d2 = (_c2 = (_b2 = store == null ? void 0 : store.getState) == null ? void 0 : _b2.call(store)) == null ? void 0 : _c2.global) == null ? void 0 : _d2.globalConfig) == null ? void 0 : _e2.id
          },
          {
            key: "shopApi",
            value: JSON.stringify(window == null ? void 0 : window.shopApi, (key, value) => {
              if (typeof value === "function") {
                return "function";
              }
              return value;
            })
          }
        ]
      });
      if (addonsEdit) {
        await handleSaveAddons();
      }
      if (infoEdit) {
        callbackData = await api(values, state.bookingId);
        if (messageShow) {
          import_antd.message.success(
            import_utils.locales.getText(
              state.bookingId ? "pisell2.text.appointment-updated" : "pisell2.text.created-successfully"
            )
          );
        }
      }
      state == null ? void 0 : state.callback(callbackData, type);
      clearTimeout(loadingTimer);
      _setLoading(false);
      return callbackData || values;
    } catch (err) {
      console.log(err);
      if ((err == null ? void 0 : err.code) === 70101) {
        import_antd.message.error(err == null ? void 0 : err.message);
      }
      clearTimeout(loadingTimer);
      _setLoading(false);
    }
  };
  const onSelect = async (e) => {
    const status = "completed";
    dispatch({
      type: "setStatus",
      payload: status
    });
    const data = await state.apis.editBookingStatus({
      appointment_status: status
    });
    import_antd.message.success(import_utils.locales.getText("pisell1.text.edit-status-success"));
    state == null ? void 0 : state.callback({ order_id: state.bookingId });
  };
  const handleRefund = () => {
    var _a2, _b2;
    if (isTerminal == null ? void 0 : isTerminal()) {
      return (_b2 = (_a2 = interaction == null ? void 0 : interaction.utils) == null ? void 0 : _a2.postMessageToApp) == null ? void 0 : _b2.call(_a2, {
        module: "booking",
        key: "booking_refund",
        data: {
          order_id: state.bookingId
        },
        origin: "/booking"
      });
    }
    state.action({
      type: "pisell1.handleRefund",
      data: {
        orderId: state.bookingId
      },
      callback: () => {
        state == null ? void 0 : state.callback({ order_id: state.bookingId });
      }
    });
  };
  const paymentRefundedStatus = (0, import_react.useMemo)(() => {
    var _a2;
    return ["partially_refunded", "refunded"].includes(
      (_a2 = state == null ? void 0 : state.bookingDetail) == null ? void 0 : _a2.payment_status
    );
  }, [state == null ? void 0 : state.bookingDetail]);
  const checkoutButton = (0, import_react.useMemo)(() => {
    let buttonType = "primary";
    if (transaction_habit_selection.type === "service_now_pay_later") {
      buttonType = "default";
    }
    if (source === "payment") {
      buttonType = "primary";
    }
    if (!isEdit) {
      buttonType = "primary";
    }
    return /* @__PURE__ */ import_react.default.createElement(
      import_antd.ConfigProvider,
      {
        theme: {
          token: {
            colorPrimary: buttonType === "primary" ? "#7F56DA" : "#F79009"
          }
        }
      },
      /* @__PURE__ */ import_react.default.createElement(
        import_antd.Button,
        {
          className: (0, import_classnames.default)("pisell-lowcode__booking-footer-buttons-item", {
            ["pisell-lowcode__booking-footer-buttons-item-primary"]: buttonType === "primary"
          }),
          type: "primary",
          loading: checkoutLoading,
          onClick: () => {
            handleCheckout();
          },
          disabled: isDisabled
        },
        import_utils.locales.getText("pisell2.text.checkout")
      )
    );
  }, [isEdit, checkoutLoading, isDisabled, state, source]);
  const handleMenuClick = async (e) => {
    var _a2, _b2;
    let id = state.bookingId;
    let customer = state.bookingDetail.customer;
    if (isEdit) {
      const res = await handleSave({ type: "checkout", messageShow: false });
      id = (res == null ? void 0 : res.order_id) || state.bookingId;
      customer = (res == null ? void 0 : res.customer_id) ? { id: res == null ? void 0 : res.customer_id } : state.bookingDetail.customer;
    }
    if (e.key === "sendMail") {
      console.log(e);
      state.action({
        type: "pisell1.sendPayLinkEmail",
        data: {
          id,
          is_deposit: state.bookingDetail.is_deposit || Number((_a2 = state.bookingDetail) == null ? void 0 : _a2.deposit_amount),
          deposit_payment_time: state.bookingDetail.deposit_payment_time,
          customer,
          contacts: (_b2 = state.bookingDetail) == null ? void 0 : _b2.contacts
        },
        callback: () => {
        }
      });
    }
    if (e.key === "copy") {
      state.action({
        type: "pisell1.genClientPayLink",
        data: {
          id
        },
        callback: () => {
        }
      });
    }
  };
  const handleRebook = () => {
    var _a2;
    (_a2 = state.onRebook) == null ? void 0 : _a2.call(state);
  };
  const handleSale = () => {
    var _a2, _b2;
    if (isTerminal == null ? void 0 : isTerminal()) {
      return (_b2 = (_a2 = interaction == null ? void 0 : interaction.utils) == null ? void 0 : _a2.postMessageToApp) == null ? void 0 : _b2.call(_a2, {
        module: "booking",
        key: "edit_order",
        data: {
          order_id: state.bookingId
        }
      });
    }
    if (state.channelDisabledEdit) {
      modal.warning({
        okText: import_utils.locales.getText("pisell2.text.ok"),
        content: import_utils.locales.getText("pisell2.text.terminal-edit-message")
      });
      return;
    }
    setActiveTab == null ? void 0 : setActiveTab("addons");
  };
  const handlePrint = () => {
  };
  const handleOrderDetail = () => {
    if (isTerminal == null ? void 0 : isTerminal()) {
      return interaction.utils.postMessageToApp({
        module: "booking",
        key: "view_order",
        data: {
          order_id: state.bookingId
        },
        origin: "/booking"
      });
    }
    state.action({
      type: "pisell1.goOrderDetail",
      data: {
        orderId: state.bookingId
      },
      callback: () => {
        state == null ? void 0 : state.callback();
      }
    });
  };
  const handleCancel = () => {
  };
  const paymentLinkButton = (0, import_react.useMemo)(() => {
    const items = [
      { label: import_utils.locales.getText("pisell2.text.send-mail"), key: "sendMail" },
      { label: import_utils.locales.getText("pisell2.text.copy-to-clipboard"), key: "copy" }
    ];
    return /* @__PURE__ */ import_react.default.createElement(import_antd.Dropdown, { menu: { items, onClick: handleMenuClick } }, /* @__PURE__ */ import_react.default.createElement(import_antd.Button, { className: "pisell-lowcode__booking-footer-buttons-item" }, /* @__PURE__ */ import_react.default.createElement(import_antd.Space, null, import_utils.locales.getText("pisell2.text.payment-link"), /* @__PURE__ */ import_react.default.createElement(import_icons.DownOutlined, null))));
  }, [handleMenuClick]);
  const saveButton = (0, import_react.useMemo)(() => {
    let buttonType = "default";
    if (transaction_habit_selection.type === "service_now_pay_later") {
      buttonType = "primary";
    }
    return /* @__PURE__ */ import_react.default.createElement(
      import_antd.ConfigProvider,
      {
        theme: {
          token: {
            colorPrimary: buttonType === "primary" ? "#7F56DA" : "#F79009"
          }
        }
      },
      /* @__PURE__ */ import_react.default.createElement(
        import_antd.Button,
        {
          className: (0, import_classnames.default)("pisell-lowcode__booking-footer-buttons-item", {
            ["pisell-lowcode__booking-footer-buttons-item-primary"]: buttonType === "primary"
          }),
          type: "primary",
          onClick: () => {
            handleSave({ type: "save" });
          },
          disabled: isDisabled || !isEdit,
          loading
        },
        import_utils.locales.getText("pisell2.text.save")
      )
    );
  }, [loading, isDisabled, isEdit, infoEdit, addonsEdit, state]);
  const completeButton = (0, import_react.useMemo)(() => {
    return /* @__PURE__ */ import_react.default.createElement(
      import_antd.Button,
      {
        className: "pisell-lowcode__booking-footer-buttons-item",
        type: "primary",
        onClick: onSelect,
        disabled: state.appointment_status === "completed"
      },
      import_utils.locales.getText("pisell2.text.status.completed")
    );
  }, [state.appointment_status]);
  const rebookButton = (0, import_react.useMemo)(() => {
    return /* @__PURE__ */ import_react.default.createElement(
      import_antd.Button,
      {
        className: "pisell-lowcode__booking-footer-buttons-item",
        onClick: handleRebook
      },
      import_utils.locales.getText("pisell2.text.rebook")
    );
  }, [state == null ? void 0 : state.onRebook]);
  const refundButton = (0, import_react.useMemo)(() => {
    return /* @__PURE__ */ import_react.default.createElement(
      import_antd.Button,
      {
        className: "pisell-lowcode__booking-footer-buttons-item",
        type: "default",
        onClick: handleRefund
      },
      import_utils.locales.getText("pisell2.text.refund")
    );
  }, []);
  const handleClearAll = () => {
    var _a2;
    (_a2 = state == null ? void 0 : state.clearAllValue) == null ? void 0 : _a2.call(state);
  };
  const clearAllButton = (0, import_react.useMemo)(() => {
    return /* @__PURE__ */ import_react.default.createElement(
      import_antd.ConfigProvider,
      {
        theme: {
          token: {
            colorPrimary: "#f04438"
          }
        }
      },
      /* @__PURE__ */ import_react.default.createElement(
        import_antd.Button,
        {
          className: "pisell-lowcode__booking-footer-buttons-item",
          type: "primary",
          onClick: handleClearAll
        },
        import_utils.locales.getText("pisell2.booking.info.text.clear-all")
      )
    );
  }, []);
  let buttonMap = {
    checkout: checkoutButton,
    save: saveButton,
    complete: completeButton,
    refund: refundButton,
    paymentLink: paymentLinkButton,
    rebook: rebookButton,
    clearAll: clearAllButton
  };
  const isShowClearAll = (0, import_react.useMemo)(() => {
    if (!state.bookingId) {
      return true;
    }
  }, [state.bookingId]);
  const isCheckout = (0, import_react.useMemo)(() => {
    var _a2, _b2, _c2, _d2;
    let list = ["unfulfilled", "unpaid", "payment_processing"];
    if (!state.bookingId || ((_b2 = (_a2 = state.bookingDetail) == null ? void 0 : _a2.bookings) == null ? void 0 : _b2.appointment_status) !== "cancelled" && list.includes(
      ((_c2 = state == null ? void 0 : state.bookingDetail) == null ? void 0 : _c2.payment_status) === "partially_paid" ? "unpaid" : (_d2 = state == null ? void 0 : state.bookingDetail) == null ? void 0 : _d2.payment_status
    ) && !state.disabledEdit) {
      return true;
    } else {
      if (total.notPaidAmount > 0) {
        return true;
      }
      return false;
    }
  }, [state.bookingDetail, total.notPaidAmount]);
  const _buttons = (0, import_react.useMemo)(() => {
    const isEvent = (0, import_utils2.isEventBooking)(state);
    if (state.appointment_status === "cancelled") {
      return [buttonMap.rebook];
    }
    if (paymentRefundedStatus) {
      if (isEvent) {
        return [""];
      }
      return [buttonMap.rebook];
    }
    if (source === "addons") {
      let arr = [];
      arr = [...buttons];
      if (isEdit) {
        arr.push(buttonMap.save);
      }
      return arr;
    }
    if (source === "payment") {
      let arr = [];
      if (state.bookingId && isShowPaymentLink) {
        arr.push(buttonMap.paymentLink);
      }
      if (!isTeam) {
        if (total.paidAmount > 0) {
          arr.push(buttonMap.refund);
        }
        if (isCheckout) {
          arr.push(buttonMap.checkout);
        }
      }
      return arr;
    }
    if (source === "info") {
      let arr = [];
      if (isShowClearAll) {
        arr.push(buttonMap.clearAll);
      }
      if (isCheckout) {
        if (!isTeam) {
          arr.push(buttonMap.checkout);
        }
      } else {
        if (!isEdit) {
          arr.push(buttonMap.complete);
        }
      }
      if (isEdit) {
        arr.push(buttonMap.save);
      }
      return arr;
    }
    if (source === "addTime") {
      let arr = [];
      arr = [...buttons];
      return arr;
    }
    return [];
  }, [
    buttons,
    total,
    isEdit,
    checkoutLoading,
    isDisabled,
    source,
    buttonMap,
    loading,
    isCheckout,
    state,
    isTeam,
    isShowClearAll
  ]);
  const moreButton = (0, import_react.useMemo)(() => {
    var _a2, _b2;
    let arr = [];
    if (!state.bookingId) {
      return [];
    }
    if (source !== "info") {
      return [];
    }
    if (state.renderType === "eventBooking") {
      return [];
    }
    if (((_a2 = state == null ? void 0 : state.bookingDetail) == null ? void 0 : _a2.payment_status) === "refunded") {
      return [];
    }
    if (_buttons.length !== 0) {
      if (state.bookingId && isShowPaymentLink && ((_b2 = state == null ? void 0 : state.bookingDetail) == null ? void 0 : _b2.payment_status) !== "partially_refunded") {
        arr.push(actionMap.paymentLink);
      }
    }
    if (transaction_habit_selection.button_rows == 1) {
      if (state.appointment_status !== "cancelled") {
        if (!state.disabledEdit && !state.isBookingCreatePage && !(0, import_utils2.isDayBooking)(state)) {
          arr.push(actionMap.sale);
        }
      }
    }
    if (!isTeam) {
      if (transaction_habit_selection.button_rows == 1) {
        arr.push(actionMap.orderDetail);
      }
      if (total.paidAmount > 0) {
        arr.push(actionMap.refund);
      }
    }
    if (state.appointment_status !== "cancelled") {
      arr.push(actionMap.rebook);
    }
    return arr;
  }, [
    state,
    total,
    isShowPaymentLink,
    source,
    _buttons.length,
    (_j = state == null ? void 0 : state.bookingDetail) == null ? void 0 : _j.payment_status
  ]);
  const isOnlyDeposit = (0, import_react.useMemo)(() => {
    var _a2, _b2, _c2, _d2;
    if (((_a2 = state == null ? void 0 : state.bookingDetail) == null ? void 0 : _a2.deposit_payment_time) && ((_d2 = (_c2 = (_b2 = state == null ? void 0 : state.bookingDetail) == null ? void 0 : _b2.payment_types) == null ? void 0 : _c2.every) == null ? void 0 : _d2.call(
      _c2,
      (item) => item === "deposit"
    ))) {
      return true;
    }
    return false;
  }, [state == null ? void 0 : state.bookingDetail]);
  const totalText = (0, import_react.useMemo)(() => {
    var _a2;
    let str = "";
    if (total.totalRefundAmount > 0) {
      return `${import_utils.locales.getText(
        "pisell2.text.refunded-amount"
      )}: ${(0, import_utils.formatAmount)(
        total.totalRefundAmount,
        2,
        (state == null ? void 0 : state.amountSymbol) || "$"
      )}`;
    }
    if (isOnlyDeposit) {
      return `${import_utils.locales.getText("pisell2.text.deposit-paid")} ${(0, import_utils.formatAmount)(
        (_a2 = state == null ? void 0 : state.bookingDetail) == null ? void 0 : _a2.deposit_paid_amount,
        2,
        (state == null ? void 0 : state.amountSymbol) || "$"
      )} ${total.duration ? `(${total.duration})` : ""}`;
    }
    if (total.notPaidAmount <= 0 && state.bookingId) {
      str = `${import_utils.locales.getText("pisell1.text.fully-paid")}: ${(0, import_utils.formatAmount)(
        total.sumTotalAmount,
        2,
        (state == null ? void 0 : state.amountSymbol) || "$"
      )}`;
    }
    if (total.notPaidAmount > 0 || !state.bookingId) {
      str = `${import_utils.locales.getText("pisell2.text.to-pay")}: ${(0, import_utils.formatAmount)(
        total.notPaidAmount,
        2,
        (state == null ? void 0 : state.amountSymbol) || "$"
      )}`;
    }
    if (total.duration) {
      str = str + ` (${total.duration})`;
    }
    return str;
  }, [state, total, state.bookingId, isOnlyDeposit]);
  const arrearsText = (0, import_react.useMemo)(() => {
    let str = "";
    if (isOnlyDeposit) {
      return str;
    }
    if (total.dueAmount < 0) {
      str = `${import_utils.locales.getText("pisell1.text.refund-customer")}: ${(0, import_utils.formatAmount)(
        total.dueAmount,
        2,
        (state == null ? void 0 : state.amountSymbol) || "$"
      )}`;
    }
    return str;
  }, [state, total, isOnlyDeposit]);
  const taxText = (0, import_react.useMemo)(() => {
    if (!(state == null ? void 0 : state.bookingDetail)) {
      return "";
    }
    let str = "";
    str = str + state.bookingDetail.tax_title;
    str = str + " " + Number(state.bookingDetail.tax_rate) * 100 + "%";
    if ((0, import_amount.is_price_include_tax)(state)) {
      str = str + " " + import_utils.locales.getText("pisell1.text.included");
    } else {
      str = str + " " + import_utils.locales.getText("pisell1.text.not-contain");
    }
    return str;
  }, [state == null ? void 0 : state.bookingDetail]);
  const showFooter = (0, import_react.useMemo)(() => {
    var _a2;
    if (state.bookingId) {
      if (!state.bookingDetail) {
        return true;
      }
      if (!((_a2 = state.addons) == null ? void 0 : _a2.load) && state.renderType !== "eventBooking" && !state.isBookingCreatePage) {
        return true;
      }
    }
    return false;
  }, [
    state.bookingId,
    state.bookingDetail,
    (_k = state.addons) == null ? void 0 : _k.load,
    state.renderType
  ]);
  const menuChange = (e) => {
    console.log("e.key", e.key);
    switch (e.key) {
      case "sendMail":
        handleMenuClick(e);
        break;
      case "copy":
        handleMenuClick(e);
        break;
      case "rebook":
        handleRebook();
        break;
      case "sale":
        handleSale();
        break;
      case "print":
        handlePrint();
        break;
      case "orderDetail":
        handleOrderDetail();
        break;
      case "refund":
        handleRefund();
        break;
      case "cancelOrder":
        handleCancel();
        break;
      default:
        break;
    }
  };
  const subTotalList = (0, import_react.useMemo)(() => {
    var _a2, _b2, _c2;
    const surcharge = (((_a2 = state.bookingDetail) == null ? void 0 : _a2.surcharge) || []).map(
      (d, index) => {
        return {
          key: `custom_surcharge_${index}`,
          label: d.name[state.locale],
          value: d.amount
        };
      }
    );
    return [
      // 小计
      {
        key: "sub_total",
        value: total.productAmount
      },
      // 自定义手续费
      ...surcharge,
      // 税费
      {
        hidden: !state.bookingId,
        key: "tax",
        value: total.tax,
        tax: {
          rate: (_b2 = state == null ? void 0 : state.bookingDetail) == null ? void 0 : _b2.tax_rate,
          is_price_include_tax: (0, import_amount.is_price_include_tax)(state),
          title: (_c2 = state == null ? void 0 : state.bookingDetail) == null ? void 0 : _c2.tax_title
        }
      },
      // 订单折扣
      {
        hidden: !state.bookingId,
        key: "discount",
        value: total.shopDiscount
      },
      // 总计
      {
        key: "total",
        value: total.expectAmount
      },
      // 舍入金额
      {
        hidden: !total.roundingAmount,
        key: "custom_roundingAmount",
        value: total.roundingAmount,
        label: import_utils.locales.getText("pisell1.text.rounding")
      }
    ];
  }, [total, (_l = state.bookingDetail) == null ? void 0 : _l.surcharge, state, state.bookingId]);
  const orderTotalList = (0, import_react.useMemo)(() => {
    return [
      // 订单已付金额
      {
        hidden: !state.bookingId,
        key: "custom_orderPaidAmount",
        value: total.orderPaidAmount,
        label: import_utils.locales.getText("pisell2.text.amount-paid-on-order")
      },
      // 支付手续费
      {
        hidden: !state.bookingId,
        key: "custom_paySurchargeFee",
        value: total.paySurchargeFee,
        label: import_utils.locales.getText("pisell1.text.payment-fee")
      },
      // 客户实付金额
      {
        hidden: !state.bookingId,
        key: "custom_actualPaidAmount",
        value: total.actualPaidAmount,
        label: import_utils.locales.getText(
          "pisell2.text.amount-actually-paid-by-the-customer"
        )
      },
      // 退款金额
      {
        hidden: !state.bookingId || !total.totalRefundAmount,
        key: "custom_totalRefundAmount",
        value: total.totalRefundAmount,
        label: import_utils.locales.getText("pisell2.text.refunded-amount")
      }
    ];
  }, [total, (_m = state.bookingDetail) == null ? void 0 : _m.surcharge, state, state.bookingId]);
  return /* @__PURE__ */ import_react.default.createElement(import_antd.Skeleton, { title: false, round: true, loading: showFooter, active: true }, (hasGoodPassApp || hasDiscountCardApp) && ["addons", "info"].includes(source) && !paymentRefundedStatus ? /* @__PURE__ */ import_react.default.createElement(import_voucher.default, { state, dispatch, source }) : null, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode__booking-footer-total" }, /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-lowcode__booking-footer-left" }, /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-lowcode__booking-footer-left-total" }, totalText), /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-lowcode__booking-footer-left-arrears" }, arrearsText)), /* @__PURE__ */ import_react.default.createElement(
    "span",
    {
      className: "pisell-lowcode__booking-footer-right",
      onClick: () => {
        setShowDetail(!showDetail);
      }
    },
    import_utils.locales.getText("pisell2.text.details"),
    " ",
    /* @__PURE__ */ import_react.default.createElement(
      import_ChevronDown.default,
      {
        className: (0, import_classnames.default)("pisell-lowcode__booking-footer-right-icon", {
          "pisell-lowcode__booking-footer-right-icon-show": showDetail
        })
      }
    )
  )), /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: (0, import_classnames.default)("pisell-lowcode__booking-footer-total-detail", {
        "pisell-lowcode__booking-footer-total-detail-show": showDetail
      })
    },
    /* @__PURE__ */ import_react.default.createElement("div", { className: "order-total-item-border" }),
    /* @__PURE__ */ import_react.default.createElement(import__.SubTotal, { mode: "column1", list: subTotalList, style: { padding: `0` } }),
    /* @__PURE__ */ import_react.default.createElement("div", { className: state.bookingId ? "order-total-item-border" : "" }),
    !!state.bookingId && /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(
      import__.SubTotal,
      {
        mode: "column1",
        list: orderTotalList,
        style: { padding: ` 0 0 16px` }
      }
    ))
  ), !(state == null ? void 0 : state.disableEventBookingEdit) && /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode__booking-footer-buttons" }, /* @__PURE__ */ import_react.default.createElement(
    import_FooterMenus.default,
    {
      items: moreButton,
      state,
      dispatch,
      source,
      menuChange
    }
  ), _buttons.length ? _buttons : state.bookingId && isShowPaymentLink ? paymentLinkButton : null), source === "info" && state.bookingId && !state.disabledEdit && (transaction_habit_selection == null ? void 0 : transaction_habit_selection.button_rows) == 2 ? /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: "pisell-lowcode__booking-footer-buttons",
      style: { marginTop: 12 }
    },
    state.appointment_status !== "cancelled" && !state.isBookingCreatePage && !(0, import_utils2.isDayBooking)(state) ? /* @__PURE__ */ import_react.default.createElement(
      import_antd.Button,
      {
        onClick: () => handleSale(),
        size: "large",
        className: "pisell-lowcode__booking-footer-buttons-item"
      },
      actionMap.sale.label
    ) : null,
    isTeam ? null : /* @__PURE__ */ import_react.default.createElement(
      import_antd.Button,
      {
        onClick: () => handleOrderDetail(),
        size: "large",
        className: "pisell-lowcode__booking-footer-buttons-item"
      },
      actionMap.orderDetail.label
    )
  ) : null, contextHolder, /* @__PURE__ */ import_react.default.createElement(import_AppointmentProductModal.default, { ref: appointmentProductRef }));
};
var footer_default = Footer;
