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 _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; }
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 _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); }); }; }
import { useState, useEffect, useMemo } from 'react';
import { locales } from '@pisell/utils';
import { usePisellOS } from "../../hooks/useEngineContext";
import useEngineContext from "../../hooks/useEngineContext";
import { processResourceList, getCustomer, currentAppointmentBoard, currentRenderLists, getFormInsertBeforeKey, checkAndGoNext, checkAndMarkCartRenderError, formatHolder, Toast } from "./utils";
import { useAppointmentBookingContext } from "./context";
import { scrollToFirstErrorCard } from "./components/Resource/utils";
export var useAppointmentBooking = function useAppointmentBooking() {
  var pisellOS = usePisellOS();
  return pisellOS.getModule('appointmentBooking');
};
export var useShopDiscount = function useShopDiscount() {
  var pisellOS = usePisellOS();
  return pisellOS.getModule('shopDiscount');
};
export var contextUtils = function contextUtils() {
  var _context$appHelper;
  var context = useEngineContext();
  var utils = (context === null || context === void 0 || (_context$appHelper = context.appHelper) === null || _context$appHelper === void 0 ? void 0 : _context$appHelper.utils) || {};
  return utils;
};

/**
 * @title: 监听步骤发生变化
 * @description:
 * @return {*}
 * @Author: WangHan
 * @Date: 2025-04-15 11:11
 */
