var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/pisellRecordBoard/shellFrame/ResourceWall/venueWallUtils.ts
var venueWallUtils_exports = {};
__export(venueWallUtils_exports, {
  DEFAULT_RESOURCE_WALL_STATUS_SORT_FIELD_KEYS: () => DEFAULT_RESOURCE_WALL_STATUS_SORT_FIELD_KEYS,
  VENUE_WALL_STATUS_COLOR_MAP: () => VENUE_WALL_STATUS_COLOR_MAP,
  VENUE_WALL_STATUS_KEYS: () => VENUE_WALL_STATUS_KEYS,
  alphaColor: () => alphaColor,
  clamp: () => clamp,
  deriveVenueWallStatus: () => deriveVenueWallStatus,
  diffVenueWallStatusToneOverrides: () => diffVenueWallStatusToneOverrides,
  formatDurationHM: () => formatDurationHM,
  formatVenueWallCountdown: () => formatVenueWallCountdown,
  getVenueWallStatusToneMap: () => getVenueWallStatusToneMap,
  matchesResourceWallStatusSortField: () => matchesResourceWallStatusSortField,
  parseRecordBoardToolbarSortParam: () => parseRecordBoardToolbarSortParam,
  venueWallOccupiedSortRank: () => venueWallOccupiedSortRank
});
module.exports = __toCommonJS(venueWallUtils_exports);
var import_locales = require("../../../../locales");
var VENUE_WALL_STATUS_KEYS = [
  "inUse",
  "endingSoon",
  "expired",
  "available",
  "boardingSoon",
  "late"
];
var VENUE_WALL_STATUS_COLOR_MAP = {
  inUse: {
    key: "inUse",
    label: "In Use",
    note: "This court is currently in use.",
    color: "#6f4ae6",
    noteBg: "rgba(111,74,230,0.92)"
  },
  endingSoon: {
    key: "endingSoon",
    label: "Ending Soon",
    note: "Please leave on time to avoid overtime charges.",
    color: "#f59e0b",
    noteBg: "rgba(245,158,11,0.96)"
  },
  expired: {
    key: "expired",
    label: "Expired",
    note: "This booking has ended. Please clear the court.",
    color: "#ef4444",
    noteBg: "rgba(239,68,68,0.96)"
  },
  available: {
    key: "available",
    label: "Available",
    note: "This court is now available.",
    /** 大屏空闲态：淡灰中性色（与占用紫、预约紫区分） */
    color: "#94a3b8",
    noteBg: "rgba(148,163,184,0.22)"
  },
  boardingSoon: {
    key: "boardingSoon",
    label: "Boarding Soon",
    note: "Please check in to start.",
    color: "#6f4ae6",
    noteBg: "rgba(111,74,230,0.18)"
  },
  late: {
    key: "late",
    label: "Late",
    note: "Please check in as soon as possible.",
    /** 与超时/结束同系红，大屏提醒迟到 */
    color: "#ef4444",
    noteBg: "rgba(239,68,68,0.22)"
  }
};
function alphaColor(hex, alpha) {
  const clean = hex.replace("#", "");
  const full = clean.length === 3 ? clean.split("").map((c) => c + c).join("") : clean;
  const num = parseInt(full, 16);
  const r = num >> 16 & 255;
  const g = num >> 8 & 255;
  const b = num & 255;
  return `rgba(${r}, ${g}, ${b}, ${alpha})`;
}
var clamp = (value, min, max) => Math.max(min, Math.min(max, value));
function deriveVenueWallStatus(card) {
  const s = card.status;
  if (s === "available") return "available";
  if (s === "boardingSoon") return "boardingSoon";
  if (s === "late") return "late";
  if (s === "endingSoon") return "endingSoon";
  if (s === "expired") return "expired";
  if (s === "inUse") return "inUse";
  if (card.currentBooking === "Available to Book") return "available";
  const rm = card.remainingMin;
  if (rm != null && rm <= 0) return "expired";
  if (rm != null && rm <= 10) return "endingSoon";
  return "inUse";
}
function parseRecordBoardToolbarSortParam(sort) {
  if (sort == null || typeof sort !== "string") return null;
  const idx = sort.indexOf(":");
  if (idx <= 0) return null;
  const field = sort.slice(0, idx);
  const rest = sort.slice(idx + 1);
  const dirSep = rest.indexOf(":");
  const dirRaw = dirSep >= 0 ? rest.slice(0, dirSep) : rest;
  if (dirRaw !== "asc" && dirRaw !== "desc") return null;
  return { field, dir: dirRaw };
}
var DEFAULT_RESOURCE_WALL_STATUS_SORT_FIELD_KEYS = ["status"];
function matchesResourceWallStatusSortField(sortField, keys) {
  const n = sortField.trim().toLowerCase();
  return keys.some((k) => k.trim().toLowerCase() === n);
}
function venueWallOccupiedSortRank(card) {
  const k = deriveVenueWallStatus(card);
  return k === "inUse" || k === "endingSoon" || k === "expired" ? 1 : 0;
}
function formatDurationHM(minAbs) {
  const safe = Number.isFinite(minAbs) ? Math.max(0, Math.floor(minAbs)) : 0;
  if (safe < 60) return `${safe}m`;
  const h = Math.floor(safe / 60);
  const m = safe % 60;
  return `${h}h ${String(m).padStart(2, "0")}m`;
}
function formatVenueWallCountdown(min) {
  if (min < 0) {
    const n = formatDurationHM(Math.abs(min));
    return (0, import_locales.getText)("pisell-resource-wall-countdown-overtime").replace("{n}", n);
  }
  if (min === 0) return (0, import_locales.getText)("pisell-resource-wall-countdown-ending-now");
  return (0, import_locales.getText)("pisell-resource-wall-countdown-left").replace(
    "{n}",
    formatDurationHM(min)
  );
}
function cloneTone(t) {
  return { ...t };
}
function getVenueWallStatusToneMap(overrides) {
  const out = {};
  for (const key of VENUE_WALL_STATUS_KEYS) {
    const base = cloneTone(VENUE_WALL_STATUS_COLOR_MAP[key]);
    base.label = (0, import_locales.getText)(`pisell-resource-wall-tone-${key}-label`);
    base.note = (0, import_locales.getText)(`pisell-resource-wall-tone-${key}-note`);
    const patch = overrides == null ? void 0 : overrides[key];
    out[key] = patch ? {
      ...base,
      ...patch,
      key
    } : base;
  }
  return out;
}
function diffVenueWallStatusToneOverrides(draft) {
  const defaults = getVenueWallStatusToneMap();
  const out = {};
  for (const k of VENUE_WALL_STATUS_KEYS) {
    const d = draft[k];
    const b = defaults[k];
    const patch = {};
    if (d.label !== b.label) patch.label = d.label;
    if (d.note !== b.note) patch.note = d.note;
    if (d.color !== b.color) patch.color = d.color;
    if (d.noteBg !== b.noteBg) patch.noteBg = d.noteBg;
    if (Object.keys(patch).length > 0) out[k] = patch;
  }
  return out;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  DEFAULT_RESOURCE_WALL_STATUS_SORT_FIELD_KEYS,
  VENUE_WALL_STATUS_COLOR_MAP,
  VENUE_WALL_STATUS_KEYS,
  alphaColor,
  clamp,
  deriveVenueWallStatus,
  diffVenueWallStatusToneOverrides,
  formatDurationHM,
  formatVenueWallCountdown,
  getVenueWallStatusToneMap,
  matchesResourceWallStatusSortField,
  parseRecordBoardToolbarSortParam,
  venueWallOccupiedSortRank
});
