'use strict'; /* global $, S, store, plan, planTab, savePlan, loadPlan, renderPlan, planSlot, applyBrand, cleanErr, newPersona, cal, camp, results, CONTENT_TYPES, ymd, resetPlanLoaded, online, brandBasicsReady, aiOn, makePortraits, askCloudflare, DEMO_VERSION, demoPlan, marketFacts, offlineMarket, applyMarketDraft, view, showView, renderPlanChip */ // The plan's seven steps (the sidebar), a short guide per step (what, why, example, what to do, key words; folded by // default), checks that mark a step done, ✨ Draft with AI (Cloudflare, 70B), the coach (Check my work), and the demo. const words = t => String(t || '').trim().split(/\s+/).filter(Boolean).length; const STEPS = [ { id: 'brand', day: 1, title: 'Brand identity', tab: 'Brand', lesson: { what: 'Your brand is how people recognise you and how they feel about you: what you offer, why you exist, how you sound and how you look.', why: 'A clear brand makes every post feel like it comes from the same place, so people remember you.', example: 'Bean & Bloom · “Your daily cup of calm.” A warm corner where neighbours meet over great coffee and cakes baked every morning.', exercise: 'Fill in your brand and save your Brand Identity Summary.', terms: [['Mission', 'One sentence: who you serve, what you do and why.'], ['Tone of voice', 'How your brand sounds in writing, e.g. warm and chatty, or calm and expert.'], ['Tagline', 'A short line people remember: seven words or fewer.']] }, checks: () => { const b = plan.brand || {}; return [ ['Brand name and what you offer', !!(b.name && b.offer)], ['Mission of 10 to 45 words: who you help and what you do', words(b.mission) >= 10 && words(b.mission) <= 45], ['At least 3 values', String(b.values || '').split(',').filter(x => x.trim()).length >= 3], ['Personality: 1 to 3 picked', (b.personality || []).length >= 1], ['Tone of voice described', words(b.tone) >= 2], ['Tagline of 7 words or fewer', words(b.tagline) >= 2 && words(b.tagline) <= 8], ['Two or more brand colours', (b.colors || []).length >= 2], ]; } }, { id: 'personas', day: 1, title: 'Customer personas', tab: 'Personas', lesson: { what: 'A persona is a short, realistic picture of one typical customer: who they are, what they need, what annoys them and where they spend time online.', why: 'Writing for one real-feeling person makes posts more personal, and shows you which channels to use.', example: 'Sofia, 34, remote designer · needs a calm place to work for a few hours · dislikes noisy chains · finds places on Instagram and Google.', exercise: 'Create two personas and mark the main one. Give each a picture.', terms: [['Persona', 'A made-up but realistic customer that stands for a group of real ones.'], ['Pain point', 'A problem or frustration your customer has that you can solve.']] }, checks: () => { const ps = (plan.personas || []).filter(p => p.name); return [ ['Two personas', ps.length >= 2], ['Each has an age and a job or situation', ps.length >= 2 && ps.every(p => p.age && p.job)], ['Each has needs and frustrations', ps.length >= 2 && ps.every(p => words(p.needs) >= 4 && words(p.pains) >= 2)], ['Each says where they are online', ps.length >= 2 && ps.every(p => (p.where || []).length)], ['One is marked Main', ps.some(p => p.main)], ]; } }, { id: 'market', day: 1, title: 'Competitors and channels', tab: 'Competitors', lesson: { what: 'Look at two or three competitors, see what works for them, decide how you are different, and choose the places online where your brand will be.', why: 'Knowing the competition shows you what customers already like and where you can stand out; a presence map keeps you focused on the channels that reach your customers.', example: 'Bean & Bloom vs. the chain café nearby: they post discounts; we show the baking at 6 a.m. Channels: Instagram (daily life), Google Business profile (be found), Facebook (events).', exercise: 'Analyse two competitors, write how you are different, and fill in your digital presence map.', terms: [['Positioning', 'How a brand wants to be seen compared with others: cheaper, more premium, more local…'], ['Digital presence', 'All the places your brand can be found online: social media, website, Google, email.']] }, checks: () => { const m = plan.market || { competitors: [], presence: {} }, comps = (m.competitors || []).filter(c => c.name), used = Object.entries(m.presence || {}).filter(([, e]) => e.use); return [ ['Two competitors named', comps.length >= 2], ['What works for each of them', comps.length >= 2 && comps.every(c => words(c.works) >= 3)], ['How we are different (one or two sentences)', words(m.difference) >= 8], ['Two or more channels in the presence map', used.length >= 2], ['Each channel has a purpose', used.length >= 2 && used.every(([, e]) => words(e.purpose) >= 3)], ]; } }, { id: 'campaign', day: 2, title: 'Campaign and funnel', tab: 'Campaign', lesson: { what: 'A campaign is a set of posts with one goal, one message and a start and end date. The funnel shows how people move from first seeing you to buying.', why: 'One goal and one message keep your posts focused; the funnel makes sure you also plan the posts that bring sales.', example: 'Autumn Cake Week · goal: shop visits · “A new homemade cake every day this week.” · offer: free cake with your second coffee.', exercise: 'Name your campaign, choose a goal, write the key message, sketch the funnel and pick three success metrics with targets.', terms: [['Funnel', 'Awareness (they see you) → Engagement (they interact) → Conversion (they buy or visit).'], ['Value proposition', 'Why someone should choose you over others, in one line.'], ['Call to action', 'What you ask people to do next: Order now, Book a table…'], ['Metric', 'A number that shows success, like reach or engagement rate, with a target.']] }, checks: () => { const c = plan.campaign || {}; return [ ['Campaign name and goal', !!(c.name && c.goal)], ['Key message of 20 words or fewer', words(c.message) >= 3 && words(c.message) <= 20], ['Why choose us', words(c.value) >= 3], ['Call to action', !!c.cta], ['At least one channel', (c.channels || []).length > 0], ['All three funnel steps written', ['awareness', 'engagement', 'conversion'].every(k => words(((c.funnel || {})[k] || {}).what) >= 3)], ['Three metrics, each with a target', (c.metrics || []).length === 3 && c.metrics.every(m => +m.target > 0)], ]; } }, { id: 'calendar', day: 2, title: 'Content plan', tab: 'Content plan', lesson: { what: 'A good content plan mixes kinds of posts: educational, storytelling, behind the scenes, community and lifestyle, plus a few offers.', why: 'Variety keeps followers interested, and a calendar keeps you posting regularly instead of when you remember.', example: 'Monday: 3 quick tips · Wednesday: why we started · Friday: behind the scenes in the kitchen.', exercise: 'Write at least 10 content ideas, fill a 30-day calendar, make two posts and write their captions.', terms: [['Content mix', 'The share of each kind of post in your plan.'], ['Caption', 'The text under a post: a hook, a few lines, a call to action and hashtags.']] }, checks: () => { const k = plan.calendar || { ideas: [], days: {} }, d = Object.values(k.days || {}).filter(x => x.text); return [ ['10 or more content ideas', (k.ideas || []).length >= 10], ['4 or more kinds of content', new Set((k.ideas || []).map(i => i.type)).size >= 4], ['8 or more posts in the calendar', d.length >= 8], ['Content made for at least two days', d.filter(x => x.item).length >= 2], ['Captions written for at least two days', d.filter(x => Object.values(x.captions || {}).some(c => words(c) > 3)).length >= 2], ]; } }, { id: 'automate', day: 3, title: 'Campaigns', tab: 'Campaigns', lesson: { what: 'Automation lets a tool do a repeated task for you. n8n connects apps without code: here it logs every post in a Google Sheet, emails you a reminder on the morning of each post and posts on LinkedIn. Each month you send is a campaign: you can see it day by day, and delete a day or the whole month.', why: 'Small tasks done by hand every week add up. Automating them saves time and means a planned post is never forgotten.', example: 'Bean & Bloom sends its month to n8n on the 1st: 13 rows appear in the content sheet, and every posting day starts with an email that has the caption ready to copy.', exercise: 'Connect n8n, then Google Sheets and Gmail, send your month of posts, and check the sheet and a reminder. Then open the campaign below and look at its days.', terms: [['Automation', 'A task a tool does for you, the same way every time.'], ['Workflow', 'The steps n8n follows, drawn as connected boxes.'], ['Trigger', 'What starts a workflow: here, Ora sending posts to its link.'], ['Credential', 'Your sign-in to an app (Google, LinkedIn), saved inside n8n.']] }, checks: () => { const n = online.n8n || {}, a = n.accounts || {}, off = n.off || {}, k = plan.calendar || { days: {} }; return [ ['n8n connected', !!n.connected], ['Google Sheets connected in n8n', !!(a.sheets && a.sheets.ok && !off.sheets)], ['Gmail reminders connected in n8n', !!(a.gmail && a.gmail.ok && !off.gmail)], ['Your month sent to n8n', !!(plan.automate && plan.automate.sentAt)], ['Reminders set for upcoming posts', Object.values(k.days || {}).some(d => d.reminder)], ]; } }, { id: 'results', day: 3, title: 'Results', tab: 'Results', lesson: { what: 'Results show what worked. Reach is how many people saw a post; engagement rate is likes + comments + shares + saves, divided by reach.', why: 'Numbers tell you what to do more of, and what to drop, next month.', example: 'Reach 6,500 (target 5,000) · engagement rate 7.1% · storytelling posts work best.', exercise: 'Track the numbers of your posts and compare them with your three targets.', terms: [['Reach', 'How many different people saw a post.'], ['Impressions', 'How many times it was seen (one person can see it twice).'], ['Engagement rate', '(likes + comments + shares + saves) ÷ reach × 100.']] }, checks: () => { const rows = ((plan.results || {}).rows || []); return [ ['3 or more posts with their reach', rows.filter(r => +r.reach > 0).length >= 3], ['Interactions typed in (likes, comments…)', rows.filter(r => (+r.likes || 0) + (+r.comments || 0) > 0).length >= 3], ['Targets set in the campaign', ((plan.campaign || {}).metrics || []).some(m => +m.target > 0)], ]; } }, { id: 'present', day: 3, title: 'Presentation', tab: 'Presentation', lesson: { what: 'Bring everything together in a short presentation: brand, audience, campaign, content plan and results.', why: 'A short presentation is how you share the plan with your team, a client or investors, and get feedback.', example: 'Ten slides, five minutes: who we are, who we talk to, what we will post, how we will know it worked.', exercise: 'Make your presentation (PDF or PowerPoint) and share it.', terms: [] }, checks: () => [['Presenter name', !!plan.presentedBy], ['Presentation made', !!plan.presentedAt]] }, ]; const stepOf = id => STEPS.find(s => s.id === id) || STEPS[0]; const done = st => st.checks().every(c => c[1]); // --- steps list and lesson card ------------------------------------------------------------------------------------------ function renderCourseSteps() { const nav = $('planSteps'); nav.innerHTML = ''; nav.setAttribute('role', 'tablist'); for (const st of STEPS) { const ch = st.checks(), ok = ch.filter(c => c[1]).length; const b = document.createElement('button'); const on = view === 'plan' && planTab === st.id; b.type = 'button'; b.className = 'step'; b.setAttribute('role', 'tab'); b.setAttribute('aria-selected', String(on)); b.setAttribute('aria-current', String(on)); b.innerHTML = ''; b.querySelector('.step-n').textContent = ok === ch.length ? '✓' : String(STEPS.indexOf(st) + 1); b.querySelector('.step-n').classList.toggle('ok', ok === ch.length); b.querySelector('.step-n').classList.toggle('warn', ok < ch.length && showMissing.has(st.id)); b.querySelector('.step-t').textContent = st.tab || st.title; // the tooltip says what is still missing b.title = ok === ch.length ? `${st.title}: done` : `${st.title}: still missing ${ch.filter(c => !c[1]).map(c => c[0].charAt(0).toLowerCase() + c[0].slice(1)).join('; ')}`; b.addEventListener('click', () => goStep(st.id)); nav.appendChild(b); } const total = STEPS.length, fin = STEPS.filter(done).length; const p = document.createElement('div'); p.className = 'step-progress'; p.innerHTML = `${fin} of ${total} steps done`; p.querySelector('.bar span').style.width = `${fin / total * 100}%`; nav.appendChild(p); const i = STEPS.findIndex(s => s.id === planTab); $('planPrev').hidden = i <= 0; $('planNext').textContent = nextAnyway === planTab ? 'Go on anyway →' : i >= STEPS.length - 1 ? 'Finish' : `Next: ${STEPS[i + 1].title} →`; } // --- missing items, marked like a form: a red outline and a note on the fields a check still needs ------------------------ // for each check of a step (same order), the fields to mark when it is not met const personaCards = () => [...document.querySelectorAll('#personaGrid .persona')]; const compCards = () => [...document.querySelectorAll('#compList .comp')]; const TARGETS = { brand: [() => [!(plan.brand || {}).name && $('bName'), !(plan.brand || {}).offer && $('bOffer')], () => [$('bMission')], () => [$('bValues')], () => [$('bPersonality')], () => [$('bTone')], () => [$('bTagline')], () => [$('bColors')]], personas: [ () => [$('addPersona')], () => personaCards().flatMap((c, i) => { const p = plan.personas[i] || {}; return [!p.age && c.querySelector('[data-k=age]'), !p.job && c.querySelector('[data-k=job]')]; }), () => personaCards().flatMap((c, i) => { const p = plan.personas[i] || {}; return [words(p.needs) < 4 && c.querySelector('[data-k=needs]'), words(p.pains) < 2 && c.querySelector('[data-k=pains]')]; }), () => personaCards().map((c, i) => !((plan.personas[i] || {}).where || []).length && c.querySelector('[data-k=where]')), () => [personaCards()[0] && personaCards()[0].querySelector('input[type=radio]').closest('label')], ], market: [ () => compCards().slice(0, 2).map((c, i) => !((((plan.market || {}).competitors || [])[i] || {}).name) && c.querySelector('[data-k=name]')), () => compCards().map((c, i) => { const x = ((plan.market || {}).competitors || [])[i] || {}; return x.name && words(x.works) < 3 && c.querySelector('[data-k=works]'); }), () => [$('mDifference')], () => [$('presenceList')], () => [...document.querySelectorAll('#presenceList .pres:not(.off)')].map(r => words(r.querySelector('[data-k=purpose]').value) < 3 && r.querySelector('[data-k=purpose]')), ], campaign: [() => [$('cName')], () => [$('cMessage')], () => [$('cValue')], () => [$('cCta')], () => [$('cChannels')], () => [...document.querySelectorAll('#cFunnel textarea')].map(t => words(t.value) < 3 && t), () => [$('cMetrics')]], calendar: [() => [document.querySelector('.cal-ideas .idea-add')], () => [document.querySelector('.cal-ideas .idea-add')], () => [$('calGrid')], () => [$('calMakeAll')], () => [$('calGrid')]], automate: [() => [$('campList')], () => [$('campList')], () => [$('campList')], () => [$('campList')], () => [$('campList')]], results: [() => [document.querySelector('.rtable-wrap')], () => [document.querySelector('.rtable-wrap')], () => [$('rTiles')]], present: [() => [$('presentBy')], () => [$('presentMake')]], }; const showMissing = new Set(); // steps whose missing items are marked (after Next or Check my work) let nextAnyway = null; // the step where Next was pressed once with items missing function missingOf(st) { const t = TARGETS[st.id] || []; return st.checks().map(([label, ok], i) => ok ? null : { label, els: (t[i] ? t[i]() : []).filter(Boolean) }).filter(Boolean); } // marks the fields (one note per field, listing what it needs); scroll: move to the first one function markMissing(miss, scroll) { for (const el of document.querySelectorAll('.need, .need-el')) el.classList.remove('need', 'need-el'); for (const el of document.querySelectorAll('.need-note')) el.remove(); const byEl = new Map(); for (const m of miss) for (const el of m.els) byEl.set(el, [...(byEl.get(el) || []), m.label]); for (const [el, labels] of byEl) { const note = document.createElement('span'); note.className = 'need-note'; note.textContent = `Needed: ${labels.map(l => l.charAt(0).toLowerCase() + l.slice(1)).join('; ')}`; const field = el.closest('.field'); if (field) { field.classList.add('need'); field.appendChild(note); } else { el.classList.add('need-el'); el.after(note); } } const first = [...byEl.keys()][0]; if (scroll && first) { first.scrollIntoView({ behavior: 'smooth', block: 'center' }); if (/^(INPUT|TEXTAREA|SELECT)$/.test(first.tagName)) first.focus({ preventScroll: true }); } const n = miss.length; $('planNavNote').textContent = !n ? '' : `${n} thing${n > 1 ? 's' : ''} on this step ${n > 1 ? 'are' : 'is'} still missing (marked in red).${nextAnyway === planTab ? ' Fix them, or press Go on anyway.' : ''}`; } // after a change or a redraw: the marks follow the plan (fixed items lose their mark) function applyMissing() { if (!showMissing.has(planTab)) { $('planNavNote').textContent = ''; return; } const miss = missingOf(stepOf(planTab)); markMissing(miss, false); if (!miss.length) { showMissing.delete(planTab); if (nextAnyway === planTab) nextAnyway = null; renderCourseSteps(); } } function renderCourse() { renderCourseSteps(); const st = stepOf(planTab), L = st.lesson, open = store('ora.lessonOpen') === true, n = STEPS.indexOf(st) + 1; $('topKicker').textContent = `Step ${n} of ${STEPS.length} · Day ${st.day}`; $('topTitle').textContent = st.title; const card = $('lessonCard'); card.hidden = st.id === 'automate'; // Campaigns: only the sent campaigns, no lesson card card.innerHTML = `
To do