export var useAppointmentBookingStep = function useAppointmentBookingStep() {
  var _appointmentBooking$s;
  var pisellOS = usePisellOS();
  var _ref = useAppointmentBookingContext(),
    appointmentBooking = _ref.appointmentBooking,
    setCurrentStep = _ref.setCurrentStep,
    carts = _ref.carts,
    openPolicy = _ref.openPolicy,
    setLoading = _ref.setLoading,
    setCurrentSelectedResources = _ref.setCurrentSelectedResources,
    currentStepParams = _ref.currentStepParams,
    setIsErrorHolder = _ref.setIsErrorHolder;
  var _useAppointmentBookin = useAppointmentBookingSetting(),
    isRetailTemplate = _useAppointmentBookin.isRetailTemplate;
  var stepList = (appointmentBooking === null || appointmentBooking === void 0 || (_appointmentBooking$s = appointmentBooking.store) === null || _appointmentBooking$s === void 0 || (_appointmentBooking$s = _appointmentBooking$s.step) === null || _appointmentBooking$s === void 0 || (_appointmentBooking$s = _appointmentBooking$s.store) === null || _appointmentBooking$s === void 0 ? void 0 : _appointmentBooking$s.stepList) || [];
  var _useAppointmentBookin2 = useAppointmentBookingLogin(),
    isLogin = _useAppointmentBookin2.isLogin,
    openLoginModal = _useAppointmentBookin2.openLoginModal;
  var _useAppointmentBookin3 = useAppointmentBookingSetting(),
    isFormSubject = _useAppointmentBookin3.isFormSubject;
  var _useAppointmentBookin4 = useAppointmentBookingAccount(),
    getHolders = _useAppointmentBookin4.getHolders,
    checkAccount = _useAppointmentBookin4.checkAccount;
  var utils = contextUtils();

  // 判断是否是最后一步
  var getCurrentAndLastStep = function getCurrentAndLastStep() {
    var currentStep = appointmentBooking === null || appointmentBooking === void 0 ? void 0 : appointmentBooking.getCurrentStep();
    setCurrentStep(currentStep);
  };
  useEffect(function () {
    getCurrentAndLastStep();
    pisellOS.effects.on('appointmentBooking_step:changed', /*#__PURE__*/function () {
      var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(res) {
        return _regeneratorRuntime().wrap(function _callee$(_context) {
          while (1) switch (_context.prev = _context.next) {
            case 0:
              if (res.path === 'currentStep') {
                getCurrentAndLastStep();
              }
            case 1:
            case "end":
              return _context.stop();
          }
        }, _callee);
      }));
      return function (_x) {
        return _ref2.apply(this, arguments);
      };
    }());
  }, []);

  // 设置步骤
  var getStepIndex = function getStepIndex(type) {
    var skipNumber = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
    var currentStep = appointmentBooking === null || appointmentBooking === void 0 ? void 0 : appointmentBooking.getCurrentStep();
    var index = (currentStep === null || currentStep === void 0 ? void 0 : currentStep.index) || 1;
    if (type === 'next') {
      var nextIndex = index + skipNumber;
      return nextIndex + 1 > stepList.length ? stepList.length - 1 : nextIndex;
    }
    if (type === 'prev') {
      var prevIndex = index - skipNumber;
      return prevIndex < 0 ? 0 : prevIndex;
    }
  };

  // 移除某一步
  var removeStep = function removeStep(key) {
    return appointmentBooking.removeStep(key);
  };

  // 添加某一步
  var addStep = function addStep(props, stepKey) {
    var index = props.index,
      key = props.key,
      description = props.description;
    return appointmentBooking.addStep({
      index: index,
      key: key,
      description: description
    }, stepKey);
  };

  // 更新步骤
  var updateStep = function updateStep(key, step) {
    appointmentBooking.updateStep(key, {
      index: step === null || step === void 0 ? void 0 : step.index,
      key: key,
      isSkip: (step === null || step === void 0 ? void 0 : step.isSkip) || false
    });
  };

  // 下一步
  var nextStep = function nextStep() {
    var _nextStep, _nextStep2, _nextStep3;
    var stepList = appointmentBooking.getStepList() || [];
    var currentKey = currentStepParams === null || currentStepParams === void 0 ? void 0 : currentStepParams.key;
    var currentSelectedResources = appointmentBooking.getOtherData('current_selected_resources');

    // 先确定点击时的步骤，如果当前步骤是选择服务
    if (!isRetailTemplate && currentKey === 'select-service') {
      var _appointmentBooking$o, _stepList, _stepList2;
      var _ref3 = (appointmentBooking === null || appointmentBooking === void 0 || (_appointmentBooking$o = appointmentBooking.otherParams) === null || _appointmentBooking$o === void 0 ? void 0 : _appointmentBooking$o.productModuleParams) || {},
        bookingProcess = _ref3.bookingProcess;
      var isDateSelectedFirst = bookingProcess === 'date_first';
      var hasResourceStep = (_stepList = stepList) === null || _stepList === void 0 ? void 0 : _stepList.find(function (item) {
        return (item === null || item === void 0 ? void 0 : item.key) === 'select-resource';
      });
      var hasSelectGuestStep = (_stepList2 = stepList) === null || _stepList2 === void 0 || (_stepList2 = _stepList2.find(function (item) {
        return (item === null || item === void 0 ? void 0 : item.key) === 'select-guest';
      })) === null || _stepList2 === void 0 ? void 0 : _stepList2.key;
      // 判断购物车里是否全是是普通商品
      var isAllNormalProduct = appointmentBooking === null || appointmentBooking === void 0 ? void 0 : appointmentBooking.isCartAllNormalProducts();
      if (isAllNormalProduct) {
        removeStep('select-resource');
        removeStep('select-time');
        removeStep('fill-form');
        if (!isDateSelectedFirst) {
          removeStep('select-date');
        }
      } else if (!hasResourceStep) {
        // 如果不全是普通商品，并且还没有选择资源步骤，证明之前被删除过，要给她加回来
        // 判断当前步骤里有没有添加预约人，如果有的话则应该是在添加预约人之后添加步骤
        var targetKey = hasSelectGuestStep ? hasSelectGuestStep : 'select-service';
        var isHasDurationProduct = appointmentBooking === null || appointmentBooking === void 0 ? void 0 : appointmentBooking.isCartHasDurationProduct();
        // 如果购物车里有 duration 商品（目前来说，只能是纯 duration 商品）
        if (isHasDurationProduct) {
          // 如果是先选商品，则添加日期、资源、时间步骤
          if (!isDateSelectedFirst) {
            appointmentBooking.addStep({
              key: 'select-date',
              description: locales.getText('pisell2.appointment.select.date')
            }, targetKey);
            targetKey = 'select-date';
          }
          // 如果是先选日期，则添加资源、时间
          appointmentBooking.addStep({
            key: 'select-resource',
            description: locales.getText('pisell2.appointment.select.resource')
          }, targetKey);
          targetKey = 'select-resource';
          appointmentBooking.addStep({
            key: 'select-time',
            description: locales.getText('pisell2.appointment.select.time')
          }, targetKey);
        } else {
          // 如果购物车里是session 商品，则只添加选择资源步骤
          appointmentBooking.addStep({
            key: 'select-resource',
            description: locales.getText('pisell2.appointment.select.resource')
          }, targetKey);
        }
      }
      stepList = (appointmentBooking === null || appointmentBooking === void 0 ? void 0 : appointmentBooking.getStepList()) || [];
    }
    var nextStep = stepList[(currentStepParams === null || currentStepParams === void 0 ? void 0 : currentStepParams.index) + 1];

    // 判断选定的日期是否存在可用的预约
    if (!isRetailTemplate && ((_nextStep = nextStep) === null || _nextStep === void 0 ? void 0 : _nextStep.key) === 'select-resource') {
      var result = appointmentBooking.checkResourceListForDate();
      if (!result) {
        return Toast(locales.getText('pisell2.appointment.unuse.date'));
      }
      var capacityResult = appointmentBooking.checkMaxDurationCapacity();
      if (!capacityResult.success) {
        var getMessage = locales.getText('pisell2.appointment.unuse.capacity');
        var message = typeof getMessage === 'function' ? getMessage(capacityResult.minAvailableCount) : getMessage;
        return Toast(message);
      }
    }
    if (!isRetailTemplate && currentKey !== null && currentKey !== void 0 && currentKey.startsWith('select-resource')) {
      var _currentSelectedResou;
      // 1. 检测购物车中是否选择了资源
      var _checkAndMarkCartRend = checkAndMarkCartRenderError(currentSelectedResources, appointmentBooking, utils),
        hasError = _checkAndMarkCartRend.hasError,
        updatedCartList = _checkAndMarkCartRend.updatedCartList;
      if (hasError) {
        setCurrentSelectedResources(updatedCartList);
        scrollToFirstErrorCard();
        return;
      }
      // 2. 插入表单步骤
      var preKey = '';
      currentSelectedResources === null || currentSelectedResources === void 0 || currentSelectedResources.forEach(function (cart) {
        var _selectedResource$ren, _selectedResource$ren2;
        var selectedResource = cart === null || cart === void 0 ? void 0 : cart.currentSelectedResource;
        var resourceItem = (selectedResource === null || selectedResource === void 0 ? void 0 : selectedResource.resourceItem) || {};
        var formId = selectedResource === null || selectedResource === void 0 || (_selectedResource$ren = selectedResource.renderItem) === null || _selectedResource$ren === void 0 ? void 0 : _selectedResource$ren.resource_form_id;
        var policyId = selectedResource === null || selectedResource === void 0 || (_selectedResource$ren2 = selectedResource.renderItem) === null || _selectedResource$ren2 === void 0 ? void 0 : _selectedResource$ren2.policy_id;
        var formKey = "fill-form_@".concat(resourceItem === null || resourceItem === void 0 ? void 0 : resourceItem.form_id, "-").concat(resourceItem === null || resourceItem === void 0 ? void 0 : resourceItem.code, "-").concat(cart === null || cart === void 0 ? void 0 : cart._id, "-").concat(formId, "-").concat(policyId);

        // 如果有表单id则插入表单步骤
        if (formId) {
          var description = locales.getText('pisell2.appointment.fill-form');
          var beforeKey = getFormInsertBeforeKey(currentKey, stepList);
          appointmentBooking.addStep({
            key: formKey,
            description: description
          }, preKey || beforeKey);
          // 如果有同时有多个预约表单，则需要记录下当前的表单key，用于后续插入表单步骤
          preKey = formKey;
        } else {
          appointmentBooking.removeStep(formKey);
        }
      });

      // 3. 插入下一个资源步骤
      stepList = appointmentBooking.getStepList();
      var selectedResource = currentSelectedResources === null || currentSelectedResources === void 0 || (_currentSelectedResou = currentSelectedResources[0]) === null || _currentSelectedResou === void 0 ? void 0 : _currentSelectedResou.currentSelectedResource;
      if (selectedResource) {
        var _selectedResource$res;
        var originRenderLists = (selectedResource === null || selectedResource === void 0 || (_selectedResource$res = selectedResource.resourceItem) === null || _selectedResource$res === void 0 ? void 0 : _selectedResource$res.originRenderLists) || [];
        var currentResourceIndex = originRenderLists === null || originRenderLists === void 0 ? void 0 : originRenderLists.findIndex(function (item) {
          var _selectedResource$ren3;
          return item.id === (selectedResource === null || selectedResource === void 0 || (_selectedResource$ren3 = selectedResource.renderItem) === null || _selectedResource$ren3 === void 0 ? void 0 : _selectedResource$ren3.form_id);
        });
        var nextResource = originRenderLists === null || originRenderLists === void 0 ? void 0 : originRenderLists[currentResourceIndex + 1];
        var resourceKey = "select-resource_@".concat(nextResource === null || nextResource === void 0 ? void 0 : nextResource.form_id, "-").concat(nextResource === null || nextResource === void 0 ? void 0 : nextResource.code);

        // 如果有下一个资源数据，则插入下一个资源步骤
        if (nextResource) {
          var _stepList3;
          var beforeKey = (_stepList3 = stepList[stepList.length - 2]) === null || _stepList3 === void 0 ? void 0 : _stepList3.key;
          appointmentBooking.addStep({
            key: resourceKey,
            description: ''
          }, beforeKey);
        } else {
          appointmentBooking.removeStep(resourceKey);
        }
      }
    }

    // 4. 检测是否登录和打开协议弹窗
    stepList = appointmentBooking.getStepList();
    nextStep = stepList[(currentStepParams === null || currentStepParams === void 0 ? void 0 : currentStepParams.index) + 1];
    if ((_nextStep2 = nextStep) !== null && _nextStep2 !== void 0 && (_nextStep2 = _nextStep2.key) !== null && _nextStep2 !== void 0 && _nextStep2.startsWith('select-resource_') || ((_nextStep3 = nextStep) === null || _nextStep3 === void 0 ? void 0 : _nextStep3.key) === 'confirm-information') {
      var _currentSelectedResou2, _nextStep4;
      var _selectedResource = (currentSelectedResources === null || currentSelectedResources === void 0 || (_currentSelectedResou2 = currentSelectedResources[0]) === null || _currentSelectedResou2 === void 0 ? void 0 : _currentSelectedResou2.currentSelectedResource) || {};
      var renderItem = (_selectedResource === null || _selectedResource === void 0 ? void 0 : _selectedResource.renderItem) || {};

      // 监测holder数据
      var checkHolder = /*#__PURE__*/function () {
        var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
          var cartLists, newCarts, appoimentCarts, _checkAndGoNext, hasError;
          return _regeneratorRuntime().wrap(function _callee2$(_context2) {
            while (1) switch (_context2.prev = _context2.next) {
              case 0:
                setLoading(false);

                // 零售订单不需要验证holder
                if (!(isRetailTemplate || appointmentBooking !== null && appointmentBooking !== void 0 && appointmentBooking.isCartAllNormalProducts())) {
                  _context2.next = 3;
                  break;
                }
                return _context2.abrupt("return", appointmentBooking.next());
              case 3:
                cartLists = carts || [];
                if (carts !== null && carts !== void 0 && carts.length) {
                  _context2.next = 11;
                  break;
                }
                _context2.next = 7;
                return appointmentBooking.getCart();
              case 7:
                newCarts = _context2.sent;
                cartLists = newCarts || [];
                _context2.next = 12;
                break;
              case 11:
                cartLists = carts || [];
              case 12:
                appoimentCarts = cartLists.filter(function (n) {
                  return !(appointmentBooking !== null && appointmentBooking !== void 0 && appointmentBooking.isTargetCartIdNormalProduct(n._id));
                });
                _checkAndGoNext = checkAndGoNext(isFormSubject, checkAccount, appoimentCarts), hasError = _checkAndGoNext.hasError;
                setIsErrorHolder(hasError);
                if (!hasError) {
                  _context2.next = 17;
                  break;
                }
                return _context2.abrupt("return");
              case 17:
                if (!(renderItem !== null && renderItem !== void 0 && renderItem.policy_id)) {
                  _context2.next = 21;
                  break;
                }
                openPolicy({
                  id: renderItem === null || renderItem === void 0 ? void 0 : renderItem.policy_id
                }, function () {
                  return appointmentBooking.next();
                });
                _context2.next = 22;
                break;
              case 21:
                return _context2.abrupt("return", appointmentBooking.next());
              case 22:
              case "end":
                return _context2.stop();
            }
          }, _callee2);
        }));
        return function checkHolder() {
          return _ref4.apply(this, arguments);
        };
      }();

      // 检测是否登录
      var checkLogin = /*#__PURE__*/function () {
        var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
          var pubsub;
          return _regeneratorRuntime().wrap(function _callee3$(_context3) {
            while (1) switch (_context3.prev = _context3.next) {
              case 0:
                if (isLogin) {
                  _context3.next = 6;
                  break;
                }
                // const accountLists = await appointmentBooking.getAccounts()
                pubsub = utils.pubsub;
                pubsub.once('pisell1.login.success', function (res) {
                  if (res === 'success') {
                    checkHolder();
                  }

                  // 关闭登录弹窗
                  if (res === 'close') {
                    setLoading(false);
                  }
                });
                return _context3.abrupt("return", openLoginModal({
                  callback: function callback(status) {
                    // if (status === 'success') {
                    //   // if (!isFormSubject) {
                    //   //   const user = JSON.parse(utils?.storage?.get('customer') || '{}');
                    //   //   const currentUser = formatCustomer(user);
                    //   //   const meAccount = accountLists?.find((d: any) => !d?.isGuest);
                    //   //   appointmentBooking.setLoginAccount(meAccount?.id, currentUser);
                    //   // } else {
                    //   //   if (!isRetailTemplate) {
                    //   //     getHolders();
                    //   //   }
                    //   // }
                    //   // 继续后续流程
                    //   checkHolder()
                    // }
                  }
                }));
              case 6:
                return _context3.abrupt("return", checkHolder());
              case 7:
              case "end":
                return _context3.stop();
            }
          }, _callee3);
        }));
        return function checkLogin() {
          return _ref5.apply(this, arguments);
        };
      }();

      // 如果下一步不是确认信息，则打开协议弹窗
      if (((_nextStep4 = nextStep) === null || _nextStep4 === void 0 ? void 0 : _nextStep4.key) !== 'confirm-information') {
        if (!(renderItem !== null && renderItem !== void 0 && renderItem.policy_id)) {
          return appointmentBooking.next();
        }
        return openPolicy({
          id: renderItem === null || renderItem === void 0 ? void 0 : renderItem.policy_id
        }, function () {
          // 触发购物车数据发生改变，重新得出当前的资源
          var cartItem = carts === null || carts === void 0 ? void 0 : carts[0];
          appointmentBooking.updateCart(_objectSpread({
            _id: cartItem === null || cartItem === void 0 ? void 0 : cartItem._id
          }, cartItem));
          appointmentBooking.next();
        });
      } else {
        // 如果下一步是确认信息，则检测是否需要登录和检测holder数据
        return checkLogin();
      }
    }
    appointmentBooking.next();
  };
  return {
    getStepIndex: getStepIndex,
    stepList: stepList,
    removeStep: removeStep,
    addStep: addStep,
    updateStep: updateStep,
    nextStep: nextStep
  };
};

