"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }require('./chunk-DGUM43GV.js');

// src/routing/checkRedirect.ts
async function checkRedirectForPath(params) {
  const { client, siteId, path } = params;
  try {
    const response = await client.checkRedirect({
      siteId,
      path
    });
    if (response.redirectTo) {
      const isPermanent = response.status === 301 || response.status === 308;
      return {
        hasRedirect: true,
        redirect: {
          destination: response.redirectTo,
          permanent: isPermanent
        }
      };
    }
    return { hasRedirect: false, redirect: null };
  } catch (error) {
    console.warn("[checkRedirectForPath] Failed to check redirect", {
      siteId,
      path,
      error: error instanceof Error ? error.message : String(error)
    });
    return { hasRedirect: false, redirect: null };
  }
}

// src/routing/resolveRoute.ts
async function resolveRoute(params) {
  const { client, siteId, path, preview = false } = params;
  try {
    const pageResponse = await client.getPage({
      siteId,
      path,
      preview
    });
    if (pageResponse) {
      const { loadPage } = await Promise.resolve().then(() => _interopRequireWildcard(require("./loadPage-IDGVDFBB.js")));
      const pageData = await loadPage({
        client,
        siteId,
        path,
        preview
      });
      return {
        type: "page",
        pageData
      };
    }
  } catch (error) {
    const is404 = error instanceof Error && (error.message.includes("404") || error.message.includes("Not Found") || error.message.includes("not found"));
    if (is404) {
      console.debug("[resolveRoute] Page not found", { path });
    } else {
      console.warn("[resolveRoute] Failed to fetch page", {
        path,
        error: error instanceof Error ? error.message : String(error)
      });
    }
  }
  try {
    const redirectResult = await checkRedirectForPath({
      client,
      siteId,
      path
    });
    if (redirectResult.hasRedirect) {
      return {
        type: "redirect",
        destination: redirectResult.redirect.destination,
        permanent: redirectResult.redirect.permanent
      };
    }
  } catch (redirectError) {
    console.debug("[resolveRoute] Redirect check failed", {
      path,
      error: redirectError instanceof Error ? redirectError.message : String(redirectError)
    });
  }
  return {
    type: "not-found"
  };
}
async function resolveRoutes(params) {
  const { client, siteId, paths, preview } = params;
  const resolutions = await Promise.all(
    paths.map(async (path) => {
      const resolution = await resolveRoute({
        client,
        siteId,
        path,
        preview
      });
      return { path, resolution };
    })
  );
  return resolutions;
}

// src/routing/contentRoutes.ts
function getContentEntryPrefixes(config) {
  const contentTypes = _nullishCoalesce(_optionalChain([config, 'access', _ => _.content, 'optionalAccess', _2 => _2.contentTypes]), () => ( []));
  return contentTypes.filter(
    (ct) => ct.hasPages && typeof ct.routePattern === "string"
  ).map((ct) => {
    const match = ct.routePattern.match(/^\/([^/]+)/);
    const segment = _optionalChain([match, 'optionalAccess', _3 => _3[1]]);
    if (_optionalChain([segment, 'optionalAccess', _4 => _4.includes, 'call', _5 => _5("{")])) return void 0;
    return segment;
  }).filter((prefix) => typeof prefix === "string");
}
function isContentEntryPath(config, path) {
  const segments = typeof path === "string" ? path.split("/").filter(Boolean) : path;
  const contentTypes = _nullishCoalesce(_optionalChain([config, 'access', _6 => _6.content, 'optionalAccess', _7 => _7.contentTypes]), () => ( []));
  for (const ct of contentTypes) {
    if (!ct.hasPages || !ct.routePattern) continue;
    const patternSegments = parseRoutePattern(ct.routePattern);
    const match = matchPattern(segments, patternSegments);
    if (match.matches) {
      return {
        isEntry: true,
        contentType: ct.key,
        slug: match.slug
      };
    }
  }
  return { isEntry: false };
}
function parseRoutePattern(pattern) {
  const segments = pattern.split("/").filter(Boolean);
  const staticSegments = [];
  for (const segment of segments) {
    if (segment.includes("{")) break;
    staticSegments.push(segment);
  }
  return staticSegments;
}
function matchPattern(pathSegments, patternSegments) {
  if (pathSegments.length < patternSegments.length + 1) {
    return { matches: false };
  }
  for (let i = 0; i < patternSegments.length; i++) {
    if (pathSegments[i] !== patternSegments[i]) {
      return { matches: false };
    }
  }
  const slugSegments = pathSegments.slice(patternSegments.length);
  const slug = slugSegments.join("/");
  return { matches: true, slug };
}

// src/routing/resolveOccurrence.ts
function isISODateString(str) {
  return /^\d{4}-\d{2}-\d{2}$/.test(str);
}
function isUUID(str) {
  return /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(str);
}
function isValidSegment(segment) {
  return isISODateString(segment) || isUUID(segment);
}
async function resolveOccurrence(params) {
  const { client, siteId, entryId, segment } = params;
  if (!isValidSegment(segment)) {
    console.debug("[resolveOccurrence] Invalid segment format", { segment });
    return { found: false, occurrence: null };
  }
  try {
    const response = await client.resolveEventOccurrence({
      siteId,
      entryId,
      segment
    });
    if (response.occurrence) {
      return {
        found: true,
        occurrence: response.occurrence
      };
    }
    return { found: false, occurrence: null };
  } catch (error) {
    console.warn("[resolveOccurrence] Failed to resolve occurrence", {
      siteId,
      entryId,
      segment,
      error: error instanceof Error ? error.message : String(error)
    });
    return { found: false, occurrence: null };
  }
}










exports.checkRedirectForPath = checkRedirectForPath; exports.getContentEntryPrefixes = getContentEntryPrefixes; exports.isContentEntryPath = isContentEntryPath; exports.isISODateString = isISODateString; exports.isUUID = isUUID; exports.isValidSegment = isValidSegment; exports.resolveOccurrence = resolveOccurrence; exports.resolveRoute = resolveRoute; exports.resolveRoutes = resolveRoutes;
//# sourceMappingURL=routing.js.map