What

Why it matters

A good example

What to do

`; card.querySelector('[data-k=todo]').textContent = L.exercise; for (const k of ['what', 'why', 'example', 'exercise']) card.querySelector(`[data-k=${k}]`).textContent = L[k]; const terms = card.querySelector('.lesson-terms'); for (const [t, d] of L.terms) { const x = document.createElement('span'); x.className = 'term'; x.tabIndex = 0; x.textContent = t; x.title = d; x.setAttribute('aria-label', `${t}: ${d}`); terms.appendChild(x); } card.querySelector('[data-a=toggle]').textContent = open ? 'Hide guide' : 'Show guide'; card.querySelector('[data-a=toggle]').addEventListener('click', () => { store('ora.lessonOpen', !open); renderCourse(); }); const draft = card.querySelector('[data-a=draft]'); draft.hidden = !['brand', 'personas', 'market', 'campaign', 'calendar'].includes(st.id); draft.addEventListener('click', e => draftStep(st.id, e.currentTarget)); card.querySelector('[data-a=coach]').addEventListener('click', e => coach(st, e.currentTarget)); $('coachBox').hidden = true; decorateAi(); } function goStep(id) { planTab = id; nextAnyway = null; if (view !== 'plan') showView('plan'); else renderPlan(); $('main').scrollTop = 0; } $('planPrev').addEventListener('click', () => { const i = STEPS.findIndex(s => s.id === planTab); if (i > 0) goStep(STEPS[i - 1].id); }); // Next with items missing: the first press marks them (like a form), a second press goes on anyway $('planNext').addEventListener('click', () => { const st = stepOf(planTab), i = STEPS.indexOf(st), miss = missingOf(st); if (miss.length && nextAnyway !== st.id) { nextAnyway = st.id; showMissing.add(st.id); renderCourseSteps(); markMissing(miss, true); return; } if (i < STEPS.length - 1) goStep(STEPS[i + 1].id); else goStep('present'); }); // --- ✨ Draft with AI ------------------------------------------------------------------------------------------------------ // fields Ora drafted and the person has not touched yet: shown with an "AI draft" label const AI_FIELDS = { 'market.difference': 'mDifference', 'market.presence': 'presenceList', 'brand.mission': 'bMission', 'brand.values': 'bValues', 'brand.tone': 'bTone', 'brand.tagline': 'bTagline', 'brand.personality': 'bPersonality', 'campaign.name': 'cName', 'campaign.message': 'cMessage', 'campaign.value': 'cValue', 'campaign.offer': 'cOffer', 'campaign.cta': 'cCta', 'campaign.channels': 'cChannels', 'campaign.funnel': 'cFunnel', 'campaign.metrics': 'cMetrics' }; function decorateAi() { plan.ai = plan.ai || {}; for (const b of document.querySelectorAll('.ai-badge')) b.remove(); for (const [key, id] of Object.entries(AI_FIELDS)) { if (!plan.ai[key]) continue; const el = $(id); if (!el) continue; const host = el.closest('.field') ? el.closest('.field').querySelector('.label') : el.closest('.plan-card').querySelector('h3'); if (!host) continue; const b = document.createElement('span'); b.className = 'ai-badge'; b.innerHTML = 'AI draft '; b.title = 'Ora drafted this. Read it, make it yours, or press Keep.'; b.querySelector('button').addEventListener('click', () => { delete plan.ai[key]; savePlan(); b.remove(); }); host.appendChild(b); } // drafted competitors are kinds of competitor, to be swapped for real ones for (const card of document.querySelectorAll('#compList .comp')) { const i = [...card.parentNode.children].indexOf(card), c = ((plan.market || {}).competitors || [])[i]; if (c && c.ai && !card.querySelector('.ai-badge')) { const b = document.createElement('span'); b.className = 'ai-badge'; b.title = 'A kind of competitor, not a real business: write the name of one you know, or press Keep.'; b.innerHTML = 'AI draft · a kind '; b.querySelector('button').addEventListener('click', () => { delete c.ai; savePlan(); b.remove(); }); card.querySelector('.comp-head').after(b); } } for (const card of document.querySelectorAll('#personaGrid .persona')) { const i = [...card.parentNode.children].indexOf(card), p = plan.personas[i]; if (p && p.ai && !card.querySelector('.ai-badge')) { const b = document.createElement('span'); b.className = 'ai-badge'; b.innerHTML = 'AI draft '; b.querySelector('button').addEventListener('click', () => { delete p.ai; savePlan(); b.remove(); }); card.querySelector('.persona-foot').prepend(b); } } } // typing in a drafted field makes it the person's own document.addEventListener('input', e => { if (!plan.ai || !e.target.id) return; for (const [key, id] of Object.entries(AI_FIELDS)) if (id === e.target.id && plan.ai[key]) { delete plan.ai[key]; savePlan(); decorateAi(); } }, true); function brandFactsText() { const b = plan.brand || {}; return [`Brand name: ${b.name}`, `What it offers and where: ${b.offer}`, b.mission && `Mission so far: ${b.mission}`, b.values && `Values so far: ${b.values}`].filter(Boolean).join('\n'); } function planFactsText() { const b = plan.brand || {}; return [brandFactsText(), b.personality && b.personality.length && `Personality: ${b.personality.join(', ')}`, b.tone && `Tone: ${b.tone}`, b.tagline && `Tagline: ${b.tagline}`, ...(plan.personas || []).filter(p => p.name).map(p => `Customer: ${p.name}, ${p.age}, ${p.job}; needs ${p.needs}; online on ${(p.where || []).join(', ')}`)].filter(Boolean).join('\n'); } // Ora's own drafts when Cloudflare is not connected: simple, honest starting points built from the person's words function offlineDraft(kind) { const b = plan.brand || {}, what = String(b.offer || 'what we make').split(/\s+(in|for|near|at)\s+/i)[0], whatL = what.charAt(0).toLowerCase() + what.slice(1); const where = (String(b.offer || '').match(/\s(in|near|at)\s+(.+)$/i) || [])[2] || 'our area'; if (kind === 'brand') return { mission: `${b.name || 'We'} offers ${whatL} in ${where}, with honest advice and a personal touch, for people who want quality without the hassle.`, values: 'quality, friendly service, local, honest', personality: ['Friendly', 'Warm', 'Trustworthy'], tone: 'friendly, clear and simple', tagline: `${b.name || 'We'}: made for you.` }; if (kind === 'personas') return [ { name: 'Anna', gender: 'woman', age: '32', job: `Busy professional in ${where}`, needs: `Good ${whatL} that fits a busy day`, pains: 'Little time; disappointed by average quality', motivations: 'Quality, convenience, friendly service', where: ['Instagram', 'Google'], quote: 'I want something good without the hassle.' }, { name: 'Paul', gender: 'man', age: '55', job: 'Local resident and regular customer', needs: `A place he trusts for ${whatL}`, pains: 'Feels ignored by big chains', motivations: 'Personal welcome, fair prices', where: ['Facebook', 'Google'], quote: 'I come back where they know my name.' }, ]; if (kind === 'campaign') { const month = new Date(Date.now() + 7 * 864e5).toLocaleDateString('en', { month: 'long' }); return { name: `${month} at ${b.name || 'our place'}`, goal: 'visits', message: `Discover our ${whatL} this ${month}.`, value: b.values ? `We are ${b.values.split(',').slice(0, 2).join(' and ').trim()}` : 'Made with care, close to you', offer: 'A small welcome gift for first-time customers', cta: 'Visit us', channels: ['Instagram', 'Facebook'], funnel: { awareness: { what: `A short video showing our ${whatL} to new people nearby.` }, engagement: { what: 'A carousel of tips and a question in stories to start conversations.' }, conversion: { what: 'A poster with the welcome offer and how to find us.' } }, metrics: [{ id: 'reach', target: '2000' }, { id: 'er', target: '4' }, { id: 'followers', target: '50' }] }; } return null; } async function draftStep(kind, btn) { const note = btn.parentNode.querySelector('[data-k=note]'); const b = plan.brand || {}; if (!brandBasicsReady('Needed for ✨ Draft with AI')) { // the lesson card is redrawn on the Brand step: put the hint on the new one setTimeout(() => { $('lessonCard').querySelector('[data-k=note]').textContent = 'First fill in the marked fields: Ora drafts the rest of your plan from your brand name and what you offer.'; }, 90); return; } if (kind !== 'calendar' && !aiOn()) await askCloudflare('✨ Draft with AI writes with your free Cloudflare account. Connect it now, or skip and Ora writes a simple starting point from your words.', 'Draft with AI'); if (kind === 'calendar') { $('ideaSuggest').click(); setTimeout(() => $('calFill').click(), 2500); note.textContent = 'Suggesting ideas, then filling the month…'; return; } const label = btn.textContent; btn.disabled = true; btn.textContent = 'Drafting…'; let out = null, online = true; try { out = await window.ora.planAi(kind, kind === 'brand' ? brandFactsText() : kind === 'market' ? marketFacts() : planFactsText()); } catch (e) { online = false; out = kind === 'market' ? offlineMarket() : offlineDraft(kind); var why = cleanErr(e); } btn.disabled = false; btn.textContent = label; if (!out) return; plan.ai = plan.ai || {}; if (kind === 'brand') { for (const k of ['mission', 'values', 'tone', 'tagline']) if (out[k] && (!b[k] || plan.ai[`brand.${k}`])) { b[k] = out[k]; plan.ai[`brand.${k}`] = true; } if (out.personality && out.personality.length && (!(b.personality || []).length || plan.ai['brand.personality'])) { b.personality = out.personality; plan.ai['brand.personality'] = true; } } else if (kind === 'personas') { const keep = (plan.personas || []).filter(p => p.name && !p.ai); const fresh = out.slice(0, Math.max(0, 2 - keep.length) || 2).map((p, i) => ({ ...newPersona(), id: `p${Date.now()}${i}`, ...p, ai: true })); plan.personas = [...keep, ...fresh].slice(0, 3); if (!plan.personas.some(p => p.main) && plan.personas[0]) plan.personas[0].main = true; var portraitNote = await makePortraits(fresh.filter(p => plan.personas.includes(p))); // eslint-disable-line no-var } else if (kind === 'market') { applyMarketDraft(out); } else if (kind === 'campaign') { const c = camp(); for (const k of ['name', 'message', 'value', 'offer', 'cta']) if (out[k] && (!c[k] || plan.ai[`campaign.${k}`])) { c[k] = out[k]; plan.ai[`campaign.${k}`] = true; } if (out.goal && (!c.name || plan.ai['campaign.name'])) c.goal = out.goal; if (out.channels && out.channels.length && (!c.channels.length || plan.ai['campaign.channels'])) { c.channels = out.channels; plan.ai['campaign.channels'] = true; } if (out.funnel && (!Object.values(c.funnel || {}).some(f => f && f.what) || plan.ai['campaign.funnel'])) { c.funnel = out.funnel; plan.ai['campaign.funnel'] = true; } if (out.metrics && out.metrics.length === 3 && (!c.metrics.some(m => +m.target > 0) || plan.ai['campaign.metrics'])) { c.metrics = out.metrics; plan.ai['campaign.metrics'] = true; } } savePlan(); renderPlan(); setTimeout(() => { const n = $('lessonCard').querySelector('[data-k=note]'); const kinds = kind === 'market' && ((plan.market || {}).competitors || []).some(c => c.ai) ? ' The competitors are kinds of competitor, not real businesses: replace them with 2 or 3 you know.' : ''; if (n) n.textContent = online ? `Drafted with AI (Cloudflare). Read every line: keep what fits, change what does not. Anything you wrote yourself was kept.${kinds}${portraitNote || ''}` : /offline/.test(why) ? 'Connect Cloudflare (free, in Settings › Accounts) for real AI drafts. Here is a simple starting point built from your words; make it yours.' : `The AI did not give a usable answer this time (try again in a moment). Here is a simple starting point built from your words.${kinds}`; }, 50); } // --- coach: Check my work ------------------------------------------------------------------------------------------------- function stepWork(id) { const b = plan.brand || {}, c = plan.campaign || {}; // word counts are given, so the coach judges lengths against the criteria instead of guessing const n = t => `(${words(t)} words)`; if (id === 'brand') return `Brand: ${b.name}\nOffer: ${b.offer}\nMission ${n(b.mission)}: ${b.mission}\nValues: ${b.values}\nPersonality: ${(b.personality || []).join(', ')}\nTone: ${b.tone}\nTagline ${n(b.tagline)}: ${b.tagline}\nColours (${(b.colors || []).length}): ${(b.colors || []).join(', ')}`; if (id === 'personas') return (plan.personas || []).filter(p => p.name).map(p => `${p.name}, ${p.age}, ${p.job}. Needs: ${p.needs}. Gender: ${p.gender || 'not set'}. Frustrations: ${p.pains}. Chooses a brand for: ${p.motivations}. Online: ${(p.where || []).join(', ')}. Quote: ${p.quote}`).join('\n') || '(no personas yet)'; if (id === 'market') { const m = plan.market || { competitors: [], presence: {} }; return `Competitors:\n${(m.competitors || []).filter(x => x.name).map(x => `- ${x.name} (on ${(x.where || []).join(', ')}): works: ${x.works}; positioning: ${x.position}`).join('\n')}\nHow we are different: ${m.difference}\nPresence: ${Object.entries(m.presence || {}).filter(([, e]) => e.use).map(([k, e]) => `${k}: ${e.purpose} (${e.freq})`).join('; ')}`; } if (id === 'campaign') return `Name: ${c.name}\nGoal: ${c.goal}\nMessage ${n(c.message)}: ${c.message}\nWhy choose us: ${c.value}\nOffer: ${c.offer}\nCall to action: ${c.cta}\nChannels: ${(c.channels || []).join(', ')}\nFunnel: ${['awareness', 'engagement', 'conversion'].map(k => `${k}: ${((c.funnel || {})[k] || {}).what || ''}`).join(' | ')}\nMetrics: ${(c.metrics || []).map(m => `${m.id} target ${m.target}`).join(', ')}`; if (id === 'calendar') { const k = plan.calendar || { ideas: [], days: {} }; return `Ideas: ${(k.ideas || []).map(i => `${i.type}: ${i.text}`).join('; ')}\nPosts in the calendar: ${Object.values(k.days || {}).filter(d => d.text).length}, made: ${Object.values(k.days || {}).filter(d => d.item).length}`; } if (id === 'automate') { const n = online.n8n || {}, a = n.accounts || {}; return `n8n: ${n.connected ? 'connected' : 'not connected'}; Google Sheets: ${a.sheets && a.sheets.ok ? 'works' : 'not yet'}; Gmail reminders: ${a.gmail && a.gmail.ok ? 'works' : 'not yet'}; month sent: ${plan.automate && plan.automate.sentAt ? `yes (${plan.automate.posts} posts)` : 'no'}`; } if (id === 'results') { const rows = ((plan.results || {}).rows || []); return rows.map(r => `${r.date} ${r.platform} "${r.title}": reach ${r.reach}, likes ${r.likes}, comments ${r.comments}, followers ${r.followers}`).join('\n') || '(no results yet)'; } return `Presented by: ${plan.presentedBy || ''}`; } async function coach(st, btn) { if (!aiOn()) await askCloudflare('The coach writes feedback on your words with your free Cloudflare account. Connect it now, or skip to see only the checks.', 'Check my work'); const box = $('coachBox'), ch = st.checks(); // the fields that still need something are marked too showMissing.add(st.id); markMissing(missingOf(st), false); renderCourseSteps(); box.hidden = false; box.innerHTML = '

Coach

Looking at your work…

'; const label = btn.textContent; btn.disabled = true; let ai = null; try { ai = await window.ora.planAi('coach', `Exercise: ${st.lesson.exercise}\nCriteria:\n${ch.map(c => `- ${c[0]}`).join('\n')}\n\nTheir work:\n${stepWork(st.id)}`); } catch { ai = null; } btn.disabled = false; btn.textContent = label; const ok = ch.filter(c => c[1]), miss = ch.filter(c => !c[1]); box.innerHTML = '

Coach

'; const list = document.createElement('ul'); list.className = 'coach-checks'; for (const [t, good] of ch) { const li = document.createElement('li'); li.className = good ? 'ok' : 'miss'; li.textContent = `${good ? '✓' : '○'} ${t}`; list.appendChild(li); } box.appendChild(list); const fb = document.createElement('div'); fb.className = 'coach-ai'; if (ai) { fb.innerHTML = '

'; fb.querySelector('.good').textContent = `👍 ${ai.good}`; for (const t of ai.improve) { const li = document.createElement('li'); li.textContent = t; fb.querySelector('ul').appendChild(li); } fb.querySelector('.muted').textContent = `Coach's score: ${'★'.repeat(ai.score)}${'☆'.repeat(5 - ai.score)} · written by AI (Cloudflare): use your own judgement too.`; } else { fb.innerHTML = `