/**
 * @title: 获取商品数据
 * @description:
 * @return {*}
 * @Author: WangHan
 * @Date: 2025-04-15 11:12
 */
export var useAppointmentBookingProduct = function useAppointmentBookingProduct() {
  var _ref6 = useAppointmentBookingContext(),
    appointmentBooking = _ref6.appointmentBooking;
  var _ref7 = (appointmentBooking === null || appointmentBooking === void 0 ? void 0 : appointmentBooking.otherParams) || {},
    productModuleParams = _ref7.productModuleParams;
  var _ref8 = productModuleParams || {},
    bookingProcess = _ref8.bookingProcess;

  // 获取商品列表
  var getProducts = /*#__PURE__*/function () {
    var _ref9 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
      var _dates$, dates, _ref10, _productModuleParams, _productList, _ref11, productModuleParams, productList;
      return _regeneratorRuntime().wrap(function _callee4$(_context4) {
        while (1) switch (_context4.prev = _context4.next) {
          case 0:
            if (!(bookingProcess === 'date_first')) {
              _context4.next = 11;
              break;
            }
            _context4.next = 3;
            return appointmentBooking.getDateRange();
          case 3:
            dates = _context4.sent;
            if (!(!dates || !dates.length)) {
              _context4.next = 6;
              break;
            }
            return _context4.abrupt("return");
          case 6:
            _ref10 = (appointmentBooking === null || appointmentBooking === void 0 ? void 0 : appointmentBooking.otherParams) || {}, _productModuleParams = _ref10.productModuleParams;
            _context4.next = 9;
            return appointmentBooking.loadProductByScheduleDate(_objectSpread({
              date: (_dates$ = dates[0]) === null || _dates$ === void 0 ? void 0 : _dates$.date
            }, _productModuleParams));
          case 9:
            _productList = _context4.sent;
            return _context4.abrupt("return", _productList);
          case 11:
            // 先选商品
            _ref11 = (appointmentBooking === null || appointmentBooking === void 0 ? void 0 : appointmentBooking.otherParams) || {}, productModuleParams = _ref11.productModuleParams;
            _context4.next = 14;
            return appointmentBooking.loadProducts(productModuleParams);
          case 14:
            productList = _context4.sent;
            return _context4.abrupt("return", productList);
          case 16:
          case "end":
            return _context4.stop();
        }
      }, _callee4);
    }));
    return function getProducts() {
      return _ref9.apply(this, arguments);
    };
  }();

  // 检测商品类型
  var checkProductType = /*#__PURE__*/function () {
    var _ref12 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(productId) {
      var result;
      return _regeneratorRuntime().wrap(function _callee5$(_context5) {
        while (1) switch (_context5.prev = _context5.next) {
          case 0:
            _context5.next = 2;
            return appointmentBooking.getProductTypeById(productId);
          case 2:
            result = _context5.sent;
            return _context5.abrupt("return", result);
          case 4:
          case "end":
            return _context5.stop();
        }
      }, _callee5);
    }));
    return function checkProductType(_x2) {
      return _ref12.apply(this, arguments);
    };
  }();
  return {
    checkProductType: checkProductType,
    getProducts: getProducts
  };
};

