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 React, { useMemo } from 'react';
import { useAppointmentBooking } from "../../../hooks";
import { useAppointmentBookingContext } from "../../../context";
import useComponents from "../../../../../hooks/useComponents";
import { processResourceList, getResourceTitle } from "../../../utils";
import { contextUtils } from "../../../hooks";
import { clearDataByStepKey } from "../../../utils";
var SelectDate = function SelectDate(props) {
  var onDateChange = props.onDateChange,
    times = props.times,
    currentDate = props.currentDate;
  var appointmentBooking = useAppointmentBooking();
  var _useAppointmentBookin = useAppointmentBookingContext(),
    currentSelectedResources = _useAppointmentBookin.currentSelectedResources,
    setTimes = _useAppointmentBookin.setTimes;
  var utils = contextUtils();
  var _useComponents = useComponents({
      components: ['SelectDateOS']
    }),
    _useComponents2 = _slicedToArray(_useComponents, 1),
    SelectDateOS = _useComponents2[0];

  /**
   * @description: 获取资源代码
   * @param {*}
   * @return {*}
   */
  var resourceCode = useMemo(function () {
    var _ref = (appointmentBooking === null || appointmentBooking === void 0 ? void 0 : appointmentBooking.otherParams) || {},
      resourceSort = _ref.resourceSort;
    var resources = appointmentBooking.getResourcesList();
    var _processResourceList = processResourceList(resources, resourceSort),
      resourceCodes = _processResourceList.resourceCodes;
    return (resourceCodes === null || resourceCodes === void 0 ? void 0 : resourceCodes[0]) || '';
  }, []);

  /**
   * @description: 获取资源名称
   * @param {*} useMemo
   * @return {*}
   */
  var currentResourceName = useMemo(function () {
    var _currentSelectedResou;
    var currentResource = currentSelectedResources === null || currentSelectedResources === void 0 || (_currentSelectedResou = currentSelectedResources[0]) === null || _currentSelectedResou === void 0 ? void 0 : _currentSelectedResou.currentSelectedResource;
    var resourceItem = (currentResource === null || currentResource === void 0 ? void 0 : currentResource.resourceItem) || {};
    var name = getResourceTitle(appointmentBooking, resourceItem === null || resourceItem === void 0 ? void 0 : resourceItem.code, utils, resourceItem);
    return name;
  }, [currentSelectedResources]);

  /**
   * @description: 跳转到服务步骤
   * @param {any} step
   * @return {*}
   */
  var onStepChange = function onStepChange() {
    // 清空数据
    clearDataByStepKey('select-service', appointmentBooking, setTimes);

    // 跳转到服务步骤
    var stepLists = appointmentBooking.getStepList();
    var serviceIndex = stepLists.findIndex(function (item) {
      return (item === null || item === void 0 ? void 0 : item.key) === 'select-service';
    });
    appointmentBooking.gotoStep(serviceIndex);
  };
  return SelectDateOS ? /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(SelectDateOS, {
    isTimeSlicing: true,
    currentDate: currentDate,
    resourceCode: resourceCode,
    resourceName: currentResourceName,
    onDateChange: onDateChange,
    onStepChange: onStepChange,
    times: times
  })) : null;
};
export default SelectDate;