var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/pisellTimeRangeDisplay/PisellTimeRangeDisplay.tsx
var PisellTimeRangeDisplay_exports = {};
__export(PisellTimeRangeDisplay_exports, {
  PisellTimeRangeDisplay: () => PisellTimeRangeDisplay,
  default: () => PisellTimeRangeDisplay_default
});
module.exports = __toCommonJS(PisellTimeRangeDisplay_exports);
var import_react = __toESM(require("react"));
var import_dayjs = __toESM(require("dayjs"));
var import_zh_cn = require("dayjs/locale/zh-cn");
var import_en = require("dayjs/locale/en");
var import_utils = require("./utils");
var import_components = require("./components");
var import_useEngineContext = __toESM(require("../../hooks/useEngineContext"));
var import_PisellTimeRangeDisplay = require("./PisellTimeRangeDisplay.less");
var PisellTimeRangeDisplay = (props) => {
  var _a, _b;
  const {
    startAt,
    endAt,
    textAlign = "center",
    fields,
    showDateForSameDay = true,
    timeFormat,
    dateFormat,
    weekdayFormat,
    durationFormat,
    containerStyle,
    timeStyle,
    dateStyle,
    weekdayStyle,
    durationStyle,
    locale: localeProp,
    className,
    style,
    onClick
  } = props;
  const context = (0, import_useEngineContext.default)();
  const resolvedLocale = localeProp || ((_b = (_a = context == null ? void 0 : context.engine) == null ? void 0 : _a.props) == null ? void 0 : _b.locale) || "en";
  const effectiveLocale = (0, import_react.useMemo)(
    () => (0, import_utils.getDayjsLocale)(resolvedLocale),
    [resolvedLocale]
  );
  const { start, end, isSameDay } = (0, import_react.useMemo)(
    () => (0, import_utils.parseTimeRange)(startAt, endAt, effectiveLocale),
    [startAt, endAt, effectiveLocale]
  );
  const durationMs = (0, import_react.useMemo)(() => end.diff(start), [start, end]);
  const {
    showTimeRange = true,
    showDate = true,
    showWeekday = true,
    showDuration = true,
    fieldOrder = ["weekday", "date", "time", "duration"]
  } = fields || {};
  const showSeconds = (durationFormat == null ? void 0 : durationFormat.showSeconds) ?? false;
  const effectiveDateFormat = (0, import_react.useMemo)(
    () => ({ showRelativeDay: false, ...dateFormat }),
    [dateFormat]
  );
  const referenceDate = (0, import_dayjs.default)();
  const relativeDay = (effectiveDateFormat == null ? void 0 : effectiveDateFormat.showRelativeDay) ? (0, import_utils.getRelativeDay)(start, referenceDate) : null;
  const hideWeekdayWhenDateRelative = showDate && relativeDay !== null;
  const justifyContent = textAlign === "right" ? "flex-end" : textAlign === "left" ? "flex-start" : "center";
  const containerInlineStyle = {
    background: containerStyle == null ? void 0 : containerStyle.background,
    borderRadius: containerStyle == null ? void 0 : containerStyle.borderRadius,
    border: containerStyle == null ? void 0 : containerStyle.border,
    boxShadow: containerStyle == null ? void 0 : containerStyle.boxShadow,
    padding: containerStyle == null ? void 0 : containerStyle.padding,
    gap: containerStyle == null ? void 0 : containerStyle.gap,
    textAlign,
    justifyContent,
    ...style
  };
  const renderField = (fieldType) => {
    switch (fieldType) {
      case "time":
        return showTimeRange ? /* @__PURE__ */ import_react.default.createElement(
          import_components.TimeRangeBlock,
          {
            key: "time",
            start,
            end,
            isSameDay,
            timeFormat,
            dateFormat: effectiveDateFormat,
            weekdayFormat,
            referenceDate: (0, import_dayjs.default)(),
            style: timeStyle
          }
        ) : null;
      case "date":
        if (!showDate) return null;
        if (!isSameDay) return null;
        if (!showDateForSameDay) return null;
        return /* @__PURE__ */ import_react.default.createElement(
          import_components.DateBlock,
          {
            key: "date",
            date: start,
            format: effectiveDateFormat,
            referenceDate: (0, import_dayjs.default)(),
            style: dateStyle
          }
        );
      case "weekday":
        if (!showWeekday) return null;
        if (!isSameDay) return null;
        if (!showDateForSameDay) return null;
        if (hideWeekdayWhenDateRelative) return null;
        return /* @__PURE__ */ import_react.default.createElement(
          import_components.WeekdayBlock,
          {
            key: "weekday",
            weekday: start,
            format: weekdayFormat,
            style: weekdayStyle
          }
        );
      case "duration":
        return showDuration ? /* @__PURE__ */ import_react.default.createElement(
          import_components.DurationBlock,
          {
            key: "duration",
            durationMs,
            showSeconds,
            locale: effectiveLocale,
            style: durationStyle
          }
        ) : null;
      default:
        return null;
    }
  };
  const items = [];
  fieldOrder.forEach((fieldType) => {
    const node = renderField(fieldType);
    if (node != null) {
      items.push({ type: fieldType, node });
    }
  });
  if (items.length === 0) {
    return null;
  }
  const renderedWithSeparator = items.flatMap(({ type, node }, index) => {
    const needDotBefore = type === "duration" && index > 0;
    const needDotAfter = type === "duration" && index < items.length - 1;
    const sep = /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-time-range-display-sep", "aria-hidden": true }, " · ");
    const el = import_react.default.cloneElement(node, { key: type });
    if (needDotBefore) return [sep, el];
    if (needDotAfter) return [el, sep];
    return [el];
  });
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: `pisell-time-range-display ${className || ""}`.trim(),
      style: containerInlineStyle,
      onClick
    },
    renderedWithSeparator
  );
};
var PisellTimeRangeDisplay_default = import_react.default.memo(PisellTimeRangeDisplay);
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  PisellTimeRangeDisplay
});