/**
 * @title: 更新购物车数据
 * @description:
 * @return {*}
 * @Author: WangHan
 * @Date: 2025-04-15 11:12
 */
export var useAppointmentBookingCart = function useAppointmentBookingCart() {
  var _appointmentBooking$o2;
  var pisellOS = usePisellOS();
  var utils = contextUtils();
  var _ref13 = useAppointmentBookingContext(),
    appointmentBooking = _ref13.appointmentBooking,
    setCarts = _ref13.setCarts,
    setSummary = _ref13.setSummary,
    setIsAgreeDepositPolicy = _ref13.setIsAgreeDepositPolicy;
  var _ref14 = (appointmentBooking === null || appointmentBooking === void 0 || (_appointmentBooking$o2 = appointmentBooking.otherParams) === null || _appointmentBooking$o2 === void 0 ? void 0 : _appointmentBooking$o2.productModuleParams) || {},
    bookingSubject = _ref14.bookingSubject;
  var getCartAndSummary = /*#__PURE__*/function () {
    var _ref15 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
      var _utils$storage;
      var locale, symbol, carts, accountLists, newCarts, summary;
      return _regeneratorRuntime().wrap(function _callee6$(_context6) {
        while (1) switch (_context6.prev = _context6.next) {
          case 0:
            locale = (utils === null || utils === void 0 || (_utils$storage = utils.storage) === null || _utils$storage === void 0 ? void 0 : _utils$storage.get('umi_locale')) || 'en-US';
            symbol = (utils === null || utils === void 0 ? void 0 : utils.getSymbolic()) || '$';
            _context6.next = 4;
            return appointmentBooking.getCart();
          case 4:
            carts = _context6.sent;
            _context6.next = 7;
            return appointmentBooking.getAccounts();
          case 7:
            accountLists = _context6.sent;
            newCarts = carts === null || carts === void 0 ? void 0 : carts.map(function (item) {
              var _item$duration;
              return _objectSpread(_objectSpread({}, item), {}, {
                addHolderButtonText: utils === null || utils === void 0 ? void 0 : utils.translation(bookingSubject === null || bookingSubject === void 0 ? void 0 : bookingSubject.form_name),
                format: ['HH:mm', 'HH:mm'],
                show_time: true,
                duration_type: (item === null || item === void 0 || (_item$duration = item.duration) === null || _item$duration === void 0 ? void 0 : _item$duration.type) || 'minutes',
                locale: locale,
                symbol: symbol,
                holders: formatHolder(accountLists),
                allowClearHolder: true,
                allowClearResource: true,
                isMultipleResource: true
              });
            });
            setCarts(newCarts || []);
            _context6.next = 12;
            return appointmentBooking.getSummary();
          case 12:
            summary = _context6.sent;
            setSummary(summary || {});

            // 清空勾选定金协议
            if (!carts.length) {
              setIsAgreeDepositPolicy(false);
            }
          case 15:
          case "end":
            return _context6.stop();
        }
      }, _callee6);
    }));
    return function getCartAndSummary() {
      return _ref15.apply(this, arguments);
    };
  }();
  useEffect(function () {
    getCartAndSummary();
    pisellOS.effects.on('appointmentBooking_cart:changed', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
      return _regeneratorRuntime().wrap(function _callee7$(_context7) {
        while (1) switch (_context7.prev = _context7.next) {
          case 0:
            getCartAndSummary();
          case 1:
          case "end":
            return _context7.stop();
        }
      }, _callee7);
    })));
  }, []);
};

