"use strict";
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);
var modelOrdering_exports = {};
__export(modelOrdering_exports, {
  compareModelsLatestFirst: () => compareModelsLatestFirst,
  isDeprecatedModelStatus: () => isDeprecatedModelStatus
});
module.exports = __toCommonJS(modelOrdering_exports);
const ISO_DATE_PATTERN = /^(\d{4})-(\d{2})-(\d{2})$/;
const NUMBER_GROUP_PATTERN = /\d+/g;
const NAME_COLLATOR = new Intl.Collator("en", { numeric: true, sensitivity: "base" });
function parseIsoDateToTimestamp(value) {
  const match = ISO_DATE_PATTERN.exec(value.trim());
  if (!match) return null;
  const year = Number(match[1]);
  const month = Number(match[2]);
  const day = Number(match[3]);
  if (!Number.isInteger(year) || !Number.isInteger(month) || !Number.isInteger(day)) {
    return null;
  }
  const timestamp = Date.UTC(year, month - 1, day);
  const parsed = new Date(timestamp);
  if (parsed.getUTCFullYear() !== year || parsed.getUTCMonth() !== month - 1 || parsed.getUTCDate() !== day) {
    return null;
  }
  return timestamp;
}
function stripDateTokens(name) {
  return name.replace(/\d{4}-\d{2}-\d{2}/g, " ").replace(/\d{8}/g, " ").replace(/\s+/g, " ").trim();
}
function extractVersionPartsFromModelName(name) {
  const modelTail = name.includes("/") ? name.slice(name.lastIndexOf("/") + 1) : name;
  const normalized = stripDateTokens(modelTail.toLowerCase());
  const parts = Array.from(normalized.matchAll(NUMBER_GROUP_PATTERN)).map((match) => {
    const raw = match[0];
    if (!raw) return null;
    if (raw.length >= 6) return null;
    const parsed = Number(raw);
    return Number.isFinite(parsed) ? parsed : null;
  }).filter((part) => part !== null);
  return parts;
}
function compareVersionPartsDescending(left, right) {
  const maxParts = Math.max(left.length, right.length);
  for (let i = 0; i < maxParts; i++) {
    const leftPart = left[i];
    const rightPart = right[i];
    if (leftPart === void 0 && rightPart === void 0) {
      continue;
    }
    if (leftPart === void 0) {
      return 1;
    }
    if (rightPart === void 0) {
      return -1;
    }
    if (leftPart !== rightPart) {
      return rightPart - leftPart;
    }
  }
  return 0;
}
function compareModelsLatestFirst(left, right) {
  const leftDate = left.releaseDate ? parseIsoDateToTimestamp(left.releaseDate) : null;
  const rightDate = right.releaseDate ? parseIsoDateToTimestamp(right.releaseDate) : null;
  if (leftDate !== null && rightDate !== null && leftDate !== rightDate) {
    return rightDate - leftDate;
  }
  if (leftDate !== null && rightDate === null) {
    return -1;
  }
  if (leftDate === null && rightDate !== null) {
    return 1;
  }
  const leftVersion = extractVersionPartsFromModelName(left.name);
  const rightVersion = extractVersionPartsFromModelName(right.name);
  const byVersion = compareVersionPartsDescending(leftVersion, rightVersion);
  if (byVersion !== 0) {
    return byVersion;
  }
  return NAME_COLLATOR.compare(right.name, left.name);
}
function isDeprecatedModelStatus(status) {
  return status?.toLowerCase() === "deprecated";
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  compareModelsLatestFirst,
  isDeprecatedModelStatus
});