${aiOn() ? 'The AI coach did not answer this time: press Check my work again in a moment for written feedback.' : 'Connect Cloudflare (free, in Settings › Accounts) for written feedback on your words.'}

`; fb.querySelector('p').textContent = !miss.length ? 'All checks passed: this step is done. Ask someone to read it with fresh eyes, then move on.' : `${ok.length} of ${ch.length} checks passed. Next: ${miss[0][0].charAt(0).toLowerCase()}${miss[0][0].slice(1)}.`; } box.appendChild(fb); renderCourseSteps(); box.scrollIntoView({ behavior: 'smooth', block: 'nearest' }); } // --- the demo: a finished plan for the café Bean & Bloom -------------------------------------------------------------------- async function openDemo() { $('demoOpen').disabled = true; $('demoOpen').textContent = 'Opening…'; try { const items = await window.ora.demoInstall(); S.pictures = (await window.ora.state()).pictures; store('ora.planSlot', 'demo'); const existing = await window.ora.planGet('demo'); if (!existing || existing.demoVersion !== DEMO_VERSION) await window.ora.planSet(await demoPlan(items), 'demo'); planReload(); } catch (e) { alert(`Could not open the demo: ${cleanErr(e)}`); } finally { $('demoOpen').disabled = false; $('demoOpen').textContent = 'Open the demo'; } } function closeDemo() { store('ora.planSlot', 'mine'); planReload(); applyBrand(); } function planReload() { resetPlanLoaded(); planTab = 'brand'; renderPlan(); renderDemoBar(); } function renderDemoBar() { const demo = planSlot() === 'demo'; $('demoTag').hidden = !demo; $('demoClose').hidden = !demo; $('demoOpen').hidden = demo; $('demoRemove').hidden = !demo; document.body.classList.toggle('is-demo', demo); if (typeof renderPlanChip === 'function') renderPlanChip(); } $('demoOpen').addEventListener('click', openDemo); $('demoClose').addEventListener('click', closeDemo); renderDemoBar();