/**
 * @title: 获取登录状态
 * @description:
 * @return {*}
 * @Author: WangHan
 * @Date: 2025-04-15 11:14
 */
export var useAppointmentBookingLogin = function useAppointmentBookingLogin() {
  var _utils$token, _utils$token$get;
  var utils = contextUtils();
  var isLogin = !!(utils !== null && utils !== void 0 && (_utils$token = utils.token) !== null && _utils$token !== void 0 && (_utils$token$get = _utils$token.get) !== null && _utils$token$get !== void 0 && _utils$token$get.call(_utils$token));
  var openLoginModal = function openLoginModal(params) {
    var _ref17 = params || {},
      callback = _ref17.callback;
    utils.action({
      type: 'pisell1.login',
      data: {
        // type: 'plugin'
      },
      callback: callback
    });
  };
  return {
    isLogin: isLogin,
    openLoginModal: openLoginModal
  };
};

/**
 * @title: 获取账户
 * @description:
 * @return {*}
 * @Author: WangHan
 * @Date: 2025-04-15 11:15
 */
export var useAppointmentBookingAccount = function useAppointmentBookingAccount() {
  var _appointmentBooking$o3;
  var utils = contextUtils();
  var pisellOS = usePisellOS();
  var appointmentBooking = useAppointmentBooking();
  var _useState = useState([]),
    _useState2 = _slicedToArray(_useState, 2),
    accountLists = _useState2[0],
    setAccountLists = _useState2[1];
  var _ref18 = (appointmentBooking === null || appointmentBooking === void 0 || (_appointmentBooking$o3 = appointmentBooking.otherParams) === null || _appointmentBooking$o3 === void 0 ? void 0 : _appointmentBooking$o3.productModuleParams) || {},
    bookingSubject = _ref18.bookingSubject;
  var form_id = bookingSubject === null || bookingSubject === void 0 ? void 0 : bookingSubject.form_id;

  // 获取账户列表数据
  var getAccountLists = /*#__PURE__*/function () {
    var _ref19 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
      var data;
      return _regeneratorRuntime().wrap(function _callee8$(_context8) {
        while (1) switch (_context8.prev = _context8.next) {
          case 0:
            _context8.next = 2;
            return appointmentBooking.getAccounts();
          case 2:
            data = _context8.sent;
            setAccountLists(data || []);
          case 4:
          case "end":
            return _context8.stop();
        }
      }, _callee8);
    }));
    return function getAccountLists() {
      return _ref19.apply(this, arguments);
    };
  }();
  useEffect(function () {
    getAccountLists();
    pisellOS.effects.on('appointmentBooking_accountList:changed', /*#__PURE__*/function () {
      var _ref20 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(res) {
        return _regeneratorRuntime().wrap(function _callee9$(_context9) {
          while (1) switch (_context9.prev = _context9.next) {
            case 0:
              if (res.path === 'accounts') {
                getAccountLists();
              }
            case 1:
            case "end":
              return _context9.stop();
          }
        }, _callee9);
      }));
      return function (_x3) {
        return _ref20.apply(this, arguments);
      };
    }());
  }, []);

  // 获取表单数据
  var getHolders = /*#__PURE__*/function () {
    var _ref21 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
      var _utils$getStore$getSt;
      var shop_id, customer, params, data, newData;
      return _regeneratorRuntime().wrap(function _callee10$(_context10) {
        while (1) switch (_context10.prev = _context10.next) {
          case 0:
            shop_id = (_utils$getStore$getSt = utils.getStore().getState()) === null || _utils$getStore$getSt === void 0 || (_utils$getStore$getSt = _utils$getStore$getSt.global) === null || _utils$getStore$getSt === void 0 || (_utils$getStore$getSt = _utils$getStore$getSt.shop) === null || _utils$getStore$getSt === void 0 ? void 0 : _utils$getStore$getSt.id;
            customer = getCustomer(utils);
            if (!(!shop_id || !form_id || !(customer !== null && customer !== void 0 && customer.id))) {
              _context10.next = 4;
              break;
            }
            return _context10.abrupt("return", []);
          case 4:
            params = {
              url: '/form/data/v1',
              query: {
                customer_id: customer === null || customer === void 0 ? void 0 : customer.id,
                form_id: form_id,
                shop_id: shop_id
              }
            };
            _context10.next = 7;
            return appointmentBooking.fetchHolderAccountsAsync(params);
          case 7:
            data = _context10.sent;
            newData = data === null || data === void 0 ? void 0 : data.map(function (item) {
              return {
                id: item === null || item === void 0 ? void 0 : item.form_record_id,
                label: item === null || item === void 0 ? void 0 : item.main_field
              };
            });
            return _context10.abrupt("return", newData || []);
          case 10:
          case "end":
            return _context10.stop();
        }
      }, _callee10);
    }));
    return function getHolders() {
      return _ref21.apply(this, arguments);
    };
  }();

  // 添加账户
  var addAccount = /*#__PURE__*/function () {
    var _ref22 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(val, type) {
      var customer, result;
      return _regeneratorRuntime().wrap(function _callee11$(_context11) {
        while (1) switch (_context11.prev = _context11.next) {
          case 0:
            customer = getCustomer(utils);
            _context11.next = 3;
            return appointmentBooking.addAccount(val, {
              type: type,
              customerId: customer === null || customer === void 0 ? void 0 : customer.id
            });
          case 3:
            result = _context11.sent;
            return _context11.abrupt("return", result);
          case 5:
          case "end":
            return _context11.stop();
        }
      }, _callee11);
    }));
    return function addAccount(_x4, _x5) {
      return _ref22.apply(this, arguments);
    };
  }();

  // 检测账户
  var checkAccount = function checkAccount(type) {
    return appointmentBooking.checkBeforeSubmitOrder(type);
  };
  return {
    accountLists: accountLists,
    getHolders: getHolders,
    form_id: form_id,
    addAccount: addAccount,
    checkAccount: checkAccount
  };
};

