function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
import { DownOutlined } from '@ant-design/icons';
import ChevronDown from '@pisell/icon/es/ChevronDown';
import { formatAmount, locales } from '@pisell/utils';
import { Button, Dropdown, Modal, Skeleton, Space, message, ConfigProvider } from 'antd';
import classNames from 'classnames';
import React, { useEffect, useMemo, useRef, useState } from 'react';
import useEngineContext from "../../../../hooks/useEngineContext";
import { formatProducts } from "../../addons";
import { getIsSubjectRequire, isDayBooking, isHasDayAppointmentProduct } from "../../info/service2/utils";
import { createBookings, editBookings } from "../../info2/serve";
import AppointmentProductModal from "./AppointmentProductModal";
import FooterMenus from "./FooterMenus";
import { getSumTotal, is_price_include_tax } from "./amount";
import "./index.less";
import { createEventBooking, editEventBooking } from "./serve";
import { checkHolderIsError, formatValues } from "./utils";
import VoucherCard from "../voucher";
import { SubTotal } from "../../../../index";
import { useIsBooking4Shop } from "../../hooks/useIsBooking4Shop";
import { sendWarningLog } from '@pisell/utils';
import dayjs from 'dayjs';
/**
 * @title: 底部
 * @description:
 * @param {any} props
 * @return {*}
 * @Author: zhiwei.Wang
 * @Date: 2024-01-30 16:51
 */
