import { React, html, useEffect, useState } from "./runtime.js";
import { useApp } from "./store.js";
import { useEngine } from "./engine.js";
import { useCloud } from "./cloud.js";
import { levelTitle, wordCount } from "./marking.js";
// ---------------------------------------------------------------------------
// Icons
// ---------------------------------------------------------------------------
const PATHS = {
home: ["M3 10.5 12 3l9 7.5V20a1 1 0 0 1-1 1h-5v-6H9v6H4a1 1 0 0 1-1-1z"],
chat: ["M21 11.5a8.4 8.4 0 0 1-8.5 8.5H7l-4 3v-7.2A8.5 8.5 0 1 1 21 11.5z"],
pen: ["M12 20h9", "M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4z"],
book: ["M4 19.5A2.5 2.5 0 0 1 6.5 17H20", "M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z"],
feather: ["M20 4a6.5 6.5 0 0 0-9.2 0L4 10.8V20h9.2L20 13.2A6.5 6.5 0 0 0 20 4z", "M4 20 15 9"],
sparkle: ["M12 3l1.9 4.6L18.5 9.5l-4.6 1.9L12 16l-1.9-4.6L5.5 9.5l4.6-1.9z", "M19 16l.7 1.8L21.5 19l-1.8.7L19 21.5l-.7-1.8L16.5 19l1.8-.7z"],
file: ["M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z", "M14 2v6h6", "M8 13h8", "M8 17h5"],
clock: ["M12 22a10 10 0 1 0 0-20 10 10 0 0 0 0 20z", "M12 6v6l4 2"],
list: ["M8 6h13", "M8 12h13", "M8 18h13", "M3 6h.01", "M3 12h.01", "M3 18h.01"],
settings: ["M12 15.5a3.5 3.5 0 1 0 0-7 3.5 3.5 0 0 0 0 7z", "M19.4 15a1.7 1.7 0 0 0 .3 1.9l.1.1a2 2 0 1 1-2.8 2.8l-.1-.1a1.7 1.7 0 0 0-1.9-.3 1.7 1.7 0 0 0-1 1.5V21a2 2 0 1 1-4 0v-.1a1.7 1.7 0 0 0-1-1.5 1.7 1.7 0 0 0-1.9.3l-.1.1a2 2 0 1 1-2.8-2.8l.1-.1a1.7 1.7 0 0 0 .3-1.9 1.7 1.7 0 0 0-1.5-1H3a2 2 0 1 1 0-4h.1a1.7 1.7 0 0 0 1.5-1 1.7 1.7 0 0 0-.3-1.9l-.1-.1a2 2 0 1 1 2.8-2.8l.1.1a1.7 1.7 0 0 0 1.9.3H9a1.7 1.7 0 0 0 1-1.5V3a2 2 0 1 1 4 0v.1a1.7 1.7 0 0 0 1 1.5 1.7 1.7 0 0 0 1.9-.3l.1-.1a2 2 0 1 1 2.8 2.8l-.1.1a1.7 1.7 0 0 0-.3 1.9V9a1.7 1.7 0 0 0 1.5 1H21a2 2 0 1 1 0 4h-.1a1.7 1.7 0 0 0-1.5 1z"],
menu: ["M3 6h18", "M3 12h18", "M3 18h18"],
plus: ["M12 5v14", "M5 12h14"],
up: ["M12 19V5", "M5 12l7-7 7 7"],
down: ["M12 5v14", "M19 12l-7 7-7-7"],
download: ["M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4", "M7 10l5 5 5-5", "M12 15V3"],
check: ["M20 6 9 17l-5-5"],
x: ["M18 6 6 18", "M6 6l12 12"],
lock: ["M5 11h14v10H5z", "M8 11V7a4 4 0 0 1 8 0v4"],
refresh: ["M21 12a9 9 0 1 1-2.6-6.4", "M21 3v6h-6"],
chevron: ["M9 6l6 6-6 6"],
camera: ["M3 7h3l2-3h8l2 3h3v13H3z", "M12 17a4 4 0 1 0 0-8 4 4 0 0 0 0 8z"],
external: ["M14 3h7v7", "M21 3l-9 9", "M21 14v5a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5"],
trash: ["M3 6h18", "M8 6V4h8v2", "M19 6l-1 14H6L5 6"],
user: ["M20 21v-1a7 7 0 0 0-14 0v1", "M12 11a4 4 0 1 0 0-8 4 4 0 0 0 0 8z"],
tag: ["M20.6 13.4 12 22l-9-9V4h9z", "M7.5 7.5h.01"],
code: ["M16 18l6-6-6-6", "M8 6l-6 6 6 6"]
};
export function Icon({ name, size = 16, stroke = 1.8 }) {
const paths = PATHS[name] || PATHS.file;
return html``;
}
// ---------------------------------------------------------------------------
// Brand
// ---------------------------------------------------------------------------
export function Mark({ size = 32 }) {
return html`
`;
}
export function Brand({ small = false }) {
return html`
<${Mark} size=${small ? 28 : 32} />
Explication
${!small && html`
GCSE English Literature
`}
`;
}
// ---------------------------------------------------------------------------
// Navigation
// ---------------------------------------------------------------------------
export const SECTIONS = [
{ id: "dashboard", title: "Today", group: "Progress", icon: "home" },
{ id: "chat", title: "Chat", group: "Write", icon: "chat" },
{ id: "coach", title: "Paragraph coach", group: "Write", icon: "pen" },
{ id: "essay", title: "Essay", group: "Write", icon: "book" },
{ id: "improve", title: "Improve", group: "Write", icon: "sparkle" },
{ id: "poetry", title: "Unseen poetry", group: "Study", icon: "feather" },
{ id: "modelAnswer", title: "Model answers", group: "Study", icon: "file" },
{ id: "mockExam", title: "Mock exam", group: "Study", icon: "clock" },
{ id: "process", title: "Process log", group: "Study", icon: "list" },
{ id: "settings", title: "Settings", group: "Tools", icon: "settings" },
{ id: "pricing", title: "Plans", group: "Account", icon: "tag" },
{ id: "account", title: "Account", group: "Account", icon: "user" },
{ id: "developer", title: "Developer", group: "Account", icon: "code" }
];
const GROUPS = ["Progress", "Write", "Study", "Tools", "Account"];
function NavList({ current, onNavigate }) {
const app = useApp();
const cloud = useCloud();
return html`
${GROUPS.map(
(group) => html`
${group}
${SECTIONS.filter((s) => s.group === group && (s.id !== "developer" || cloud.isDev)).map(
(s) => html`
`
)}
`
)}
Review
<${Icon} name="lock" size=${11} />
Rule-based · offline
Marks in this browser. No upload.
`;
}
export function Sidebar({ current, onNavigate }) {
return html``;
}
export function Drawer({ current, onNavigate, onClose }) {
useEffect(() => {
const onKey = (e) => e.key === "Escape" && onClose();
window.addEventListener("keydown", onKey);
return () => window.removeEventListener("keydown", onKey);
}, [onClose]);
return html`<${React.Fragment}>
<${NavList} current=${current} onNavigate=${(id) => { onNavigate(id); onClose(); }} />
/>`;
}
export function TopBar({ section, onMenu, onNavigate }) {
const app = useApp();
const engine = useEngine();
const cloud = useCloud();
const title = (SECTIONS.find((s) => s.id === section) || SECTIONS[0]).title;
return html`
${title}
✦ ${app.credits}
${cloud.user
? html``
: html``}
`;
}
// ---------------------------------------------------------------------------
// Small pieces
// ---------------------------------------------------------------------------
export function Notice({ kind = "info", children }) {
return html`<${Icon} name=${kind === "error" ? "x" : "lock"} size=${12} />
${children}
`;
}
export function Pill({ children, tone = "neutral" }) {
return html`${children}`;
}
export function ScoreRing({ total, max }) {
const pct = max ? Math.round((total / max) * 100) : 0;
return html``;
}
export function CriterionList({ criteria }) {
return html`
${criteria.map(
(c) => html`
${c.title}
${c.score}/${c.max}
${c.note && html`
${c.note}
`}
`
)}
`;
}
export function FeedbackPanel({ feedback, onSave, saved }) {
if (!feedback) {
return html`
<${Mark} size=${36} />
Mark your writing and the feedback appears here: a mark for every criterion, then one thing to change.
`;
}
return html`
<${ScoreRing} total=${feedback.total} max=${feedback.max} />
${feedback.engine === "model" ? "Model mark" : "Offline review"}
${feedback.total >= feedback.max * 0.8 ? "Strong work." : feedback.total >= feedback.max * 0.55 ? "Solid, with room to sharpen." : "A start to build on."}
${feedback.criteria.reduce((s, c) => s + c.max, 0)} marks available
${onSave &&
html`
`}
<${CriterionList} criteria=${feedback.criteria} />
${feedback.strengths.length > 0 &&
html`
What works. ${feedback.strengths.join(" ")}
`}
${feedback.improvements.length > 0 &&
html`
Next. ${feedback.improvements.join(" ")}
`}
${feedback.nextStep && html`
Do this once. ${feedback.nextStep}
`}
${feedback.quotes && feedback.quotes.length > 0 &&
html`
Quotations checked
${feedback.quotes.map(
(q, i) => html`
“${q.text}” ${q.note ? "— " + q.note : ""}
`
)}
`}
`;
}
// ---------------------------------------------------------------------------
// Hooks
// ---------------------------------------------------------------------------
export function usePersistent(key, initial) {
const [value, setValue] = useState(() => {
try {
const raw = localStorage.getItem(key);
return raw ? JSON.parse(raw) : initial;
} catch {
return initial;
}
});
useEffect(() => {
try {
localStorage.setItem(key, JSON.stringify(value));
} catch {
// ignore
}
}, [key, value]);
return [value, setValue];
}
export function download(filename, text, type = "text/markdown") {
const blob = new Blob([text], { type });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
a.remove();
setTimeout(() => URL.revokeObjectURL(url), 1000);
}
export { wordCount, levelTitle };