/**
 * @title: 获取资源数据
 * @description:
 * @return {*}
 * @Author: WangHan
 * @Date: 2025-04-15 11:29
 */
export var useAppointmentBookingResource = function useAppointmentBookingResource() {
  var _ref23 = useAppointmentBookingContext(),
    appointmentBooking = _ref23.appointmentBooking,
    setResources = _ref23.setResources,
    setTimes = _ref23.setTimes;
  var _ref24 = (appointmentBooking === null || appointmentBooking === void 0 ? void 0 : appointmentBooking.otherParams) || {},
    resourceSort = _ref24.resourceSort;

  // 设置资源列表
  var getResourceList = function getResourceList() {
    var resources = appointmentBooking.getResourcesList();
    var _processResourceList = processResourceList(resources, resourceSort),
      processedResources = _processResourceList.resources,
      resourceCodes = _processResourceList.resourceCodes;
    setResources(processedResources || []);
    return {
      resources: processedResources,
      resourceCodes: resourceCodes
    };
  };

  // 设置时间切片
  var getResourceTimeSlot = /*#__PURE__*/function () {
    var _ref25 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(index) {
      var _getResourceList, resourceCodes, code, data;
      return _regeneratorRuntime().wrap(function _callee12$(_context12) {
        while (1) switch (_context12.prev = _context12.next) {
          case 0:
            _getResourceList = getResourceList(), resourceCodes = _getResourceList.resourceCodes;
            code = resourceCodes === null || resourceCodes === void 0 ? void 0 : resourceCodes[index || 0];
            _context12.next = 4;
            return appointmentBooking.getTimeSlotByAllResources(code);
          case 4:
            data = _context12.sent;
            setTimes(data || []);
          case 6:
          case "end":
            return _context12.stop();
        }
      }, _callee12);
    }));
    return function getResourceTimeSlot(_x6) {
      return _ref25.apply(this, arguments);
    };
  }();
  return {
    getResourceTimeSlot: getResourceTimeSlot,
    getResourceList: getResourceList
  };
};