var Footer = function Footer(props) {
  var _context$appHelper, _state$bookingConfig2, _state$bookingConfig4, _state$addons2, _businessUtils$getApp, _businessUtils$getApp2, _state$bookingDetail8, _state$addons4, _state$bookingDetail16, _state$bookingDetail17;
  var state = props.state,
    buttons = props.buttons,
    dispatch = props.dispatch,
    source = props.source;
  // 是否展开更多
  var _useState = useState(false),
    _useState2 = _slicedToArray(_useState, 2),
    showDetail = _useState2[0],
    setShowDetail = _useState2[1];
  // save loading
  var _useState3 = useState(false),
    _useState4 = _slicedToArray(_useState3, 2),
    loading = _useState4[0],
    setLoading = _useState4[1];
  // checkout loading
  var _useState5 = useState(false),
    _useState6 = _slicedToArray(_useState5, 2),
    checkoutLoading = _useState6[0],
    setCheckoutLoading = _useState6[1];
  var _useState7 = useState(false),
    _useState8 = _slicedToArray(_useState7, 2),
    isShowPaymentLink = _useState8[0],
    setIsShowPaymentLink = _useState8[1];
  var isBooking4Shop = useIsBooking4Shop(state);
  var appointmentProductRef = useRef(null);
  var context = useEngineContext();
  var _context$appHelper$ut = (_context$appHelper = context.appHelper) === null || _context$appHelper === void 0 ? void 0 : _context$appHelper.utils,
    isTerminal = _context$appHelper$ut.isTerminal,
    interaction = _context$appHelper$ut.interaction,
    store = _context$appHelper$ut.store,
    storage = _context$appHelper$ut.storage,
    businessUtils = _context$appHelper$ut.businessUtils;
  useEffect(function () {
    store === null || store === void 0 || store.dispatch({
      type: 'global/_getMetadataMap',
      callback: function callback(data) {
        console.log(data, 'data');
        setIsShowPaymentLink(!!data['payment_collection_link_config_switch']);
      }
    });
  }, []);
  var _Modal$useModal = Modal.useModal(),
    _Modal$useModal2 = _slicedToArray(_Modal$useModal, 2),
    modal = _Modal$useModal2[0],
    contextHolder = _Modal$useModal2[1];
  var setActiveTab = state.setActiveTab;
  var isTeam = useMemo(function () {
    return storage.get('channel') === 'android_team_portal' || storage.get('channel') === 'ios_team_portal';
  }, []);
  var actionMap = {
    sale: {
      label: locales.getText('pisell2.text.addons'),
      key: 'sale'
    },
    paymentLink: {
      label: locales.getText('pisell2.text.payment-link'),
      key: 'payment',
      children: [{
        label: locales.getText('pisell2.text.send-mail'),
        key: 'sendMail'
      }, {
        label: locales.getText('pisell2.text.copy-to-clipboard'),
        key: 'copy'
      }]
    },
    print: {
      label: 'Print',
      key: 'print'
    },
    orderDetail: {
      label: locales.getText('pisell2.text.deposit-order-detail'),
      key: 'orderDetail'
    },
    refund: {
      label: locales.getText('pisell2.text.refund'),
      key: 'refund'
    },
    rebook: {
      label: locales.getText('pisell2.text.rebook'),
      key: 'rebook'
    },
    cancelOrder: {
      label: 'Cancel order',
      key: 'cancelOrder'
    }
  };
  useEffect(function () {
    if (state.bookingDetail) {
      state.action({
        type: 'pisell1.registerPlugin',
        data: {
          pluginList: ['RefundPlugin']
        }
      });
    }
  }, [state.bookingDetail]);

  // useEffect(() => {
  //   console.log('_getPaymentLinkBtnShow_getPaymentLinkBtnShow');
  //   // store?.dispatch({
  //   //   type: 'global/_getPaymentLinkBtnShow',
  //   // });
  // }, []);

  // board 配置
  var params = useMemo(function () {
    var _state$bookingConfig;
    return (state === null || state === void 0 || (_state$bookingConfig = state.bookingConfig) === null || _state$bookingConfig === void 0 || (_state$bookingConfig = _state$bookingConfig.config) === null || _state$bookingConfig === void 0 || (_state$bookingConfig = _state$bookingConfig.basic) === null || _state$bookingConfig === void 0 ? void 0 : _state$bookingConfig.appointment_subject) || {};
  }, [state === null || state === void 0 || (_state$bookingConfig2 = state.bookingConfig) === null || _state$bookingConfig2 === void 0 || (_state$bookingConfig2 = _state$bookingConfig2.config) === null || _state$bookingConfig2 === void 0 || (_state$bookingConfig2 = _state$bookingConfig2.basic) === null || _state$bookingConfig2 === void 0 ? void 0 : _state$bookingConfig2.appointment_subject]);
  var transaction_habit_selection = useMemo(function () {
    var _state$bookingConfig3;
    return (state === null || state === void 0 || (_state$bookingConfig3 = state.bookingConfig) === null || _state$bookingConfig3 === void 0 || (_state$bookingConfig3 = _state$bookingConfig3.config) === null || _state$bookingConfig3 === void 0 || (_state$bookingConfig3 = _state$bookingConfig3.information_tab) === null || _state$bookingConfig3 === void 0 ? void 0 : _state$bookingConfig3.transaction_habit_selection) || {
      type: 'service_now_pay_later',
      button_rows: 1
    };
  }, [state === null || state === void 0 || (_state$bookingConfig4 = state.bookingConfig) === null || _state$bookingConfig4 === void 0 || (_state$bookingConfig4 = _state$bookingConfig4.config) === null || _state$bookingConfig4 === void 0 ? void 0 : _state$bookingConfig4.information_tab]);

  // addons 是否有编辑
  var addonsEdit = useMemo(function () {
    var _state$addons;
    if ((_state$addons = state.addons) !== null && _state$addons !== void 0 && _state$addons.edit) {
      return true;
    }
    return false;
  }, [(_state$addons2 = state.addons) === null || _state$addons2 === void 0 ? void 0 : _state$addons2.edit]);

  // info 是否有编辑
  var infoEdit = useMemo(function () {
    var _state$client, _state$date, _state$pet, _state$service, _state$notes, _state$contacts;
    if (!state.bookingId) {
      return true;
    }
    if ((_state$client = state.client) !== null && _state$client !== void 0 && _state$client.edit) {
      return true;
    }
    if ((_state$date = state.date) !== null && _state$date !== void 0 && _state$date.edit) {
      return true;
    }
    if ((_state$pet = state.pet) !== null && _state$pet !== void 0 && _state$pet.edit) {
      return true;
    }
    if ((_state$service = state.service) !== null && _state$service !== void 0 && _state$service.edit) {
      return true;
    }
    if ((_state$notes = state.notes) !== null && _state$notes !== void 0 && _state$notes.edit) {
      return true;
    }
    if ((_state$contacts = state.contacts) !== null && _state$contacts !== void 0 && _state$contacts.edit) {
      return true;
    }
    return false;
  }, [state]);

  // addons 和 info 是否都在编辑中
  var isEdit = useMemo(function () {
    return infoEdit || addonsEdit;
  }, [infoEdit, addonsEdit]);

  // 订单金额计算
  var total = useMemo(function () {
    return getSumTotal(state, isEdit);
  }, [state, isEdit]);

  // 是否禁止保存, 校验必填项
  var isDisabled = useMemo(function () {
    var _state$service$value;
    var isClient = state.client.value;
    if (!isClient) {
      return true;
    }
    var isService = (_state$service$value = state.service.value) === null || _state$service$value === void 0 ? void 0 : _state$service$value.length;
    if (!isService) {
      return true;
    }
    var isDate = state.date.value;
    if (!isDate) {
      return true;
    }

    // if (params.type === "form") {
    // 	const petForm = (state.pet?.formData || [])[0];
    // 	const petValue = (state.pet?.value || {})[petForm?.id];
    // 	if (!petValue || !petValue.length) {
    // 		return true;
    // 	}
    // }

    return false;
  }, [state, params]);

  // 是否安装商品券应用
  var hasGoodPassApp = !!(businessUtils !== null && businessUtils !== void 0 && (_businessUtils$getApp = businessUtils.getAppByModal) !== null && _businessUtils$getApp !== void 0 && _businessUtils$getApp.call(businessUtils, 'goodpass'));
  var hasDiscountCardApp = !!(businessUtils !== null && businessUtils !== void 0 && (_businessUtils$getApp2 = businessUtils.getAppByModal) !== null && _businessUtils$getApp2 !== void 0 && _businessUtils$getApp2.call(businessUtils, 'discountcard'));
  console.log('has goodpass app:', hasGoodPassApp);

  /**
   * @title: 跳转到 checkout页面
   * @description:
   * @param {any} order_id
   * @return {*}
   * @Author: zhiwei.Wang
   * @Date: 2024-01-30 16:53
   */
  var goCheckout = /*#__PURE__*/function () {
    var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(order_id) {
      var _interaction$utils, _interaction$utils$po;
      return _regeneratorRuntime().wrap(function _callee$(_context) {
        while (1) switch (_context.prev = _context.next) {
          case 0:
            if (order_id) {
              _context.next = 2;
              break;
            }
            return _context.abrupt("return");
          case 2:
            if (!(isTerminal !== null && isTerminal !== void 0 && isTerminal())) {
              _context.next = 4;
              break;
            }
            return _context.abrupt("return", interaction === null || interaction === void 0 || (_interaction$utils = interaction.utils) === null || _interaction$utils === void 0 || (_interaction$utils$po = _interaction$utils.postMessageToApp) === null || _interaction$utils$po === void 0 ? void 0 : _interaction$utils$po.call(_interaction$utils, {
              module: 'booking',
              key: 'booking_checkout',
              data: {
                order_id: order_id,
                callbackType: 'pisell2'
              }
            }));
          case 4:
            state.action({
              type: 'pisell1.handlePayment',
              data: {
                orderId: order_id
              },
              callback: function callback() {
                state === null || state === void 0 || state.callback();
              }
            });
          case 5:
          case "end":
            return _context.stop();
        }
      }, _callee);
    }));
    return function goCheckout(_x) {
      return _ref.apply(this, arguments);
    };
  }();

  /**
   * @title: 处理checkout
   * @description:
   * @return {*}
   * @Author: zhiwei.Wang
   * @Date: 2024-01-30 16:53
   */
  var handleCheckout = /*#__PURE__*/function () {
    var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
      var isHasDayProducts, res;
      return _regeneratorRuntime().wrap(function _callee2$(_context2) {
        while (1) switch (_context2.prev = _context2.next) {
          case 0:
            if (!isEdit) {
              _context2.next = 10;
              break;
            }
            if (!isDayBooking(state)) {
              _context2.next = 5;
              break;
            }
            isHasDayProducts = handleDaySubmit();
            if (!isHasDayProducts) {
              _context2.next = 5;
              break;
            }
            return _context2.abrupt("return");
          case 5:
            _context2.next = 7;
            return handleSave({
              type: 'checkout',
              messageShow: !(isTerminal !== null && isTerminal !== void 0 && isTerminal())
            });
          case 7:
            res = _context2.sent;
            goCheckout((res === null || res === void 0 ? void 0 : res.order_id) || state.bookingId);
            return _context2.abrupt("return");
          case 10:
            return _context2.abrupt("return", goCheckout(state.bookingId));
          case 11:
          case "end":
            return _context2.stop();
        }
      }, _callee2);
    }));
    return function handleCheckout() {
      return _ref2.apply(this, arguments);
    };
  }();

  /**
   * @title: 保存额外商品
   * @description:
   * @return {*}
   * @Author: zhiwei.Wang
   * @Date: 2024-01-30 16:54
   */
  var handleSaveAddons = /*#__PURE__*/function () {
    var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
      var _list;
      return _regeneratorRuntime().wrap(function _callee3$(_context3) {
        while (1) switch (_context3.prev = _context3.next) {
          case 0:
            _context3.prev = 0;
            _list = _toConsumableArray(state.addons.value);
            _context3.next = 4;
            return state.apis.saveAddonsByOrderId({
              products: formatProducts(_list),
              shop_discount: state.bookingDetail.shop_discount,
              shop_discount_reason: state.bookingDetail.shop_discount_reason
            });
          case 4:
            message.success(locales.getText('pisell2.text.addons') + locales.getText('pisell2.text.updated'));
            _context3.next = 10;
            break;
          case 7:
            _context3.prev = 7;
            _context3.t0 = _context3["catch"](0);
            console.log('state.bookingId && state.addons.edit', _context3.t0);
          case 10:
          case "end":
            return _context3.stop();
        }
      }, _callee3, null, [[0, 7]]);
    }));
    return function handleSaveAddons() {
      return _ref3.apply(this, arguments);
    };
  }();
  var getApis = function getApis() {
    if (isBooking4Shop || state.renderType === 'dayBooking') {
      return {
        editBooking: editBookings,
        createBooking: createBookings
      };
    }
    return {
      editBooking: state.apis.editBooking,
      createBooking: state.apis.createBooking
    };
  };

  /**
   * @title: 跨日预约提交之前的验证
   * @description:
   * @return {*}
   * @Author: WangHan
   * @Date: 2024-12-12 16:18
   */
  var handleDaySubmit = function handleDaySubmit() {
    var _isHasDayProducts = isHasDayAppointmentProduct(state);
    if (_isHasDayProducts) {
      var _appointmentProductRe;
      appointmentProductRef === null || appointmentProductRef === void 0 || (_appointmentProductRe = appointmentProductRef.current) === null || _appointmentProductRe === void 0 || _appointmentProductRe.open();
    }
    return _isHasDayProducts;
  };

  /**
   * @title: 保存info
   * @description:
   * @param {object} param1
   * @return {*}
   * @Author: zhiwei.Wang
   * @Date: 2024-01-30 16:54
   */
  var handleSave = /*#__PURE__*/function () {
    var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_ref4) {
      var type, _ref4$messageShow, messageShow, isHasDayProducts, _setLoading, _getApis, createBooking, editBooking, editApi, createApi, saveOtherValue, _state$onSave, callbackData, values, api;
      return _regeneratorRuntime().wrap(function _callee4$(_context4) {
        while (1) switch (_context4.prev = _context4.next) {
          case 0:
            type = _ref4.type, _ref4$messageShow = _ref4.messageShow, messageShow = _ref4$messageShow === void 0 ? true : _ref4$messageShow;
            if (!isDayBooking(state)) {
              _context4.next = 5;
              break;
            }
            isHasDayProducts = handleDaySubmit();
            if (!isHasDayProducts) {
              _context4.next = 5;
              break;
            }
            return _context4.abrupt("return");
          case 5:
            if (!(isBooking4Shop && getIsSubjectRequire(state) && checkHolderIsError(state))) {
              _context4.next = 7;
              break;
            }
            return _context4.abrupt("return");
          case 7:
            // 区分loading, 是点击的checkout 还是save
            _setLoading = type === 'checkout' ? setCheckoutLoading : setLoading;
            _setLoading(true);
            _getApis = getApis(), createBooking = _getApis.createBooking, editBooking = _getApis.editBooking;
            editApi = state.renderType === 'eventBooking' ? editEventBooking : editBooking;
            createApi = state.renderType === 'eventBooking' ? createEventBooking : createBooking;
            saveOtherValue = {};
            if (!(type === 'save')) {
              _context4.next = 20;
              break;
            }
            _context4.next = 16;
            return state === null || state === void 0 || (_state$onSave = state.onSave) === null || _state$onSave === void 0 ? void 0 : _state$onSave.call(state, state.client);
          case 16:
            _context4.t0 = _context4.sent;
            if (_context4.t0) {
              _context4.next = 19;
              break;
            }
            _context4.t0 = {};
          case 19:
            saveOtherValue = _context4.t0;
          case 20:
            _context4.prev = 20;
            callbackData = null; // 格式化提交的参数
            values = formatValues(_objectSpread(_objectSpread({}, state), saveOtherValue)); // 区分是新增还是编辑
            api = state.bookingId ? editApi : createApi; // 增加日志记录
            sendWarningLog({
              title: 'saveBooking',
              content: [{
                key: '下单前数据',
                value: JSON.stringify(values)
              }, {
                key: '日期',
                value: dayjs().format('YYYY-MM-DD HH:mm')
              }]
            });

            // 活动预约新建时校验重复 -- 暂不处理
            // if (!state.bookingId && state.renderType === 'eventBooking') {
            //   const { data } = await eventBookingCheck(values);
            //   if (data.list.length) {
            //     const confirmed = await modal.confirm({
            //       icon: null,
            //       title: locales.getText(
            //         'page.event.booking.text.duplicate-enrollment'
            //       ),
            //       content: locales.getText(
            //         'page.event.booking.text.duplicate-enrollment-content'
            //       )({
            //         customerName: data.customer_name,
            //         title: data.title,
            //         list: data.list,
            //       }),
            //       width: 480,
            //       okText: locales.getText(
            //         'page.event.booking.text.duplicate-enrollment-confirm'
            //       ),
            //     });
            //     if (!confirmed) {
            //       _setLoading(false);
            //       return;
            //     }
            //   }
            // }

            // 如果有addons改动, 则先保存
            if (!addonsEdit) {
              _context4.next = 28;
              break;
            }
            _context4.next = 28;
            return handleSaveAddons();
          case 28:
            if (!infoEdit) {
              _context4.next = 33;
              break;
            }
            _context4.next = 31;
            return api(values, state.bookingId);
          case 31:
            callbackData = _context4.sent;
            if (messageShow) {
              message.success(locales.getText(state.bookingId ? 'pisell2.text.appointment-updated' : 'pisell2.text.created-successfully'));
            }
          case 33:
            // 回调关闭弹窗
            state === null || state === void 0 || state.callback(callbackData, type);
            _setLoading(false);

            // return数据  checkout时需要
            return _context4.abrupt("return", callbackData || values);
          case 38:
            _context4.prev = 38;
            _context4.t1 = _context4["catch"](20);
            console.log(_context4.t1);
            if ((_context4.t1 === null || _context4.t1 === void 0 ? void 0 : _context4.t1.code) === 70101) {
              message.error(_context4.t1 === null || _context4.t1 === void 0 ? void 0 : _context4.t1.message);
            }
            _setLoading(false);
          case 43:
          case "end":
            return _context4.stop();
        }
      }, _callee4, null, [[20, 38]]);
    }));
    return function handleSave(_x2) {
      return _ref5.apply(this, arguments);
    };
  }();

  /**
   * @title: 将预约状态修改为已完成
   * @description:
   * @param {any} e
   * @return {*}
   * @Author: zhiwei.Wang
   * @Date: 2024-01-30 16:57
   */
  var onSelect = /*#__PURE__*/function () {
    var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(e) {
      var status, data;
      return _regeneratorRuntime().wrap(function _callee5$(_context5) {
        while (1) switch (_context5.prev = _context5.next) {
          case 0:
            status = 'completed';
            dispatch({
              type: 'setStatus',
              payload: status
            });
            _context5.next = 4;
            return state.apis.editBookingStatus({
              appointment_status: status
            });
          case 4:
            data = _context5.sent;
            message.success(locales.getText('pisell1.text.edit-status-success'));
            state === null || state === void 0 || state.callback({
              order_id: state.bookingId
            });
          case 7:
          case "end":
            return _context5.stop();
        }
      }, _callee5);
    }));
    return function onSelect(_x3) {
      return _ref6.apply(this, arguments);
    };
  }();

  /**
   * @title: 退款
   * @description:
   * @return {*}
   * @Author: zhiwei.Wang
   * @Date: 2024-01-30 16:57
   */
  var handleRefund = function handleRefund() {
    if (isTerminal !== null && isTerminal !== void 0 && isTerminal()) {
      var _interaction$utils2, _interaction$utils2$p;
      return interaction === null || interaction === void 0 || (_interaction$utils2 = interaction.utils) === null || _interaction$utils2 === void 0 || (_interaction$utils2$p = _interaction$utils2.postMessageToApp) === null || _interaction$utils2$p === void 0 ? void 0 : _interaction$utils2$p.call(_interaction$utils2, {
        module: 'booking',
        key: 'booking_refund',
        data: {
          order_id: state.bookingId
        },
        origin: '/booking'
      });
    }
    state.action({
      type: 'pisell1.handleRefund',
      data: {
        orderId: state.bookingId
      },
      callback: function callback() {
        state === null || state === void 0 || state.callback({
          order_id: state.bookingId
        });
      }
    });
  };
  var paymentRefundedStatus = useMemo(function () {
    var _state$bookingDetail;
    return ['partially_refunded', 'refunded'].includes(state === null || state === void 0 || (_state$bookingDetail = state.bookingDetail) === null || _state$bookingDetail === void 0 ? void 0 : _state$bookingDetail.payment_status);
  }, [state === null || state === void 0 ? void 0 : state.bookingDetail]);

  /**
   * @title: checkout按钮
   * @description:
   * @param {*} useMemo
   * @return {*}
   * @Author: zhiwei.Wang
   * @Date: 2024-01-30 16:57
   */
  var checkoutButton = useMemo(function () {
    var buttonType = 'primary';
    if (transaction_habit_selection.type === 'service_now_pay_later') {
      buttonType = 'default';
    }
    if (source === 'payment') {
      buttonType = 'primary';
    }
    if (!isEdit) {
      buttonType = 'primary';
    }
    return /*#__PURE__*/React.createElement(ConfigProvider, {
      theme: {
        token: {
          colorPrimary: buttonType === 'primary' ? '#7F56DA' : '#F79009'
        }
      }
    }, /*#__PURE__*/React.createElement(Button, {
      className: classNames('pisell-lowcode__booking-footer-buttons-item', _defineProperty({}, 'pisell-lowcode__booking-footer-buttons-item-primary', buttonType === 'primary'))
      // payment页面为主按钮  info页面 编辑时默认按钮 否则是主按钮
      ,
      type: 'primary',
      loading: checkoutLoading,
      onClick: function onClick() {
        handleCheckout();
      },
      disabled: isDisabled
    }, locales.getText('pisell2.text.checkout')));
  }, [isEdit, checkoutLoading, isDisabled, state, source]);
  var handleMenuClick = /*#__PURE__*/function () {
    var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(e) {
      var id, customer, res, _state$bookingDetail2, _state$bookingDetail3;
      return _regeneratorRuntime().wrap(function _callee6$(_context6) {
        while (1) switch (_context6.prev = _context6.next) {
          case 0:
            id = state.bookingId;
            customer = state.bookingDetail.customer;
            if (!isEdit) {
              _context6.next = 8;
              break;
            }
            _context6.next = 5;
            return handleSave({
              type: 'checkout',
              messageShow: false
            });
          case 5:
            res = _context6.sent;
            id = (res === null || res === void 0 ? void 0 : res.order_id) || state.bookingId;
            customer = res !== null && res !== void 0 && res.customer_id ? {
              id: res === null || res === void 0 ? void 0 : res.customer_id
            } : state.bookingDetail.customer;
          case 8:
            if (e.key === 'sendMail') {
              console.log(e);
              state.action({
                type: 'pisell1.sendPayLinkEmail',
                data: {
                  id: id,
                  is_deposit: state.bookingDetail.is_deposit || Number((_state$bookingDetail2 = state.bookingDetail) === null || _state$bookingDetail2 === void 0 ? void 0 : _state$bookingDetail2.deposit_amount),
                  deposit_payment_time: state.bookingDetail.deposit_payment_time,
                  customer: customer,
                  contacts: (_state$bookingDetail3 = state.bookingDetail) === null || _state$bookingDetail3 === void 0 ? void 0 : _state$bookingDetail3.contacts
                },
                callback: function callback() {}
              });
            }
            if (e.key === 'copy') {
              state.action({
                type: 'pisell1.genClientPayLink',
                data: {
                  id: id
                },
                callback: function callback() {}
              });
            }
          case 10:
          case "end":
            return _context6.stop();
        }
      }, _callee6);
    }));
    return function handleMenuClick(_x4) {
      return _ref7.apply(this, arguments);
    };
  }();

  // 重新预约
  var handleRebook = function handleRebook() {
    var _state$onRebook;
    (_state$onRebook = state.onRebook) === null || _state$onRebook === void 0 || _state$onRebook.call(state);
  };
  // 销售
  var handleSale = function handleSale() {
    if (isTerminal !== null && isTerminal !== void 0 && isTerminal()) {
      var _interaction$utils3, _interaction$utils3$p;
      return interaction === null || interaction === void 0 || (_interaction$utils3 = interaction.utils) === null || _interaction$utils3 === void 0 || (_interaction$utils3$p = _interaction$utils3.postMessageToApp) === null || _interaction$utils3$p === void 0 ? void 0 : _interaction$utils3$p.call(_interaction$utils3, {
        module: 'booking',
        key: 'edit_order',
        data: {
          order_id: state.bookingId
        }
      });
    }
    if (state.channelDisabledEdit) {
      modal.warning({
        okText: locales.getText('pisell2.text.ok'),
        content: locales.getText('pisell2.text.terminal-edit-message')
      });
      return;
    }
    setActiveTab === null || setActiveTab === void 0 || setActiveTab('addons');
  };
  // 打印
  var handlePrint = function handlePrint() {};
  // 订单详情
  var handleOrderDetail = function handleOrderDetail() {
    if (isTerminal !== null && isTerminal !== 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: function callback() {
        state === null || state === void 0 || state.callback();
      }
    });
  };
  // 取消订单
  var handleCancel = function handleCancel() {};
  var paymentLinkButton = useMemo(function () {
    var items = [{
      label: locales.getText('pisell2.text.send-mail'),
      key: 'sendMail'
    }, {
      label: locales.getText('pisell2.text.copy-to-clipboard'),
      key: 'copy'
    }];
    return /*#__PURE__*/React.createElement(Dropdown, {
      menu: {
        items: items,
        onClick: handleMenuClick
      }
    }, /*#__PURE__*/React.createElement(Button, {
      className: "pisell-lowcode__booking-footer-buttons-item"
    }, /*#__PURE__*/React.createElement(Space, null, locales.getText('pisell2.text.payment-link'), /*#__PURE__*/React.createElement(DownOutlined, null))));
  }, [handleMenuClick]);

  /**
   * @title: 保存按钮
   * @description:
   * @param {*} useMemo
   * @return {*}
   * @Author: zhiwei.Wang
   * @Date: 2024-01-30 16:58
   */
  var saveButton = useMemo(function () {
    var buttonType = 'default';
    if (transaction_habit_selection.type === 'service_now_pay_later') {
      buttonType = 'primary';
    }
    return /*#__PURE__*/React.createElement(ConfigProvider, {
      theme: {
        token: {
          colorPrimary: buttonType === 'primary' ? '#7F56DA' : '#F79009'
        }
      }
    }, /*#__PURE__*/React.createElement(Button, {
      className: classNames('pisell-lowcode__booking-footer-buttons-item', _defineProperty({}, 'pisell-lowcode__booking-footer-buttons-item-primary', buttonType === 'primary')),
      type: 'primary',
      onClick: function onClick() {
        handleSave({
          type: 'save'
        });
      },
      disabled: isDisabled || !isEdit,
      loading: loading
    }, locales.getText('pisell2.text.save')));
  }, [loading, isDisabled, isEdit, infoEdit, addonsEdit, state]);

  /**
   * @title: 完成按钮
   * @description:
   * @param {*} useMemo
   * @return {*}
   * @Author: zhiwei.Wang
   * @Date: 2024-01-30 16:58
   */
  var completeButton = useMemo(function () {
    return /*#__PURE__*/React.createElement(Button, {
      className: "pisell-lowcode__booking-footer-buttons-item",
      type: 'primary',
      onClick: onSelect,
      disabled: state.appointment_status === 'completed'
    }, locales.getText('pisell2.text.status.completed'));
  }, [state.appointment_status]);

  /**
   * @title: Rebook按钮
   * @description:
   * @param {*} useMemo
   * @return {*}
   * @Author: zhiwei.Wang
   * @Date: 2024-01-30 16:58
   */
  var rebookButton = useMemo(function () {
    return /*#__PURE__*/React.createElement(Button, {
      className: "pisell-lowcode__booking-footer-buttons-item",
      onClick: handleRebook
    }, locales.getText('pisell2.text.rebook'));
  }, [state === null || state === void 0 ? void 0 : state.onRebook]);

  /**
   * @title: 退款按钮
   * @description:
   * @param {*} useMemo
   * @return {*}
   * @Author: zhiwei.Wang
   * @Date: 2024-01-30 16:58
   */
  var refundButton = useMemo(function () {
    return /*#__PURE__*/React.createElement(Button, {
      className: "pisell-lowcode__booking-footer-buttons-item",
      type: "default",
      onClick: handleRefund
    }, locales.getText('pisell2.text.refund'));
  }, []);
  var handleClearAll = function handleClearAll() {
    var _state$clearAllValue;
    state === null || state === void 0 || (_state$clearAllValue = state.clearAllValue) === null || _state$clearAllValue === void 0 || _state$clearAllValue.call(state);
  };

  /**
   * @title: 清空按钮
   * @description:
   * @return: *
   * @Author: shengjie.zuo
   * @Date: 2024-10-26 10:52:01
   */
  var clearAllButton = useMemo(function () {
    return /*#__PURE__*/React.createElement(ConfigProvider, {
      theme: {
        token: {
          colorPrimary: '#f04438'
        }
      }
    }, /*#__PURE__*/React.createElement(Button, {
      className: "pisell-lowcode__booking-footer-buttons-item",
      type: "primary",
      onClick: handleClearAll
      // color="#f04438"
      // style={{ backgroundColor: '#f04438', color: '#fff' }}
    }, locales.getText('pisell2.booking.info.text.clear-all')));
  }, []);
  var buttonMap = {
    checkout: checkoutButton,
    save: saveButton,
    complete: completeButton,
    refund: refundButton,
    paymentLink: paymentLinkButton,
    rebook: rebookButton,
    clearAll: clearAllButton
  };
  var isShowClearAll = useMemo(function () {
    // 目前新建状态时展示清除全部按钮
    if (!state.bookingId) {
      return true;
    }
  }, [state.bookingId]);

  /**
   * @title: 是否可以checkout
   * @description:
   * @param {*} useMemo
   * @return {*}
   * @Author: zhiwei.Wang
   * @Date: 2024-01-30 16:58
   */
  var isCheckout = useMemo(function () {
    var _state$bookingDetail4, _state$bookingDetail5;
    var list = ['unfulfilled', 'partially_paid', 'unpaid', 'payment_processing'];
    // (支付状态 = 已支付 || 部分付款 || 未付款 || 支付处理中) && 预约状态 !== 已取消
    if (!state.bookingId || ((_state$bookingDetail4 = state.bookingDetail) === null || _state$bookingDetail4 === void 0 || (_state$bookingDetail4 = _state$bookingDetail4.bookings) === null || _state$bookingDetail4 === void 0 ? void 0 : _state$bookingDetail4.appointment_status) !== 'cancelled' && list.includes(state === null || state === void 0 || (_state$bookingDetail5 = state.bookingDetail) === null || _state$bookingDetail5 === void 0 ? void 0 : _state$bookingDetail5.payment_status) && !state.disabledEdit) {
      return true;
    } else {
      if (total.notPaidAmount > 0) {
        return true;
      }
      return false;
    }
  }, [state.bookingDetail, total.notPaidAmount]);
  var _buttons = useMemo(function () {
    // 如果预约是取消状态,则不展示任何按钮
    // 如果订单已退款 | 部分退款，则展示再次预约按钮
    if (state.appointment_status === 'cancelled' || paymentRefundedStatus) {
      return [buttonMap.rebook];
    }

    // addons 默认为新增按钮, 如果有新增数据 则添加save按钮
    if (source === 'addons') {
      var arr = [];
      arr = _toConsumableArray(buttons);
      if (isEdit) {
        arr.push(buttonMap.save);
      }
      return arr;
    }

    // 编辑预约 && 没有未支付金额 && 未修改订单   展示完成按钮
    // if (total.notPaidAmount <= 0 && state.bookingId && !isEdit) {
    // 	return [buttonMap.complete];
    // }

    // payment
    if (source === 'payment') {
      var _arr = [];
      if (state.bookingId && isShowPaymentLink) {
        _arr.push(buttonMap.paymentLink);
      }
      if (!isTeam) {
        // 有已支付金额, 展示退款
        if (total.paidAmount > 0) {
          _arr.push(buttonMap.refund);
        }
        // 有未支付金额 展示checkout
        if (isCheckout) {
          _arr.push(buttonMap.checkout);
        }
      }
      return _arr;
    }

    // info
    if (source === 'info') {
      var _arr2 = [];
      if (isShowClearAll) {
        _arr2.push(buttonMap.clearAll);
      }
      // if (state.bookingId && isShowPaymentLink) {
      // 	arr.push(buttonMap.paymentLink);
      // }
      // 有未支付金额 展示checkout
      if (isCheckout) {
        // 有未支付金额 展示checkout
        if (!isTeam) {
          _arr2.push(buttonMap.checkout);
        }
      } else {
        // 没有任何编辑时,展示完成按钮
        if (!isEdit) {
          _arr2.push(buttonMap.complete);
        }
      }
      // 有编辑,展示save按钮
      if (isEdit) {
        _arr2.push(buttonMap.save);
      }
      // if (isTeam) {
      //   if (arr.length === 0) {
      //     return [buttonMap.rebook];
      //   }
      // }

      return _arr2;
    }
    if (source === 'addTime') {
      var _arr3 = [];
      _arr3 = _toConsumableArray(buttons);
      return _arr3;
    }
    return [];
  }, [buttons, total, isEdit, checkoutLoading, isDisabled, source, buttonMap, loading, isCheckout, state, isTeam, isShowClearAll]);
  var moreButton = useMemo(function () {
    var _state$bookingDetail6;
    var arr = [];
    if (!state.bookingId) {
      return [];
    }
    if (source !== 'info') {
      return [];
    }
    if (state.renderType === 'eventBooking') {
      return [];
    }

    // 如果订单已退款, 则不展示任何按钮
    if ((state === null || state === void 0 || (_state$bookingDetail6 = state.bookingDetail) === null || _state$bookingDetail6 === void 0 ? void 0 : _state$bookingDetail6.payment_status) === 'refunded') {
      return [];
    }

    // 如果外部没有按钮, 则rebook按钮放在外面
    if (_buttons.length !== 0) {
      var _state$bookingDetail7;
      // 支付链接, 部分退款时, 不展示支付链接
      if (state.bookingId && isShowPaymentLink && (state === null || state === void 0 || (_state$bookingDetail7 = state.bookingDetail) === null || _state$bookingDetail7 === void 0 ? void 0 : _state$bookingDetail7.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 && !isDayBooking(state)) {
          arr.push(actionMap.sale);
        }
      }
    }

    // if (transaction_habit_selection.button_rows == 1) {
    // 	if (isTerminal?.()) {
    // 		arr.push(actionMap.print);
    // 	}
    // }

    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);
    }
    // 取消订单
    // arr.push(actionMap.cancelOrder);
    return arr;
  }, [state, total, isShowPaymentLink, source, _buttons.length, state === null || state === void 0 || (_state$bookingDetail8 = state.bookingDetail) === null || _state$bookingDetail8 === void 0 ? void 0 : _state$bookingDetail8.payment_status]);

  /**
   * 是否只有定金支付
   */
  var isOnlyDeposit = useMemo(function () {
    var _state$bookingDetail9, _state$bookingDetail10, _state$bookingDetail11;
    if (state !== null && state !== void 0 && (_state$bookingDetail9 = state.bookingDetail) !== null && _state$bookingDetail9 !== void 0 && _state$bookingDetail9.deposit_payment_time && state !== null && state !== void 0 && (_state$bookingDetail10 = state.bookingDetail) !== null && _state$bookingDetail10 !== void 0 && (_state$bookingDetail10 = _state$bookingDetail10.payment_types) !== null && _state$bookingDetail10 !== void 0 && (_state$bookingDetail11 = _state$bookingDetail10.every) !== null && _state$bookingDetail11 !== void 0 && _state$bookingDetail11.call(_state$bookingDetail10, function (item) {
      return item === 'deposit';
    })) {
      return true;
    }
    return false;
  }, [state === null || state === void 0 ? void 0 : state.bookingDetail]);

  /**
   * @title: 总计文案
   * @description:
   * @param {*} useMemo
   * @return {*}
   * @Author: zhiwei.Wang
   * @Date: 2024-01-30 17:00
   */
  var totalText = useMemo(function () {
    var str = '';

    // 只有定金支付时，直接展示
    if (isOnlyDeposit) {
      var _state$bookingDetail12;
      return "".concat(locales.getText('pisell2.text.deposit-paid'), " ").concat(formatAmount(state === null || state === void 0 || (_state$bookingDetail12 = state.bookingDetail) === null || _state$bookingDetail12 === void 0 ? void 0 : _state$bookingDetail12.deposit_paid_amount, 2, (state === null || state === void 0 ? void 0 : state.amountSymbol) || '$'), " ").concat(total.duration ? "(".concat(total.duration, ")") : '');
    }

    // 有退款金额时, 直接展示 退款:$8.00
    if (total.totalRefundAmount > 0) {
      return "".concat(locales.getText('pisell2.text.refunded-amount'), ": ").concat(formatAmount(total.totalRefundAmount, 2, (state === null || state === void 0 ? void 0 : state.amountSymbol) || '$'));
    }

    // 如果待支付金额小于0 则展示全额支付
    if (total.notPaidAmount <= 0 && state.bookingId) {
      str = "".concat(locales.getText('pisell1.text.fully-paid'), ": ").concat(formatAmount(total.sumTotalAmount, 2, (state === null || state === void 0 ? void 0 : state.amountSymbol) || '$'));
    }

    // 待支付金额大于0 并且是新增时, 展示 待支付金额
    if (total.notPaidAmount > 0 || !state.bookingId) {
      str = "".concat(locales.getText('pisell2.text.to-pay'), ": ").concat(formatAmount(total.notPaidAmount, 2, (state === null || state === void 0 ? void 0 : state.amountSymbol) || '$'));
    }
    if (total.duration) {
      str = str + " (".concat(total.duration, ")");
    }
    return str;
  }, [state, total, state.bookingId, isOnlyDeposit]);

  /**
   * @title: 欠款文案
   * @description: 商家欠用户钱
   * @param {*} useMemo
   * @return {*}
   * @Author: zhiwei.Wang
   * @Date: 2024-01-30 17:01
   */
  var arrearsText = useMemo(function () {
    var str = '';
    // 只有定金支付时不展示退款金额
    if (isOnlyDeposit) {
      return str;
    }
    // 欠款
    if (total.dueAmount < 0) {
      str = "".concat(locales.getText('pisell1.text.refund-customer'), ": ").concat(formatAmount(total.dueAmount, 2, (state === null || state === void 0 ? void 0 : state.amountSymbol) || '$'));
    }
    return str;
  }, [state, total, isOnlyDeposit]);

  /**
   * @title: 税费文案
   * @description:
   * @param {*} useMemo
   * @return {*}
   * @Author: zhiwei.Wang
   * @Date: 2024-01-30 17:02
   */
  var taxText = useMemo(function () {
    if (!(state !== null && state !== void 0 && state.bookingDetail)) {
      return '';
    }
    var str = '';
    str = str + state.bookingDetail.tax_title;
    str = str + ' ' + Number(state.bookingDetail.tax_rate) * 100 + '%';

    // 判断税费是 包含在订单内  还是单独的
    if (is_price_include_tax(state)) {
      str = str + ' ' + locales.getText('pisell1.text.included');
    } else {
      str = str + ' ' + locales.getText('pisell1.text.not-contain');
    }
    return str;
  }, [state === null || state === void 0 ? void 0 : state.bookingDetail]);

  /**
   * @title: 是否显示footer loading
   * @description:  避免数据未获取完时页面闪动
   * @param {*} useMemo
   * @return {*}
   * @Author: zhiwei.Wang
   * @Date: 2024-01-30 17:03
   */
  var showFooter = useMemo(function () {
    // 编辑情况下, 必须获取到预约详情和 addons  才能确定按钮的内容
    if (state.bookingId) {
      var _state$addons3;
      if (!state.bookingDetail) {
        return true;
      }
      if (!((_state$addons3 = state.addons) !== null && _state$addons3 !== void 0 && _state$addons3.load) && state.renderType !== 'eventBooking' && !state.isBookingCreatePage) {
        return true;
      }
    }
    return false;
  }, [state.bookingId, state.bookingDetail, (_state$addons4 = state.addons) === null || _state$addons4 === void 0 ? void 0 : _state$addons4.load, state.renderType]);
  var menuChange = function 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;
    }
  };
  var subTotalList = useMemo(function () {
    var _state$bookingDetail13, _state$bookingDetail14, _state$bookingDetail15;
    var surcharge = (((_state$bookingDetail13 = state.bookingDetail) === null || _state$bookingDetail13 === void 0 ? void 0 : _state$bookingDetail13.surcharge) || []).map(function (d, index) {
      return {
        key: "custom_surcharge_".concat(index),
        label: d.name[state.locale],
        value: d.amount
      };
    });
    return [
    // 小计
    {
      key: 'sub_total',
      value: total.productAmount
    }].concat(_toConsumableArray(surcharge), [
    // 税费
    {
      hidden: !state.bookingId,
      key: 'tax',
      value: total.tax,
      tax: {
        rate: state === null || state === void 0 || (_state$bookingDetail14 = state.bookingDetail) === null || _state$bookingDetail14 === void 0 ? void 0 : _state$bookingDetail14.tax_rate,
        is_price_include_tax: is_price_include_tax(state),
        title: state === null || state === void 0 || (_state$bookingDetail15 = state.bookingDetail) === null || _state$bookingDetail15 === void 0 ? void 0 : _state$bookingDetail15.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: locales.getText('pisell1.text.rounding')
    }]);
  }, [total, (_state$bookingDetail16 = state.bookingDetail) === null || _state$bookingDetail16 === void 0 ? void 0 : _state$bookingDetail16.surcharge, state, state.bookingId]);
  var orderTotalList = useMemo(function () {
    return [
    // 订单已付金额
    {
      hidden: !state.bookingId,
      key: 'custom_orderPaidAmount',
      value: total.orderPaidAmount,
      label: locales.getText('pisell2.text.amount-paid-on-order')
    },
    // 支付手续费
    {
      hidden: !state.bookingId,
      key: 'custom_paySurchargeFee',
      value: total.paySurchargeFee,
      label: locales.getText('pisell1.text.payment-fee')
    },
    // 客户实付金额
    {
      hidden: !state.bookingId,
      key: 'custom_actualPaidAmount',
      value: total.actualPaidAmount,
      label: locales.getText('pisell2.text.amount-actually-paid-by-the-customer')
    },
    // 退款金额
    {
      hidden: !state.bookingId || !total.totalRefundAmount,
      key: 'custom_totalRefundAmount',
      value: total.totalRefundAmount,
      label: locales.getText('pisell2.text.refunded-amount')
    }];
  }, [total, (_state$bookingDetail17 = state.bookingDetail) === null || _state$bookingDetail17 === void 0 ? void 0 : _state$bookingDetail17.surcharge, state, state.bookingId]);
  return /*#__PURE__*/React.createElement(Skeleton, {
    title: false,
    round: true,
    loading: showFooter,
    active: true
  }, (hasGoodPassApp || hasDiscountCardApp) && ['addons', 'info'].includes(source) && !paymentRefundedStatus ? /*#__PURE__*/React.createElement(VoucherCard, {
    state: state,
    dispatch: dispatch,
    source: source
  }) : null, /*#__PURE__*/React.createElement("div", {
    className: "pisell-lowcode__booking-footer-total"
  }, /*#__PURE__*/React.createElement("span", {
    className: "pisell-lowcode__booking-footer-left"
  }, /*#__PURE__*/React.createElement("span", {
    className: "pisell-lowcode__booking-footer-left-total"
  }, totalText), /*#__PURE__*/React.createElement("span", {
    className: "pisell-lowcode__booking-footer-left-arrears"
  }, arrearsText)), /*#__PURE__*/React.createElement("span", {
    className: "pisell-lowcode__booking-footer-right",
    onClick: function onClick() {
      setShowDetail(!showDetail);
    }
  }, locales.getText('pisell2.text.details'), ' ', /*#__PURE__*/React.createElement(ChevronDown, {
    className: classNames('pisell-lowcode__booking-footer-right-icon', {
      'pisell-lowcode__booking-footer-right-icon-show': showDetail
    })
  }))), /*#__PURE__*/React.createElement("div", {
    className: classNames('pisell-lowcode__booking-footer-total-detail', {
      'pisell-lowcode__booking-footer-total-detail-show': showDetail
    })
  }, /*#__PURE__*/React.createElement("div", {
    className: "order-total-item-border"
  }), /*#__PURE__*/React.createElement(SubTotal, {
    mode: "column1",
    list: subTotalList,
    style: {
      padding: "0"
    }
  }), /*#__PURE__*/React.createElement("div", {
    className: state.bookingId ? 'order-total-item-border' : ''
  }), !!state.bookingId && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(SubTotal, {
    mode: "column1",
    list: orderTotalList,
    style: {
      padding: " 0 0 16px"
    }
  }))), !(state !== null && state !== void 0 && state.disableEventBookingEdit) && /*#__PURE__*/React.createElement("div", {
    className: "pisell-lowcode__booking-footer-buttons"
  }, /*#__PURE__*/React.createElement(FooterMenus, {
    items: moreButton,
    state: state,
    dispatch: dispatch,
    source: source,
    menuChange: menuChange
  }), _buttons.length ? _buttons : state.bookingId && isShowPaymentLink ? paymentLinkButton : null), source === 'info' && state.bookingId && !state.disabledEdit && (transaction_habit_selection === null || transaction_habit_selection === void 0 ? void 0 : transaction_habit_selection.button_rows) == 2 ? /*#__PURE__*/React.createElement("div", {
    className: "pisell-lowcode__booking-footer-buttons",
    style: {
      marginTop: 12
    }
  }, state.appointment_status !== 'cancelled' && !state.isBookingCreatePage && !isDayBooking(state) ? /*#__PURE__*/React.createElement(Button, {
    onClick: function onClick() {
      return handleSale();
    },
    size: "large",
    className: "pisell-lowcode__booking-footer-buttons-item"
  }, actionMap.sale.label) : null, isTeam ? null : /*#__PURE__*/React.createElement(Button, {
    onClick: function onClick() {
      return handleOrderDetail();
    },
    size: "large",
    className: "pisell-lowcode__booking-footer-buttons-item"
  }, actionMap.orderDetail.label)) : null, contextHolder, /*#__PURE__*/React.createElement(AppointmentProductModal, {
    ref: appointmentProductRef
  }));
};
export default Footer;