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); }
import React from 'react';
import dayjs from 'dayjs';
import { formatDate, formatTime, getDatePartDisplay } from "../utils";
/**
 * 时间区间展示块
 * - 同一天：HH:mm-HH:mm
 * - 跨天：起止完整日期时间；若某端为相对日（今天/昨天/明天）则只显示「时间 相对日」，不显示星期+日期
 */
export var TimeRangeBlock = function TimeRangeBlock(_ref) {
  var _startStyle$fontSize, _startStyle$fontWeigh, _startStyle$color, _startStyle$lineHeigh, _endStyle$fontSize, _endStyle$fontWeight, _endStyle$color, _endStyle$lineHeight, _dateFormat$showYear;
  var start = _ref.start,
    end = _ref.end,
    isSameDay = _ref.isSameDay,
    timeFormat = _ref.timeFormat,
    dateFormat = _ref.dateFormat,
    weekdayFormat = _ref.weekdayFormat,
    _ref$showWeekdayInCro = _ref.showWeekdayInCrossDay,
    showWeekdayInCrossDay = _ref$showWeekdayInCro === void 0 ? true : _ref$showWeekdayInCro,
    _ref$referenceDate = _ref.referenceDate,
    referenceDate = _ref$referenceDate === void 0 ? dayjs() : _ref$referenceDate,
    style = _ref.style,
    startStyle = _ref.startStyle,
    endStyle = _ref.endStyle,
    className = _ref.className;
  var inlineStyle = {
    fontSize: style === null || style === void 0 ? void 0 : style.fontSize,
    fontWeight: style === null || style === void 0 ? void 0 : style.fontWeight,
    color: style === null || style === void 0 ? void 0 : style.color,
    lineHeight: style === null || style === void 0 ? void 0 : style.lineHeight
  };
  var startInlineStyle = _objectSpread(_objectSpread({}, inlineStyle), {}, {
    fontSize: (_startStyle$fontSize = startStyle === null || startStyle === void 0 ? void 0 : startStyle.fontSize) !== null && _startStyle$fontSize !== void 0 ? _startStyle$fontSize : inlineStyle.fontSize,
    fontWeight: (_startStyle$fontWeigh = startStyle === null || startStyle === void 0 ? void 0 : startStyle.fontWeight) !== null && _startStyle$fontWeigh !== void 0 ? _startStyle$fontWeigh : inlineStyle.fontWeight,
    color: (_startStyle$color = startStyle === null || startStyle === void 0 ? void 0 : startStyle.color) !== null && _startStyle$color !== void 0 ? _startStyle$color : inlineStyle.color,
    lineHeight: (_startStyle$lineHeigh = startStyle === null || startStyle === void 0 ? void 0 : startStyle.lineHeight) !== null && _startStyle$lineHeigh !== void 0 ? _startStyle$lineHeigh : inlineStyle.lineHeight
  });
  var endInlineStyle = _objectSpread(_objectSpread({}, inlineStyle), {}, {
    fontSize: (_endStyle$fontSize = endStyle === null || endStyle === void 0 ? void 0 : endStyle.fontSize) !== null && _endStyle$fontSize !== void 0 ? _endStyle$fontSize : inlineStyle.fontSize,
    fontWeight: (_endStyle$fontWeight = endStyle === null || endStyle === void 0 ? void 0 : endStyle.fontWeight) !== null && _endStyle$fontWeight !== void 0 ? _endStyle$fontWeight : inlineStyle.fontWeight,
    color: (_endStyle$color = endStyle === null || endStyle === void 0 ? void 0 : endStyle.color) !== null && _endStyle$color !== void 0 ? _endStyle$color : inlineStyle.color,
    lineHeight: (_endStyle$lineHeight = endStyle === null || endStyle === void 0 ? void 0 : endStyle.lineHeight) !== null && _endStyle$lineHeight !== void 0 ? _endStyle$lineHeight : inlineStyle.lineHeight
  });
  if (isSameDay) {
    var startStr = formatTime(start, timeFormat);
    var endStr = formatTime(end, timeFormat);
    // 小宽度支持：开始时间可单独一行，「 - 结束时间」整段折行
    return /*#__PURE__*/React.createElement("span", {
      className: "pisell-time-range-display-time ".concat(className || '').trim(),
      style: inlineStyle
    }, /*#__PURE__*/React.createElement("span", {
      className: "pisell-time-range-display-time-start",
      style: startInlineStyle
    }, startStr), /*#__PURE__*/React.createElement("span", {
      className: "pisell-time-range-display-time-end-wrap"
    }, /*#__PURE__*/React.createElement("span", {
      className: "pisell-time-range-display-time-sep",
      style: inlineStyle,
      "aria-hidden": true
    }, " - "), /*#__PURE__*/React.createElement("span", {
      className: "pisell-time-range-display-time-end",
      style: endInlineStyle
    }, endStr)));
  }

  // 跨天：时间 + 日期部分；日期部分由 datetime 内置 getDatePartDisplay 统一处理（相对日 or 星期+日期）
  var isCrossYear = start.year() !== end.year();
  var dateFormatOverride = {
    order: 'DMY',
    shortMonth: true,
    showYear: (_dateFormat$showYear = dateFormat === null || dateFormat === void 0 ? void 0 : dateFormat.showYear) !== null && _dateFormat$showYear !== void 0 ? _dateFormat$showYear : isCrossYear,
    showMonth: true,
    showDay: true,
    useCommaBeforeYear: false
  };
  var startTimeStr = formatTime(start, timeFormat);
  var endTimeStr = formatTime(end, timeFormat);
  var getCrossDayDatePart = function getCrossDayDatePart(date) {
    if (!showWeekdayInCrossDay) {
      return formatDate(date, _objectSpread(_objectSpread({}, dateFormat), dateFormatOverride));
    }
    return getDatePartDisplay({
      date: date,
      dateFormat: dateFormat,
      weekdayFormat: weekdayFormat,
      referenceDate: referenceDate,
      dateFormatOverride: dateFormatOverride
    });
  };
  var startDatePart = getCrossDayDatePart(start);
  var endDatePart = getCrossDayDatePart(end);
  var startPart = "".concat(startTimeStr, " ").concat(startDatePart);
  var endPart = "".concat(endTimeStr, " ").concat(endDatePart);

  // 跨天拆成 2 个块，便于按块换行：块1 起止时间+日期，块2 「 - 」+ 结束时间+日期
  var timeClass = 'pisell-time-range-display-time pisell-time-range-display-time-cross';
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("span", {
    key: "time-start",
    className: "".concat(timeClass, " ").concat(className || '').trim(),
    style: startInlineStyle
  }, startPart), /*#__PURE__*/React.createElement("span", {
    key: "time-end",
    className: "".concat(timeClass, " ").concat(className || '').trim(),
    style: inlineStyle
  }, /*#__PURE__*/React.createElement("span", {
    className: "pisell-time-range-display-time-cross-sep",
    style: inlineStyle,
    "aria-hidden": true
  }, ' - '), /*#__PURE__*/React.createElement("span", {
    className: "pisell-time-range-display-time-cross-end",
    style: endInlineStyle
  }, endPart)));
};
export default TimeRangeBlock;