import { inputClass } from "@/components/ui"; import { countWords, type Copy, type StudioType } from "@/lib/studio"; /* The copy, field by field, as the type is made of it - with the word count against the type's limits always in view. The Copywriter's draft lands here to be read and changed; or the user writes it here from nothing. */ const LABELS: Record = { quote: "الاقتباس", source: "المصدر", headline: "العنوان", offer: "العرض", cta: "زر الدعوة", line: "الجملة", title: "العنوان", subtitle: "سطر تمهيدي", points: "النقاط", slides: "الشرائح", sections: "الأقسام", number: "الرقم", label: "ماذا يقيس", description: "الوصف", steps: "الخطوات", left: "العمود الأول", right: "العمود الثاني", name: "اسم المناسبة", tagline: "سطر تعريفي", date: "التاريخ والوقت", place: "المكان", highlights: "المزايا", audience: "الفئة", }; const LONG = new Set(["quote", "offer", "description", "line", "tagline"]); const ITEM_LISTS = new Set(["slides", "steps", "sections"]); export function emptyCopy(t: StudioType): Copy { const out: Copy = {}; for (const f of t.fields) { if (f === "points" || f === "highlights") out[f] = Array(Math.max(t.items[0], 1)).fill(""); else if (ITEM_LISTS.has(f)) { out[f] = Array.from({ length: Math.max(t.items[0], 1) }, () => f === "sections" ? { title: "", text: "", figure: "" } : { title: "", text: "" }); } else if (f === "left" || f === "right") out[f] = { label: "", items: ["", ""] }; else out[f] = ""; } return out; } export function WordMeter({ t, copy }: { t: StudioType; copy: Copy }) { const [lo, hi] = t.words; if (t.per_slide) { const slides = (copy.slides as { title?: string; text?: string }[] | undefined) ?? []; return (
{slides.map((s, i) => { const n = countWords([s.title, s.text]); const tone = n > hi ? "err" : n < lo ? "warn" : "ok"; return ( شريحة {i + 1}: {n}/{hi} ); })}
); } const n = countWords(copy); const tone = n > hi ? "err" : n < lo ? "warn" : "ok"; return ( {n} كلمة · الحد {lo}–{hi} ); } export default function CopyEditor({ t, copy, onChange, dir }: { t: StudioType; copy: Copy; onChange: (c: Copy) => void; dir: "rtl" | "ltr"; }) { const set = (k: string, v: unknown) => onChange({ ...copy, [k]: v }); return (
{t.fields.map((f) => { const v = copy[f]; if (f === "points" || f === "highlights") { const list = (v as string[]) ?? []; return ( set(f, [...list, ""])}> {list.map((x, i) => ( 1 ? () => set(f, list.filter((_, j) => j !== i)) : undefined}> set(f, list.map((y, j) => (j === i ? e.target.value : y)))} /> ))} ); } if (ITEM_LISTS.has(f)) { const list = (v as { title: string; text: string; figure?: string }[]) ?? []; const blank = f === "sections" ? { title: "", text: "", figure: "" } : { title: "", text: "" }; return ( set(f, [...list, blank])}> {list.map((x, i) => { const upd = (patch: object) => set(f, list.map((y, j) => (j === i ? { ...y, ...patch } : y))); return ( 1 ? () => set(f, list.filter((_, j) => j !== i)) : undefined}>
upd({ title: e.target.value })} /> {f === "sections" && ( upd({ figure: e.target.value })} /> )}