import { getText } from "../../../../locales/index.js";
import { _objectSpread2 } from "../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import { clamp, deriveVenueWallStatus, formatDurationHM, formatVenueWallCountdown } from "./venueWallUtils.js";
//#region src/components/pisellRecordBoard/shellFrame/ResourceWall/venueWallCardPresentation.ts
function resolveFloorLikeStatus(statusKey) {
	if (statusKey === "available") return "empty";
	if (statusKey === "boardingSoon" || statusKey === "late") return "reserved";
	return "occupied";
}
function resolveHeaderStatusKey(statusKey) {
	if (statusKey === "available") return "empty";
	if (statusKey === "boardingSoon") return "reserved";
	if (statusKey === "late") return "late";
	if (statusKey === "expired") return "expired";
	return "occupied";
}
function headerLabelForKey(key) {
	switch (key) {
		case "empty":
 /** 空闲态：右上胶囊与当前区文案统一为「Not in use」 */
		return getText("pisell-resource-wall-card-current-not-in-use");
		case "reserved": return getText("pisell-resource-wall-floor-status-reserved");
		case "late": return getText("pisell-resource-wall-floor-status-late");
		case "expired": return getText("pisell-resource-wall-floor-status-expired");
		default: return getText("pisell-resource-wall-floor-status-occupied");
	}
}
function sanitizeContact(booking) {
	var _booking$trim;
	const c = (_booking$trim = booking === null || booking === void 0 ? void 0 : booking.trim()) !== null && _booking$trim !== void 0 ? _booking$trim : "";
	if (c === "Available to Book") return "";
	return c;
}
/**
* 占用中进度条：**已使用时间占比**（左空右满随进行而增长）。
* - 有场次起止：`elapsedMs / durationMs`
* - 无起止：仍以 60 分为近似总长，`(60 - 剩余精确分) / 60`
*/
function resolveInUseProgressPercent(args) {
	const { card, wallNowMs, liveRemainingPreciseMin } = args;
	const end = card.sessionEndMs;
	const start = card.sessionStartMs;
	if (end != null && start != null && Number.isFinite(end) && Number.isFinite(start) && end > start) {
		const durationMs = end - start;
		return clamp(Math.min(Math.max(0, wallNowMs - start), durationMs) / durationMs * 100, 0, 100);
	}
	const denomMin = 60;
	return clamp((denomMin - liveRemainingPreciseMin) / denomMin * 100, 0, 100);
}
/**
* 纯函数：三态大屏文案 + 进度 + 条件跑马灯。
* 右上角标题栏仅保留 empty/reserved/occupied；迟到/超时只出现在当前区一档主提示。
*/
function buildVenueWallCardPresentation(args) {
	var _toneMap$statusKey, _toneMap$late, _toneMap$expired, _card$currentTime;
	const { card, toneMap, wallNowMs, liveRemainingMin, liveRemainingPreciseMin, liveStartsInMin, liveLateMin, boardingSoonBeforeMin, idleMain, idleSub, availableCardColor } = args;
	const statusKey = deriveVenueWallStatus(_objectSpread2(_objectSpread2({}, card), {}, { remainingMin: liveRemainingMin }));
	const floorLikeStatus = resolveFloorLikeStatus(statusKey);
	const headerStatusKey = resolveHeaderStatusKey(statusKey);
	const headerStatusLabel = headerLabelForKey(headerStatusKey);
	(_toneMap$statusKey = toneMap[statusKey]) !== null && _toneMap$statusKey !== void 0 || toneMap.inUse;
	const endingSoonTone = toneMap.endingSoon;
	const boardingTone = toneMap.boardingSoon;
	const lateTone = (_toneMap$late = toneMap.late) !== null && _toneMap$late !== void 0 ? _toneMap$late : boardingTone;
	const expiredTone = (_toneMap$expired = toneMap.expired) !== null && _toneMap$expired !== void 0 ? _toneMap$expired : endingSoonTone;
	const cardVariant = floorLikeStatus === "occupied" ? "occupied" : "accent";
	const mainOnOccupied = "#ffffff";
	/**
	* 占用卡内次级文案默认色（下一预约区等）；「当前预约」标题/时段/联系人在 VenueWallCard 内单独铺纯白 + 阴影。
	*/
	const subOnOccupied = "rgba(255,255,255,0.88)";
	const mainColor = cardVariant === "occupied" ? mainOnOccupied : idleMain;
	const subColor = cardVariant === "occupied" ? subOnOccupied : idleSub;
	let surfaceAccentColor = availableCardColor;
	if (floorLikeStatus === "reserved") surfaceAccentColor = boardingTone.color;
	const timeRangeLine = ((_card$currentTime = card.currentTime) !== null && _card$currentTime !== void 0 ? _card$currentTime : "").trim();
	const contactLine = sanitizeContact(card.currentBooking);
	let primaryEmphasisLine = "";
	let primaryEmphasisColor = mainColor;
	let progress = 0;
	let progressColor = mainOnOccupied;
	let showProgress = false;
	const rmDisplay = Math.max(0, liveRemainingMin);
	const inEndingSoonWindow = floorLikeStatus === "occupied" && liveRemainingMin >= 0 && liveRemainingMin <= Math.max(1, boardingSoonBeforeMin);
	/** 临近结束（含剩余 0）时跑马灯；已过期/负剩余不展示 */
	const showEndingSoonMarquee = floorLikeStatus === "occupied" && inEndingSoonWindow && statusKey !== "expired";
	if (statusKey === "available") {
		primaryEmphasisLine = "";
		primaryEmphasisColor = mainColor;
	} else if (statusKey === "boardingSoon") {
		/** 仅「占用中」展示进度条；预约中仅文案与色 */
		primaryEmphasisLine = getText("pisell-resource-wall-card-starts-in").replace("{n}", formatDurationHM(liveStartsInMin));
		primaryEmphasisColor = boardingTone.color;
	} else if (statusKey === "late") {
		primaryEmphasisLine = getText("pisell-resource-wall-card-late").replace("{n}", formatDurationHM(Math.max(0, Math.floor(liveLateMin))));
		primaryEmphasisColor = lateTone.color;
	} else if (statusKey === "inUse" || statusKey === "endingSoon" || statusKey === "expired") {
		showProgress = true;
		if (statusKey === "expired" || liveRemainingMin < 0) {
			/** 已结束/超时：进度条满格表示时段已用尽 */
			progress = 100;
			progressColor = expiredTone.color;
			if (liveRemainingMin < 0) primaryEmphasisLine = formatVenueWallCountdown(liveRemainingMin);
			else primaryEmphasisLine = getText("pisell-resource-wall-countdown-zero-overtime");
			primaryEmphasisColor = expiredTone.color;
		} else {
			progress = resolveInUseProgressPercent({
				card,
				wallNowMs,
				liveRemainingPreciseMin
			});
			progressColor = statusKey === "endingSoon" || inEndingSoonWindow ? endingSoonTone.color : mainOnOccupied;
			primaryEmphasisLine = formatVenueWallCountdown(rmDisplay);
			primaryEmphasisColor = statusKey === "endingSoon" || inEndingSoonWindow ? endingSoonTone.color : mainOnOccupied;
		}
	}
	const marqueeText = showEndingSoonMarquee ? getText("pisell-resource-wall-marquee-ending-soon") : "";
	/** 跑马灯文案固定白色 */
	const marqueeColor = showEndingSoonMarquee ? "#ffffff" : cardVariant === "occupied" ? "rgba(255,255,255,0.92)" : endingSoonTone.color;
	/** 与当前区一档状态字同色相叠底（快结束时与倒计时一致） */
	const marqueeShellBackground = showEndingSoonMarquee ? primaryEmphasisColor : "transparent";
	/** 标题胶囊主色：迟到/超时取各自 tone（红），其余沿用既有规则（empty=avail、reserved=boarding、occupied=白） */
	let headerStatusColor;
	if (headerStatusKey === "empty") headerStatusColor = availableCardColor;
	else if (headerStatusKey === "reserved") headerStatusColor = boardingTone.color;
	else if (headerStatusKey === "late") headerStatusColor = lateTone.color;
	else if (headerStatusKey === "expired") headerStatusColor = expiredTone.color;
	else headerStatusColor = "#ffffff";
	return {
		statusKey,
		floorLikeStatus,
		headerStatusKey,
		headerStatusLabel,
		headerStatusColor,
		cardVariant,
		mainColor,
		subColor,
		surfaceAccentColor,
		primaryEmphasisLine,
		primaryEmphasisColor,
		timeRangeLine,
		contactLine,
		showProgress,
		progress,
		progressColor,
		showEndingSoonMarquee,
		marqueeText,
		marqueeColor,
		marqueeShellBackground
	};
}
//#endregion
export { buildVenueWallCardPresentation };