/**
 * @title: 是否跳过资源选择步骤
 * @description:
 * @return {*}
 * @Author: WangHan
 * @Date: 2025-04-21 11:47
 */
export var useIsSkipResourceStep = function useIsSkipResourceStep() {
  var _ref26 = useAppointmentBookingContext(),
    currentStepParams = _ref26.currentStepParams;
  var _useAppointmentBookin5 = useAppointmentBookingResource(),
    getResourceList = _useAppointmentBookin5.getResourceList;
  var _useAppointmentBookin6 = useAppointmentBookingSetting(),
    isFormSubject = _useAppointmentBookin6.isFormSubject;
  var appointmentBooking = useAppointmentBooking();
  var _useAppointmentBookin7 = useAppointmentBookingStep(),
    nextStep = _useAppointmentBookin7.nextStep;
  var checkSkipResourceStep = /*#__PURE__*/function () {
    var _ref27 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
      var _getResourceList2, resources, accountLists, _currentAppointmentBo, isSystem, isSkip, form_code, renderLists, _isSkip;
      return _regeneratorRuntime().wrap(function _callee13$(_context13) {
        while (1) switch (_context13.prev = _context13.next) {
          case 0:
            _context13.prev = 0;
            _getResourceList2 = getResourceList(), resources = _getResourceList2.resources;
            _context13.next = 4;
            return appointmentBooking.getAccounts();
          case 4:
            accountLists = _context13.sent;
            _currentAppointmentBo = currentAppointmentBoard(currentStepParams.key, resources, appointmentBooking), isSystem = _currentAppointmentBo.isSystem, isSkip = _currentAppointmentBo.isSkip, form_code = _currentAppointmentBo.form_code; // 客户不可选择资源，系统自动分派
            if (!isSystem) {
              _context13.next = 9;
              break;
            }
            nextStep();
            return _context13.abrupt("return", true);
          case 9:
            if (!((accountLists === null || accountLists === void 0 ? void 0 : accountLists.length) === 1 || isFormSubject)) {
              _context13.next = 19;
              break;
            }
            renderLists = currentRenderLists(resources, form_code);
            _isSkip = false;
            if ((renderLists === null || renderLists === void 0 ? void 0 : renderLists.length) === 1) {
              _isSkip = isSkip || false;
            } else {
              _isSkip = false;
            }

            // 如果跳过资源选择步骤，则执行跳过的逻辑
            if (!_isSkip) {
              _context13.next = 16;
              break;
            }
            nextStep();
            return _context13.abrupt("return", true);
          case 16:
            return _context13.abrupt("return", _isSkip);
          case 19:
            return _context13.abrupt("return", false);
          case 20:
            _context13.next = 25;
            break;
          case 22:
            _context13.prev = 22;
            _context13.t0 = _context13["catch"](0);
            return _context13.abrupt("return", false);
          case 25:
          case "end":
            return _context13.stop();
        }
      }, _callee13, null, [[0, 22]]);
    }));
    return function checkSkipResourceStep() {
      return _ref27.apply(this, arguments);
    };
  }();
  return {
    checkSkipResourceStep: checkSkipResourceStep
  };
};

