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 { useState, useRef, useEffect } from 'react';
import dayjs from 'dayjs';
import { Iconfont } from '@pisell/materials';
import classNames from 'classnames';
import WeekItem from "./WeekItem/index";
import { getCallToBookStatus, getStatus } from "../state";
import CallToBook from "./CallToBook";
import "./index.less";
var CalenDateWeek = function CalenDateWeek(props) {
  var currentDate = props.currentDate,
    dateChange = props.dateChange,
    productId = props.productId,
    timeList = props.timeList,
    dateLimitData = props.dateLimitData,
    getLimitData = props.getLimitData,
    cutTime = props.cutTime;
  var _useState = useState([]),
    _useState2 = _slicedToArray(_useState, 2),
    weekList = _useState2[0],
    setWeekList = _useState2[1];
  var _useState3 = useState(false),
    _useState4 = _slicedToArray(_useState3, 2),
    showCallToBook = _useState4[0],
    setShowCallToBook = _useState4[1];
  // const { shop }: any = useShallowEqualSelector(({ global }: any) => global);
  var weekListRef = useRef(null);
  var _useState5 = useState(''),
    _useState6 = _slicedToArray(_useState5, 2),
    selectStatus = _useState6[0],
    setSelectStatus = _useState6[1];
  var _useState7 = useState(false),
    _useState8 = _slicedToArray(_useState7, 2),
    selectDisabled = _useState8[0],
    setSelectDisabled = _useState8[1];

  /**
   * @title: 根据时间生成本周数据
   * @description:
   * @return {*}
   * @Author: xiangxiang.shao
   * @Date: 2024-02-07 15:13
   */
  var initCurrentWeekData = function initCurrentWeekData(dateText) {
    // 设置周日为一周的开始
    // dayjs.locale('en', {
    //   weekStartsOn: 0, // 周日为0，周一为1，以此类推
    // });

    // 获取当前日期的moment对象
    var currentMoment = dayjs(dateText);

    // 调整当前日期，使其为本周的周日
    var startOfWeek = currentMoment.startOf('week');

    // 如果当前日期不是周日，则向前调整到本周的周日
    if (startOfWeek.day() !== 0) {
      startOfWeek.subtract(startOfWeek.day(), 'days');
    }

    // 创建一个数组来存储本周的所有日期
    var weekDates = [];

    // 循环7天，获取本周的所有日期
    for (var i = 0; i < 7; i++) {
      var _date = startOfWeek.clone().add(i, 'days');
      weekDates.push(_date.format('YYYY-MM-DD'));
    }
    return weekDates;
  };

  /**
   * @title: 构造初始化周数据
   * @description:
   * @return {*}
   * @Author: xiangxiang.shao
   * @Date: 2024-02-07 15:13
   */
  var initWeekData = function initWeekData() {
    var list = initCurrentWeekData(currentDate);
    setWeekList(list);
  };

  /**
   * @title: 判断是否重新生成还是滚动到指定位置
   * @description:
   * @return {*}
   * @Author: xiangxiang.shao
   * @Date: 2024-02-07 15:13
   */
  var init = function init() {
    initWeekData();
  };
  useEffect(function () {
    init();
  }, [currentDate]);

  // 判断是否显示电话预定
  useEffect(function () {
    var _getStatus = getStatus(dateLimitData, currentDate, cutTime),
      status = _getStatus.status,
      disabled = _getStatus.disabled;
    var isShow = getCallToBookStatus(currentDate, dateLimitData, cutTime);
    if (isShow && (status === 'lots_of_space' || status === 'filling_up_fast')) {
      setShowCallToBook(true);
    } else {
      setShowCallToBook(false);
    }
    setSelectStatus(status);
    setSelectDisabled(disabled);
  }, [currentDate, timeList, cutTime]);
  useEffect(function () {
    var index = weekList.findIndex(function (date) {
      return date === currentDate;
    });
    if (weekListRef !== null && weekListRef !== void 0 && weekListRef.current && index !== -1) {
      weekListRef.current.scrollLeft = (index - 1) * 50;
    }
  }, [currentDate, weekList]);
  return /*#__PURE__*/React.createElement("div", {
    className: "calendar-week-wrap"
  }, /*#__PURE__*/React.createElement("div", {
    ref: weekListRef,
    className: "calendar-week-list"
  }, /*#__PURE__*/React.createElement(WeekItem, {
    weekList: weekList,
    currentDate: currentDate,
    dateChange: dateChange,
    isActive: true,
    productId: productId,
    setCurrentDate: dateChange,
    timeList: timeList,
    dateLimitData: dateLimitData
    // getLimitData={getLimitData}
    ,
    cutTime: cutTime
  })), selectStatus === 'sold_out' || selectDisabled ? /*#__PURE__*/React.createElement("div", {
    className: 'disabled-status'
  }, /*#__PURE__*/React.createElement(Iconfont, {
    className: classNames('disabled-icon', 'iconhourglass_disabled_wght300_24px')
  }), /*#__PURE__*/React.createElement("div", {
    className: 'disabled-status-text'
  }, selectDisabled ? 2 : 5)) : null, /*#__PURE__*/React.createElement(CallToBook, {
    show: showCallToBook
  }));
};
export default CalenDateWeek;