const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_index = require("../../../../locales/index.js");
const require_venueWallUtils = require("./venueWallUtils.js");
const require_NoteTicker = require("./NoteTicker.js");
const require_venueWallCardPresentation = require("./venueWallCardPresentation.js");
let react = require("react");
react = require_runtime.__toESM(react);
require("./VenueWallCard.less");
//#region src/components/pisellRecordBoard/shellFrame/ResourceWall/VenueWallCard.tsx
/**
* 将服务端给出的「整分钟」计数与收到时的墙钟对齐，随 `now` 递减；
* `value` 或 `resourceId` 从上游变更时重新锚定。
*/
function useDriftMinutesFromEpoch(value, resourceId, now, allowNegative = false) {
	const [epoch, setEpoch] = (0, react.useState)(() => ({
		min: value !== null && value !== void 0 ? value : 0,
		at: Date.now()
	}));
	(0, react.useEffect)(() => {
		setEpoch({
			min: value !== null && value !== void 0 ? value : 0,
			at: Date.now()
		});
	}, [resourceId, value]);
	const elapsedMs = now - epoch.at;
	const precise = epoch.min - elapsedMs / 6e4;
	const drifted = epoch.min - Math.floor(elapsedMs / 6e4);
	return {
		whole: allowNegative ? drifted : Math.max(0, drifted),
		precise: allowNegative ? precise : Math.max(0, precise)
	};
}
/**
* 迟到分钟等：自服务给出的整分起，随 `now` 递增；`value` 或 `resourceId` 变化时重锚定。
*/
function useDriftAccumulatedMinutesFromEpoch(value, resourceId, now) {
	const [epoch, setEpoch] = (0, react.useState)(() => ({
		min: value !== null && value !== void 0 ? value : 0,
		at: Date.now()
	}));
	(0, react.useEffect)(() => {
		setEpoch({
			min: value !== null && value !== void 0 ? value : 0,
			at: Date.now()
		});
	}, [resourceId, value]);
	return epoch.min + Math.floor((now - epoch.at) / 6e4);
}
/** 下一预约行里「无数据」占位（不展示联系人兜底） */
const NEXT_LIST_PLACEHOLDER_VALUES = new Set([
	"",
	"-",
	"–",
	"—",
	"―",
	"—",
	"–"
]);
function nextListFieldIsMeaningful(raw) {
	const s = String(raw !== null && raw !== void 0 ? raw : "").trim();
	if (!s) return false;
	return !NEXT_LIST_PLACEHOLDER_VALUES.has(s);
}
const DEFAULT_OCCUPIED = "#6f4ae6";
/** 空闲态卡片主色（淡灰，随 alpha 打底条等） */
const DEFAULT_AVAILABLE = "#94a3b8";
function VenueWallCardInner({ card, wallNowMs, boardingSoonBeforeMin = 10, occupiedCardColor = DEFAULT_OCCUPIED, availableCardColor = DEFAULT_AVAILABLE, statusToneMap: statusToneMapProp, appearance = "light" }) {
	var _card$nextList, _card$resource, _card$area;
	const toneMap = statusToneMapProp !== null && statusToneMapProp !== void 0 ? statusToneMapProp : require_venueWallUtils.getVenueWallStatusToneMap();
	const isDark = appearance === "dark";
	const idleMain = isDark ? "#e2e8f0" : "#0f172a";
	const idleSub = isDark ? "#94a3b8" : "#94a3b8";
	const { whole: liveRemainingMin, precise: liveRemainingPreciseMin } = useDriftMinutesFromEpoch(card.remainingMin, card.resourceId, wallNowMs, true);
	const { whole: liveStartsInMin } = useDriftMinutesFromEpoch(card.startsInMin, card.resourceId, wallNowMs, false);
	const liveLateMin = useDriftAccumulatedMinutesFromEpoch(card.lateMin, card.resourceId, wallNowMs);
	const { floorLikeStatus, headerStatusKey, headerStatusLabel, headerStatusColor, cardVariant, mainColor, subColor, surfaceAccentColor, primaryEmphasisLine, primaryEmphasisColor, timeRangeLine, contactLine, showProgress, progress, progressColor, showEndingSoonMarquee, marqueeText, marqueeColor, marqueeShellBackground } = (0, react.useMemo)(() => require_venueWallCardPresentation.buildVenueWallCardPresentation({
		card,
		toneMap,
		wallNowMs,
		liveRemainingMin,
		liveRemainingPreciseMin,
		liveStartsInMin,
		liveLateMin,
		boardingSoonBeforeMin,
		idleMain,
		idleSub,
		occupiedCardColor,
		availableCardColor
	}), [
		card,
		toneMap,
		wallNowMs,
		liveRemainingMin,
		liveRemainingPreciseMin,
		liveStartsInMin,
		liveLateMin,
		boardingSoonBeforeMin,
		idleMain,
		idleSub,
		occupiedCardColor,
		availableCardColor
	]);
	const nextItem = (_card$nextList = card.nextList) === null || _card$nextList === void 0 ? void 0 : _card$nextList[0];
	const nextTimeMeaningful = nextItem ? nextListFieldIsMeaningful(nextItem.time) : false;
	const nextContactMeaningful = nextItem ? nextListFieldIsMeaningful(nextItem.booking) : false;
	/** 当前区为「未开始」预约：{@link RecordBoardResourceWallCardModel.wallUseNextLabelHideNextRow} 为真时不渲染下方 Next 条带 */
	const showNextSection = Boolean(nextItem && (nextTimeMeaningful || nextContactMeaningful)) && !card.wallUseNextLabelHideNextRow;
	const useNextAsCurrentTitle = Boolean(card.wallUseNextLabelHideNextRow);
	const nextTimeSoloLarge = nextTimeMeaningful && !nextContactMeaningful;
	const cardBg = cardVariant === "occupied" ? `linear-gradient(180deg, ${require_venueWallUtils.alphaColor(occupiedCardColor, .96)} 0%, ${require_venueWallUtils.alphaColor(occupiedCardColor, .88)} 100%)` : require_venueWallUtils.alphaColor(surfaceAccentColor, floorLikeStatus === "reserved" ? .06 : .03);
	const cardBorder = cardVariant === "occupied" ? require_venueWallUtils.alphaColor(occupiedCardColor, .5) : require_venueWallUtils.alphaColor(surfaceAccentColor, .18);
	const moduleBorder = cardVariant === "occupied" ? "rgba(255,255,255,0.10)" : require_venueWallUtils.alphaColor(surfaceAccentColor, .2);
	const currentPanelBg = cardVariant === "occupied" ? "rgba(255,255,255,0.16)" : require_venueWallUtils.alphaColor(surfaceAccentColor, floorLikeStatus === "reserved" ? .18 : .2);
	/**
	* 「当前预约」区块标题 / 时段 / 联系人：
	* - 占用卡：纯白
	* - 预约中（Reserved）：主色 slate 略透明，比纯黑柔和、仍明显强于 subColor
	* - 空闲等：沿用 subColor
	*/
	const currentSectionInk = cardVariant === "occupied" ? "#ffffff" : floorLikeStatus === "reserved" ? require_venueWallUtils.alphaColor(idleMain, .78) : subColor;
	const nextPanelBg = cardVariant === "occupied" ? "rgba(255,255,255,0.04)" : require_venueWallUtils.alphaColor(surfaceAccentColor, floorLikeStatus === "reserved" ? .1 : .08);
	/** 预约中：Next 区联系人/时段与「当前预约」区一致，用主字色半透明，避免仅 subColor 发灰 */
	const nextSectionInk = cardVariant === "occupied" ? subColor : floorLikeStatus === "reserved" ? require_venueWallUtils.alphaColor(idleMain, .78) : subColor;
	const resourceTitleLabel = String((_card$resource = card.resource) !== null && _card$resource !== void 0 ? _card$resource : "").trim();
	String((_card$area = card.area) !== null && _card$area !== void 0 ? _card$area : "").trim();
	const headerStatusClass = `pisell-resource-wall-card__header-status--${headerStatusKey}`;
	/**
	* 5 态胶囊：
	* - empty / reserved：沿用旧 accent 描边样式（颜色取 tone）
	* - late：accent 卡上浮红描边 + 红字（与一档强调色同源）
	* - occupied（inUse / endingSoon）：白字白描边白底（沿用旧占用样式）
	* - expired：占用卡上以红色实心胶囊 + 白字（与倒计时红同色相）
	*/
	const headerStatusStyle = (() => {
		if (headerStatusKey === "empty") return { color: headerStatusColor };
		if (headerStatusKey === "reserved" || headerStatusKey === "late") return { color: headerStatusColor };
		if (headerStatusKey === "expired") return {
			color: "#ffffff",
			background: headerStatusColor
		};
		return { color: "#ffffff" };
	})();
	return /* @__PURE__ */ react.default.createElement("div", {
		className: "pisell-resource-wall-card",
		style: {
			background: cardBg,
			borderColor: cardBorder,
			boxShadow: isDark ? "0 18px 48px rgba(0,0,0,0.35)" : "0 18px 48px rgba(15,23,42,0.06)"
		}
	}, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-resource-wall-card__scale-root" }, /* @__PURE__ */ react.default.createElement("div", { className: `pisell-resource-wall-card__grid ${showNextSection ? "pisell-resource-wall-card__grid--with-next" : "pisell-resource-wall-card__grid--no-next"}` }, /* @__PURE__ */ react.default.createElement("header", { className: "pisell-resource-wall-card__header" }, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-resource-wall-card__header-main" }, null, /* @__PURE__ */ react.default.createElement("div", {
		className: "pisell-resource-wall-card__header-name",
		style: { color: mainColor }
	}, resourceTitleLabel || "\xA0")), /* @__PURE__ */ react.default.createElement("div", {
		className: `pisell-resource-wall-card__header-status ${headerStatusClass}`,
		style: headerStatusStyle
	}, headerStatusLabel)), /* @__PURE__ */ react.default.createElement("section", {
		className: `pisell-resource-wall-card__panel${cardVariant === "occupied" ? " pisell-resource-wall-card__panel--occupied-current" : floorLikeStatus === "reserved" ? " pisell-resource-wall-card__panel--reserved-current" : ""}`,
		style: {
			borderColor: cardVariant === "occupied" ? "rgba(255,255,255,0.28)" : moduleBorder,
			background: currentPanelBg,
			minHeight: 0
		}
	}, /* @__PURE__ */ react.default.createElement("div", {
		className: `pisell-resource-wall-card__section-title${cardVariant === "occupied" ? " pisell-resource-wall-card__section-title--occupied-current" : floorLikeStatus === "reserved" ? " pisell-resource-wall-card__section-title--reserved-current" : ""}`,
		style: { color: currentSectionInk }
	}, require_index.getText(useNextAsCurrentTitle ? "pisell-resource-wall-card-label-next" : "pisell-resource-wall-card-label-current")), /* @__PURE__ */ react.default.createElement("div", { className: "pisell-resource-wall-card__current-body" }, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-resource-wall-card__current-main" }, timeRangeLine ? /* @__PURE__ */ react.default.createElement("div", {
		className: "pisell-resource-wall-card__tier2",
		style: { color: currentSectionInk }
	}, timeRangeLine) : null, contactLine ? /* @__PURE__ */ react.default.createElement("div", {
		className: "pisell-resource-wall-card__tier2",
		style: { color: currentSectionInk }
	}, contactLine) : null), primaryEmphasisLine || showProgress || showEndingSoonMarquee && marqueeText || floorLikeStatus === "empty" ? /* @__PURE__ */ react.default.createElement("div", { className: "pisell-resource-wall-card__current-footer" }, floorLikeStatus === "empty" ? /* @__PURE__ */ react.default.createElement("div", {
		className: "pisell-resource-wall-card__current-footer-emphasis pisell-resource-wall-card__tier2",
		style: { color: currentSectionInk }
	}, require_index.getText("pisell-resource-wall-card-current-not-in-use")) : null, primaryEmphasisLine ? /* @__PURE__ */ react.default.createElement("div", {
		className: "pisell-resource-wall-card__current-footer-emphasis pisell-resource-wall-card__tier1",
		style: { color: primaryEmphasisColor }
	}, primaryEmphasisLine) : null, showProgress ? /* @__PURE__ */ react.default.createElement("div", {
		className: "pisell-resource-wall-card__progress-wrap",
		style: { background: cardVariant === "occupied" ? "rgba(255,255,255,0.14)" : "rgba(148,163,184,0.18)" }
	}, /* @__PURE__ */ react.default.createElement("div", {
		className: "pisell-resource-wall-card__progress-fill",
		style: {
			width: `${progress}%`,
			background: progressColor
		}
	})) : null, showEndingSoonMarquee && marqueeText ? /* @__PURE__ */ react.default.createElement("div", {
		className: "pisell-resource-wall-card__marquee-shell",
		style: { background: marqueeShellBackground }
	}, /* @__PURE__ */ react.default.createElement("div", {
		className: "pisell-resource-wall-card__tier3",
		style: { color: marqueeColor }
	}, /* @__PURE__ */ react.default.createElement(require_NoteTicker.NoteTicker, {
		text: marqueeText,
		color: marqueeColor,
		duration: 24,
		shouldMarquee: marqueeText.length > 32
	}))) : null) : null)), showNextSection ? /* @__PURE__ */ react.default.createElement("section", {
		className: `pisell-resource-wall-card__panel${floorLikeStatus === "reserved" ? " pisell-resource-wall-card__panel--reserved-next" : ""}`,
		style: {
			borderColor: moduleBorder,
			background: nextPanelBg,
			minHeight: 0
		}
	}, /* @__PURE__ */ react.default.createElement("div", {
		className: `pisell-resource-wall-card__section-title${floorLikeStatus === "reserved" ? " pisell-resource-wall-card__section-title--reserved-next" : ""}`,
		style: { color: nextSectionInk }
	}, require_index.getText("pisell-resource-wall-card-label-next")), /* @__PURE__ */ react.default.createElement("div", { className: `pisell-resource-wall-card__next-stack${nextContactMeaningful && nextTimeMeaningful ? " pisell-resource-wall-card__next-stack--both-lines" : ""}` }, nextContactMeaningful && nextItem ? /* @__PURE__ */ react.default.createElement("div", {
		className: "pisell-resource-wall-card__tier2",
		style: { color: nextSectionInk }
	}, String(nextItem.booking).trim()) : null, nextTimeMeaningful && nextItem ? /* @__PURE__ */ react.default.createElement("div", {
		className: nextTimeSoloLarge ? "pisell-resource-wall-card__next-time-solo" : "pisell-resource-wall-card__tier2",
		style: { color: nextSectionInk }
	}, String(nextItem.time).trim()) : null)) : null)));
}
/** 单块场地大屏卡：漂移与文案由 {@link buildVenueWallCardPresentation} 统一计算 */
const VenueWallCard = react.default.memo(VenueWallCardInner);
VenueWallCard.displayName = "VenueWallCard";
//#endregion
exports.VenueWallCard = VenueWallCard;