/**
 * @title: 获取预约配置
 * @description:
 * @return {*}
 * @Author: WangHan
 * @Date: 2025-04-24 18:15
 */
export var useAppointmentBookingSetting = function useAppointmentBookingSetting() {
  var _appointmentBooking$o4, _appointmentBooking$o5, _appointmentBooking$o6;
  var utils = contextUtils();
  var _ref28 = useAppointmentBookingContext(),
    appointmentBooking = _ref28.appointmentBooking;
  var _ref29 = (appointmentBooking === null || appointmentBooking === void 0 || (_appointmentBooking$o4 = appointmentBooking.otherParams) === null || _appointmentBooking$o4 === void 0 ? void 0 : _appointmentBooking$o4.productModuleParams) || {},
    bookingProcess = _ref29.bookingProcess,
    bookingSubject = _ref29.bookingSubject,
    customPageId = _ref29.customPageId,
    channel = _ref29.channel;

  // 设置缓存
  var setOtherData = function setOtherData(key, val) {
    return appointmentBooking.setOtherData(key, val);
  };

  // 读取缓存
  var getOtherData = function getOtherData(key) {
    return appointmentBooking.getOtherData(key);
  };
  var formName = useMemo(function () {
    return utils === null || utils === void 0 ? void 0 : utils.translation(bookingSubject === null || bookingSubject === void 0 ? void 0 : bookingSubject.form_name);
  }, [bookingSubject]);
  return {
    // 是否先选择日期
    isDateSelectedFirst: bookingProcess === 'date_first',
    // 主体是否是表单
    isFormSubject: (bookingSubject === null || bookingSubject === void 0 ? void 0 : bookingSubject.type) === 'form',
    // 是否是零售模版
    isRetailTemplate: (appointmentBooking === null || appointmentBooking === void 0 || (_appointmentBooking$o5 = appointmentBooking.otherParams) === null || _appointmentBooking$o5 === void 0 ? void 0 : _appointmentBooking$o5.isRetailTemplate) || false,
    customPageId: customPageId,
    channel: channel,
    bookingSubject: bookingSubject,
    setOtherData: setOtherData,
    getOtherData: getOtherData,
    formName: formName,
    bookingSetting: (appointmentBooking === null || appointmentBooking === void 0 || (_appointmentBooking$o6 = appointmentBooking.otherParams) === null || _appointmentBooking$o6 === void 0 ? void 0 : _appointmentBooking$o6.bookingSetting) || {}
  };
};