/* Daily Word - endpoint diagnostic  v3
   The chain RETURNS the result, so Safari shows it inline under "result:".
   Also stashed on window.DW_DIAG so you can inspect it afterwards.
   Edit URL_ if your application slug is not "daily-word". */

var URL_ = "/api/v2/lava-app/1/daily-word/save-plan";

fetch(URL_, {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "X-Helix-CSRF-Protection": "true"
  },
  body: JSON.stringify({ plan: JSON.stringify({ hello: "world" }) })
})
  .then(function (r) {
    return r.text().then(function (t) {
      var out = {
        STATUS: r.status + " " + r.statusText,
        CONTENT_TYPE: r.headers.get("content-type"),
        BODY_LENGTH: t.length,
        BODY: JSON.stringify(t)
      };
      window.DW_DIAG = out;
      return out;
    });
  })
  .catch(function (e) {
    var out = { STATUS: "FETCH FAILED", BODY: e && e.message };
    window.DW_DIAG = out;
    return out;
  });
