Book Sales Prediction
United Kingdom
United States
Canada
${i + 1}. ${escapeHtml(s.title || "Suggestion")}
Why it helps: ${escapeHtml(s.whyItHelps || "")}
${steps ? `How to apply:
` : ""}
- ${steps}
${escapeHtml(c.name || "Channel")}
Why: ${escapeHtml(c.why || "")}
${firstSteps ? `First steps:
` : ""}
- ${firstSteps}
Results for: ${escapeHtml(analysis.country || "")}
1) Specialised improvement suggestions
${improv || `No suggestions returned.
`}2) Sales potential analysis
Verdict: ${escapeHtml(analysis.salesPotential?.verdict || "")}
${reasoning ? `Reasoning:
` : ""}
${audience ? `- ${reasoning}
Likely audience:
` : ""}
- ${audience}
Positioning
Genre fit: ${escapeHtml(analysis.salesPotential?.positioning?.genreFit || "")}
Unique hook: ${escapeHtml(analysis.salesPotential?.positioning?.uniqueHook || "")}
${comparables ? `Comparables:
` : ""}
- ${comparables}
Pricing notes:
` : ""}
- ${pricingNotes}
3) Marketing strategy
Core message: ${escapeHtml(analysis.marketingStrategy?.coreMessage || "")}
${channels ? `Channels:${channels}
` : ""}
Launch plan
${preLaunch ? `Pre-launch:
` : ""}
${launchWeek ? `- ${preLaunch}
Launch week:
` : ""}
${postLaunch ? `- ${launchWeek}
Post-launch:
` : ""}
- ${postLaunch}
Ad ideas:
` : ""}
${emailSeq ? `- ${adIdeas}
Email sequence:
` : ""}
- ${emailSeq}
Please enter a summary.
"; return; } // Optional: match backend validation if (summary.length < 30) { resultBox.innerHTML = "Please enter at least 30 characters.
"; return; } resultBox.innerHTML = "Analysing sales potential...
"; btn.disabled = true; btn.style.opacity = "0.7"; try { const response = await fetch(SALES_API_URL, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ summary, country }) }); const data = await response.json(); if (!response.ok) { // Backend might return: { error: "...", raw?: "..." } const msg = data?.error ? data.error : "Server responded with an error"; resultBox.innerHTML = `Error: ${escapeHtml(msg)}
` + (data?.raw ? `Debug details
${escapeHtml(data.raw)}Error: Unexpected response format.
`; return; } resultBox.innerHTML = renderAnalysis(data.analysis); } catch (err) { resultBox.innerHTML = `Error: ${escapeHtml(err.message)}
`; } finally { btn.disabled = false; btn.style.opacity = "1"; } }
