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, { useEffect, useState } from 'react';
import { Iconfont, PisellEmpty } from '@pisell/materials';
import { isMobile, locales } from '@pisell/utils';
import dayjs from 'dayjs';
import "./index.less";
var ScheduleTimeItem = function ScheduleTimeItem(_ref) {
  var timeList = _ref.timeList;
  var _useState = useState([]),
    _useState2 = _slicedToArray(_useState, 2),
    times = _useState2[0],
    setTimes = _useState2[1];
  var _useState3 = useState(false),
    _useState4 = _slicedToArray(_useState3, 2),
    isExpand = _useState4[0],
    setIsExpand = _useState4[1];
  useEffect(function () {
    // 如果times的长度大于4，则只取前4个，然后显示折叠按钮
    if ((timeList === null || timeList === void 0 ? void 0 : timeList.length) > 4) {
      setTimes(timeList === null || timeList === void 0 ? void 0 : timeList.slice(0, 4));
    } else {
      setTimes(timeList);
    }
  }, [timeList]);
  var handleExpand = function handleExpand() {
    var nextExpandStatus = !isExpand;
    if (nextExpandStatus) {
      setTimes(timeList);
    } else {
      setTimes(timeList === null || timeList === void 0 ? void 0 : timeList.slice(0, 4));
    }
    setIsExpand(nextExpandStatus);
  };
  return /*#__PURE__*/React.createElement("div", {
    className: "schedule-time-item"
  }, /*#__PURE__*/React.createElement("div", {
    className: "schedule-time-item-content-wrapper"
  }, (times === null || times === void 0 ? void 0 : times.length) > 0 ? times === null || times === void 0 ? void 0 : times.map(function (item) {
    return /*#__PURE__*/React.createElement("div", {
      className: isMobile() ? 'schedule-time-item-content-mobile' : 'schedule-time-item-content',
      key: (item.start_at || '') + (item.end_at || '')
    }, /*#__PURE__*/React.createElement("div", {
      className: "schedule-time-item-content-time"
    }, (item === null || item === void 0 ? void 0 : item.start_date) || ''), /*#__PURE__*/React.createElement("div", {
      className: "schedule-time-item-content-time"
    }, dayjs((item === null || item === void 0 ? void 0 : item.start_at) || '').format('HH:mm'), ' - ', dayjs((item === null || item === void 0 ? void 0 : item.end_at) || '').format('HH:mm')));
  }) : /*#__PURE__*/React.createElement(PisellEmpty, null)), (timeList === null || timeList === void 0 ? void 0 : timeList.length) > 4 && /*#__PURE__*/React.createElement("div", {
    className: "schedule-time-item-expand-btn",
    onClick: handleExpand
  }, isExpand ? locales.getText('pisell2.event.schedule.item.collapse') : locales.getText('pisell2.event.schedule.item.expand'), /*#__PURE__*/React.createElement(Iconfont, {
    type: isExpand ? 'pisell2-chevron-up-double' : 'pisell2-chevron-down-double',
    className: "schedule-time-item-expand-btn-icon"
  })));
};
export default ScheduleTimeItem;