{
  "version": 3,
  "sources": ["around-flow.js"],
  "sourcesContent": ["// The way past a page's blanks on the publish screen, as steps the person can follow (Kolin, 2026-10-29: \"make the UX\n// flow around rewriting with Klaude to help with go live more seamless and obvious for the user what is happening\").\n// Pure: account/review-room.js draws it; test/around-flow.test.js checks it. No DOM, no network.\n//\n//   1  N details still blank   what stops it\n//   2  Klaude rewrites them    the quick rewrite, line by line (or the full rewrite, or \"You fill them in\")\n//   3  You review the changes  keep, skip or edit each line; nothing saved until Use these changes\n//   4  Checked again           saved, and the page's checks run again\n//   5  Ready to publish        or, for a writer, ready for an Admin to publish\n//\n// Every state comes from the publish check's answer (c, with c.flow from functions/api/review/_around.js aroundFlowOf)\n// and what the screen is doing right now (around: the dialog's own state), so the screen opened again picks up where\n// it was.\n\n// A blank by its first words: \"[Wholesale terms: cost per unit, ...]\" → \"Wholesale terms\".\nexport function blankName(b) {\n  const t = String(b || \"\").replace(/^\\[+|\\]+$/g, \"\").trim();\n  const head = t.split(/[:.;]/)[0].trim() || t;\n  return head.length > 48 ? `${head.slice(0, 46).trim()}…` : head;\n}\nconst n2 = (n, one, many) => `${n} ${n === 1 ? one : many}`;\n\n// The line under the track while Klaude writes: which line it's on, of how many.\nexport function writingLine(rows) {\n  const list = rows || [], total = list.length;\n  const done = list.filter((r) => r.state === \"ready\" || r.state === \"couldnt\").length;\n  const at = list.findIndex((r) => r.state === \"writing\");\n  if (!total) return \"Finding the lines with blanks…\";\n  if (at < 0) return done === total ? `Rewrote ${n2(total, \"line\", \"lines\")}.` : `Starting on ${n2(total, \"line\", \"lines\")}…`;\n  const r = list[at];\n  const name = blankName((r.blanks || [])[0] || r.before);\n  return `Rewriting line ${at + 1} of ${total}: ${name}${name.endsWith(\"…\") ? \"\" : \"…\"}`;\n}\n\n// → { show, steps: [{ key, label, state: \"done\" | \"now\" | \"todo\" | \"off\" }], now, say, tone }\n//   c       the publish check: { blanks, flow, quality, writes_only, operator, customer_publish, publishes }\n//   around  the screen's own state: null, or { phase: \"listing\" | \"writing\" | \"review\" | \"saving\" | \"undoing\" | \"checking\" | \"self\", rows }\n//   fixing  the full rewrite, started from this screen: null, or { why }\nexport function aroundStep(c, around = null, fixing = null) {\n  const blanks = (c && c.blanks) || [], flow = (c && c.flow) || {}, n = blanks.length;\n  const allowed = !!(c && (c.operator || c.customer_publish || c.publishes)) && !(c && c.writes_only);\n  const otherStops = ((c && c.quality) || []).filter((q) => !q.ok && q.level === \"block\" && q.id !== \"blanks\");\n  const phase = around && around.phase;\n  const slow = !!(fixing || flow.slow);\n  const self = phase === \"self\" || (!phase && !slow && !!flow.self);\n  const slowDone = !phase && !slow && !!flow.slowDone;\n  const applied = !n && !!flow.applied;\n  const show = n > 0 || !!phase || slow || applied || slowDone;\n  // Which step it's on, 1 to 5.\n  const at = phase === \"checking\" ? 4\n    : phase === \"review\" || phase === \"saving\" || phase === \"undoing\" || slowDone ? 3\n    : phase === \"listing\" || phase === \"writing\" || slow || self ? 2\n    : n ? (flow.preview ? 3 : 1)\n    : otherStops.length ? 4 : 5;\n  const labels = [\n    n ? `${n2(n, \"detail\", \"details\")} still blank` : \"Blanks found\",\n    self ? \"You fill them in\" : slowDone || (flow.applied && flow.applied.full) ? \"Klaude rewrote the page\" : slow ? \"Klaude rewrites the page\" : \"Klaude rewrites those lines\",\n    \"You review the changes\",\n    \"Checked again\",\n    allowed ? \"Ready to publish\" : \"Ready for your Admin\",\n  ];\n  const keys = [\"blanks\", \"rewrite\", \"review\", \"check\", \"ready\"];\n  const steps = keys.map((key, i) => ({ key, label: labels[i], state: i + 1 < at ? \"done\" : i + 1 === at ? \"now\" : \"todo\" }));\n  // Filling them in by hand skips Klaude's review: the page is checked again when they're done.\n  if (self) steps[2].state = \"off\";\n  const rows = (around && around.rows) || [];\n  const lines = rows.length || n;\n  let say, tone = \"work\";\n  if (at === 1) { say = `${n === 1 ? \"1 detail is\" : `${n} details are`} still blank, so this page can't go live yet. Klaude can rewrite just ${n === 1 ? \"that line\" : \"those lines\"} in a few seconds, leaving out what we don't know, or you can fill ${n === 1 ? \"it\" : \"them\"} in yourself.`; tone = \"stop\"; }\n  else if (at === 2 && self) say = `You're filling ${n === 1 ? \"it\" : \"them\"} in yourself. Type the missing ${n === 1 ? \"detail\" : \"details\"} on the page, and this screen checks again when you open it. Klaude can still do it for you.`;\n  else if (at === 2 && slow) say = `This one needs a full rewrite, so Klaude is rewriting the page around ${n === 1 ? \"the blank\" : \"the blanks\"}. It usually takes a few minutes. You can close this: the page shows Klaude is on it, and this screen picks up here when you open it again.`;\n  else if (at === 2) say = `Klaude is rewriting ${n2(lines, \"line\", \"lines\")}. Nothing else on the page changes.`;\n  else if (at === 3 && phase === \"saving\") say = \"Saving your changes to the draft…\";\n  else if (at === 3 && phase === \"undoing\") say = \"Putting back the draft from before Klaude's changes…\";\n  else if (at === 3 && slowDone) say = \"Klaude rewrote the page around the blanks. Check what changed, then keep it or undo it. Nothing goes live until you publish.\";\n  else if (at === 3) say = \"Check each change: keep it, skip it, or edit the words. Nothing is saved until you press Use these changes.\";\n  else if (at === 4 && phase === \"checking\") say = \"Saved. Checking the page again…\";\n  else if (at === 4) { say = `Checked again: ${n2(otherStops.length, \"thing\", \"things\")} still to fix before it can go live.`; tone = \"stop\"; }\n  else { say = allowed ? \"Ready: all checks passed.\" : \"Ready: all checks passed. An Admin on your team publishes it; you can't publish this page yourself.\"; tone = \"ok\"; }\n  return { show, steps, now: keys[at - 1], at, say, tone };\n}\n\n// The rows to review from what's kept on the room (c.flow.preview), for the screen opened again.\nexport function rowsFromPreview(p) {\n  if (!p) return [];\n  return [...(p.changes || []).map((x) => ({ ...x, state: \"ready\", keep: true, editing: false })),\n    ...(p.skipped || []).map((x) => ({ ...x, state: \"couldnt\", keep: false, editing: false }))];\n}\n"],
  "mappings": "AAeO,gBAAS,UAAUA,EAAG,CAC3B,MAAM,EAAI,OAAOA,GAAK,EAAE,EAAE,QAAQ,aAAc,EAAE,EAAE,KAAK,EACnDC,EAAO,EAAE,MAAM,OAA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AS,+FACjIvB,IAAO,GAAKY,EAAMW,EAAM,yEAAyE,IAAM,EAAI,YAAc,YAAY,8IACrIvB,IAAO,EAAGuB,EAAM,uBAAuB/B,EAAG8B,EAAO,OAAQ,OAAO,CAAC,sCACjEtB,IAAO,GAAKW,IAAU,SAAUY,EAAM,oCACtCvB,IAAO,GAAKW,IAAU,UAAWY,EAAM,uDACvCvB,IAAO,GAAKc,EAAUS,EAAM,+HAC5BvB,IAAO,EAAGuB,EAAM,8GAChBvB,IAAO,GAAKW,IAAU,WAAYY,EAAM,kCACxCvB,IAAO,GAAKuB,EAAM,kBAAkB/B,EAAGiB,EAAW,OAAQ,QAAS,QAAQ,CAAC,uCAAwCe,EAAO,SAC7HD,EAAMf,EAAU,4BAA8B,sGAAuGgB,EAAO,MAC5J,CAAE,KAAAR,EAAM,MAAAG,EAAO,IAAKD,EAAKlB,EAAK,CAAC,EAAG,GAAAA,EAAI,IAAAuB,EAAK,KAAAC,CAAK,CACzD,CAGO,gBAAS,gBAAgBC,EAAG,CACjC,OAAKA,EACE,CAAC,IAAIA,EAAE,SAAW,CAAC,GAAG,IAAKC,IAAO,CAAE,GAAGA,EAAG,MAAO,QAAS,KAAM,GAAM,QAAS,EAAM,EAAE,EAC5F,IAAID,EAAE,SAAW,CAAC,GAAG,IAAKC,IAAO,CAAE,GAAGA,EAAG,MAAO,UAAW,KAAM,GAAO,QAAS,EAAM,EAAE,CAAC,EAF7E,CAAC,CAGlB",
  "names": ["b", "head", "n2", "n", "one", "many", "rows", "list", "total", "done", "at", "r", "name", "c", "around", "fixing", "blanks", "flow", "allowed", "otherStops", "q", "phase", "slow", "self", "slowDone", "applied", "show", "labels", "keys", "steps", "key", "i", "lines", "say", "tone", "p", "x"]
}
