// A study started from one day of a reading plan: a chunk for each whole chapter in the day, with the notes template // you last used when starting a study by hand (so the prompts and starter text are the ones you're used to). import { templateStarter } from './studyTemplates.js'; export const lastTemplateId = () => { try { return localStorage.getItem('last-template') || 'blank'; } catch { return 'blank'; } }; export const rememberTemplate = (id) => { try { localStorage.setItem('last-template', id || 'blank'); } catch { /* storage unavailable */ } }; // chapters: [{ bookAbbrev, bookName, chapter, verses: [{ number, text }] }]; ids come from `makeId`. export function planStudyProject({ chapters, title, templateId = 'blank', templateDef = null, makeId, now = Date.now() }) { const built = chapters.map(({ bookAbbrev, bookName, chapter, verses }) => ({ book: bookName, bookAbbrev, chapter: String(chapter), verses, chunks: [{ id: makeId(), startVerse: verses[0]?.number ?? 1, endVerse: verses.at(-1)?.number ?? 1, spilloverEndVerse: null, observation: '', interpretation: '', application: '', crossReferences: [], greekWords: [], generalNotes: '', episodeNumber: '', episodeTitle: '', finalScript: '', tags: [], ...templateStarter(templateDef ?? templateId), }], })); return { id: makeId(), title: title || 'Reading Plan Study', translation: 'BSB', templateId, ...(templateDef ? { templateDef } : {}), lastEdited: now, selectedChunkId: built[0]?.chunks[0]?.id ?? null, chapters: built, }; }