{
  "version": 3,
  "sources": ["/cdn/shop/t/9/assets/btk-kitchen-planner-help.js?cb=2442"],
  "sourcesContent": ["/* btk-kitchen-planner-help.js\n * ----------------------------------------------------------------\n * In-planner Help. The \"?\" on the plan (data-btk-kp-help) opens a modal:\n *   LEFT:  sections as icon buttons; the active section expands to its guides.\n *   RIGHT: the selected guide.\n * The Planner Home \"How To Guides\" view reads the same content through\n * window.BTKKPHelp (see openHowtoGuides in btk-kitchen-planner.js).\n *\n * WHERE THE CONTENT COMES FROM\n * The help lives in Shopify metaobjects (help_section, help_topic), edited in\n * admin. templates/page.help-data.liquid renders them as JSON, and this file\n * fetches that the FIRST time someone opens help. It is deliberately lazy:\n * the content is ~130KB and most visits never open help, so it stays off the\n * planner's first load.\n *\n * There is no built-in fallback content. There used to be: an 18-topic\n * DEFAULT_HELP that had drifted out of date (it described stages and buttons\n * the planner no longer has). Wrong help is worse than none, so if the fetch\n * fails the customer is told so and pointed at Get Help instead.\n *\n * A page can still set window.BTKPlannerHelp itself (same shape) and skip the\n * fetch, e.g. for a test harness.\n *\n * Shape: [{ id, title, summary, icon (SVG), sort, guides: [{ id, title,\n *          body (HTML), keywords, seeAlso, public }] }]\n */\n(function () {\n  'use strict';\n\n  const esc = (s) => String(s == null ? '' : s)\n    .replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\"/g, '&quot;');\n\n  // \u2500\u2500 Loading \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n  let loading = null;\n\n  // The JSON view of whatever page this is. help.js only runs on the planner\n  // page, so this needs no page handle hard-coded. A theme preview carries\n  // preview_theme_id; keep it, or the request would be answered by the live\n  // theme, which has no help-data template.\n  function dataUrl() {\n    const u = new URL(location.pathname, location.origin);\n    u.searchParams.set('view', 'help-data');\n    const preview = new URLSearchParams(location.search).get('preview_theme_id');\n    if (preview) u.searchParams.set('preview_theme_id', preview);\n    return u.toString();\n  }\n\n  function loaded() {\n    return Array.isArray(window.BTKPlannerHelp) && window.BTKPlannerHelp.length > 0;\n  }\n\n  // Fetch once; every caller shares the same promise. A failure clears it so\n  // the next open retries rather than being stuck on a transient error.\n  function load() {\n    if (loaded()) return Promise.resolve(window.BTKPlannerHelp);\n    if (!loading) {\n      loading = fetch(dataUrl(), { credentials: 'same-origin' })\n        .then((r) => { if (!r.ok) throw new Error('help data HTTP ' + r.status); return r.text(); })\n        .then((text) => {\n          const data = JSON.parse(text);\n          if (!Array.isArray(data) || !data.length) throw new Error('help data is empty');\n          data.sort((a, b) => (a.sort == null ? 999 : a.sort) - (b.sort == null ? 999 : b.sort));\n          window.BTKPlannerHelp = data;\n          return data;\n        })\n        .catch((e) => { loading = null; throw e; });\n    }\n    return loading;\n  }\n\n  // Synchronous read for callers that render after load() has resolved.\n  // Empty until then - never stale fallback content.\n  function getContent() {\n    return loaded() ? window.BTKPlannerHelp : [];\n  }\n\n  const FAILED_HTML =\n    '<p class=\"btk-kp-help-text\">The guides could not be loaded just now. Please try again in a moment, ' +\n    'or use <strong>Get Help</strong> at the bottom of the menu and our team will help you directly.</p>';\n\n  // \u2500\u2500 Modal \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n  let overlay = null;\n  const state = { sectionId: null, guideId: null, asking: false };\n\n  function findSection(data, id) { return data.find((s) => s.id === id) || data[0]; }\n  function findGuide(section, id) {\n    return (section.guides || []).find((g) => g.id === id) || (section.guides || [])[0] || null;\n  }\n\n  // The assistant, when it is available to this person. Kept behind a guard so\n  // that help works exactly as before if the chat script is not loaded, and so\n  // that everyone but the pilot group sees the modal they always saw.\n  function chat() {\n    return (window.BTKKPHelpChat && window.BTKKPHelpChat.available()) ? window.BTKKPHelpChat : null;\n  }\n\n  function askEntryHtml(active) {\n    return '<div class=\"btk-kp-help-section btk-kp-help-ask\">'\n      + '<button type=\"button\" class=\"btk-kp-help-section-btn' + (active ? ' is-active' : '')\n      + '\" data-help-ask>'\n      + '<span class=\"btk-kp-help-section-icon\">'\n      + '<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" '\n      + 'stroke-linecap=\"round\" stroke-linejoin=\"round\">'\n      + '<path d=\"M21 11.5a8.4 8.4 0 0 1-9 8.4 8.5 8.5 0 0 1-3.9-.9L3 21l1.9-5.1A8.4 8.4 0 0 1 4 11.5a8.5 8.5 0 0 1 17 0z\"/>'\n      + '</svg></span>'\n      + '<span>Ask a question</span></button></div>';\n  }\n\n  function render() {\n    if (!overlay) return;\n    const data = getContent();\n    if (!data.length) return;\n    const section = findSection(data, state.sectionId);\n    const guide = findGuide(section, state.guideId);\n\n    const menu = overlay.querySelector('[data-help-menu]');\n    const content = overlay.querySelector('[data-help-content]');\n\n    // Chat pane: the menu still lists every section, so someone can read a\n    // guide and go back to asking without closing anything.\n    if (state.asking && chat()) {\n      menu.innerHTML = askEntryHtml(true) + sectionsHtml(data, null, null);\n      content.classList.add('is-chat');\n      content.innerHTML = window.BTKKPHelpChat.paneHtml();\n      window.BTKKPHelpChat.render();\n      const input = content.querySelector('[data-chat-input]');\n      if (input) input.focus();\n      return;\n    }\n\n    menu.innerHTML = (chat() ? askEntryHtml(false) : '') + sectionsHtml(data, section, guide);\n    content.classList.remove('is-chat');\n\n    content.innerHTML = guide\n      ? '<h3 class=\"btk-kp-help-title\">' + esc(guide.title) + '</h3>' +\n        '<div class=\"btk-kp-help-text\">' + guide.body + '</div>'\n      : '<p class=\"btk-kp-help-text\">Select a topic on the left.</p>';\n  }\n\n  // `section` null means nothing is expanded, which is how the menu looks\n  // while the chat pane has the right-hand side.\n  function sectionsHtml(data, section, guide) {\n    // Titles and ids are ESCAPED: they are typed in Shopify admin now, not in\n    // a reviewed file. The icon is theme-owned SVG and the body is Shopify's\n    // own rich text rendering, so those two are inserted as markup.\n    return data.map((s) => {\n      const isActiveSection = !!section && s.id === section.id;\n      const guidesHtml = isActiveSection\n        ? '<div class=\"btk-kp-help-guides\">' + (s.guides || []).map((g) =>\n            '<button type=\"button\" class=\"btk-kp-help-guide' +\n            (guide && g.id === guide.id ? ' is-active' : '') +\n            '\" data-help-guide=\"' + esc(g.id) + '\">' + esc(g.title) + '</button>'\n          ).join('') + '</div>'\n        : '';\n      return '<div class=\"btk-kp-help-section' + (isActiveSection ? ' is-open' : '') + '\">' +\n        '<button type=\"button\" class=\"btk-kp-help-section-btn' + (isActiveSection ? ' is-active' : '') +\n        '\" data-help-section=\"' + esc(s.id) + '\">' +\n        '<span class=\"btk-kp-help-section-icon\">' + (s.icon || '') + '</span>' +\n        '<span>' + esc(s.title) + '</span></button>' + guidesHtml +\n      '</div>';\n    }).join('');\n  }\n\n  function open() {\n    if (overlay) return;\n    overlay = document.createElement('div');\n    overlay.className = 'btk-kp-help-overlay';\n    overlay.innerHTML =\n      '<div class=\"btk-kp-help-modal\" role=\"dialog\" aria-modal=\"true\" aria-label=\"Planner help\">' +\n        '<div class=\"btk-kp-help-head\">' +\n          '<h2 class=\"btk-kp-help-heading\">How to use the planner</h2>' +\n          '<button type=\"button\" class=\"btk-kp-help-close\" data-help-close aria-label=\"Close help\">&times;</button>' +\n        '</div>' +\n        '<div class=\"btk-kp-help-body\">' +\n          '<nav class=\"btk-kp-help-menu\" data-help-menu aria-label=\"Help topics\"></nav>' +\n          '<div class=\"btk-kp-help-content\" data-help-content>' +\n            (loaded() ? '' : '<p class=\"btk-kp-help-text\">Loading the guides\u2026</p>') +\n          '</div>' +\n        '</div>' +\n      '</div>';\n    document.body.appendChild(overlay);\n    document.addEventListener('keydown', onKey);\n\n    const mine = overlay;   // the modal may be closed before the fetch lands\n    load().then((data) => {\n      if (overlay !== mine) return;\n      state.sectionId = data[0].id;\n      state.guideId = data[0].guides && data[0].guides[0] ? data[0].guides[0].id : null;\n      render();\n    }).catch(() => {\n      if (overlay !== mine) return;\n      const content = overlay.querySelector('[data-help-content]');\n      if (content) content.innerHTML = FAILED_HTML;\n    });\n  }\n\n  function close() {\n    if (!overlay) return;\n    overlay.remove();\n    overlay = null;\n    // A new visit starts a new conversation. Leaving the thread in place would\n    // carry stale context into an unrelated question, and the assistant is\n    // given that history verbatim.\n    state.asking = false;\n    if (window.BTKKPHelpChat) window.BTKKPHelpChat.reset();\n    document.removeEventListener('keydown', onKey);\n  }\n\n  function onKey(e) { if (e.key === 'Escape') close(); }\n\n  // Delegated handling: open button + in-modal interactions.\n  document.addEventListener('click', function (e) {\n    const trigger = e.target.closest('[data-btk-kp-help]');\n    if (trigger) { e.preventDefault(); open(); return; }\n\n    if (!overlay) return;\n\n    if (e.target === overlay || e.target.closest('[data-help-close]')) { close(); return; }\n\n    if (e.target.closest('[data-help-ask]')) {\n      if (chat()) { state.asking = true; render(); }\n      return;\n    }\n\n    const sec = e.target.closest('[data-help-section]');\n    if (sec) {\n      state.asking = false;\n      state.sectionId = sec.getAttribute('data-help-section');\n      const s = findSection(getContent(), state.sectionId);\n      state.guideId = s && s.guides && s.guides[0] ? s.guides[0].id : null;\n      render();\n      return;\n    }\n    const g = e.target.closest('[data-help-guide]');\n    if (g) {\n      state.asking = false;\n      state.guideId = g.getAttribute('data-help-guide');\n      render();\n      return;\n    }\n  });\n\n  // Shared with the Planner Home \"How To Guides\" view, which must call load()\n  // before its first render; getContent() is empty until that resolves.\n  window.BTKKPHelp = { load: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