{
  "version": 3,
  "sources": ["stale_day.js"],
  "sourcesContent": ["/*\n * static/js/stale_day.js \u2014 \"Showing 18 Oct \u00B7 Reload\" when the page is a day old (SNOW-920).\n *\n * A navigation the worker serves from Cache Storage after its network budget\n * ran out carries the day it was rendered on (``#season-scrubber[data-today]``),\n * and ``readDisplayDate`` trusts it (SNOW-793). This module asks the server\n * what day it is and, when the answer differs, reveals ``#stale-day-notice``:\n * the page's day and a Reload button that clears the shell caches and fetches\n * the shell from the network.\n *\n * Decisions, and why:\n *\n *   - NEVER AUTOMATIC. Nothing reloads by itself; the visitor may be\n *     mid-gesture or mid-form, and an unprompted reload is worse than a\n *     stale label. The button is the whole remedy.\n *   - NO BROWSER CLOCK. The comparison is page day vs server day, both\n *     strings; ``new Date()`` is never asked what day it is (SNOW-793).\n *   - A FAILED OR EMPTY ANSWER SAYS NOTHING. Offline, unreachable or a server\n *     that predates ``today`` is \"cannot confirm\", which never raises the\n *     label (stale_day_core.js ``isStale``). Only a clear mismatch does.\n *   - IT CLEARS ITSELF. A later poll that agrees hides the label again, so a\n *     visitor who reloads some other way is not left with a stale warning.\n *   - WHEN IT ASKS: once on load, and when the page comes back to the\n *     foreground (visibilitychange / pageshow), at most once a minute \u2014 the\n *     ``/api/version`` edge cache is 60 s, so asking faster is wasted. The\n *     second trigger is what catches a tab or installed app left open across\n *     midnight, which no cold-start check could.\n *   - AN EXPLICIT ``?d=`` IS LEFT ALONE. The visitor asked for that day; the\n *     label is about the page's default one. Choosing a day while the label\n *     is showing hides it at once (snowdesk:date-changed, popstate).\n *\n * Depends on pwa_version_check.js (window.pwaVersionInfo.refresh / .reload),\n * stale_day_core.js and i18n_strings.js, all loaded before it.\n */\n(function staleDayInit() {\n  'use strict';\n\n  const MIN_POLL_GAP_MS = 60 * 1000;\n\n  const scrubber = document.getElementById('season-scrubber');\n  const notice = document.getElementById('stale-day-notice');\n  const core = window.pwaStaleDayCore;\n  if (!scrubber || !notice || !core) return;\n\n  const label = notice.querySelector('[data-stale-day-label]');\n  const reloadBtn = notice.querySelector('[data-stale-day-reload]');\n  if (!label || !reloadBtn) return;\n\n  const STRINGS = window.pwaStrings.read('stale-day-strings-template', {\n    'stale-day-showing': 'Showing %(day)s',\n  });\n\n  let lastPollAt = 0;\n  let polling = false;\n  // The last day the server named, so a change of URL can re-judge it\n  // without another request. Null until a poll has answered.\n  let lastServerDay = null;\n\n  /** The URL's ``?d=``, or ``''`` when the visitor chose no day. */\n  function explicitDay() {\n    try {\n      return new URLSearchParams(location.search).get('d') || '';\n    } catch (_err) {\n      return '';\n    }\n  }\n\n  /**\n   * Show or hide the notice for one server answer.\n   *\n   * @param {string} serverDay The server's ``today``, possibly empty.\n   */\n  function apply(serverDay) {\n    lastServerDay = serverDay;\n    const pageDay = scrubber.dataset.today || '';\n    const stale = core.isStale(pageDay, serverDay, explicitDay());\n    notice.hidden = !stale;\n    if (stale) {\n      label.textContent = window.pwaStrings.interpolate(STRINGS['stale-day-showing'], {\n        day: core.formatDay(pageDay, document.documentElement.lang),\n      });\n    }\n  }\n\n  /** Ask the server for its day, at most once a minute. */\n  async function check() {\n    const info = window.pwaVersionInfo;\n    if (polling || !info || typeof info.refresh !== 'function') return;\n    const now = Date.now(); // a throttle interval, not a calendar day\n    if (lastPollAt && now - lastPollAt < MIN_POLL_GAP_MS) return;\n    polling = true;\n    lastPollAt = now;\n    try {\n      const verdict = await info.refresh();\n      // null = could not confirm: leave whatever is showing as it is.\n      if (verdict) apply(verdict.today || '');\n    } catch (_err) {\n      // Never let this break the page.\n    } finally {\n      polling = false;\n    }\n  }\n\n  reloadBtn.addEventListener('click', () => {\n    const info = window.pwaVersionInfo;\n    const reload = info && typeof info.reload === 'function' ? info.reload : null;\n    Promise.resolve(reload ? reload() : window.location.reload()).catch(() =>\n      window.location.reload()\n    );\n  });\n\n  document.addEventListener('visibilitychange', () => {\n    if (document.visibilityState === 'visible') check();\n  });\n  window.addEventListener('pageshow', check);\n  // A day chosen on the calendar or scrubber writes ``?d=`` and emits\n  // ``snowdesk:date-changed`` (the URL first); back/forward moves ``?d=``\n  // too. Either makes the day the visitor's own choice, so re-judge at once\n  // rather than leave a label naming the page's rendered day beside it.\n  const rejudge = () => {\n    if (lastServerDay !== null) apply(lastServerDay);\n  };\n  document.addEventListener('snowdesk:date-changed', rejudge);\n  window.addEventListener('popstate', rejudge);\n  check();\n})();\n"],
  "mappings": "CAkCC,UAAwB,CACvB,aAIA,MAAMA,EAAW,SAAS,eAAe,iBAAiB,EACpDC,EAAS,SAAS,eAAe,kBAAkB,EACnDC,EAAO,OAAO,gBACpB,GAAI,CAACF,GAAY,CAACC,GAAU,CAACC,EAAM,OAEnC,MAAMC,EAAQF,EAAO,cAAc,wBAAwB,EACrDG,EAAYH,EAAO,cAAc,yBAAyB,EAChE,GAAI,CAACE,GAAS,CAACC,EAAW,OAE1B,MAAMC,EAAU,OAAO,WAAW,KAAK,6BAA8B,CACnE,oBAAqB,iBACvB,CAAC,EAED,IAAIC,EAAa,EACbC,EAAU,GAGVC,EAAgB,KAGpB,SAASC,GAAc,CACrB,GAAI,CACF,OAAO,IAAI,gBAAgB,SAAS,MAAM,EAAE,IAAI,GAAG,GAAK,EAC1D,MAAe,CACb,MAAO,EACT,CACF,CAOA,SAASC,EAAMC,EAAW,CACxBH,EAAgBG,EAChB,MAAMC,EAAUZ,EAAS,QAAQ,OAAS,GACpCa,EAAQX,EAAK,QAAQU,EAASD,EAAWF,EAAY,CAAC,EAC5DR,EAAO,OAAS,CAACY,EACbA,IACFV,EAAM,YAAc,OAAO,WAAW,YAAYE,EAAQ,mBAAmB,EAAG,CAC9E,IAAKH,EAAK,UAAUU,EAAS,SAAS,gBAAgB,IAAI,CAC5D,CAAC,EAEL,CAGA,eAAeE,GAAQ,CACrB,MAAMC,EAAO,OAAO,eACpB,GAAIR,GAAW,CAACQ,GAAQ,OAAOA,EAAK,SAAY,WAAY,OAC5D,MAAMC,EAAM,KAAK,IAAI,EACrB,GAAI,EAAAV,GAAcU,EAAMV,EAAa,KACrC,CAAAC,EAAU,GACVD,EAAaU,EACb,GAAI,CACF,MAAMC,EAAU,MAAMF,EAAK,QAAQ,EAE/BE,GAASP,EAAMO,EAAQ,OAAS,EAAE,CACxC,MAAe,CAEf,QAAE,CACAV,EAAU,EACZ,EACF,CAEAH,EAAU,iBAAiB,QAAS,IAAM,CACxC,MAAMW,EAAO,OAAO,eACdG,EAASH,GAAQ,OAAOA,EAAK,QAAW,WAAaA,EAAK,OAAS,KACzE,QAAQ,QAAQG,EAASA,EAAO,EAAI,OAAO,SAAS,OAAO,CAAC,EAAE,MAAM,IAClE,OAAO,SAAS,OAAO,CACzB,CACF,CAAC,EAED,SAAS,iBAAiB,mBAAoB,IAAM,CAC9C,SAAS,kBAAoB,WAAWJ,EAAM,CACpD,CAAC,EACD,OAAO,iBAAiB,WAAYA,CAAK,EAKzC,MAAMK,EAAU,IAAM,CAChBX,IAAkB,MAAME,EAAMF,CAAa,CACjD,EACA,SAAS,iBAAiB,wBAAyBW,CAAO,EAC1D,OAAO,iBAAiB,WAAYA,CAAO,EAC3CL,EAAM,CACR,GAAG",
  "names": ["scrubber", "notice", "core", "label", "reloadBtn", "STRINGS", "lastPollAt", "polling", "lastServerDay", "explicitDay", "apply", "serverDay", "pageDay", "stale", "check", "info", "now", "verdict", "reload", "rejudge"]
}
