import React from 'react';
import dayjs from 'dayjs';
import { formatTime, getDatePartDisplay } from "../utils";
/**
 * 时间区间展示块
 * - 同一天：HH:mm-HH:mm
 * - 跨天：起止完整日期时间；若某端为相对日（今天/昨天/明天）则只显示「时间 相对日」，不显示星期+日期
 */
export var TimeRangeBlock = function TimeRangeBlock(_ref) {
  var start = _ref.start,
    end = _ref.end,
    isSameDay = _ref.isSameDay,
    timeFormat = _ref.timeFormat,
    dateFormat = _ref.dateFormat,
    weekdayFormat = _ref.weekdayFormat,
    _ref$referenceDate = _ref.referenceDate,
    referenceDate = _ref$referenceDate === void 0 ? dayjs() : _ref$referenceDate,
    style = _ref.style,
    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
  };
  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"
    }, startStr), /*#__PURE__*/React.createElement("span", {
      className: "pisell-time-range-display-time-end-wrap"
    }, /*#__PURE__*/React.createElement("span", {
      className: "pisell-time-range-display-time-sep",
      "aria-hidden": true
    }, " - "), /*#__PURE__*/React.createElement("span", {
      className: "pisell-time-range-display-time-end"
    }, endStr)));
  }

  // 跨天：时间 + 日期部分；日期部分由 datetime 内置 getDatePartDisplay 统一处理（相对日 or 星期+日期）
  var isCrossYear = start.year() !== end.year();
  var dateFormatOverride = {
    order: 'DMY',
    shortMonth: true,
    showYear: isCrossYear,
    showMonth: true,
    showDay: true,
    useCommaBeforeYear: false
  };
  var startTimeStr = formatTime(start, timeFormat);
  var endTimeStr = formatTime(end, timeFormat);
  var startDatePart = getDatePartDisplay({
    date: start,
    dateFormat: dateFormat,
    weekdayFormat: weekdayFormat,
    referenceDate: referenceDate,
    dateFormatOverride: dateFormatOverride
  });
  var endDatePart = getDatePartDisplay({
    date: end,
    dateFormat: dateFormat,
    weekdayFormat: weekdayFormat,
    referenceDate: referenceDate,
    dateFormatOverride: dateFormatOverride
  });
  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: inlineStyle
  }, startPart), /*#__PURE__*/React.createElement("span", {
    key: "time-end",
    className: "".concat(timeClass, " ").concat(className || '').trim(),
    style: inlineStyle
  }, ' - ', endPart));
};
export default TimeRangeBlock;