import { isOfflineBoom } from "./form-availability.js";
import { unavailableViewModel } from "./models/unavailable-view-model.js";

/**
 * Registers a server-wide onPreResponse extension that intercepts the offline
 * Boom thrown and renders the unavailable view.
 *
 * Must be registered after the engine's routes so it sees their responses,
 * but before any global error-page handler that would re-shape Boom errors.
 */
export function registerUnavailableResponse(server) {
  server.ext('onPreResponse', (request, h) => {
    const response = request.response;
    if (!isOfflineBoom(response)) {
      return h.continue;
    }
    const {
      metadata
    } = response.data;
    return h.view('unavailable', unavailableViewModel(metadata)).header('Cache-Control', 'no-store, no-cache, must-revalidate').header('X-Robots-Tag', 'noindex, nofollow').code(200).takeover();
  });
}
//# sourceMappingURL=unavailable-response.js.map